|
@@ -5,6 +5,7 @@
|
|
|
#include "BsGpuParamBlockBuffer.h"
|
|
#include "BsGpuParamBlockBuffer.h"
|
|
|
#include "BsVector2.h"
|
|
#include "BsVector2.h"
|
|
|
#include "BsTexture.h"
|
|
#include "BsTexture.h"
|
|
|
|
|
+#include "BsGpuBuffer.h"
|
|
|
#include "BsSamplerState.h"
|
|
#include "BsSamplerState.h"
|
|
|
#include "BsFrameAlloc.h"
|
|
#include "BsFrameAlloc.h"
|
|
|
#include "BsDebug.h"
|
|
#include "BsDebug.h"
|
|
@@ -15,8 +16,8 @@
|
|
|
namespace BansheeEngine
|
|
namespace BansheeEngine
|
|
|
{
|
|
{
|
|
|
GpuParamsBase::GpuParamsBase(const SPtr<GpuParamDesc>& paramDesc, bool transposeMatrices)
|
|
GpuParamsBase::GpuParamsBase(const SPtr<GpuParamDesc>& paramDesc, bool transposeMatrices)
|
|
|
- : mParamDesc(paramDesc), mNumParamBlocks(0), mNumTextures(0), mNumLoadStoreTextures(0), mNumSamplerStates(0)
|
|
|
|
|
- , mLoadStoreSurfaces(nullptr), mTransposeMatrices(transposeMatrices)
|
|
|
|
|
|
|
+ : mParamDesc(paramDesc), mNumParamBlocks(0), mNumTextures(0), mNumLoadStoreTextures(0), mNumBuffers(0)
|
|
|
|
|
+ , mNumSamplerStates(0), mLoadStoreSurfaces(nullptr), mTransposeMatrices(transposeMatrices)
|
|
|
{
|
|
{
|
|
|
for (auto& paramBlock : mParamDesc->paramBlocks)
|
|
for (auto& paramBlock : mParamDesc->paramBlocks)
|
|
|
{
|
|
{
|
|
@@ -36,6 +37,12 @@ namespace BansheeEngine
|
|
|
mNumLoadStoreTextures = texture.second.slot + 1;
|
|
mNumLoadStoreTextures = texture.second.slot + 1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ for (auto& buffer : mParamDesc->buffers)
|
|
|
|
|
+ {
|
|
|
|
|
+ if ((buffer.second.slot + 1) > mNumBuffers)
|
|
|
|
|
+ mNumBuffers = buffer.second.slot + 1;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
for (auto& sampler : mParamDesc->samplers)
|
|
for (auto& sampler : mParamDesc->samplers)
|
|
|
{
|
|
{
|
|
|
if ((sampler.second.slot + 1) > mNumSamplerStates)
|
|
if ((sampler.second.slot + 1) > mNumSamplerStates)
|
|
@@ -73,6 +80,15 @@ UINT32 GpuParamsBase::getDataParamSize(const String& name) const
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ bool GpuParamsBase::hasBuffer(const String& name) const
|
|
|
|
|
+ {
|
|
|
|
|
+ auto paramIter = mParamDesc->buffers.find(name);
|
|
|
|
|
+ if (paramIter != mParamDesc->buffers.end())
|
|
|
|
|
+ return true;
|
|
|
|
|
+
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
bool GpuParamsBase::hasLoadStoreTexture(const String& name) const
|
|
bool GpuParamsBase::hasLoadStoreTexture(const String& name) const
|
|
|
{
|
|
{
|
|
|
auto paramIter = mParamDesc->loadStoreTextures.find(name);
|
|
auto paramIter = mParamDesc->loadStoreTextures.find(name);
|
|
@@ -134,7 +150,7 @@ UINT32 GpuParamsBase::getDataParamSize(const String& name) const
|
|
|
template<bool Core>
|
|
template<bool Core>
|
|
|
TGpuParams<Core>::TGpuParams(const SPtr<GpuParamDesc>& paramDesc, bool transposeMatrices)
|
|
TGpuParams<Core>::TGpuParams(const SPtr<GpuParamDesc>& paramDesc, bool transposeMatrices)
|
|
|
: GpuParamsBase(paramDesc, transposeMatrices), mParamBlockBuffers(nullptr), mTextures(nullptr)
|
|
: GpuParamsBase(paramDesc, transposeMatrices), mParamBlockBuffers(nullptr), mTextures(nullptr)
|
|
|
- , mLoadStoreTextures(nullptr), mSamplerStates(nullptr)
|
|
|
|
|
|
|
+ , mLoadStoreTextures(nullptr), mBuffers(nullptr), mSamplerStates(nullptr)
|
|
|
{
|
|
{
|
|
|
if (mNumParamBlocks > 0)
|
|
if (mNumParamBlocks > 0)
|
|
|
mParamBlockBuffers = bs_newN<ParamsBufferType>(mNumParamBlocks);
|
|
mParamBlockBuffers = bs_newN<ParamsBufferType>(mNumParamBlocks);
|
|
@@ -145,6 +161,9 @@ UINT32 GpuParamsBase::getDataParamSize(const String& name) const
|
|
|
if (mNumLoadStoreTextures > 0)
|
|
if (mNumLoadStoreTextures > 0)
|
|
|
mLoadStoreTextures = bs_newN<TextureType>(mNumLoadStoreTextures);
|
|
mLoadStoreTextures = bs_newN<TextureType>(mNumLoadStoreTextures);
|
|
|
|
|
|
|
|
|
|
+ if(mNumBuffers > 0)
|
|
|
|
|
+ mBuffers = bs_newN<BufferType>(mNumBuffers);
|
|
|
|
|
+
|
|
|
if (mNumSamplerStates > 0)
|
|
if (mNumSamplerStates > 0)
|
|
|
mSamplerStates = bs_newN<SamplerType>(mNumSamplerStates);
|
|
mSamplerStates = bs_newN<SamplerType>(mNumSamplerStates);
|
|
|
}
|
|
}
|
|
@@ -161,6 +180,9 @@ UINT32 GpuParamsBase::getDataParamSize(const String& name) const
|
|
|
if (mLoadStoreTextures != nullptr)
|
|
if (mLoadStoreTextures != nullptr)
|
|
|
bs_deleteN(mLoadStoreTextures, mNumLoadStoreTextures);
|
|
bs_deleteN(mLoadStoreTextures, mNumLoadStoreTextures);
|
|
|
|
|
|
|
|
|
|
+ if (mBuffers != nullptr)
|
|
|
|
|
+ bs_deleteN(mBuffers, mNumBuffers);
|
|
|
|
|
+
|
|
|
if (mSamplerStates != nullptr)
|
|
if (mSamplerStates != nullptr)
|
|
|
bs_deleteN(mSamplerStates, mNumSamplerStates);
|
|
bs_deleteN(mSamplerStates, mNumSamplerStates);
|
|
|
}
|
|
}
|
|
@@ -252,6 +274,20 @@ UINT32 GpuParamsBase::getDataParamSize(const String& name) const
|
|
|
output = TGpuParamLoadStoreTexture<Core>(&iterFind->second, _getThisPtr());
|
|
output = TGpuParamLoadStoreTexture<Core>(&iterFind->second, _getThisPtr());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ template<bool Core>
|
|
|
|
|
+ void TGpuParams<Core>::getBufferParam(const String& name, TGpuParamBuffer<Core>& output) const
|
|
|
|
|
+ {
|
|
|
|
|
+ auto iterFind = mParamDesc->buffers.find(name);
|
|
|
|
|
+
|
|
|
|
|
+ if (iterFind == mParamDesc->buffers.end())
|
|
|
|
|
+ {
|
|
|
|
|
+ output = TGpuParamBuffer<Core>(nullptr, nullptr);
|
|
|
|
|
+ LOGWRN("Cannot find buffer parameter with the name '" + name + "'");
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ output = TGpuParamBuffer<Core>(&iterFind->second, _getThisPtr());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
template<bool Core>
|
|
template<bool Core>
|
|
|
void TGpuParams<Core>::getSamplerStateParam(const String& name, TGpuParamSampState<Core>& output) const
|
|
void TGpuParams<Core>::getSamplerStateParam(const String& name, TGpuParamSampState<Core>& output) const
|
|
|
{
|
|
{
|
|
@@ -302,6 +338,18 @@ UINT32 GpuParamsBase::getDataParamSize(const String& name) const
|
|
|
return mLoadStoreTextures[slot];
|
|
return mLoadStoreTextures[slot];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ template<bool Core>
|
|
|
|
|
+ typename TGpuParams<Core>::BufferType TGpuParams<Core>::getBuffer(UINT32 slot)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (slot < 0 || slot >= mNumBuffers)
|
|
|
|
|
+ {
|
|
|
|
|
+ BS_EXCEPT(InvalidParametersException, "Index out of range: Valid range: 0 .. " +
|
|
|
|
|
+ toString(mNumBuffers - 1) + ". Requested: " + toString(slot));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return mBuffers[slot];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
template<bool Core>
|
|
template<bool Core>
|
|
|
typename TGpuParams<Core>::SamplerType TGpuParams<Core>::getSamplerState(UINT32 slot)
|
|
typename TGpuParams<Core>::SamplerType TGpuParams<Core>::getSamplerState(UINT32 slot)
|
|
|
{
|
|
{
|
|
@@ -344,6 +392,21 @@ UINT32 GpuParamsBase::getDataParamSize(const String& name) const
|
|
|
_markCoreDirty();
|
|
_markCoreDirty();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ template<bool Core>
|
|
|
|
|
+ void TGpuParams<Core>::setBuffer(UINT32 slot, const BufferType& buffer)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (slot < 0 || slot >= mNumBuffers)
|
|
|
|
|
+ {
|
|
|
|
|
+ BS_EXCEPT(InvalidParametersException, "Index out of range: Valid range: 0 .. " +
|
|
|
|
|
+ toString(mNumBuffers - 1) + ". Requested: " + toString(slot));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ mBuffers[slot] = buffer;
|
|
|
|
|
+
|
|
|
|
|
+ _markResourcesDirty();
|
|
|
|
|
+ _markCoreDirty();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
template<bool Core>
|
|
template<bool Core>
|
|
|
void TGpuParams<Core>::setSamplerState(UINT32 slot, const SamplerType& sampler)
|
|
void TGpuParams<Core>::setSamplerState(UINT32 slot, const SamplerType& sampler)
|
|
|
{
|
|
{
|
|
@@ -428,16 +491,18 @@ UINT32 GpuParamsBase::getDataParamSize(const String& name) const
|
|
|
UINT32 paramBufferSize = mNumParamBlocks * sizeof(SPtr<GpuParamBlockBufferCore>);
|
|
UINT32 paramBufferSize = mNumParamBlocks * sizeof(SPtr<GpuParamBlockBufferCore>);
|
|
|
UINT32 textureArraySize = mNumTextures * sizeof(SPtr<TextureCore>);
|
|
UINT32 textureArraySize = mNumTextures * sizeof(SPtr<TextureCore>);
|
|
|
UINT32 loadStoreTextureArraySize = mNumLoadStoreTextures * sizeof(SPtr<TextureCore>);
|
|
UINT32 loadStoreTextureArraySize = mNumLoadStoreTextures * sizeof(SPtr<TextureCore>);
|
|
|
|
|
+ UINT32 bufferArraySize = mNumBuffers * sizeof(SPtr<GpuBufferCore>);
|
|
|
UINT32 samplerArraySize = mNumSamplerStates * sizeof(SPtr<SamplerStateCore>);
|
|
UINT32 samplerArraySize = mNumSamplerStates * sizeof(SPtr<SamplerStateCore>);
|
|
|
|
|
|
|
|
UINT32 totalSize = loadStoreSurfacesSize + paramBufferSize + textureArraySize + loadStoreTextureArraySize
|
|
UINT32 totalSize = loadStoreSurfacesSize + paramBufferSize + textureArraySize + loadStoreTextureArraySize
|
|
|
- + samplerArraySize;
|
|
|
|
|
|
|
+ + bufferArraySize + samplerArraySize;
|
|
|
|
|
|
|
|
UINT32 textureInfoOffset = 0;
|
|
UINT32 textureInfoOffset = 0;
|
|
|
UINT32 paramBufferOffset = textureInfoOffset + loadStoreSurfacesSize;
|
|
UINT32 paramBufferOffset = textureInfoOffset + loadStoreSurfacesSize;
|
|
|
UINT32 textureArrayOffset = paramBufferOffset + paramBufferSize;
|
|
UINT32 textureArrayOffset = paramBufferOffset + paramBufferSize;
|
|
|
UINT32 loadStoreTextureArrayOffset = textureArrayOffset + textureArraySize;
|
|
UINT32 loadStoreTextureArrayOffset = textureArrayOffset + textureArraySize;
|
|
|
- UINT32 samplerArrayOffset = loadStoreTextureArrayOffset + loadStoreTextureArraySize;
|
|
|
|
|
|
|
+ UINT32 bufferArrayOffset = loadStoreTextureArrayOffset + bufferArraySize;
|
|
|
|
|
+ UINT32 samplerArrayOffset = bufferArrayOffset + loadStoreTextureArraySize;
|
|
|
|
|
|
|
|
assert(data.getBufferSize() == totalSize);
|
|
assert(data.getBufferSize() == totalSize);
|
|
|
|
|
|
|
@@ -447,6 +512,7 @@ UINT32 GpuParamsBase::getDataParamSize(const String& name) const
|
|
|
SPtr<GpuParamBlockBufferCore>* paramBuffers = (SPtr<GpuParamBlockBufferCore>*)(dataPtr + paramBufferOffset);
|
|
SPtr<GpuParamBlockBufferCore>* paramBuffers = (SPtr<GpuParamBlockBufferCore>*)(dataPtr + paramBufferOffset);
|
|
|
SPtr<TextureCore>* textures = (SPtr<TextureCore>*)(dataPtr + textureArrayOffset);
|
|
SPtr<TextureCore>* textures = (SPtr<TextureCore>*)(dataPtr + textureArrayOffset);
|
|
|
SPtr<TextureCore>* loadStoreTextures = (SPtr<TextureCore>*)(dataPtr + loadStoreTextureArrayOffset);
|
|
SPtr<TextureCore>* loadStoreTextures = (SPtr<TextureCore>*)(dataPtr + loadStoreTextureArrayOffset);
|
|
|
|
|
+ SPtr<GpuBufferCore>* buffers = (SPtr<GpuBufferCore>*)(dataPtr + bufferArrayOffset);
|
|
|
SPtr<SamplerStateCore>* samplers = (SPtr<SamplerStateCore>*)(dataPtr + samplerArrayOffset);
|
|
SPtr<SamplerStateCore>* samplers = (SPtr<SamplerStateCore>*)(dataPtr + samplerArrayOffset);
|
|
|
|
|
|
|
|
// Copy & destruct
|
|
// Copy & destruct
|
|
@@ -471,6 +537,12 @@ UINT32 GpuParamsBase::getDataParamSize(const String& name) const
|
|
|
loadStoreTextures[i].~SPtr<TextureCore>();
|
|
loadStoreTextures[i].~SPtr<TextureCore>();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ for (UINT32 i = 0; i < mNumBuffers; i++)
|
|
|
|
|
+ {
|
|
|
|
|
+ mBuffers[i] = buffers[i];
|
|
|
|
|
+ buffers[i].~SPtr<GpuBufferCore>();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
for (UINT32 i = 0; i < mNumSamplerStates; i++)
|
|
for (UINT32 i = 0; i < mNumSamplerStates; i++)
|
|
|
{
|
|
{
|
|
|
mSamplerStates[i] = samplers[i];
|
|
mSamplerStates[i] = samplers[i];
|
|
@@ -541,6 +613,7 @@ UINT32 GpuParamsBase::getDataParamSize(const String& name) const
|
|
|
UINT32 paramBufferSize = mNumParamBlocks * sizeof(SPtr<GpuParamBlockBufferCore>);
|
|
UINT32 paramBufferSize = mNumParamBlocks * sizeof(SPtr<GpuParamBlockBufferCore>);
|
|
|
UINT32 textureArraySize = mNumTextures * sizeof(SPtr<TextureCore>);
|
|
UINT32 textureArraySize = mNumTextures * sizeof(SPtr<TextureCore>);
|
|
|
UINT32 loadStoreTextureArraySize = mNumLoadStoreTextures * sizeof(SPtr<TextureCore>);
|
|
UINT32 loadStoreTextureArraySize = mNumLoadStoreTextures * sizeof(SPtr<TextureCore>);
|
|
|
|
|
+ UINT32 bufferArraySize = mNumBuffers * sizeof(SPtr<GpuBufferCore>);
|
|
|
UINT32 samplerArraySize = mNumSamplerStates * sizeof(SPtr<SamplerStateCore>);
|
|
UINT32 samplerArraySize = mNumSamplerStates * sizeof(SPtr<SamplerStateCore>);
|
|
|
|
|
|
|
|
UINT32 totalSize = loadStoreSurfacesSize + paramBufferSize + textureArraySize + loadStoreTextureArraySize
|
|
UINT32 totalSize = loadStoreSurfacesSize + paramBufferSize + textureArraySize + loadStoreTextureArraySize
|
|
@@ -550,7 +623,8 @@ UINT32 GpuParamsBase::getDataParamSize(const String& name) const
|
|
|
UINT32 paramBufferOffset = textureInfoOffset + loadStoreSurfacesSize;
|
|
UINT32 paramBufferOffset = textureInfoOffset + loadStoreSurfacesSize;
|
|
|
UINT32 textureArrayOffset = paramBufferOffset + paramBufferSize;
|
|
UINT32 textureArrayOffset = paramBufferOffset + paramBufferSize;
|
|
|
UINT32 loadStoreTextureArrayOffset = textureArrayOffset + textureArraySize;
|
|
UINT32 loadStoreTextureArrayOffset = textureArrayOffset + textureArraySize;
|
|
|
- UINT32 samplerArrayOffset = loadStoreTextureArrayOffset + loadStoreTextureArraySize;
|
|
|
|
|
|
|
+ UINT32 bufferArrayOffset = loadStoreTextureArrayOffset + bufferArraySize;
|
|
|
|
|
+ UINT32 samplerArrayOffset = bufferArrayOffset + loadStoreTextureArraySize;
|
|
|
|
|
|
|
|
UINT8* data = allocator->alloc(totalSize);
|
|
UINT8* data = allocator->alloc(totalSize);
|
|
|
|
|
|
|
@@ -558,6 +632,7 @@ UINT32 GpuParamsBase::getDataParamSize(const String& name) const
|
|
|
SPtr<GpuParamBlockBufferCore>* paramBuffers = (SPtr<GpuParamBlockBufferCore>*)(data + paramBufferOffset);
|
|
SPtr<GpuParamBlockBufferCore>* paramBuffers = (SPtr<GpuParamBlockBufferCore>*)(data + paramBufferOffset);
|
|
|
SPtr<TextureCore>* textures = (SPtr<TextureCore>*)(data + textureArrayOffset);
|
|
SPtr<TextureCore>* textures = (SPtr<TextureCore>*)(data + textureArrayOffset);
|
|
|
SPtr<TextureCore>* loadStoreTextures = (SPtr<TextureCore>*)(data + loadStoreTextureArrayOffset);
|
|
SPtr<TextureCore>* loadStoreTextures = (SPtr<TextureCore>*)(data + loadStoreTextureArrayOffset);
|
|
|
|
|
+ SPtr<GpuBufferCore>* buffers = (SPtr<GpuBufferCore>*)(data + bufferArrayOffset);
|
|
|
SPtr<SamplerStateCore>* samplers = (SPtr<SamplerStateCore>*)(data + samplerArrayOffset);
|
|
SPtr<SamplerStateCore>* samplers = (SPtr<SamplerStateCore>*)(data + samplerArrayOffset);
|
|
|
|
|
|
|
|
// Construct & copy
|
|
// Construct & copy
|
|
@@ -592,6 +667,16 @@ UINT32 GpuParamsBase::getDataParamSize(const String& name) const
|
|
|
loadStoreTextures[i] = nullptr;
|
|
loadStoreTextures[i] = nullptr;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ for (UINT32 i = 0; i < mNumBuffers; i++)
|
|
|
|
|
+ {
|
|
|
|
|
+ new (&buffers[i]) SPtr<GpuBufferCore>();
|
|
|
|
|
+
|
|
|
|
|
+ if (mBuffers[i] != nullptr)
|
|
|
|
|
+ buffers[i] = mBuffers[i]->getCore();
|
|
|
|
|
+ else
|
|
|
|
|
+ buffers[i] = nullptr;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
for (UINT32 i = 0; i < mNumSamplerStates; i++)
|
|
for (UINT32 i = 0; i < mNumSamplerStates; i++)
|
|
|
{
|
|
{
|
|
|
new (&samplers[i]) SPtr<SamplerStateCore>();
|
|
new (&samplers[i]) SPtr<SamplerStateCore>();
|