Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autodesk: Vulkan and Metal round points #3463

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pxr/imaging/hd/tokens.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ PXR_NAMESPACE_OPEN_SCOPE
(worldToViewMatrix) \
(worldToViewInverseMatrix) \
(stepSize) \
(stepSizeLighting)
(stepSizeLighting) \
(multisampleCount)

// Deprecated. Use: HdStMaterialTagTokens
#define HD_MATERIALTAG_TOKENS \
Expand Down
1 change: 1 addition & 0 deletions pxr/imaging/hdSt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ pxr_library(hdSt
shaders/meshWire.glslfx
shaders/points.glslfx
shaders/pointId.glslfx
shaders/pointDisk.glslfx
shaders/ptexTexture.glslfx
shaders/renderPass.glslfx
shaders/renderPassShader.glslfx
Expand Down
7 changes: 6 additions & 1 deletion pxr/imaging/hdSt/basisCurves.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,10 @@ HdStBasisCurves::_UpdateDrawItemGeometricShader(
resourceRegistry->GetHgi()->GetCapabilities()->
IsSet(HgiDeviceCapabilitiesBitsMetalTessellation);

bool const nativeRoundPoints =
resourceRegistry->GetHgi()->GetCapabilities()->
IsSet(HgiDeviceCapabilitiesBitsRoundPoints);

HdSt_BasisCurvesShaderKey shaderKey(curveType,
curveBasis,
drawStyle,
Expand All @@ -368,7 +372,8 @@ HdStBasisCurves::_UpdateDrawItemGeometricShader(
shadingTerminal,
hasAuthoredTopologicalVisiblity,
_pointsShadingEnabled,
hasMetalTessellation);
hasMetalTessellation,
nativeRoundPoints);

TF_DEBUG(HD_RPRIM_UPDATED).
Msg("HdStBasisCurves(%s) - Shader Key PrimType: %s\n ",
Expand Down
26 changes: 21 additions & 5 deletions pxr/imaging/hdSt/basisCurvesShaderKey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ TF_DEFINE_PRIVATE_TOKENS(
((surfaceFS, "Fragment.Surface"))
((surfaceUnlitFS, "Fragment.SurfaceUnlit"))
((scalarOverrideFS, "Fragment.ScalarOverride"))

// rounded points
((pointSizeBiasVS, "PointDisk.Vertex.PointSizeBias"))
((noPointSizeBiasVS, "PointDisk.Vertex.None"))
((diskSampleMaskFS, "PointDisk.Fragment.SampleMask"))
((noDiskSampleMaskFS, "PointDisk.Fragment.None"))
);

static TfToken HdSt_BasisToShaderKey(const TfToken& basis){
Expand All @@ -151,7 +157,8 @@ HdSt_BasisCurvesShaderKey::HdSt_BasisCurvesShaderKey(
TfToken shadingTerminal,
bool hasAuthoredTopologicalVisibility,
bool pointsShadingEnabled,
bool hasMetalTessellation)
bool hasMetalTessellation,
bool nativeRoundPoints)
: useMetalTessellation(false)
, glslfx(_tokens->baseGLSLFX)
{
Expand Down Expand Up @@ -201,8 +208,11 @@ HdSt_BasisCurvesShaderKey::HdSt_BasisCurvesShaderKey(
VS[vsIndex++] = _tokens->pointIdVS;
VS[vsIndex++] = _tokens->pointIdSelDecodeUtilsVS;
VS[vsIndex++] = _tokens->pointIdSelPointSelVS;
VS[vsIndex++] = nativeRoundPoints ? _tokens->noPointSizeBiasVS :
_tokens->pointSizeBiasVS;
} else {
VS[vsIndex++] = _tokens->pointIdNoneVS;
VS[vsIndex++] = _tokens->noPointSizeBiasVS;
}
VS[vsIndex] = TfToken();

Expand Down Expand Up @@ -485,11 +495,17 @@ HdSt_BasisCurvesShaderKey::HdSt_BasisCurvesShaderKey(
}
FS[fsIndex++] = _tokens->scalarOverrideFS;

FS[fsIndex++] = isPrimTypePoints?
_tokens->pointIdFS : _tokens->pointIdFallbackFS;

if (isPrimTypePoints) {
FS[fsIndex++] = _tokens->pointIdFS;
FS[fsIndex++] = nativeRoundPoints ? _tokens->noDiskSampleMaskFS :
_tokens->diskSampleMaskFS;
} else {
FS[fsIndex++] = _tokens->pointIdFallbackFS;
FS[fsIndex++] = _tokens->noDiskSampleMaskFS;
}

FS[fsIndex++] = hasAuthoredTopologicalVisibility? _tokens->topVisFS :
_tokens->topVisFallbackFS;
_tokens->topVisFallbackFS;


if (drawStyle == HdSt_BasisCurvesShaderKey::WIRE ||
Expand Down
8 changes: 5 additions & 3 deletions pxr/imaging/hdSt/basisCurvesShaderKey.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ struct HdSt_BasisCurvesShaderKey : public HdSt_ShaderKey
TfToken shadingTerminal,
bool hasAuthoredTopologicalVisibility,
bool pointsShadingEnabled,
bool hasMetalTessellation);
bool hasMetalTessellation,
bool nativeRoundPoints);

HDST_API
~HdSt_BasisCurvesShaderKey();
Expand All @@ -83,12 +84,13 @@ struct HdSt_BasisCurvesShaderKey : public HdSt_ShaderKey
HdSt_GeometricShader::PrimitiveType primType;
bool useMetalTessellation;
TfToken glslfx;
TfToken VS[7];
TfToken VS[8];
TfToken TCS[7];
TfToken TES[12];
TfToken PTCS[9];
TfToken PTVS[14];
TfToken FS[8];
TfToken GS[2];
TfToken FS[9];
};


Expand Down
24 changes: 24 additions & 0 deletions pxr/imaging/hdSt/codeGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3190,6 +3190,30 @@ HdSt_CodeGen::_CompileWithGeneratedHgiResources(
HgiShaderKeywordTokens->hdBaryCoordNoPersp);
}

if (_geometricShader->GetPrimitiveType() ==
HdSt_GeometricShader::PrimitiveType::PRIM_POINTS &&
!registry->GetHgi()->GetCapabilities()->IsSet(
HgiDeviceCapabilitiesBitsRoundPoints)) {
HgiShaderFunctionAddStageInput(&fsDesc, "gl_PointCoord", "vec2",
HgiShaderKeywordTokens->hdPointCoord);
HgiShaderFunctionAddStageInput(&fsDesc, "hd_SampleMaskIn", "uint",
HgiShaderKeywordTokens->hdSampleMaskIn);
HgiShaderFunctionAddStageOutput(&fsDesc, "hd_SampleMask", "uint",
HgiShaderKeywordTokens->hdSampleMask);
}

if (_geometricShader->GetPrimitiveType() ==
HdSt_GeometricShader::PrimitiveType::PRIM_POINTS &&
!registry->GetHgi()->GetCapabilities()->IsSet(
HgiDeviceCapabilitiesBitsRoundPoints)) {
HgiShaderFunctionAddStageInput(&fsDesc, "gl_PointCoord", "vec2",
HgiShaderKeywordTokens->hdPointCoord);
HgiShaderFunctionAddStageInput(&fsDesc, "hd_SampleMaskIn", "uint",
HgiShaderKeywordTokens->hdSampleMaskIn);
HgiShaderFunctionAddStageOutput(&fsDesc, "hd_SampleMask", "uint",
HgiShaderKeywordTokens->hdSampleMask);
}

if (!glslProgram->CompileShader(fsDesc)) {
return nullptr;
}
Expand Down
8 changes: 6 additions & 2 deletions pxr/imaging/hdSt/mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2617,6 +2617,10 @@ HdStMesh::_UpdateDrawItemGeometricShader(HdSceneDelegate *sceneDelegate,
resourceRegistry->GetHgi()->GetCapabilities()->
IsSet(HgiDeviceCapabilitiesBitsMetalTessellation);

bool const nativeRoundPoints =
resourceRegistry->GetHgi()->GetCapabilities()->
IsSet(HgiDeviceCapabilitiesBitsRoundPoints);

// create a shaderKey and set to the geometric shader.
HdSt_MeshShaderKey shaderKey(primType,
shadingTerminal,
Expand All @@ -2638,7 +2642,8 @@ HdStMesh::_UpdateDrawItemGeometricShader(HdSceneDelegate *sceneDelegate,
desc.enableScalarOverride,
_pointsShadingEnabled,
desc.forceOpaqueEdges,
desc.surfaceEdgeIds);
desc.surfaceEdgeIds,
nativeRoundPoints);

HdSt_GeometricShaderSharedPtr geomShader =
HdSt_GeometricShader::Create(shaderKey, resourceRegistry);
Expand Down Expand Up @@ -3057,4 +3062,3 @@ HdStMesh::GetInitialDirtyBitsMask() const
}

PXR_NAMESPACE_CLOSE_SCOPE

28 changes: 24 additions & 4 deletions pxr/imaging/hdSt/meshShaderKey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ TF_DEFINE_PRIVATE_TOKENS(
((pointShadedFS, "Fragment.PointShaded"))
((scalarOverrideFS, "Fragment.ScalarOverride"))
((noScalarOverrideFS, "Fragment.NoScalarOverride"))

// rounded points
((pointSizeBiasVS, "PointDisk.Vertex.PointSizeBias"))
((noPointSizeBiasVS, "PointDisk.Vertex.None"))
((diskSampleMaskFS, "PointDisk.Fragment.SampleMask"))
((noDiskSampleMaskFS, "PointDisk.Fragment.None"))
);

HdSt_MeshShaderKey::HdSt_MeshShaderKey(
Expand All @@ -159,7 +165,8 @@ HdSt_MeshShaderKey::HdSt_MeshShaderKey(
bool enableScalarOverride,
bool pointsShadingEnabled,
bool forceOpaqueEdges,
bool surfaceEdgeIds)
bool surfaceEdgeIds,
bool nativeRoundPoints)
: primType(primitiveType)
, cullStyle(cullStyle)
, hasMirroredTransform(hasMirroredTransform)
Expand Down Expand Up @@ -255,8 +262,11 @@ HdSt_MeshShaderKey::HdSt_MeshShaderKey(
VS[vsIndex++] = _tokens->pointIdVS;
VS[vsIndex++] = _tokens->selDecodeUtils;
VS[vsIndex++] = _tokens->selPointSelVS;
VS[vsIndex++] = nativeRoundPoints ? _tokens->noPointSizeBiasVS :
_tokens->pointSizeBiasVS;
} else {
VS[vsIndex++] = _tokens->pointIdNoneVS;
VS[vsIndex++] = _tokens->noPointSizeBiasVS;
}
VS[vsIndex++] = _tokens->mainVS;
VS[vsIndex] = TfToken();
Expand Down Expand Up @@ -313,8 +323,11 @@ HdSt_MeshShaderKey::HdSt_MeshShaderKey(
PTVS[ptvsIndex++] = _tokens->pointIdVS;
PTVS[ptvsIndex++] = _tokens->selDecodeUtils;
PTVS[ptvsIndex++] = _tokens->selPointSelVS;
PTVS[ptvsIndex++] = nativeRoundPoints ? _tokens->noPointSizeBiasVS :
_tokens->pointSizeBiasVS;
} else {
PTVS[ptvsIndex++] = _tokens->pointIdNoneVS;
PTVS[ptvsIndex++] = _tokens->noPointSizeBiasVS;
}

if (hasCustomDisplacement) {
Expand Down Expand Up @@ -579,10 +592,17 @@ HdSt_MeshShaderKey::HdSt_MeshShaderKey(
}

// PointId mixin for point picking and selection
FS[fsIndex++] = isPrimTypePoints? _tokens->pointIdFS :
_tokens->pointIdFallbackFS;
if (isPrimTypePoints) {
FS[fsIndex++] = _tokens->pointIdFS;
FS[fsIndex++] = nativeRoundPoints ? _tokens->noDiskSampleMaskFS :
_tokens->diskSampleMaskFS;
} else {
FS[fsIndex++] = _tokens->pointIdFallbackFS;
FS[fsIndex++] = _tokens->noDiskSampleMaskFS;
}

FS[fsIndex++] = hasTopologicalVisibility? _tokens->topVisFS :
_tokens->topVisFallbackFS;
_tokens->topVisFallbackFS;

// Triangles
if (isPrimTypeTris && ptvsStageEnabled) {
Expand Down
9 changes: 5 additions & 4 deletions pxr/imaging/hdSt/meshShaderKey.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ struct HdSt_MeshShaderKey : public HdSt_ShaderKey
bool enableScalarOverride,
bool pointsShadingEnabled,
bool forceOpaqueEdges,
bool surfaceEdgeIds);
bool surfaceEdgeIds,
bool nativeRoundPoints);

// Note: it looks like gcc 4.8 has a problem issuing
// a wrong warning as "array subscript is above array bounds"
Expand Down Expand Up @@ -103,13 +104,13 @@ struct HdSt_MeshShaderKey : public HdSt_ShaderKey
TfToken const *GetFS() const override { return FS; }

TfToken glslfx;
TfToken VS[7];
TfToken VS[8];
TfToken TCS[4];
TfToken TES[4];
TfToken PTCS[4];
TfToken PTVS[12];
TfToken PTVS[13];
TfToken GS[10];
TfToken FS[22];
TfToken FS[23];
};


