Skip to content

Commit

Permalink
Add unit tests for DiligentGraphics#75 (close DiligentGraphics#76, Di…
Browse files Browse the repository at this point in the history
  • Loading branch information
MikhailGorobets committed Dec 18, 2021
1 parent 074de5c commit 34afc69
Show file tree
Hide file tree
Showing 15 changed files with 608 additions and 11 deletions.
112 changes: 111 additions & 1 deletion RenderStateNotationParser/interface/RenderStateNotationParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ struct PipelineStateNotation
const Char** ppResourceSignatureNames DEFAULT_INITIALIZER(nullptr);

Uint32 ResourceSignaturesNameCount DEFAULT_INITIALIZER(0);

#if DILIGENT_CPP_INTERFACE
bool operator == (const PipelineStateNotation& RHS) const
{
if (!(PSODesc == RHS.PSODesc) || !(Flags == RHS.Flags) || !(ResourceSignaturesNameCount == RHS.ResourceSignaturesNameCount))
return false;

for (Uint32 SignatureID = 0; SignatureID < ResourceSignaturesNameCount; SignatureID++)
if (!SafeStrEqual(ppResourceSignatureNames[SignatureID], RHS.ppResourceSignatureNames[SignatureID]))
return false;

return true;
}
#endif
};
typedef struct PipelineStateNotation PipelineStateNotation;

Expand All @@ -66,20 +80,58 @@ struct GraphicsPipelineNotation DILIGENT_DERIVE(PipelineStateNotation)
const Char* pASName DEFAULT_INITIALIZER(nullptr);

const Char* pMSName DEFAULT_INITIALIZER(nullptr);

#if DILIGENT_CPP_INTERFACE
bool operator == (const GraphicsPipelineNotation& RHS) const
{
if (!(static_cast<const PipelineStateNotation&>(*this) == static_cast<const PipelineStateNotation&>(RHS)))
return false;

return Desc == RHS.Desc &&
SafeStrEqual(pRenderPassName, RHS.pRenderPassName) &&
SafeStrEqual(pVSName, RHS.pVSName) &&
SafeStrEqual(pPSName, RHS.pPSName) &&
SafeStrEqual(pDSName, RHS.pDSName) &&
SafeStrEqual(pHSName, RHS.pHSName) &&
SafeStrEqual(pGSName, RHS.pGSName) &&
SafeStrEqual(pASName, RHS.pASName) &&
SafeStrEqual(pMSName, RHS.pMSName);
}
#endif
};
typedef struct GraphicsPipelineNotation GraphicsPipelineNotation;


struct ComputePipelineNotation DILIGENT_DERIVE(PipelineStateNotation)

const Char* pCSName DEFAULT_INITIALIZER(nullptr);

#if DILIGENT_CPP_INTERFACE
bool operator == (const ComputePipelineNotation& RHS) const
{
if (!(static_cast<const PipelineStateNotation &>(*this) == static_cast<const PipelineStateNotation&>(RHS)))
return false;

return SafeStrEqual(pCSName, RHS.pCSName);
}
#endif
};
typedef struct ComputePipelineNotation ComputePipelineNotation;


struct TilePipelineNotation DILIGENT_DERIVE(PipelineStateNotation)

const Char* pTSName DEFAULT_INITIALIZER(nullptr);

#if DILIGENT_CPP_INTERFACE
bool operator == (const TilePipelineNotation& RHS) const
{
if (!(static_cast<const PipelineStateNotation&>(*this) == static_cast<const PipelineStateNotation&>(RHS)))
return false;

return SafeStrEqual(pTSName, RHS.pTSName);
}
#endif
};
typedef struct TilePipelineNotation TilePipelineNotation;

Expand All @@ -89,6 +141,14 @@ struct RTGeneralShaderGroupNotation
const Char* Name DEFAULT_INITIALIZER(nullptr);

const Char* pShaderName DEFAULT_INITIALIZER(nullptr);

