Minor improvement: Additional protection with asserts in Allocation::PackedData setters.

This commit is contained in:
Adam Sawicki 2020-03-16 16:40:29 +01:00
parent 38f53e8e4f
commit 33a596f18f
2 changed files with 32 additions and 4 deletions

View File

@ -4514,6 +4514,34 @@ void AllocatorPimpl::WriteBudgetToJson(JsonWriter& json, const Budget& budget)
////////////////////////////////////////////////////////////////////////////////
// Public class Allocation implementation
void Allocation::PackedData::SetType(Type type)
{
const uint32_t u = (UINT)type;
D3D12MA_ASSERT(u < (1u << 2));
m_Type = u;
}
void Allocation::PackedData::SetResourceDimension(D3D12_RESOURCE_DIMENSION resourceDimension)
{
const uint32_t u = (UINT)resourceDimension;
D3D12MA_ASSERT(u < (1u << 3));
m_ResourceDimension = u;
}
void Allocation::PackedData::SetResourceFlags(D3D12_RESOURCE_FLAGS resourceFlags)
{
const uint32_t u = (UINT)resourceFlags;
D3D12MA_ASSERT(u < (1u << 7));
m_ResourceFlags = u;
}
void Allocation::PackedData::SetTextureLayout(D3D12_TEXTURE_LAYOUT textureLayout)
{
const uint32_t u = (UINT)textureLayout;
D3D12MA_ASSERT(u < (1u << 2));
m_TextureLayout = u;
}
void Allocation::Release()
{
if(this == NULL)

View File

@ -561,10 +561,10 @@ private:
D3D12_RESOURCE_FLAGS GetResourceFlags() const { return (D3D12_RESOURCE_FLAGS)m_ResourceFlags; }
D3D12_TEXTURE_LAYOUT GetTextureLayout() const { return (D3D12_TEXTURE_LAYOUT)m_TextureLayout; }
void SetType(Type type) { m_Type = (UINT)type; }
void SetResourceDimension(D3D12_RESOURCE_DIMENSION resourceDimension) { m_ResourceDimension = (UINT)resourceDimension; }
void SetResourceFlags(D3D12_RESOURCE_FLAGS resourceFlags) { m_ResourceFlags = (UINT)resourceFlags; }
void SetTextureLayout(D3D12_TEXTURE_LAYOUT textureLayout) { m_TextureLayout = (UINT)textureLayout; }
void SetType(Type type);
void SetResourceDimension(D3D12_RESOURCE_DIMENSION resourceDimension);
void SetResourceFlags(D3D12_RESOURCE_FLAGS resourceFlags);
void SetTextureLayout(D3D12_TEXTURE_LAYOUT textureLayout);
private:
UINT m_Type : 2; // enum Type