Expand Down
8 changes: 6 additions & 2 deletions pxr/imaging/hdSt/points.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,15 @@ HdStPoints::_UpdateDrawItem(HdSceneDelegate *sceneDelegate,
constantPrimvars, HdTokens->displayOpacity);
}

HdSt_PointsShaderKey shaderKey;
HdStResourceRegistrySharedPtr resourceRegistry =
std::static_pointer_cast<HdStResourceRegistry>(
sceneDelegate->GetRenderIndex().GetResourceRegistry());

bool const nativeRoundPoints =
resourceRegistry->GetHgi()->GetCapabilities()->
IsSet(HgiDeviceCapabilitiesBitsRoundPoints);

HdSt_PointsShaderKey shaderKey{nativeRoundPoints};
drawItem->SetGeometricShader(
HdSt_GeometricShader::Create(shaderKey, resourceRegistry));

Expand Down Expand Up @@ -434,4 +439,3 @@ HdStPoints::_InitRepr(TfToken const &reprToken, HdDirtyBits *dirtyBits)
}

PXR_NAMESPACE_CLOSE_SCOPE

30 changes: 20 additions & 10 deletions pxr/imaging/hdSt/pointsShaderKey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,40 @@ TF_DEFINE_PRIVATE_TOKENS(

// instancing
((instancing, "Instancing.Transform"))

// rounded points
((pointSizeBiasVS, "PointDisk.Vertex.PointSizeBias"))
((noPointSizeBiasVS, "PointDisk.Vertex.None"))
((diskSampleMaskFS, "PointDisk.Fragment.SampleMask"))
((noDiskSampleMaskFS, "PointDisk.Fragment.None"))
);