#if DILIGENT_CPP_INTERFACE
bool operator == (const RTGeneralShaderGroupNotation& RHS) const
{
return SafeStrEqual(Name, RHS.Name) &&
SafeStrEqual(pShaderName, RHS.pShaderName);
}
#endif
};
typedef struct RTGeneralShaderGroupNotation RTGeneralShaderGroupNotation;

Expand All @@ -100,6 +160,15 @@ struct RTTriangleHitShaderGroupNotation
const Char* pClosestHitShaderName DEFAULT_INITIALIZER(nullptr);

const Char* pAnyHitShaderName DEFAULT_INITIALIZER(nullptr);

#if DILIGENT_CPP_INTERFACE
bool operator == (const RTTriangleHitShaderGroupNotation& RHS) const
{
return SafeStrEqual(Name, RHS.Name) &&
SafeStrEqual(pClosestHitShaderName, RHS.pClosestHitShaderName) &&
SafeStrEqual(pAnyHitShaderName, RHS.pAnyHitShaderName);
}
#endif
};
typedef struct RTTriangleHitShaderGroupNotation RTTriangleHitShaderGroupNotation;

Expand All @@ -113,13 +182,23 @@ struct RTProceduralHitShaderGroupNotation
const Char* pClosestHitShaderName DEFAULT_INITIALIZER(nullptr);

const Char* pAnyHitShaderName DEFAULT_INITIALIZER(nullptr);

#if DILIGENT_CPP_INTERFACE
bool operator == (const RTProceduralHitShaderGroupNotation& RHS) const
{
return SafeStrEqual(Name, RHS.Name) &&
SafeStrEqual(pIntersectionShaderName, RHS.pIntersectionShaderName) &&
SafeStrEqual(pClosestHitShaderName, RHS.pClosestHitShaderName) &&
SafeStrEqual(pAnyHitShaderName, RHS.pAnyHitShaderName);
}
#endif
};
typedef struct RTProceduralHitShaderGroupNotation RTProceduralHitShaderGroupNotation;


struct RayTracingPipelineNotation DILIGENT_DERIVE(PipelineStateNotation)

RayTracingPipelineDesc Desc;
RayTracingPipelineDesc RayTracingPipeline;

const RTGeneralShaderGroupNotation* pGeneralShaders DEFAULT_INITIALIZER(nullptr);

Expand All @@ -138,6 +217,37 @@ struct RayTracingPipelineNotation DILIGENT_DERIVE(PipelineStateNotation)
Uint32 MaxAttributeSize DEFAULT_INITIALIZER(0);

Uint32 MaxPayloadSize DEFAULT_INITIALIZER(0);

#if DILIGENT_CPP_INTERFACE
bool operator == (const RayTracingPipelineNotation& RHS) const
{
if (!(static_cast<const PipelineStateNotation&>(*this) == static_cast<const PipelineStateNotation&>(RHS)))
return false;

if (!(RayTracingPipeline == RHS.RayTracingPipeline) ||
!(GeneralShaderCount == RHS.GeneralShaderCount) ||
!(TriangleHitShaderCount == RHS.TriangleHitShaderCount) ||
!(ProceduralHitShaderCount == RHS.ProceduralHitShaderCount) ||
!(MaxAttributeSize == RHS.MaxAttributeSize) ||
!(MaxPayloadSize == RHS.MaxPayloadSize) ||
!SafeStrEqual(pShaderRecordName, RHS.pShaderRecordName))
return false;

for (Uint32 GroupID = 0; GroupID < GeneralShaderCount; GroupID++)
if (!(pGeneralShaders[GroupID] == RHS.pGeneralShaders[GroupID]))
return false;

for (Uint32 GroupID = 0; GroupID < TriangleHitShaderCount; GroupID++)
if (!(pTriangleHitShaders[GroupID] == RHS.pTriangleHitShaders[GroupID]))
return false;

for (Uint32 GroupID = 0; GroupID < ProceduralHitShaderCount; GroupID++)
if (!(pProceduralHitShaders[GroupID] == RHS.pProceduralHitShaders[GroupID]))
return false;

return true;
}
#endif
};
typedef struct RayTracingPipelineNotation RayTracingPipelineNotation;

