| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357 |
- //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
- //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
- #include "RenderAPI/BsGpuParam.h"
- #include "RenderAPI/BsGpuParams.h"
- #include "RenderAPI/BsGpuParamBlockBuffer.h"
- #include "RenderAPI/BsGpuParamDesc.h"
- #include "RenderAPI/BsRenderAPI.h"
- #include "Debug/BsDebug.h"
- #include "Error/BsException.h"
- #include "Math/BsVectorNI.h"
- #include "Math/BsVector2I.h"
- namespace bs
- {
- 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)
- :mParent(parent), mParamDesc(paramDesc)
- { }
- template<class T, bool Core>
- void TGpuDataParam<T, Core>::set(const T& value, UINT32 arrayIdx) const
- {
- if (mParent == nullptr)
- return;
- GpuParamBufferType paramBlock = mParent->getParamBlockBuffer(mParamDesc->paramBlockSet, 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
- bool transposeMatrices = ct::RenderAPI::instance().getAPIInfo().isFlagSet(RenderAPIFeatureFlag::ColumnMajorMatrices);
- if (TransposePolicy<T>::transposeEnabled(transposeMatrices))
- {
- auto 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) const
- {
- if (mParent == nullptr)
- return T();
- GpuParamBufferType paramBlock = mParent->getParamBlockBuffer(mParamDesc->paramBlockSet, 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);
- return value;
- }
- template<bool Core>
- TGpuParamStruct<Core>::TGpuParamStruct()
- :mParamDesc(nullptr)
- { }
- template<bool Core>
- TGpuParamStruct<Core>::TGpuParamStruct(GpuParamDataDesc* paramDesc, const GpuParamsType& parent)
- :mParent(parent), mParamDesc(paramDesc)
- { }
- template<bool Core>
- void TGpuParamStruct<Core>::set(const void* value, UINT32 sizeBytes, UINT32 arrayIdx) const
- {
- if (mParent == nullptr)
- return;
- GpuParamBufferType paramBlock = mParent->getParamBlockBuffer(mParamDesc->paramBlockSet, 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) const
- {
- if (mParent == nullptr)
- return;
- GpuParamBufferType paramBlock = mParent->getParamBlockBuffer(mParamDesc->paramBlockSet, 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)
- :mParent(parent), mParamDesc(paramDesc)
- { }
- template<bool Core>
- void TGpuParamTexture<Core>::set(const TextureType& texture, const TextureSurface& surface) const
- {
- if (mParent == nullptr)
- return;
- mParent->setTexture(mParamDesc->set, mParamDesc->slot, texture, surface);
- mParent->_markResourcesDirty();
- mParent->_markCoreDirty();
- }
- template<bool Core>
- typename TGpuParamTexture<Core>::TextureType TGpuParamTexture<Core>::get() const
- {
- if (mParent == nullptr)
- return TextureType();
- return mParent->getTexture(mParamDesc->set, mParamDesc->slot);
- }
- template<bool Core>
- TGpuParamBuffer<Core>::TGpuParamBuffer()
- :mParamDesc(nullptr)
- { }
- template<bool Core>
- TGpuParamBuffer<Core>::TGpuParamBuffer(GpuParamObjectDesc* paramDesc, const GpuParamsType& parent)
- : mParent(parent), mParamDesc(paramDesc)
- { }
- template<bool Core>
- void TGpuParamBuffer<Core>::set(const BufferType& buffer) const
- {
- if (mParent == nullptr)
- return;
- mParent->setBuffer(mParamDesc->set, mParamDesc->slot, buffer);
- mParent->_markResourcesDirty();
- mParent->_markCoreDirty();
- }
- template<bool Core>
- typename TGpuParamBuffer<Core>::BufferType TGpuParamBuffer<Core>::get() const
- {
- if (mParent == nullptr)
- return BufferType();
- return mParent->getBuffer(mParamDesc->set, mParamDesc->slot);
- }
- template<bool Core>
- TGpuParamLoadStoreTexture<Core>::TGpuParamLoadStoreTexture()
- :mParamDesc(nullptr)
- { }
- template<bool Core>
- TGpuParamLoadStoreTexture<Core>::TGpuParamLoadStoreTexture(GpuParamObjectDesc* paramDesc, const GpuParamsType& parent)
- :mParent(parent), mParamDesc(paramDesc)
- { }
- template<bool Core>
- void TGpuParamLoadStoreTexture<Core>::set(const TextureType& texture, const TextureSurface& surface) const
- {
- if (mParent == nullptr)
- return;
- mParent->setLoadStoreTexture(mParamDesc->set, mParamDesc->slot, texture, surface);
- mParent->_markResourcesDirty();
- mParent->_markCoreDirty();
- }
- template<bool Core>
- typename TGpuParamLoadStoreTexture<Core>::TextureType TGpuParamLoadStoreTexture<Core>::get() const
- {
- if (mParent == nullptr)
- return TextureType();
- return mParent->getTexture(mParamDesc->set, mParamDesc->slot);
- }
- template<bool Core>
- TGpuParamSampState<Core>::TGpuParamSampState()
- :mParamDesc(nullptr)
- { }
- template<bool Core>
- TGpuParamSampState<Core>::TGpuParamSampState(GpuParamObjectDesc* paramDesc, const GpuParamsType& parent)
- :mParent(parent), mParamDesc(paramDesc)
- { }
- template<bool Core>
- void TGpuParamSampState<Core>::set(const SamplerStateType& samplerState) const
- {
- if (mParent == nullptr)
- return;
- mParent->setSamplerState(mParamDesc->set, mParamDesc->slot, samplerState);
- mParent->_markResourcesDirty();
- mParent->_markCoreDirty();
- }
- template<bool Core>
- typename TGpuParamSampState<Core>::SamplerStateType TGpuParamSampState<Core>::get() const
- {
- if (mParent == nullptr)
- return SamplerStateType();
- return mParent->getSamplerState(mParamDesc->set, mParamDesc->slot);
- }
- template class TGpuDataParam < float, false > ;
- template class TGpuDataParam < int, false >;
- template class TGpuDataParam < Color, false > ;
- template class TGpuDataParam < Vector2, false > ;
- template class TGpuDataParam < Vector3, false > ;
- template class TGpuDataParam < Vector4, false > ;
- template class TGpuDataParam < Vector2I, false > ;
- template class TGpuDataParam < Vector3I, false > ;
- template class TGpuDataParam < Vector4I, false > ;
- template class TGpuDataParam < Matrix2, false >;
- template class TGpuDataParam < Matrix2x3, false >;
- template class TGpuDataParam < Matrix2x4, false >;
- template class TGpuDataParam < Matrix3, false > ;
- template class TGpuDataParam < Matrix3x2, false > ;
- template class TGpuDataParam < Matrix3x4, false > ;
- template class TGpuDataParam < Matrix4, false > ;
- template class TGpuDataParam < Matrix4x2, false >;
- template class TGpuDataParam < Matrix4x3, false >;
- template class TGpuDataParam < float, true > ;
- template class TGpuDataParam < int, true >;
- template class TGpuDataParam < Color, true > ;
- template class TGpuDataParam < Vector2, true > ;
- template class TGpuDataParam < Vector3, true > ;
- template class TGpuDataParam < Vector4, true > ;
- template class TGpuDataParam < Vector2I, true > ;
- template class TGpuDataParam < Vector3I, true > ;
- template class TGpuDataParam < Vector4I, true > ;
- template class TGpuDataParam < Matrix2, true >;
- template class TGpuDataParam < Matrix2x3, true >;
- template class TGpuDataParam < Matrix2x4, true >;
- template class TGpuDataParam < Matrix3, true > ;
- template class TGpuDataParam < Matrix3x2, true >;
- template class TGpuDataParam < Matrix3x4, true >;
- template class TGpuDataParam < Matrix4, true > ;
- template class TGpuDataParam < Matrix4x2, true >;
- template class TGpuDataParam < Matrix4x3, true >;
- template class TGpuParamStruct < false > ;
- template class TGpuParamStruct < true > ;
- template class TGpuParamTexture < false > ;
- template class TGpuParamTexture < true > ;
- template class TGpuParamBuffer < false >;
- template class TGpuParamBuffer < true >;
- template class TGpuParamSampState < false > ;
- template class TGpuParamSampState < true > ;
- template class TGpuParamLoadStoreTexture < false > ;
- template class TGpuParamLoadStoreTexture < true > ;
- }
|