| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301 |
- #include "BsGpuParam.h"
- #include "BsGpuParams.h"
- #include "BsGpuParamBlockBuffer.h"
- #include "BsGpuParamDesc.h"
- #include "BsDebug.h"
- #include "BsException.h"
- namespace BansheeEngine
- {
- template<class T, bool Core>
- TGpuDataParam<T, Core>::TGpuDataParam()
- :mParamDesc(nullptr)
- { }
- template<class T, bool Core>
- TGpuDataParam<T, Core>::TGpuDataParam(GpuParamDataDesc* paramDesc, const GpuParamsType& parent)
- :mParamDesc(paramDesc), mParent(parent)
- { }
- template<class T, bool Core>
- void TGpuDataParam<T, Core>::set(const T& value, UINT32 arrayIdx)
- {
- if (mParent == nullptr)
- return;
- GpuParamBufferType paramBlock = mParent->getParamBlockBuffer(mParamDesc->paramBlockSlot);
- if (paramBlock == nullptr)
- return;
- #if BS_DEBUG_MODE
- if (arrayIdx >= mParamDesc->arraySize)
- {
- BS_EXCEPT(InvalidParametersException, "Array index out of range. Array size: " +
- toString(mParamDesc->arraySize) + ". Requested size: " + toString(arrayIdx));
- }
- #endif
- UINT32 elementSizeBytes = mParamDesc->elementSize * sizeof(UINT32);
- UINT32 sizeBytes = std::min(elementSizeBytes, (UINT32)sizeof(T)); // Truncate if it doesn't fit within parameter size
- if (TransposePolicy<T>::transposeEnabled(mParent->getTransposeMatrices()))
- {
- T transposed = TransposePolicy<T>::transpose(value);
- paramBlock->write((mParamDesc->cpuMemOffset + arrayIdx * mParamDesc->arrayElementStride) * sizeof(UINT32), &transposed, sizeBytes);
- }
- else
- paramBlock->write((mParamDesc->cpuMemOffset + arrayIdx * mParamDesc->arrayElementStride) * sizeof(UINT32), &value, sizeBytes);
- // Set unused bytes to 0
- if (sizeBytes < elementSizeBytes)
- {
- UINT32 diffSize = elementSizeBytes - sizeBytes;
- paramBlock->zeroOut((mParamDesc->cpuMemOffset + arrayIdx * mParamDesc->arrayElementStride) * sizeof(UINT32) + sizeBytes, diffSize);
- }
- mParent->_markCoreDirty();
- }
- template<class T, bool Core>
- T TGpuDataParam<T, Core>::get(UINT32 arrayIdx)
- {
- if (mParent == nullptr)
- return T();
- GpuParamBufferType paramBlock = mParent->getParamBlockBuffer(mParamDesc->paramBlockSlot);
- if (paramBlock == nullptr)
- return T();
- #if BS_DEBUG_MODE
- if (arrayIdx >= mParamDesc->arraySize)
- {
- BS_EXCEPT(InvalidParametersException, "Array index out of range. Array size: " +
- toString(mParamDesc->arraySize) + ". Requested size: " + toString(arrayIdx));
- }
- #endif
- UINT32 elementSizeBytes = mParamDesc->elementSize * sizeof(UINT32);
- UINT32 sizeBytes = std::min(elementSizeBytes, (UINT32)sizeof(T));
- T value;
- paramBlock->read((mParamDesc->cpuMemOffset + arrayIdx * mParamDesc->arrayElementStride) * sizeof(UINT32), &value, sizeBytes);
- if (TransposePolicy<T>::transposeEnabled(mParent->getTransposeMatrices()))
- return TransposePolicy<T>::transpose(value);
- else
- return value;
- }
- template<bool Core>
- TGpuParamStruct<Core>::TGpuParamStruct()
- :mParamDesc(nullptr)
- { }
- template<bool Core>
- TGpuParamStruct<Core>::TGpuParamStruct(GpuParamDataDesc* paramDesc, const GpuParamsType& parent)
- :mParamDesc(paramDesc), mParent(parent)
- { }
- template<bool Core>
- void TGpuParamStruct<Core>::set(const void* value, UINT32 sizeBytes, UINT32 arrayIdx)
- {
- if (mParent == nullptr)
- return;
- GpuParamBufferType paramBlock = mParent->getParamBlockBuffer(mParamDesc->paramBlockSlot);
- if (paramBlock == nullptr)
- return;
- UINT32 elementSizeBytes = mParamDesc->elementSize * sizeof(UINT32);
- #if BS_DEBUG_MODE
- if (sizeBytes > elementSizeBytes)
- {
- LOGWRN("Provided element size larger than maximum element size. Maximum size: " +
- toString(elementSizeBytes) + ". Supplied size: " + toString(sizeBytes));
- }
- if (arrayIdx >= mParamDesc->arraySize)
- {
- BS_EXCEPT(InvalidParametersException, "Array index out of range. Array size: " +
- toString(mParamDesc->arraySize) + ". Requested size: " + toString(arrayIdx));
- }
- #endif
- sizeBytes = std::min(elementSizeBytes, sizeBytes);
- paramBlock->write((mParamDesc->cpuMemOffset + arrayIdx * mParamDesc->arrayElementStride) * sizeof(UINT32), value, sizeBytes);
- // Set unused bytes to 0
- if (sizeBytes < elementSizeBytes)
- {
- UINT32 diffSize = elementSizeBytes - sizeBytes;
- paramBlock->zeroOut((mParamDesc->cpuMemOffset + arrayIdx * mParamDesc->arrayElementStride) * sizeof(UINT32) + sizeBytes, diffSize);
- }
- mParent->_markCoreDirty();
- }
- template<bool Core>
- void TGpuParamStruct<Core>::get(void* value, UINT32 sizeBytes, UINT32 arrayIdx)
- {
- if (mParent == nullptr)
- return;
- GpuParamBufferType paramBlock = mParent->getParamBlockBuffer(mParamDesc->paramBlockSlot);
- if (paramBlock == nullptr)
- return;
- UINT32 elementSizeBytes = mParamDesc->elementSize * sizeof(UINT32);
- #if BS_DEBUG_MODE
- if (sizeBytes > elementSizeBytes)
- {
- LOGWRN("Provided element size larger than maximum element size. Maximum size: " +
- toString(elementSizeBytes) + ". Supplied size: " + toString(sizeBytes));
- }
- if (arrayIdx >= mParamDesc->arraySize)
- {
- BS_EXCEPT(InvalidParametersException, "Array index out of range. Array size: " +
- toString(mParamDesc->arraySize) + ". Requested size: " + toString(arrayIdx));
- }
- #endif
- sizeBytes = std::min(elementSizeBytes, sizeBytes);
- paramBlock->read((mParamDesc->cpuMemOffset + arrayIdx * mParamDesc->arrayElementStride) * sizeof(UINT32), value, sizeBytes);
- }
- template<bool Core>
- UINT32 TGpuParamStruct<Core>::getElementSize() const
- {
- if (mParent == nullptr)
- return 0;
- return mParamDesc->elementSize * sizeof(UINT32);
- }
- template<bool Core>
- TGpuParamTexture<Core>::TGpuParamTexture()
- :mParamDesc(nullptr)
- { }
- template<bool Core>
- TGpuParamTexture<Core>::TGpuParamTexture(GpuParamObjectDesc* paramDesc, const GpuParamsType& parent)
- :mParamDesc(paramDesc), mParent(parent)
- { }
- template<bool Core>
- void TGpuParamTexture<Core>::set(const TextureType& texture)
- {
- if (mParent == nullptr)
- return;
- mParent->setTexture(mParamDesc->slot, texture);
- mParent->setIsLoadStoreTexture(mParamDesc->slot, false);
- mParent->_markResourcesDirty();
- mParent->_markCoreDirty();
- }
- template<bool Core>
- typename TGpuParamTexture<Core>::TextureType TGpuParamTexture<Core>::get()
- {
- if (mParent == nullptr)
- return TextureType();
- return mParent->getTexture(mParamDesc->slot);
- }
- template<bool Core>
- TGpuParamLoadStoreTexture<Core>::TGpuParamLoadStoreTexture()
- :mParamDesc(nullptr)
- { }
- template<bool Core>
- TGpuParamLoadStoreTexture<Core>::TGpuParamLoadStoreTexture(GpuParamObjectDesc* paramDesc, const GpuParamsType& parent)
- :mParamDesc(paramDesc), mParent(parent)
- { }
- template<bool Core>
- void TGpuParamLoadStoreTexture<Core>::set(const TextureType& texture, const TextureSurface& surface)
- {
- if (mParent == nullptr)
- return;
- mParent->setTexture(mParamDesc->slot, texture);
- mParent->setIsLoadStoreTexture(mParamDesc->slot, true);
- mParent->setLoadStoreSurface(mParamDesc->slot, surface);
- mParent->_markResourcesDirty();
- mParent->_markCoreDirty();
- }
- template<bool Core>
- typename TGpuParamLoadStoreTexture<Core>::TextureType TGpuParamLoadStoreTexture<Core>::get()
- {
- if (mParent == nullptr)
- return TextureType();
- return mParent->getTexture(mParamDesc->slot);
- }
- template<bool Core>
- TGpuParamSampState<Core>::TGpuParamSampState()
- :mParamDesc(nullptr)
- { }
- template<bool Core>
- TGpuParamSampState<Core>::TGpuParamSampState(GpuParamObjectDesc* paramDesc, const GpuParamsType& parent)
- :mParamDesc(paramDesc), mParent(parent)
- { }
- template<bool Core>
- void TGpuParamSampState<Core>::set(const SamplerStateType& samplerState)
- {
- if (mParent == nullptr)
- return;
- mParent->setSamplerState(mParamDesc->slot, samplerState);
- mParent->_markResourcesDirty();
- mParent->_markCoreDirty();
- }
- template<bool Core>
- typename TGpuParamSampState<Core>::SamplerStateType TGpuParamSampState<Core>::get()
- {
- if (mParent == nullptr)
- return SamplerStateType();
- return mParent->getSamplerState(mParamDesc->slot);
- }
- template class TGpuDataParam < float, false > ;
- template class TGpuDataParam < Color, false > ;
- template class TGpuDataParam < Vector2, false > ;
- template class TGpuDataParam < Vector3, false > ;
- template class TGpuDataParam < Vector4, false > ;
- template class TGpuDataParam < Matrix3, false > ;
- template class TGpuDataParam < Matrix4, false > ;
- template class TGpuDataParam < float, true > ;
- template class TGpuDataParam < Color, true > ;
- template class TGpuDataParam < Vector2, true > ;
- template class TGpuDataParam < Vector3, true > ;
- template class TGpuDataParam < Vector4, true > ;
- template class TGpuDataParam < Matrix3, true > ;
- template class TGpuDataParam < Matrix4, true > ;
- template class TGpuParamStruct < false > ;
- template class TGpuParamStruct < true > ;
- template class TGpuParamTexture < false > ;
- template class TGpuParamTexture < true > ;
- template class TGpuParamSampState < false > ;
- template class TGpuParamSampState < true > ;
- template class TGpuParamLoadStoreTexture < false > ;
- template class TGpuParamLoadStoreTexture < true > ;
- }
|