Expand Down
34 changes: 24 additions & 10 deletions RenderStateNotationParser/src/RenderStateNotationParserImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ static void Deserialize(const nlohmann::json& Json, RayTracingPipelineNotation&
Deserialize(Json, static_cast<PipelineStateNotation&>(Type), Allocator);

if (Json.contains("RayTracingPipeline"))
Deserialize(Json["RayTracingPipeline"], Type.Desc, Allocator);
Deserialize(Json["RayTracingPipeline"], Type.RayTracingPipeline, Allocator);

if (Json.contains("pGeneralShaders"))
Deserialize(Json["pGeneralShaders"], Type.pGeneralShaders, Type.GeneralShaderCount, Allocator);
Expand All @@ -153,13 +153,13 @@ static void Deserialize(const nlohmann::json& Json, RayTracingPipelineNotation&
Deserialize(Json["pProceduralHitShaders"], Type.pProceduralHitShaders, Type.ProceduralHitShaderCount, Allocator);

if (Json.contains("pShaderRecordName"))
Deserialize(Json["MaxAttributeSize"], Type.pShaderRecordName, Allocator);
Deserialize(Json["pShaderRecordName"], Type.pShaderRecordName, Allocator);

if (Json.contains("MaxAttributeSize"))
Deserialize(Json["MaxAttributeSize"], Type.MaxAttributeSize, Allocator);

if (Json.contains("MaxPayloadSize"))
Deserialize(Json["MaxAttributeSize"], Type.MaxPayloadSize, Allocator);
Deserialize(Json["MaxPayloadSize"], Type.MaxPayloadSize, Allocator);
}

} // namespace Diligent
Expand Down Expand Up @@ -199,7 +199,20 @@ RenderStateNotationParserImpl::RenderStateNotationParserImpl(IReferenceCounters*
Source.assign(ParserCI.StrData);
}

nlohmann::json Json = nlohmann::json::parse(Source);
nlohmann::json Json;

try
{
Json = nlohmann::json::parse(Source);
}
catch (std::exception& e)
{
LOG_ERROR(e.what());
if (ParserCI.FilePath != nullptr)
LOG_ERROR_AND_THROW("Failed to parse file: '", ParserCI.FilePath, "'.");
else
LOG_ERROR_AND_THROW("Failed to parse string: '", ParserCI.StrData, "'.");
}

