Skip to content

Commit

Permalink
Hydrogent: set appropriate PSO flags
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMostDiligent committed Oct 8, 2023
1 parent 53dec6a commit 7d64e31
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Hydrogent/include/HnRendererImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class HnRendererImpl final : public ObjectBase<IHnRenderer>

GPUCompletionAwaitQueue<RefCntAutoPtr<ITexture>> m_MeshIdReadBackQueue;

PBR_Renderer::PSO_FLAGS m_PSOFlags = PBR_Renderer::PSO_FLAG_NONE;
PBR_Renderer::PSO_FLAGS m_DefaultPSOFlags = PBR_Renderer::PSO_FLAG_NONE;

struct MeshRenderInfo
{
Expand Down
63 changes: 32 additions & 31 deletions Hydrogent/src/HnRendererImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,26 +115,11 @@ HnRendererImpl::HnRendererImpl(IReferenceCounters* pRefCounters,
}(CI, pDevice))},
m_MeshIdReadBackQueue{pDevice}
{
m_PSOFlags |=
PBR_Renderer::PSO_FLAG_USE_VERTEX_NORMALS |
PBR_Renderer::PSO_FLAG_USE_TEXCOORD0 |
PBR_Renderer::PSO_FLAG_USE_TEXCOORD1 |
PBR_Renderer::PSO_FLAG_USE_COLOR_MAP |
PBR_Renderer::PSO_FLAG_USE_NORMAL_MAP |
PBR_Renderer::PSO_FLAG_USE_METALLIC_MAP |
PBR_Renderer::PSO_FLAG_USE_ROUGHNESS_MAP;

m_PSOFlags |=
PBR_Renderer::PSO_FLAG_USE_AO_MAP |
PBR_Renderer::PSO_FLAG_USE_EMISSIVE_MAP |
PBR_Renderer::PSO_FLAG_USE_IBL |
PBR_Renderer::PSO_FLAG_ENABLE_DEBUG_VIEW;

if (CI.FrontCCW)
m_PSOFlags |= PBR_Renderer::PSO_FLAG_FRONT_CCW;
m_DefaultPSOFlags |= PBR_Renderer::PSO_FLAG_FRONT_CCW;

if (CI.ConvertOutputToSRGB)
m_PSOFlags |= PBR_Renderer::PSO_FLAG_CONVERT_OUTPUT_TO_SRGB;
m_DefaultPSOFlags |= PBR_Renderer::PSO_FLAG_CONVERT_OUTPUT_TO_SRGB;
}

HnRendererImpl::~HnRendererImpl()
Expand Down Expand Up @@ -299,30 +284,46 @@ void HnRendererImpl::RenderMesh(IDeviceContext* pCtx,
}
}

for (size_t i = 0; i < _countof(pTexCoordVBs); ++i)
{
// Temporary workaround - assign normals VB to texture coordinate VB if the latter is not available.
// Texture coordinates will not be used in the shader anyway, but we need to have valid VB bound.
if (pTexCoordVBs[i] == nullptr)
pTexCoordVBs[i] = pNormalsVB;
}

const auto& ShaderAttribs = Material.GetShaderAttribs();

auto* pIB = (Attribs.RenderMode == HN_RENDER_MODE_MESH_EDGES) ?
Mesh.GetEdgeIndexBuffer() :
Mesh.GetTriangleIndexBuffer();

if (pPosVB == nullptr || pNormalsVB == nullptr || pTexCoordVBs[0] == nullptr || pTexCoordVBs[1] == nullptr || pIB == nullptr || pSRB == nullptr)
if (pPosVB == nullptr || pIB == nullptr || pSRB == nullptr)
return;

IPipelineState* pPSO = nullptr;
if (Attribs.RenderMode == HN_RENDER_MODE_MESH_EDGES)
pPSO = m_USDRenderer->GetWireframePSO({m_PSOFlags, PRIMITIVE_TOPOLOGY_LINE_LIST, /*DoubleSided = */ false}, true);
else if (Attribs.RenderMode == HN_RENDER_MODE_SOLID)
pPSO = m_USDRenderer->GetPbrPSO({m_PSOFlags, AlphaMode, /*DoubleSided = */ false}, true);
if (Attribs.RenderMode == HN_RENDER_MODE_SOLID)
{
auto PSOFlags = m_DefaultPSOFlags;
if (pNormalsVB != nullptr)
PSOFlags |= PBR_Renderer::PSO_FLAG_USE_VERTEX_NORMALS;
if (pTexCoordVBs[0] != nullptr)
PSOFlags |= PBR_Renderer::PSO_FLAG_USE_TEXCOORD0;
if (pTexCoordVBs[1] != nullptr)
PSOFlags |= PBR_Renderer::PSO_FLAG_USE_TEXCOORD1;

PSOFlags |=
PBR_Renderer::PSO_FLAG_USE_COLOR_MAP |
PBR_Renderer::PSO_FLAG_USE_NORMAL_MAP |
PBR_Renderer::PSO_FLAG_USE_METALLIC_MAP |
PBR_Renderer::PSO_FLAG_USE_ROUGHNESS_MAP |
PBR_Renderer::PSO_FLAG_USE_AO_MAP |
PBR_Renderer::PSO_FLAG_USE_EMISSIVE_MAP |
PBR_Renderer::PSO_FLAG_USE_IBL |
PBR_Renderer::PSO_FLAG_ENABLE_DEBUG_VIEW;

pPSO = m_USDRenderer->GetPbrPSO({PSOFlags, AlphaMode, /*DoubleSided = */ false}, true);
}
else if (Attribs.RenderMode == HN_RENDER_MODE_MESH_EDGES)
{
pPSO = m_USDRenderer->GetWireframePSO({m_DefaultPSOFlags, PRIMITIVE_TOPOLOGY_LINE_LIST, /*DoubleSided = */ false}, true);
}
else
pPSO = m_USDRenderer->GetMeshIdPSO({m_PSOFlags, /*DoubleSided = */ false}, true);
{
pPSO = m_USDRenderer->GetMeshIdPSO({m_DefaultPSOFlags, /*DoubleSided = */ false}, true);
}
pCtx->SetPipelineState(pPSO);

// Bind vertex and index buffers
Expand Down

0 comments on commit 7d64e31

Please sign in to comment.