|
|
@@ -1,30 +1,23 @@
|
|
|
#include "BsMaterialParams.h"
|
|
|
+#include "BsProfilerCPU.h"
|
|
|
|
|
|
namespace BansheeEngine
|
|
|
{
|
|
|
__MaterialParams::__MaterialParams(const HShader& shader)
|
|
|
{
|
|
|
- GpuParamDataType dataTypes[] = { GPDT_FLOAT1, GPDT_FLOAT2, GPDT_FLOAT3, GPDT_FLOAT4, GPDT_INT1, GPDT_INT2, GPDT_INT3,
|
|
|
- GPDT_INT4, GPDT_MATRIX_2X2, GPDT_MATRIX_2X3, GPDT_MATRIX_2X4, GPDT_MATRIX_3X3, GPDT_MATRIX_3X2, GPDT_MATRIX_3X4,
|
|
|
- GPDT_MATRIX_4X4, GPDT_MATRIX_4X2, GPDT_MATRIX_4X3, GPDT_COLOR, GPDT_STRUCT };
|
|
|
- UINT32* dataCounts[] = { &mNumFloatParams, &mNumVec2Params, &mNumVec3Params, &mNumVec4Params, &mNumIntParams,
|
|
|
- &mNumVec2IParams, &mNumVec3IParams, &mNumVec4IParams, &mNumMat2Params, &mNumMat2x3Params, &mNumMat2x4Params,
|
|
|
- &mNumMat3Params, &mNumMat3x2Params, &mNumMat3x4Params, &mNumMat4Params, &mNumMat4x2Params, &mNumMat4x3Params,
|
|
|
- &mNumColorParams, &mNumStructParams };
|
|
|
+ gProfilerCPU().beginSample("Create material params");
|
|
|
+
|
|
|
+ UINT32 bufferSize = 0;
|
|
|
|
|
|
auto& dataParams = shader->getDataParams();
|
|
|
for (auto& param : dataParams)
|
|
|
{
|
|
|
- for (UINT32 i = 0; i < sizeof(dataTypes); i++)
|
|
|
- {
|
|
|
- if (param.second.type == dataTypes[i])
|
|
|
- {
|
|
|
- UINT32 count = param.second.arraySize > 1 ? param.second.arraySize : 1;
|
|
|
+ UINT32 arraySize = param.second.arraySize > 1 ? param.second.arraySize : 1;
|
|
|
+ const GpuParamDataTypeInfo& typeInfo = GpuParams::PARAM_SIZES.lookup[(int)param.second.type];
|
|
|
+ UINT32 paramSize = typeInfo.numColumns * typeInfo.numRows * typeInfo.baseTypeSize;
|
|
|
+
|
|
|
+ bufferSize += arraySize * paramSize;
|
|
|
|
|
|
- *dataCounts[i] += count;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
auto& textureParams = shader->getTextureParams();
|
|
|
@@ -33,49 +26,14 @@ namespace BansheeEngine
|
|
|
mNumTextureParams = (UINT32)textureParams.size();
|
|
|
mNumSamplerParams = (UINT32)samplerParams.size();
|
|
|
|
|
|
- mFloatParams = mAlloc.construct<float>(mNumFloatParams);
|
|
|
- mVec2Params = mAlloc.construct<Vector2>(mNumVec2Params);
|
|
|
- mVec3Params = mAlloc.construct<Vector3>(mNumVec3Params);
|
|
|
- mVec4Params = mAlloc.construct<Vector4>(mNumVec4Params);
|
|
|
-
|
|
|
- mIntParams = mAlloc.construct<int>(mNumIntParams);
|
|
|
- mVec2IParams = mAlloc.construct<Vector2I>(mNumVec2IParams);
|
|
|
- mVec3IParams = mAlloc.construct<Vector3I>(mNumVec3IParams);
|
|
|
- mVec4IParams = mAlloc.construct<Vector4I>(mNumVec4IParams);
|
|
|
-
|
|
|
- mMat2Params = mAlloc.construct<Matrix2>(mNumMat2Params);
|
|
|
- mMat2x3Params = mAlloc.construct<Matrix2x3>(mNumMat2x3Params);
|
|
|
- mMat2x4Params = mAlloc.construct<Matrix2x4>(mNumMat2x4Params);
|
|
|
- mMat3Params = mAlloc.construct<Matrix3>(mNumMat3Params);
|
|
|
- mMat3x2Params = mAlloc.construct<Matrix3x2>(mNumMat3x2Params);
|
|
|
- mMat3x4Params = mAlloc.construct<Matrix3x4>(mNumMat3x4Params);
|
|
|
- mMat4Params = mAlloc.construct<Matrix4>(mNumMat4Params);
|
|
|
- mMat4x2Params = mAlloc.construct<Matrix4x2>(mNumMat4x2Params);
|
|
|
- mMat4x3Params = mAlloc.construct<Matrix4x3>(mNumMat4x3Params);
|
|
|
-
|
|
|
- mColorParams = mAlloc.construct<Color>(mNumColorParams);
|
|
|
+ mDataParamsBuffer = mAlloc.alloc(bufferSize);
|
|
|
+ memset(mDataParamsBuffer, 0, bufferSize);
|
|
|
+
|
|
|
mStructParams = mAlloc.construct<StructParamData>(mNumStructParams);
|
|
|
mTextureParams = mAlloc.construct<TextureParamData>(mNumTextureParams);
|
|
|
mSamplerStateParams = mAlloc.construct<SamplerStatePtr>(mNumSamplerParams);
|
|
|
|
|
|
- UINT32 mFloatIdx = 0;
|
|
|
- UINT32 mVec2Idx = 0;
|
|
|
- UINT32 mVec3Idx = 0;
|
|
|
- UINT32 mVec4Idx = 0;
|
|
|
- UINT32 mIntIdx = 0;
|
|
|
- UINT32 mVec2IIdx = 0;
|
|
|
- UINT32 mVec3IIdx = 0;
|
|
|
- UINT32 mVec4IIdx = 0;
|
|
|
- UINT32 mMat2Idx = 0;
|
|
|
- UINT32 mMat2x3Idx = 0;
|
|
|
- UINT32 mMat2x4Idx = 0;
|
|
|
- UINT32 mMat3Idx = 0;
|
|
|
- UINT32 mMat3x2Idx = 0;
|
|
|
- UINT32 mMat3x4Idx = 0;
|
|
|
- UINT32 mMat4Idx = 0;
|
|
|
- UINT32 mMat4x2Idx = 0;
|
|
|
- UINT32 mMat4x3Idx = 0;
|
|
|
- UINT32 mColorIdx = 0;
|
|
|
+ UINT32 mDataBufferIdx = 0;
|
|
|
UINT32 mStructIdx = 0;
|
|
|
UINT32 mTextureIdx = 0;
|
|
|
UINT32 mSamplerIdx = 0;
|
|
|
@@ -88,95 +46,24 @@ namespace BansheeEngine
|
|
|
dataParam.arraySize = arraySize;
|
|
|
dataParam.type = ParamType::Data;
|
|
|
dataParam.dataType = entry.second.type;
|
|
|
- dataParam.index = 0;
|
|
|
+
|
|
|
+ const GpuParamDataTypeInfo& typeInfo = GpuParams::PARAM_SIZES.lookup[(int)dataParam.dataType];
|
|
|
+ UINT32 paramSize = typeInfo.numColumns * typeInfo.numRows * typeInfo.baseTypeSize;
|
|
|
+
|
|
|
+ dataParam.index = mDataBufferIdx;
|
|
|
+ mDataBufferIdx += arraySize * paramSize;
|
|
|
|
|
|
- switch (entry.second.type)
|
|
|
+ if(entry.second.type == GPDT_STRUCT)
|
|
|
{
|
|
|
- case GPDT_FLOAT1:
|
|
|
for (UINT32 i = 0; i < arraySize; i++)
|
|
|
- mFloatParams[mFloatIdx + i] = 0.0f;
|
|
|
-
|
|
|
- dataParam.index = mFloatIdx;
|
|
|
- mFloatIdx += arraySize;
|
|
|
- break;
|
|
|
- case GPDT_FLOAT2:
|
|
|
- dataParam.index = mVec2Idx;
|
|
|
- mVec2Idx += arraySize;
|
|
|
- break;
|
|
|
- case GPDT_FLOAT3:
|
|
|
- dataParam.index = mVec3Idx;
|
|
|
- mVec3Idx += arraySize;
|
|
|
- break;
|
|
|
- case GPDT_FLOAT4:
|
|
|
- dataParam.index = mVec4Idx;
|
|
|
- mVec4Idx += arraySize;
|
|
|
- break;
|
|
|
- case GPDT_INT1:
|
|
|
- dataParam.index = mIntIdx;
|
|
|
- mIntIdx += arraySize;
|
|
|
- break;
|
|
|
- case GPDT_INT2:
|
|
|
- dataParam.index = mVec2IIdx;
|
|
|
- mVec2IIdx += arraySize;
|
|
|
- break;
|
|
|
- case GPDT_INT3:
|
|
|
- dataParam.index = mVec3IIdx;
|
|
|
- mVec3IIdx += arraySize;
|
|
|
- break;
|
|
|
- case GPDT_INT4:
|
|
|
- dataParam.index = mVec4IIdx;
|
|
|
- mVec4IIdx += arraySize;
|
|
|
- break;
|
|
|
- case GPDT_MATRIX_2X2:
|
|
|
- dataParam.index = mMat2Idx;
|
|
|
- mMat2Idx += arraySize;
|
|
|
- break;
|
|
|
- case GPDT_MATRIX_2X3:
|
|
|
- dataParam.index = mMat2x3Idx;
|
|
|
- mMat2x3Idx += arraySize;
|
|
|
- break;
|
|
|
- case GPDT_MATRIX_2X4:
|
|
|
- dataParam.index = mMat2x4Idx;
|
|
|
- mMat2x4Idx += arraySize;
|
|
|
- break;
|
|
|
- case GPDT_MATRIX_3X3:
|
|
|
- dataParam.index = mMat3Idx;
|
|
|
- mMat3Idx += arraySize;
|
|
|
- break;
|
|
|
- case GPDT_MATRIX_3X2:
|
|
|
- dataParam.index = mMat3x2Idx;
|
|
|
- mMat3x2Idx += arraySize;
|
|
|
- break;
|
|
|
- case GPDT_MATRIX_3X4:
|
|
|
- dataParam.index = mMat3x4Idx;
|
|
|
- mMat3x4Idx += arraySize;
|
|
|
- break;
|
|
|
- case GPDT_MATRIX_4X4:
|
|
|
- dataParam.index = mMat4Idx;
|
|
|
- mMat4Idx += arraySize;
|
|
|
- break;
|
|
|
- case GPDT_MATRIX_4X2:
|
|
|
- dataParam.index = mMat4x2Idx;
|
|
|
- mMat4x2Idx += arraySize;
|
|
|
- break;
|
|
|
- case GPDT_MATRIX_4X3:
|
|
|
- dataParam.index = mMat4x3Idx;
|
|
|
- mMat4x3Idx += arraySize;
|
|
|
- break;
|
|
|
- case GPDT_COLOR:
|
|
|
- dataParam.index = mColorIdx;
|
|
|
- mColorIdx += arraySize;
|
|
|
- break;
|
|
|
- case GPDT_STRUCT:
|
|
|
- {
|
|
|
- StructParamData& param = mStructParams[mStructIdx];
|
|
|
- param.dataSize = entry.second.elementSize;
|
|
|
- param.data = mAlloc.alloc(param.dataSize);
|
|
|
+ {
|
|
|
+ StructParamData& param = mStructParams[mStructIdx];
|
|
|
+ param.dataSize = entry.second.elementSize;
|
|
|
+ param.data = mAlloc.alloc(param.dataSize);
|
|
|
|
|
|
- dataParam.index = mStructIdx;
|
|
|
- mStructIdx += arraySize;
|
|
|
- }
|
|
|
- break;
|
|
|
+ dataParam.index = mStructIdx;
|
|
|
+ mStructIdx++;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -206,6 +93,8 @@ namespace BansheeEngine
|
|
|
|
|
|
mSamplerIdx++;
|
|
|
}
|
|
|
+
|
|
|
+ gProfilerCPU().endSample("Create material params");
|
|
|
}
|
|
|
|
|
|
__MaterialParams::~__MaterialParams()
|
|
|
@@ -216,29 +105,7 @@ namespace BansheeEngine
|
|
|
mAlloc.free(mStructParams[i].data);
|
|
|
}
|
|
|
|
|
|
- mAlloc.destruct(mFloatParams, mNumFloatParams);
|
|
|
- mAlloc.destruct(mVec2Params, mNumVec2Params);
|
|
|
- mAlloc.destruct(mVec3Params, mNumVec3Params);
|
|
|
- mAlloc.destruct(mVec4Params, mNumVec4Params);
|
|
|
-
|
|
|
- mAlloc.destruct(mIntParams, mNumIntParams);
|
|
|
- mAlloc.destruct(mVec2IParams, mNumVec2IParams);
|
|
|
- mAlloc.destruct(mVec3IParams, mNumVec3IParams);
|
|
|
- mAlloc.destruct(mVec4IParams, mNumVec4IParams);
|
|
|
-
|
|
|
- mAlloc.destruct(mMat2Params, mNumMat2Params);
|
|
|
- mAlloc.destruct(mMat2x3Params, mNumMat2x3Params);
|
|
|
- mAlloc.destruct(mMat2x4Params, mNumMat2x4Params);
|
|
|
-
|
|
|
- mAlloc.destruct(mMat3Params, mNumMat3Params);
|
|
|
- mAlloc.destruct(mMat3x2Params, mNumMat3x2Params);
|
|
|
- mAlloc.destruct(mMat3x4Params, mNumMat3x4Params);
|
|
|
-
|
|
|
- mAlloc.destruct(mMat4Params, mNumMat4Params);
|
|
|
- mAlloc.destruct(mMat4x2Params, mNumMat4x2Params);
|
|
|
- mAlloc.destruct(mMat4x3Params, mNumMat4x3Params);
|
|
|
-
|
|
|
- mAlloc.destruct(mColorParams, mNumColorParams);
|
|
|
+ mAlloc.free(mDataParamsBuffer);
|
|
|
mAlloc.destruct(mStructParams, mNumStructParams);
|
|
|
mAlloc.destruct(mTextureParams, mNumTextureParams);
|
|
|
mAlloc.destruct(mSamplerStateParams, mNumSamplerParams);
|
|
|
@@ -246,7 +113,7 @@ namespace BansheeEngine
|
|
|
mAlloc.clear();
|
|
|
}
|
|
|
|
|
|
- void __MaterialParams::getStructData(const String& name, void* value, UINT32 size, UINT32 arrayIdx)
|
|
|
+ void __MaterialParams::getStructData(const String& name, void* value, UINT32 size, UINT32 arrayIdx) const
|
|
|
{
|
|
|
const ParamData* param = getParamData(name, ParamType::Data, GPDT_STRUCT, arrayIdx);
|
|
|
if (param == nullptr)
|
|
|
@@ -264,7 +131,7 @@ namespace BansheeEngine
|
|
|
setStructData(param->index + arrayIdx, value, size);
|
|
|
}
|
|
|
|
|
|
- void __MaterialParams::getTexture(const String& name, HTexture& value)
|
|
|
+ void __MaterialParams::getTexture(const String& name, HTexture& value) const
|
|
|
{
|
|
|
const ParamData* param = getParamData(name, ParamType::Texture, GPDT_UNKNOWN, 0);
|
|
|
if (param == nullptr)
|
|
|
@@ -282,7 +149,7 @@ namespace BansheeEngine
|
|
|
setTexture(param->index, value);
|
|
|
}
|
|
|
|
|
|
- void __MaterialParams::getLoadStoreTexture(const String& name, HTexture& value, TextureSurface& surface)
|
|
|
+ void __MaterialParams::getLoadStoreTexture(const String& name, HTexture& value, TextureSurface& surface) const
|
|
|
{
|
|
|
const ParamData* param = getParamData(name, ParamType::Texture, GPDT_UNKNOWN, 0);
|
|
|
if (param == nullptr)
|
|
|
@@ -300,7 +167,7 @@ namespace BansheeEngine
|
|
|
setLoadStoreTexture(param->index, value, surface);
|
|
|
}
|
|
|
|
|
|
- void __MaterialParams::getSamplerState(const String& name, SamplerStatePtr& value)
|
|
|
+ void __MaterialParams::getSamplerState(const String& name, SamplerStatePtr& value) const
|
|
|
{
|
|
|
const ParamData* param = getParamData(name, ParamType::Sampler, GPDT_UNKNOWN, 0);
|
|
|
if (param == nullptr)
|
|
|
@@ -319,7 +186,7 @@ namespace BansheeEngine
|
|
|
}
|
|
|
|
|
|
const __MaterialParams::ParamData* __MaterialParams::getParamData(const String& name, ParamType type, GpuParamDataType dataType,
|
|
|
- UINT32 arrayIdx)
|
|
|
+ UINT32 arrayIdx) const
|
|
|
{
|
|
|
auto iterFind = mParams.find(name);
|
|
|
if (iterFind == mParams.end())
|
|
|
@@ -345,7 +212,7 @@ namespace BansheeEngine
|
|
|
return ¶m;
|
|
|
}
|
|
|
|
|
|
- void __MaterialParams::getStructData(UINT32 index, void* value, UINT32 size)
|
|
|
+ void __MaterialParams::getStructData(UINT32 index, void* value, UINT32 size) const
|
|
|
{
|
|
|
const StructParamData& structParam = mStructParams[index];
|
|
|
if (structParam.dataSize != size)
|
|
|
@@ -371,7 +238,13 @@ namespace BansheeEngine
|
|
|
memcpy(structParam.data, value, structParam.dataSize);
|
|
|
}
|
|
|
|
|
|
- void __MaterialParams::getTexture(UINT32 index, HTexture& value)
|
|
|
+ UINT32 __MaterialParams::getStructSize(UINT32 index) const
|
|
|
+ {
|
|
|
+ const StructParamData& structParam = mStructParams[index];
|
|
|
+ return structParam.dataSize;
|
|
|
+ }
|
|
|
+
|
|
|
+ void __MaterialParams::getTexture(UINT32 index, HTexture& value) const
|
|
|
{
|
|
|
TextureParamData& textureParam = mTextureParams[index];
|
|
|
value = textureParam.value;
|
|
|
@@ -384,7 +257,7 @@ namespace BansheeEngine
|
|
|
textureParam.isLoadStore = false;
|
|
|
}
|
|
|
|
|
|
- void __MaterialParams::getLoadStoreTexture(UINT32 index, HTexture& value, TextureSurface& surface)
|
|
|
+ void __MaterialParams::getLoadStoreTexture(UINT32 index, HTexture& value, TextureSurface& surface) const
|
|
|
{
|
|
|
TextureParamData& textureParam = mTextureParams[index];
|
|
|
value = textureParam.value;
|
|
|
@@ -399,7 +272,7 @@ namespace BansheeEngine
|
|
|
textureParam.surface = surface;
|
|
|
}
|
|
|
|
|
|
- void __MaterialParams::getSamplerState(UINT32 index, SamplerStatePtr& value)
|
|
|
+ void __MaterialParams::getSamplerState(UINT32 index, SamplerStatePtr& value) const
|
|
|
{
|
|
|
value = mSamplerStateParams[index];
|
|
|
}
|