for (auto const& Import : Json["Imports"])
{
Expand Down Expand Up @@ -240,7 +253,7 @@ RenderStateNotationParserImpl::RenderStateNotationParserImpl(IReferenceCounters*
m_ResourceSignatures.push_back(ResourceDesc);
}

for (auto const& Pipeline : Json["Pipeleines"])
for (auto const& Pipeline : Json["Pipelines"])
{
auto& PipelineType = Pipeline["PSODesc"]["PipelineType"];

Expand Down Expand Up @@ -298,7 +311,7 @@ RenderStateNotationParserImpl::RenderStateNotationParserImpl(IReferenceCounters*
ParseJSON(CreateInfo);

m_ParseInfo.ResourceSignatureCount = StaticCast<Uint32>(m_ResourceSignatures.size());
m_ParseInfo.ShaderCount = StaticCast<Uint32>(m_ShaderNames.size());
m_ParseInfo.ShaderCount = StaticCast<Uint32>(m_Shaders.size());
m_ParseInfo.RenderPassCount = StaticCast<Uint32>(m_RenderPasses.size());
m_ParseInfo.GraphicsPipelineStateCount = StaticCast<Uint32>(m_GraphicsPipelineStates.size());
m_ParseInfo.ComputePipelineStateCount = StaticCast<Uint32>(m_ComputePipelineStates.size());
Expand Down Expand Up @@ -356,8 +369,8 @@ const ShaderCreateInfo* RenderStateNotationParserImpl::GetShaderByName(const Cha

const RenderPassDesc* RenderStateNotationParserImpl::GetRenderPassByName(const Char* Name) const
{
auto Iter = m_RayTracingPipelineNames.find(Name);
if (Iter != m_RayTracingPipelineNames.end())
auto Iter = m_RenderPassNames.find(Name);
if (Iter != m_RenderPassNames.end())
return &m_RenderPasses[Iter->second];
return nullptr;
}
Expand Down Expand Up @@ -426,9 +439,10 @@ void CreateRenderStateNotationParser(const RenderStateNotationParserCreateInfo&
if (pParser)
pParser->QueryInterface(IID_RenderStateNotationParser, reinterpret_cast<IObject**>(ppParser));
}
catch (std::exception& err)
catch (std::exception& e)
{
LOG_ERROR("Failed to create descriptor parser: ", err.what());
LOG_ERROR(e.what());
LOG_ERROR("Failed to create descriptor parser");
}
}

Expand Down
1 change: 1 addition & 0 deletions Tests/DiligentToolsTest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ PRIVATE
Diligent-TextureLoader
Diligent-Common
Diligent-GraphicsEngine
Diligent-RenderStateNotationParser
LibPng
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"Name": "TestName0",
"Resources": [
{
"Name": "TestName0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"Pipelines": [
{
"PSODesc": {
"Name": "TestName",
"PipelineType": "COMPUTE"
},
"ppResourceSignatures": [
"TestName0"
],
"pCS": "Shader-CS"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"Pipelines": [
{
"GraphicsPipeline": {
"PrimitiveTopology": "TRIANGLE_LIST",
"pRenderPass": "RenderPassTest"
},
"PSODesc": {
"Name": "TestName",
"PipelineType": "GRAPHICS"
},
"Flags": "IGNORE_MISSING_VARIABLES",
"ppResourceSignatures": [
"TestName0",
"TestName1"
],
"pVS": "Shader-VS",
"pPS": "Shader-PS",
"pDS": "Shader-DS",
"pHS": "Shader-HS",
"pGS": "Shader-GS",
"pAS": "Shader-AS",
"pMS": "Shader-MS"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"Pipelines": [
{
"GraphicsPipeline": {
"DepthStencilDesc": {
"DepthEnable": false
},
"RasterizerDesc": {
"FillMode": "SOLID",
"CullMode": "NONE"
},
"NumRenderTargets": 1,
"RTVFormats": {
"0": "RGBA8_UNORM_SRGB"
},
"PrimitiveTopology": "TRIANGLE_LIST"
},
"PSODesc": {
"Name": "Graphics-Pipeline0",
"PipelineType": "GRAPHICS"
},
"ppResourceSignatureNames": [
"TestName0"
],
"pVS": "Shader0-VS",
"pPS": "Shader0-PS"
},
{
"PSODesc": {
"Name": "Compute-Pipeline0",
"PipelineType": "COMPUTE"
},
"ppResourceSignatureNames": [
"TestName0"
],
"pCS": "Shader0-CS"
},
{
"PSODesc": {
"Name": "Tile-Pipeline0",
"PipelineType": "TILE"
},
"ppResourceSignatureNames": [
"TestName0"
],
"pTS": "Shader0-TS"
},
{
"PSODesc": {
"Name": "RayTracing-Pipeline0",
"PipelineType": "RAY_TRACING"
},
"ppResourceSignatureNames": [
"TestName0"
],
"pGeneralShaders": [
{
"Name": "TestName",
"pShaderName": "Shader0-RT"
}
]
}
]
}

0 comments on commit 34afc69

Please sign in to comment.