|
|
@@ -4,14 +4,69 @@
|
|
|
#include "CmBindableGpuParamBlock.h"
|
|
|
#include "CmGpuParamBlockBuffer.h"
|
|
|
#include "CmDebug.h"
|
|
|
+#include "CmFrameAlloc.h"
|
|
|
|
|
|
namespace CamelotFramework
|
|
|
{
|
|
|
- BindableGpuParams::BindableGpuParams(const GpuParamDesc& sourceParamDesc)
|
|
|
- :mOwnsData(true), mParamDesc(sourceParamDesc), mData(nullptr), mNumParamBlocks(0),
|
|
|
+ BindableGpuParams::BindableGpuParams(const GpuParamsPtr& params, FrameAlloc* allocator)
|
|
|
+ :mOwnsData(true), mParamDesc(params->getParamDesc()), mData(nullptr), mNumParamBlocks(0), mAllocator(allocator),
|
|
|
mNumTextures(0), mNumSamplerStates(0),mParamBlocks(nullptr), mParamBlockBuffers(nullptr), mTextures(nullptr), mSamplerStates(nullptr)
|
|
|
{
|
|
|
- // Actual allocation of all data happens in parent GpuParams
|
|
|
+ // Allocate everything in a single block of memory to get rid of extra memory allocations
|
|
|
+ UINT32 paramBlockBufferSize = params->mNumParamBlocks * sizeof(BindableGpuParamBlock*);
|
|
|
+ UINT32 paramBlockBuffersBufferSize = params->mNumParamBlocks * sizeof(GpuParamBlockBufferPtr);
|
|
|
+ UINT32 textureBufferSize = params->mNumTextures * sizeof(HTexture);
|
|
|
+ UINT32 samplerStateBufferSize = params->mNumSamplerStates * sizeof(HSamplerState);
|
|
|
+
|
|
|
+ UINT32 bufferSize = paramBlockBufferSize + paramBlockBuffersBufferSize + textureBufferSize + samplerStateBufferSize;
|
|
|
+ for(UINT32 i = 0; i < params->mNumParamBlocks; i++)
|
|
|
+ {
|
|
|
+ if(params->mParamBlockBuffers[i] != nullptr)
|
|
|
+ bufferSize += sizeof(BindableGpuParamBlock) + params->mParamBlockBuffers[i]->getSize();
|
|
|
+ }
|
|
|
+
|
|
|
+ mData = (UINT8*)allocator->alloc(bufferSize);
|
|
|
+ mNumParamBlocks = params->mNumParamBlocks;
|
|
|
+ mNumTextures = params->mNumTextures;
|
|
|
+ mNumSamplerStates = params->mNumSamplerStates;
|
|
|
+
|
|
|
+ UINT8* dataIter = mData;
|
|
|
+ mParamBlocks = (BindableGpuParamBlock**)dataIter;
|
|
|
+ dataIter += paramBlockBufferSize;
|
|
|
+
|
|
|
+ mParamBlockBuffers = (GpuParamBlockBufferPtr*)dataIter;
|
|
|
+ dataIter += paramBlockBuffersBufferSize;
|
|
|
+
|
|
|
+ mTextures = (HTexture*)dataIter;
|
|
|
+ dataIter += textureBufferSize;
|
|
|
+
|
|
|
+ mSamplerStates = (HSamplerState*)dataIter;
|
|
|
+ dataIter += samplerStateBufferSize;
|
|
|
+
|
|
|
+ // Copy data
|
|
|
+ memcpy(mParamBlockBuffers, params->mParamBlockBuffers, paramBlockBuffersBufferSize);
|
|
|
+ memcpy(mTextures, params->mTextures, textureBufferSize);
|
|
|
+ memcpy(mSamplerStates, params->mSamplerStates, samplerStateBufferSize);
|
|
|
+
|
|
|
+ for(UINT32 i = 0; i < params->mNumParamBlocks; i++)
|
|
|
+ {
|
|
|
+ if(params->mParamBlockBuffers[i] != nullptr)
|
|
|
+ {
|
|
|
+ GpuParamBlock* paramBlock = params->mParamBlockBuffers[i]->getParamBlock();
|
|
|
+
|
|
|
+ UINT32 bufferSize = paramBlock->getSize();
|
|
|
+ mParamBlocks[i] = (BindableGpuParamBlock*)dataIter;
|
|
|
+
|
|
|
+ dataIter += sizeof(BindableGpuParamBlock);
|
|
|
+ mParamBlocks[i]->mData = dataIter;
|
|
|
+
|
|
|
+ dataIter += bufferSize;
|
|
|
+ memcpy(mParamBlocks[i]->mData, paramBlock->getData(), bufferSize);
|
|
|
+
|
|
|
+ mParamBlocks[i]->mSize = bufferSize;
|
|
|
+ mParamBlocks[i]->mDirty = paramBlock->isDirty();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
BindableGpuParams::BindableGpuParams(const BindableGpuParams& source)
|
|
|
@@ -20,6 +75,7 @@ namespace CamelotFramework
|
|
|
mOwnsData = true;
|
|
|
source.mOwnsData = false;
|
|
|
|
|
|
+ mAllocator = source.mAllocator;
|
|
|
mData = source.mData;
|
|
|
mNumParamBlocks = source.mNumParamBlocks;
|
|
|
mNumTextures = source.mNumTextures;
|
|
|
@@ -35,13 +91,10 @@ namespace CamelotFramework
|
|
|
{
|
|
|
if(mOwnsData && mData != nullptr)
|
|
|
{
|
|
|
- cm_free(mData);
|
|
|
- // TODO - Dealloc using stack
|
|
|
+ mAllocator->dealloc(mData);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // TODO - Forbid copying but allow move semantics
|
|
|
-
|
|
|
GpuParamBlockBufferPtr BindableGpuParams::getParamBlockBuffer(UINT32 slot) const
|
|
|
{
|
|
|
if(slot < 0 || slot >= mNumParamBlocks)
|