Skip to content

Commit b92984e

Browse files
Disable line strip on OpenGL
On WebGL/MacOS the presence of restart index in the buffer causes disastrous performance degradation
1 parent 1202903 commit b92984e

File tree

6 files changed

+18
-9
lines changed

6 files changed

+18
-9
lines changed

Hydrogent/interface/HnMesh.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ class HnMesh final : public pxr::HdMesh
227227
Uint32 NumIndices = 0;
228228
};
229229

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

232232
void UpdateTopology(pxr::HdSceneDelegate& SceneDelegate,
233233
pxr::HdRenderParam* RenderParam,

Hydrogent/interface/HnRenderDelegate.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,8 @@ class HnRenderDelegate final : public pxr::HdRenderDelegate
422422

423423
HnMaterial* GetFallbackMaterial() const { return m_FallbackMaterial; }
424424

425+
bool AllowPrimitiveRestart() const;
426+
425427
private:
426428
static const pxr::TfTokenVector SupportedRPrimTypes;
427429
static const pxr::TfTokenVector SupportedSPrimTypes;

Hydrogent/interface/HnRenderPass.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ class HnRenderPass final : public pxr::HdRenderPass
195195

196196
void RenderPendingDrawItems(RenderState& State);
197197

198-
GraphicsPipelineDesc GetGraphicsDesc(const HnRenderPassState& RPState) const;
198+
GraphicsPipelineDesc GetGraphicsDesc(const HnRenderPassState& RPState, bool UseStripTopology) const;
199199

200200
private:
201201
HnRenderPassParams m_Params;

Hydrogent/src/HnMesh.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ void HnMesh::UpdateRepr(pxr::HdSceneDelegate& SceneDelegate,
430430
if (IndexDataDirty && m_VertexHandle)
431431
{
432432
StagingIndexData StagingInds;
433-
UpdateIndexData(StagingInds, StagingVerts.Points);
433+
UpdateIndexData(StagingInds, StagingVerts.Points, RenderDelegate->AllowPrimitiveRestart());
434434

435435
HnGeometryPool& GeometryPool = RenderDelegate->GetGeometryPool();
436436

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

1067-
void HnMesh::UpdateIndexData(StagingIndexData& StagingInds, const pxr::VtValue& Points)
1067+
void HnMesh::UpdateIndexData(StagingIndexData& StagingInds, const pxr::VtValue& Points, bool UseStripTopology)
10681068
{
10691069
HnMeshUtils MeshUtils{m_Topology, GetId()};
10701070
pxr::VtIntArray SubsetStart;
@@ -1085,7 +1085,7 @@ void HnMesh::UpdateIndexData(StagingIndexData& StagingInds, const pxr::VtValue&
10851085
m_IndexData.Subsets.clear();
10861086
}
10871087

1088-
StagingInds.EdgeIndices = MeshUtils.ComputeEdgeIndices(!m_HasFaceVaryingPrimvars, true);
1088+
StagingInds.EdgeIndices = MeshUtils.ComputeEdgeIndices(!m_HasFaceVaryingPrimvars, UseStripTopology);
10891089
StagingInds.PointIndices = MeshUtils.ComputePointIndices(m_HasFaceVaryingPrimvars);
10901090
}
10911091

@@ -1154,7 +1154,7 @@ void HnMesh::UpdateDrawItemGpuTopology(HnRenderDelegate& RenderDelegate)
11541154
DrawItem.SetFaces({});
11551155
}
11561156

1157-
// Render edgesand points for the entire mesh at once
1157+
// Render edges and points for the entire mesh at once
11581158
DrawItem.SetEdges({
11591159
m_IndexData.Edges->GetBuffer(),
11601160
m_IndexData.Edges->GetStartIndex(),

Hydrogent/src/HnRenderDelegate.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,13 @@ IShaderResourceBinding* HnRenderDelegate::GetShadowPassFrameAttribsSRB(Uint32 Li
899899
return m_ShadowPassFrameAttribs.SRB;
900900
}
901901

902+
bool HnRenderDelegate::AllowPrimitiveRestart() const
903+
{
904+
// WebGL supports primitive restart index, however on MacOS the presence of the restart index
905+
// in the buffer causes disastrous performance degradation. So we disable it on OpenGL.
906+
return !m_pDevice->GetDeviceInfo().IsGLDevice();
907+
}
908+
902909
} // namespace USD
903910

904911
} // namespace Diligent

Hydrogent/src/HnRenderPass.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ struct HnRenderPass::RenderState
198198
{
199199
if (!PsoCache)
200200
{
201-
GraphicsPipelineDesc GraphicsDesc = RenderPass.GetGraphicsDesc(RPState);
201+
GraphicsPipelineDesc GraphicsDesc = RenderPass.GetGraphicsDesc(RPState, RenderDelegate.AllowPrimitiveRestart());
202202

203203
PsoCache = USDRenderer.GetPsoCacheAccessor(GraphicsDesc);
204204
VERIFY_EXPR(PsoCache);
@@ -220,7 +220,7 @@ struct HnRenderPass::RenderState
220220
USD_Renderer::PsoCacheAccessor PsoCache;
221221
};
222222

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

239239
case HN_RENDER_MODE_MESH_EDGES:
240-
GraphicsDesc.PrimitiveTopology = PRIMITIVE_TOPOLOGY_LINE_STRIP;
240+
GraphicsDesc.PrimitiveTopology = UseStripTopology ? PRIMITIVE_TOPOLOGY_LINE_STRIP : PRIMITIVE_TOPOLOGY_LINE_LIST;
241241
break;
242242

243243
case HN_RENDER_MODE_POINTS:

0 commit comments

Comments
 (0)