HdSt_PointsShaderKey::HdSt_PointsShaderKey()
HdSt_PointsShaderKey::HdSt_PointsShaderKey(
bool nativeRoundPoints)
: glslfx(_tokens->baseGLSLFX)
{
VS[0] = _tokens->instancing;
VS[1] = _tokens->mainVS;
VS[2] = _tokens->pointIdVS;
VS[3] = _tokens->pointIdSelDecodeUtilsVS;
VS[4] = _tokens->pointIdSelPointSelVS;
VS[5] = TfToken();
VS[1] = nativeRoundPoints ? _tokens->noPointSizeBiasVS :
_tokens->pointSizeBiasVS;
VS[2] = _tokens->mainVS;
VS[3] = _tokens->pointIdVS;
VS[4] = _tokens->pointIdSelDecodeUtilsVS;
VS[5] = _tokens->pointIdSelPointSelVS;
VS[6] = TfToken();

// Common must be first as it defines terminal interfaces
FS[0] = _tokens->commonFS;
FS[1] = _tokens->surfaceFS;
FS[2] = _tokens->noScalarOverrideFS;
FS[3] = _tokens->mainFS;
FS[4] = _tokens->pointIdFS;
FS[5] = TfToken();
FS[3] = nativeRoundPoints ? _tokens->noDiskSampleMaskFS :
_tokens->diskSampleMaskFS;
FS[4] = _tokens->mainFS;
FS[5] = _tokens->pointIdFS;
FS[6] = TfToken();
}

HdSt_PointsShaderKey::~HdSt_PointsShaderKey()
{
}

PXR_NAMESPACE_CLOSE_SCOPE

6 changes: 3 additions & 3 deletions pxr/imaging/hdSt/pointsShaderKey.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ PXR_NAMESPACE_OPEN_SCOPE
struct HdSt_PointsShaderKey : public HdSt_ShaderKey
{
HDST_API
HdSt_PointsShaderKey();
HdSt_PointsShaderKey(bool nativeRoundPoints);
HDST_API
~HdSt_PointsShaderKey();

Expand All @@ -33,8 +33,8 @@ struct HdSt_PointsShaderKey : public HdSt_ShaderKey
}

TfToken glslfx;
TfToken VS[6];
TfToken FS[6];
TfToken VS[7];
TfToken FS[7];
};


Expand Down
Loading