バージョン
menu_open

include/AK/Plugin/PluginServices/PS3/MultiCoreServices.h

説明を見る。
00001 /*******************************************************************************
00002 The content of this file includes portions of the AUDIOKINETIC Wwise Technology
00003 released in source code form as part of the SDK installer package.
00004 
00005 Commercial License Usage
00006 
00007 Licensees holding valid commercial licenses to the AUDIOKINETIC Wwise Technology
00008 may use this file in accordance with the end user license agreement provided 
00009 with the software or, alternatively, in accordance with the terms contained in a
00010 written agreement between you and Audiokinetic Inc.
00011 
00012 Apache License Usage
00013 
00014 Alternatively, this file may be used under the Apache License, Version 2.0 (the 
00015 "Apache License"); you may not use this file except in compliance with the 
00016 Apache License. You may obtain a copy of the Apache License at 
00017 http://www.apache.org/licenses/LICENSE-2.0.
00018 
00019 Unless required by applicable law or agreed to in writing, software distributed
00020 under the Apache License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
00021 OR CONDITIONS OF ANY KIND, either express or implied. See the Apache License for
00022 the specific language governing permissions and limitations under the License.
00023 
00024   Version: <VERSION>  Build: <BUILDNUMBER>
00025   Copyright (c) <COPYRIGHTYEAR> Audiokinetic Inc.
00026 *******************************************************************************/
00027 
00028 #ifndef MULTICORE_SERVICES_H_
00029 #define MULTICORE_SERVICES_H_
00030 
00031 #include <AK/SoundEngine/Common/AkTypes.h>
00032 
00033 #include <stdlib.h>
00034 #include <AK/Tools/Common/AkAssert.h>
00035 #include <string.h>
00036 
00037 #include <cell/spurs/job_chain.h>
00038 #include <cell/spurs/job_descriptor.h>
00039 #include <cell/spurs/job_commands.h>
00040 
00041 #if defined (__SPU__) && defined (_DEBUG)
00042 #include <spu_printf.h>
00043 #endif
00044 
00045 namespace AK
00046 {
00047 namespace MultiCoreServices
00048 {
00050     struct BinData
00051     {
00052         void*       pAddress;   
00053         AkUInt16    Size;       
00054     };
00055 
00056 #ifndef __SPU__
00057 
00058 
00059     static AkNoInline AkInt32 AddSpursJobDma(AkSpursJob& in_SpursJob, void *in_pSource, AkUInt32 uiLength)
00060     {
00061         // this must be __attribute__((aligned(16))) at least
00062         // __attribute__((aligned(128))) is recommended
00063         AKASSERT(((uintptr_t)in_pSource & 0x0000000F) == 0);
00064 
00065         // figure out how much we can take
00066         AkUInt16 MaxSize = sizeof(in_SpursJob.workArea.dmaList);
00067 
00068         // is there any space left ?
00069         if(in_SpursJob.header.sizeDmaList < MaxSize)
00070         {
00071             AkUInt32 NumDmas = 0;
00072             uintptr_t uiPointer = (uintptr_t) in_pSource;
00073             uint64_t uiSize = AK_ALIGN_SIZE_FOR_DMA(uiLength);
00074 
00075             AKASSERT(uiSize == uiLength);
00076 
00077             uint64_t uiSizeLeft = uiSize;
00078 
00079             // break the transfer in 16kB chunks if needed
00080             while(uiSizeLeft > 0)
00081             {
00082                 // still got some space left ?
00083                 if(in_SpursJob.header.sizeDmaList < MaxSize)
00084                 {
00085                     ++NumDmas;
00086 
00087                     // get 16kB at most
00088                     uint64_t uiChunkSize = (uiSizeLeft > 16384) ? 16384 : uiSizeLeft;
00089 
00090                     // build the dma list element
00091                     AkUInt64 DmaListElement = (0 & 1ULL) << 63 | (uiChunkSize & 0xffffULL) << 32 | ((uintptr_t) uiPointer  & 0xffffffffULL);
00092                     in_SpursJob.workArea.dmaList[in_SpursJob.header.sizeDmaList/8] = DmaListElement;
00093                     // update the dma list size
00094                     in_SpursJob.header.sizeDmaList += 8;
00095 
00096                     // keep track of what's goin on
00097                     uiSizeLeft -= uiChunkSize;
00098                     uiPointer += uiChunkSize;
00099                 }
00100                 else
00101                 {
00102                     // the whole transfer could not fit in the dma list
00103                     return -1;
00104                 }
00105             }
00106 
00107             // all is well the transfer fits in the dma list
00108             in_SpursJob.header.sizeInOrInOut += uiSize;
00109             return NumDmas;
00110         }
00111         // dma list is full
00112         return -1;
00113     }
00114 
00117     static AkForceInline void AddSpursJobSmallDma(AkSpursJob& in_SpursJob, const void *in_pSource, AkUInt32 uiLength)
00118     {
00119         // this must be __attribute__((aligned(16))) at least
00120         // __attribute__((aligned(128))) is recommended
00121         AKASSERT(uiLength <= (16*1024));
00122         AKASSERT(((uintptr_t)in_pSource & 0x0000000F) == 0);
00123         AKASSERT(uiLength== AK_ALIGN_SIZE_FOR_DMA(uiLength));
00124         AKASSERT( in_SpursJob.header.sizeDmaList < sizeof(in_SpursJob.workArea.dmaList) );
00125         AKASSERT( uiLength != 0 );
00126 
00127         AkUInt64 DmaListElement = (0 & 1ULL) << 63 | (uiLength & 0xffffULL) << 32 | ((uintptr_t) in_pSource  & 0xffffffffULL);
00128         in_SpursJob.workArea.dmaList[in_SpursJob.header.sizeDmaList/8] = DmaListElement;
00129         in_SpursJob.header.sizeDmaList += 8;
00130         in_SpursJob.header.sizeInOrInOut += uiLength;
00131     }
00132 #endif 
00133 
00134     struct DspProcess
00135     {
00136 #ifndef __SPU__
00137 
00138         inline void ResetDspProcess( 
00139             bool in_bIO     
00140             )
00141         {
00142             memset( &SpursJob, 0, sizeof( SpursJob ) ); // gets inlined into vector stores
00143             // should we use I/O buffers ?
00144             SpursJob.header.useInOutBuffer = in_bIO ? 1 : 0;
00145 #ifdef _DEBUG
00146             SpursJob.header.jobType =  CELL_SPURS_JOB_TYPE_MEMORY_CHECK;
00147 #endif
00148         }
00149 
00151         inline void SetOutputBufferSize( 
00152             AkUInt32 in_uSize   
00153             )
00154         {
00155             AKASSERT( !( in_uSize & 0xf ) ); // 16-byte aligned size
00156 
00157             SpursJob.header.sizeOut = in_uSize;
00158         }
00159 
00161         inline void SetScratchSize(
00162             AkUInt32 in_ScratchBytes    
00163             )
00164         {
00165             // convert to quads
00166             AkUInt16 ScratchSize = (in_ScratchBytes + 15) / 16;
00167             SpursJob.header.sizeScratch = ScratchSize;
00168         }
00169 
00172         inline void SetStackSize(
00173             AkUInt32 in_StackBytes  
00174             )
00175         {
00176             // convert to quads
00177             AkUInt16 StackSize = (in_StackBytes + 15) / 16;
00178             SpursJob.header.sizeStack = StackSize;
00179         }
00180 
00182         inline void SetDspProcess(BinData& in_BinData)
00183         {
00184             // this must be __attribute__((aligned(16)))
00185             AKASSERT(((uintptr_t)in_BinData.pAddress & 0x0000000F) == 0);
00186             // set the executable info
00187             SpursJob.header.eaBinary = (uintptr_t)in_BinData.pAddress;
00188             SpursJob.header.sizeBinary = in_BinData.Size;
00189         }
00190 
00192         inline int SetDspProcess( const void * in_jobbin2 )
00193         {
00194             return cellSpursJobHeaderSetJobbin2Param( &SpursJob.header, in_jobbin2 );
00195         }
00196 
00199         inline AkInt32 AddDspProcessDma(void *in_pSource, AkUInt32 uiLength)
00200         {
00201             return AddSpursJobDma(SpursJob,in_pSource,uiLength);
00202         }
00203 
00206         inline void AddDspProcessSmallDma(const void *in_pSource, AkUInt32 uiLength)
00207         {
00208             AddSpursJobSmallDma(SpursJob,in_pSource,uiLength);
00209         }
00210 
00215         inline void SetUserData( 
00216             AkUInt32 uIdx,      
00217             AkUInt64 uData      
00218             )
00219         {
00220             AKASSERT( uIdx*8 >= SpursJob.header.sizeDmaList );
00221             SpursJob.workArea.userData[ uIdx ] = uData;
00222         }
00223 
00225         inline AkUInt64 GetSpursJobCommand()
00226         {
00227             return CELL_SPURS_JOB_COMMAND_JOB(&SpursJob);
00228         }
00229 #endif
00230 
00231     private:
00232         AkSpursJob      SpursJob AK_ALIGN_FASTDMA;
00233     } AK_ALIGN_FASTDMA;
00234 
00235 #if defined(__SPU__) && defined(_DEBUG)
00236 
00237     AkForceInline void ShowContext(CellSpursJobContext2 *pContext,  CellSpursJob256 *pJob)
00238     {
00239         int NumIoBuffers = pContext->numIoBuffer;
00240         spu_printf("SPU =========> numIoBuffer      = %d\n",NumIoBuffers);
00241 
00242         // Get BufferList
00243         void *pBufferList[NumIoBuffers];
00244         int nGetBufferResult = cellSpursJobGetPointerList(pBufferList, &pJob->header, pContext);
00245 
00246         if ( nGetBufferResult == CELL_OK )
00247         {
00248             for(int Counter = 0 ; Counter < NumIoBuffers ; ++Counter)
00249             {
00250                 spu_printf("SPU =========> pBufferList[%2d] = 0x%8.8X\n",Counter, (unsigned int) pBufferList[Counter]);
00251             }
00252         }
00253         else
00254         {
00255             spu_printf("SPU =========> pBufferList : Error : Can't get buffer list. [%s%s]", nGetBufferResult == CELL_SPURS_JOB_ERROR_ALIGN ? "CELL_SPURS_JOB_ERROR_ALIGN" : "", nGetBufferResult == CELL_SPURS_JOB_ERROR_NULL_POINTER ? "CELL_SPURS_JOB_ERROR_NULL_POINTER" : "");
00256         }
00257         spu_printf("SPU =========> numCacheBuffer   = %d\n",pContext->numCacheBuffer);
00258         spu_printf("SPU =========> oBuffer          = 0x%8.8X\n",(unsigned int) pContext->oBuffer);
00259         spu_printf("SPU =========> sBuffer          = 0x%8.8X\n",(unsigned int) pContext->sBuffer);
00260         spu_printf("SPU =========> dmaTag           = %d\n",pContext->dmaTag);
00261         spu_printf("SPU =========> eaJobDescriptor  = 0x%llX\n",pContext->eaJobDescriptor);
00262     }
00263 
00265     AkForceInline void ShowJob(CellSpursJob256 *pJob)
00266     {
00267         spu_printf("SPU =========> eaBinary         = 0x%8.8X\n",(unsigned int) pJob->header.eaBinary);
00268         spu_printf("SPU =========> sizeBinary       = %d\n",pJob->header.sizeBinary);
00269         spu_printf("SPU =========> sizeDmaList      = %d\n",pJob->header.sizeDmaList);
00270         spu_printf("SPU =========> eaHighInput      = %d\n",pJob->header.eaHighInput);
00271         spu_printf("SPU =========> useInOutBuffer   = %d\n",pJob->header.useInOutBuffer);
00272         spu_printf("SPU =========> sizeInOrInOut    = %d\n",pJob->header.sizeInOrInOut);
00273         spu_printf("SPU =========> sizeOut          = %d\n",pJob->header.sizeOut);
00274         spu_printf("SPU =========> sizeStack        = %d\n",pJob->header.sizeStack);
00275         spu_printf("SPU =========> sizeScratch      = %d\n",pJob->header.sizeScratch);
00276         spu_printf("SPU =========> eaHighCache      = %d\n",pJob->header.eaHighCache);
00277         spu_printf("SPU =========> sizeCacheDmaList = %d\n",pJob->header.sizeCacheDmaList);
00278     //  CellSpursJobID idJob;
00279 
00280         uint64_t* pUserData = (uint64_t*)pJob->workArea.userData;
00281 
00282         for(int Counter = 0 ; Counter < 10 ; ++Counter)
00283         {
00284             uint64_t Data = *pUserData++;
00285             spu_printf("SPU =========> userData[%d]      = 0x%llX\n",Counter,Data);
00286         }
00287     }
00288     
00290     AkForceInline void PrintVectorHex(void* in_pVector)
00291     {
00292         spu_printf("SPU =========> 0x%8.8X 0x%8.8X 0x%8.8X 0x%8.8X\n",  *(unsigned int*)in_pVector,
00293                                                                         *((unsigned int*)in_pVector + 1),
00294                                                                         *((unsigned int*)in_pVector + 2),
00295                                                                         *((unsigned int*)in_pVector + 3));
00296     }
00297 
00299     AkForceInline void PrintVectorFloat(void* in_pVector)
00300     {
00301         spu_printf("SPU =========> %.3f %.3f %.3f %.3f\n",  *(float*)in_pVector,
00302                                                             *((float*)in_pVector + 1),
00303                                                             *((float*)in_pVector + 2),
00304                                                             *((float*)in_pVector + 3));
00305     }
00306 #endif // defined(__SPU__) && defined(_DEBUG)
00307 }
00308 }
00309 
00310 #endif // MULTICORE_SERVICES_H_

このページはお役に立ちましたか?

サポートは必要ですか?

ご質問や問題、ご不明点はございますか?お気軽にお問い合わせください。

サポートページをご確認ください

あなたのプロジェクトについて教えてください。ご不明な点はありませんか。

プロジェクトを登録していただくことで、ご利用開始のサポートをいたします。

Wwiseからはじめよう