Skip to content

Commit

Permalink
Render state notation: updated enum testing + some changes
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMostDiligent committed Dec 9, 2021
1 parent bf4d323 commit f6cc086
Show file tree
Hide file tree
Showing 12 changed files with 162 additions and 185 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{ "InputIndex": 1, "NumComponents": 4 }
]
},
"SampleMask": 0,
"SampleMask": 1245678,
"PrimitiveTopology": "POINT_LIST",
"NumRenderTargets": 2,
"NumViewports": 2,
Expand Down
20 changes: 12 additions & 8 deletions Tests/DiligentToolsTest/include/DRSNLoader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
* of the possibility of such damages.
*/

#include <type_traits>

#include "json.hpp"
#include "BasicMath.hpp"
#include "DynamicLinearAllocator.hpp"
Expand Down Expand Up @@ -67,13 +69,14 @@ inline nlohmann::json LoadDRSNFromFile(const Char* FilePath)
}
}

template <typename Type, typename Counter>
bool TestEnum(DynamicLinearAllocator& Allocator, Type ValueBegin, Type ValueEnd)
template <typename Type>
bool TestEnum(DynamicLinearAllocator& Allocator, Type FirstValue, Type LastValue)
{
for (Counter i = static_cast<Counter>(ValueBegin); i < static_cast<Counter>(ValueEnd) + 1; i++)
using UnderlyingType = typename std::underlying_type<Type>::type;
for (auto i = static_cast<UnderlyingType>(FirstValue); i <= static_cast<UnderlyingType>(LastValue); ++i)
{
nlohmann::json Json;
Type EnumReference = static_cast<Type>(i);
const auto EnumReference = static_cast<Type>(i);
Serialize(Json, EnumReference, Allocator);

Type Enum = {};
Expand All @@ -84,13 +87,14 @@ bool TestEnum(DynamicLinearAllocator& Allocator, Type ValueBegin, Type ValueEnd)
return true;
}

template <typename Type, typename Counter>
bool TestBitwiseEnum(DynamicLinearAllocator& Allocator, Type Value)
template <typename Type>
bool TestBitwiseEnum(DynamicLinearAllocator& Allocator, Type MaxBit)
{
for (Counter Bits = static_cast<Type>(Value | (Value - 1u)); Bits != 0;)
VERIFY_EXPR(IsPowerOfTwo(MaxBit));
for (auto Bits = static_cast<Type>(MaxBit | (MaxBit - 1)); Bits != 0;)
{
nlohmann::json Json;
Type EnumReference = static_cast<Type>(ExtractLSB(Bits));
const auto EnumReference = ExtractLSB(Bits);
SerializeBitwiseEnum(Json, EnumReference, Allocator);

Type Enum = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ TEST(Tools_RenderStateNotationParser, ParseBlendStateEnums)
{
DynamicLinearAllocator Allocator{DefaultRawMemoryAllocator::GetAllocator()};

ASSERT_TRUE((TestEnum<BLEND_FACTOR, Int8>(Allocator, BLEND_FACTOR_UNDEFINED, BLEND_FACTOR_NUM_FACTORS)));
ASSERT_TRUE(TestEnum<BLEND_FACTOR>(Allocator, BLEND_FACTOR_UNDEFINED, BLEND_FACTOR_NUM_FACTORS));

ASSERT_TRUE((TestEnum<BLEND_OPERATION, Int8>(Allocator, BLEND_OPERATION_UNDEFINED, BLEND_OPERATION_NUM_OPERATIONS)));
ASSERT_TRUE(TestEnum<BLEND_OPERATION>(Allocator, BLEND_OPERATION_UNDEFINED, BLEND_OPERATION_NUM_OPERATIONS));

ASSERT_TRUE((TestEnum<LOGIC_OPERATION, Int8>(Allocator, LOGIC_OP_CLEAR, LOGIC_OP_NUM_OPERATIONS)));
ASSERT_TRUE(TestEnum<LOGIC_OPERATION>(Allocator, LOGIC_OP_CLEAR, LOGIC_OP_NUM_OPERATIONS));

ASSERT_TRUE((TestBitwiseEnum<COLOR_MASK, Uint32>(Allocator, COLOR_MASK_ALL)));
ASSERT_TRUE(TestBitwiseEnum<COLOR_MASK>(Allocator, COLOR_MASK_ALPHA));
}

TEST(Tools_RenderStateNotationParser, ParseRenderTargetBlendDesc)
Expand All @@ -51,11 +51,11 @@ TEST(Tools_RenderStateNotationParser, ParseRenderTargetBlendDesc)

nlohmann::json JsonReference = LoadDRSNFromFile("RenderStates/BlendState/RenderTargetBlendDesc.json");

RenderTargetBlendDesc DescReference = {};
DescReference.DestBlend = BLEND_FACTOR_INV_DEST_ALPHA;
DescReference.LogicOp = LOGIC_OP_AND_REVERSE;
RenderTargetBlendDesc DescReference{};
DescReference.DestBlend = BLEND_FACTOR_INV_DEST_ALPHA;
DescReference.LogicOp = LOGIC_OP_AND_REVERSE;

RenderTargetBlendDesc Desc = {};
RenderTargetBlendDesc Desc{};
Deserialize(JsonReference, Desc, Allocator);
ASSERT_EQ(Desc, DescReference);
}
Expand All @@ -66,7 +66,7 @@ TEST(Tools_RenderStateNotationParser, ParseBlendStateDesc)

nlohmann::json JsonReference = LoadDRSNFromFile("RenderStates/BlendState/BlendStateDesc.json");

BlendStateDesc DescReference = {};
BlendStateDesc DescReference{};
DescReference.AlphaToCoverageEnable = true;
DescReference.IndependentBlendEnable = true;
DescReference.RenderTargets[0].DestBlend = BLEND_FACTOR_INV_DEST_ALPHA;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ TEST(Tools_RenderStateNotationParser, ParseDepthStencilStateEnums)
{
DynamicLinearAllocator Allocator{DefaultRawMemoryAllocator::GetAllocator()};

ASSERT_TRUE((TestEnum<STENCIL_OP, Int8>(Allocator, STENCIL_OP_UNDEFINED, STENCIL_OP_NUM_OPS)));
ASSERT_TRUE(TestEnum<STENCIL_OP>(Allocator, STENCIL_OP_UNDEFINED, STENCIL_OP_NUM_OPS));
}

TEST(Tools_RenderStateNotationParser, ParserStencilOpDesc)
Expand Down

0 comments on commit f6cc086

Please sign in to comment.