|
|
@@ -2,6 +2,8 @@
|
|
|
#include "BsGpuParamDesc.h"
|
|
|
#include "BsGpuParamBlockBuffer.h"
|
|
|
#include "BsVector2.h"
|
|
|
+#include "BsTexture.h"
|
|
|
+#include "BsSamplerState.h"
|
|
|
#include "BsFrameAlloc.h"
|
|
|
#include "BsDebug.h"
|
|
|
#include "BsException.h"
|
|
|
@@ -149,6 +151,52 @@ UINT32 GpuParamsBase::getDataParamSize(const String& name) const
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ void GpuParamsCore::syncToCore(const CoreSyncData& data)
|
|
|
+ {
|
|
|
+ UINT32 textureInfoSize = mNumTextures * sizeof(BoundTextureInfo);
|
|
|
+ UINT32 paramBufferSize = mNumParamBlocks * sizeof(SPtr<GpuParamBlockBufferCore>);
|
|
|
+ UINT32 textureArraySize = mNumTextures * sizeof(SPtr<TextureCore>);
|
|
|
+ UINT32 samplerArraySize = mNumSamplerStates * sizeof(SPtr<SamplerStateCore>);
|
|
|
+
|
|
|
+ UINT32 totalSize = textureInfoSize + paramBufferSize + textureArraySize + samplerArraySize;
|
|
|
+
|
|
|
+ UINT32 textureInfoOffset = 0;
|
|
|
+ UINT32 paramBufferOffset = textureInfoOffset + textureInfoSize;
|
|
|
+ UINT32 textureArrayOffset = paramBufferOffset + paramBufferSize;
|
|
|
+ UINT32 samplerArrayOffset = textureArrayOffset + textureArraySize;
|
|
|
+
|
|
|
+ assert(data.getBufferSize() == totalSize);
|
|
|
+
|
|
|
+ UINT8* dataPtr = data.getBuffer();
|
|
|
+
|
|
|
+ BoundTextureInfo* textureInfos = (BoundTextureInfo*)(dataPtr + textureInfoOffset);
|
|
|
+ SPtr<GpuParamBlockBufferCore>* paramBuffers = (SPtr<GpuParamBlockBufferCore>*)(dataPtr + paramBufferOffset);
|
|
|
+ SPtr<TextureCore>* textures = (SPtr<TextureCore>*)(dataPtr + textureArrayOffset);
|
|
|
+ SPtr<SamplerStateCore>* samplers = (SPtr<SamplerStateCore>*)(dataPtr + samplerArrayOffset);
|
|
|
+
|
|
|
+ // Copy & destruct
|
|
|
+ for (UINT32 i = 0; i < mNumParamBlocks; i++)
|
|
|
+ {
|
|
|
+ mParamBlockBuffers[i] = paramBuffers[i];
|
|
|
+ paramBuffers[i].~SPtr<GpuParamBlockBufferCore>();
|
|
|
+ }
|
|
|
+
|
|
|
+ for (UINT32 i = 0; i < mNumTextures; i++)
|
|
|
+ {
|
|
|
+ mTextureInfo[i] = textureInfos[i];
|
|
|
+ textureInfos[i].~BoundTextureInfo();
|
|
|
+
|
|
|
+ mTextures[i] = textures[i];
|
|
|
+ textures[i].~SPtr<TextureCore>();
|
|
|
+ }
|
|
|
+
|
|
|
+ for (UINT32 i = 0; i < mNumSamplerStates; i++)
|
|
|
+ {
|
|
|
+ mSamplerStates[i] = samplers[i];
|
|
|
+ samplers[i].~SPtr<SamplerStateCore>();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
SPtr<GpuParamsCore> GpuParamsCore::create(const GpuParamDescPtr& paramDesc, bool transposeMatrices)
|
|
|
{
|
|
|
GpuParamsCore* params = new (bs_alloc<GpuParamsCore>()) GpuParamsCore(paramDesc, transposeMatrices);
|
|
|
@@ -193,4 +241,60 @@ UINT32 GpuParamsBase::getDataParamSize(const String& name) const
|
|
|
|
|
|
return paramsPtr;
|
|
|
}
|
|
|
+
|
|
|
+ CoreSyncData GpuParams::syncToCore(FrameAlloc* allocator)
|
|
|
+ {
|
|
|
+ UINT32 textureInfoSize = mNumTextures * sizeof(BoundTextureInfo);
|
|
|
+ UINT32 paramBufferSize = mNumParamBlocks * sizeof(SPtr<GpuParamBlockBufferCore>);
|
|
|
+ UINT32 textureArraySize = mNumTextures * sizeof(SPtr<TextureCore>);
|
|
|
+ UINT32 samplerArraySize = mNumSamplerStates * sizeof(SPtr<SamplerStateCore>);
|
|
|
+
|
|
|
+ UINT32 totalSize = textureInfoSize + paramBufferSize + textureArraySize + samplerArraySize;
|
|
|
+
|
|
|
+ UINT32 textureInfoOffset = 0;
|
|
|
+ UINT32 paramBufferOffset = textureInfoOffset + textureInfoSize;
|
|
|
+ UINT32 textureArrayOffset = paramBufferOffset + paramBufferSize;
|
|
|
+ UINT32 samplerArrayOffset = textureArrayOffset + textureArraySize;
|
|
|
+
|
|
|
+ UINT8* data = allocator->alloc(totalSize);
|
|
|
+
|
|
|
+ BoundTextureInfo* textureInfos = (BoundTextureInfo*)(data + textureInfoOffset);
|
|
|
+ SPtr<GpuParamBlockBufferCore>* paramBuffers = (SPtr<GpuParamBlockBufferCore>*)(data + paramBufferOffset);
|
|
|
+ SPtr<TextureCore>* textures = (SPtr<TextureCore>*)(data + textureArrayOffset);
|
|
|
+ SPtr<SamplerStateCore>* samplers = (SPtr<SamplerStateCore>*)(data + samplerArrayOffset);
|
|
|
+
|
|
|
+ // Construct & copy
|
|
|
+ for (UINT32 i = 0; i < mNumParamBlocks; i++)
|
|
|
+ {
|
|
|
+ new (¶mBuffers[i]) SPtr<GpuParamBlockBufferCore>();
|
|
|
+
|
|
|
+ if (mParamBlockBuffers[i] != nullptr)
|
|
|
+ paramBuffers[i] = mParamBlockBuffers[i]->getCore();
|
|
|
+ }
|
|
|
+
|
|
|
+ for (UINT32 i = 0; i < mNumTextures; i++)
|
|
|
+ {
|
|
|
+ new (&textureInfos[i]) BoundTextureInfo();
|
|
|
+ textureInfos[i] = mTextureInfo[i];
|
|
|
+
|
|
|
+ new (&textures[i]) SPtr<TextureCore>();
|
|
|
+
|
|
|
+ if (mTextures[i].isLoaded())
|
|
|
+ textures[i] = mTextures[i]->getCore();
|
|
|
+ else
|
|
|
+ textures[i] = nullptr;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (UINT32 i = 0; i < mNumSamplerStates; i++)
|
|
|
+ {
|
|
|
+ new (&samplers[i]) SPtr<SamplerStateCore>();
|
|
|
+
|
|
|
+ if (mSamplerStates[i].isLoaded())
|
|
|
+ samplers[i] = mSamplerStates[i]->getCore();
|
|
|
+ else
|
|
|
+ samplers[i] = nullptr;
|
|
|
+ }
|
|
|
+
|
|
|
+ return CoreSyncData(data, totalSize);
|
|
|
+ }
|
|
|
}
|