Skip to content

Commit

Permalink
Disable line strip on OpenGL
Browse files Browse the repository at this point in the history
On WebGL/MacOS the presence of restart index in the buffer causes
disastrous performance degradation
  • Loading branch information
TheMostDiligent committed Nov 9, 2024
1 parent 1202903 commit b92984e
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Hydrogent/interface/HnMesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ class HnMesh final : public pxr::HdMesh
Uint32 NumIndices = 0;
};

void UpdateIndexData(StagingIndexData& StagingInds, const pxr::VtValue& Points);
void UpdateIndexData(StagingIndexData& StagingInds, const pxr::VtValue& Points, bool UseStripTopology);

void UpdateTopology(pxr::HdSceneDelegate& SceneDelegate,
pxr::HdRenderParam* RenderParam,
Expand Down
2 changes: 2 additions & 0 deletions Hydrogent/interface/HnRenderDelegate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,8 @@ class HnRenderDelegate final : public pxr::HdRenderDelegate

HnMaterial* GetFallbackMaterial() const { return m_FallbackMaterial; }

bool AllowPrimitiveRestart() const;

private:
static const pxr::TfTokenVector SupportedRPrimTypes;
static const pxr::TfTokenVector SupportedSPrimTypes;
Expand Down
2 changes: 1 addition & 1 deletion Hydrogent/interface/HnRenderPass.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ class HnRenderPass final : public pxr::HdRenderPass

void RenderPendingDrawItems(RenderState& State);

GraphicsPipelineDesc GetGraphicsDesc(const HnRenderPassState& RPState) const;
GraphicsPipelineDesc GetGraphicsDesc(const HnRenderPassState& RPState, bool UseStripTopology) const;

private:
HnRenderPassParams m_Params;
Expand Down
8 changes: 4 additions & 4 deletions Hydrogent/src/HnMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ void HnMesh::UpdateRepr(pxr::HdSceneDelegate& SceneDelegate,
if (IndexDataDirty && m_VertexHandle)
{
StagingIndexData StagingInds;
UpdateIndexData(StagingInds, StagingVerts.Points);
UpdateIndexData(StagingInds, StagingVerts.Points, RenderDelegate->AllowPrimitiveRestart());

HnGeometryPool& GeometryPool = RenderDelegate->GetGeometryPool();

Expand Down Expand Up @@ -1064,7 +1064,7 @@ void HnMesh::GenerateSmoothNormals(HnRenderDelegate& RenderDelegate, StagingVert
AddStagingBufferSourceForPrimvar(&RenderDelegate, StagingVerts, pxr::HdTokens->normals, pxr::VtValue::Take(Normals), pxr::HdInterpolationVertex);
}

void HnMesh::UpdateIndexData(StagingIndexData& StagingInds, const pxr::VtValue& Points)
void HnMesh::UpdateIndexData(StagingIndexData& StagingInds, const pxr::VtValue& Points, bool UseStripTopology)
{
HnMeshUtils MeshUtils{m_Topology, GetId()};
pxr::VtIntArray SubsetStart;
Expand All @@ -1085,7 +1085,7 @@ void HnMesh::UpdateIndexData(StagingIndexData& StagingInds, const pxr::VtValue&
m_IndexData.Subsets.clear();
}

StagingInds.EdgeIndices = MeshUtils.ComputeEdgeIndices(!m_HasFaceVaryingPrimvars, true);
StagingInds.EdgeIndices = MeshUtils.ComputeEdgeIndices(!m_HasFaceVaryingPrimvars, UseStripTopology);
StagingInds.PointIndices = MeshUtils.ComputePointIndices(m_HasFaceVaryingPrimvars);
}

Expand Down Expand Up @@ -1154,7 +1154,7 @@ void HnMesh::UpdateDrawItemGpuTopology(HnRenderDelegate& RenderDelegate)
DrawItem.SetFaces({});
}

// Render edgesand points for the entire mesh at once
// Render edges and points for the entire mesh at once
DrawItem.SetEdges({
m_IndexData.Edges->GetBuffer(),
m_IndexData.Edges->GetStartIndex(),
Expand Down
7 changes: 7 additions & 0 deletions Hydrogent/src/HnRenderDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,13 @@ IShaderResourceBinding* HnRenderDelegate::GetShadowPassFrameAttribsSRB(Uint32 Li
return m_ShadowPassFrameAttribs.SRB;
}

bool HnRenderDelegate::AllowPrimitiveRestart() const
{
// WebGL supports primitive restart index, however on MacOS the presence of the restart index
// in the buffer causes disastrous performance degradation. So we disable it on OpenGL.
return !m_pDevice->GetDeviceInfo().IsGLDevice();
}

} // namespace USD

} // namespace Diligent
6 changes: 3 additions & 3 deletions Hydrogent/src/HnRenderPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ struct HnRenderPass::RenderState
{
if (!PsoCache)
{
GraphicsPipelineDesc GraphicsDesc = RenderPass.GetGraphicsDesc(RPState);
GraphicsPipelineDesc GraphicsDesc = RenderPass.GetGraphicsDesc(RPState, RenderDelegate.AllowPrimitiveRestart());

PsoCache = USDRenderer.GetPsoCacheAccessor(GraphicsDesc);
VERIFY_EXPR(PsoCache);
Expand All @@ -220,7 +220,7 @@ struct HnRenderPass::RenderState
USD_Renderer::PsoCacheAccessor PsoCache;
};

GraphicsPipelineDesc HnRenderPass::GetGraphicsDesc(const HnRenderPassState& RPState) const
GraphicsPipelineDesc HnRenderPass::GetGraphicsDesc(const HnRenderPassState& RPState, bool UseStripTopology) const
{
GraphicsPipelineDesc GraphicsDesc = RPState.GetGraphicsPipelineDesc();
if ((m_Params.UsdPsoFlags & USD_Renderer::USD_PSO_FLAG_ENABLE_ALL_OUTPUTS) == 0)
Expand All @@ -237,7 +237,7 @@ GraphicsPipelineDesc HnRenderPass::GetGraphicsDesc(const HnRenderPassState& RPSt
break;

case HN_RENDER_MODE_MESH_EDGES:
GraphicsDesc.PrimitiveTopology = PRIMITIVE_TOPOLOGY_LINE_STRIP;
GraphicsDesc.PrimitiveTopology = UseStripTopology ? PRIMITIVE_TOPOLOGY_LINE_STRIP : PRIMITIVE_TOPOLOGY_LINE_LIST;
break;

case HN_RENDER_MODE_POINTS:
Expand Down

0 comments on commit b92984e

Please sign in to comment.