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

APPLE: Basis curves on Metal - Updated mega PR #2027

Closed
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
2 changes: 2 additions & 0 deletions pxr/imaging/hd/tokens.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ PXR_NAMESPACE_OPEN_SCOPE

#define HD_SHADER_TOKENS \
(alphaThreshold) \
(centroid) \
(clipPlanes) \
(commonShaderSource) \
(computeShader) \
Expand Down Expand Up @@ -214,6 +215,7 @@ PXR_NAMESPACE_OPEN_SCOPE
(wireframeColor) \
(worldToViewMatrix) \
(worldToViewInverseMatrix) \
(sample) \
(stepSize) \
(stepSizeLighting)

Expand Down
18 changes: 7 additions & 11 deletions pxr/imaging/hdSt/basisCurves.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,16 +289,9 @@ HdStBasisCurves::_UpdateDrawItemGeometricShader(
std::static_pointer_cast<HdStResourceRegistry>(
renderIndex.GetResourceRegistry());

// For the time being, don't use complex curves on Metal. Support for this
// is planned for the future.
const bool hasMetalTessellation =
resourceRegistry->GetHgi()->GetCapabilities()->
IsSet(HgiDeviceCapabilitiesBitsMetalTessellation);

TfToken curveType = _topology->GetCurveType();
TfToken curveBasis = _topology->GetCurveBasis();
bool supportsRefinement = _SupportsRefinement(_refineLevel) &&
!hasMetalTessellation;
bool supportsRefinement = _SupportsRefinement(_refineLevel);
if (!supportsRefinement) {
// XXX: Rendering non-linear (i.e., cubic) curves as linear segments
// when unrefined can be confusing. Should we continue to do this?
Expand Down Expand Up @@ -329,8 +322,7 @@ HdStBasisCurves::_UpdateDrawItemGeometricShader(
case HdBasisCurvesGeomStylePatch:
{
if (_SupportsRefinement(_refineLevel) &&
_SupportsUserWidths(drawItem) &&
!hasMetalTessellation) {
_SupportsUserWidths(drawItem)) {
if (_SupportsUserNormals(drawItem)){
drawStyle = HdSt_BasisCurvesShaderKey::RIBBON;
normalStyle = HdSt_BasisCurvesShaderKey::ORIENTED;
Expand Down Expand Up @@ -380,6 +372,9 @@ HdStBasisCurves::_UpdateDrawItemGeometricShader(
shadingTerminal = HdBasisCurvesReprDescTokens->surfaceShaderUnlit;
}
}
bool hasPostTessVertexSupport = resourceRegistry->GetHgi()
->GetCapabilities()->IsSet(HgiDeviceCapabilitiesBitsMetalTessellation);


HdSt_BasisCurvesShaderKey shaderKey(curveType,
curveBasis,
Expand All @@ -389,7 +384,8 @@ HdStBasisCurves::_UpdateDrawItemGeometricShader(
_basisNormalInterpolation,
shadingTerminal,
hasAuthoredTopologicalVisiblity,
_pointsShadingEnabled);
_pointsShadingEnabled,
hasPostTessVertexSupport);

TF_DEBUG(HD_RPRIM_UPDATED).
Msg("HdStBasisCurves(%s) - Shader Key PrimType: %s\n ",
Expand Down
76 changes: 71 additions & 5 deletions pxr/imaging/hdSt/basisCurvesComputations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,34 @@

#include "pxr/base/gf/vec2i.h"
#include "pxr/base/gf/vec4i.h"
#include "pxr/base/gf/half.h"


#include <algorithm>

PXR_NAMESPACE_OPEN_SCOPE

int32_t GetOneOnePacked() {
int32_t one = 0;
uint16_t const oneHalf =
reinterpret_cast<uint16_t>(GfHalf(1.0f).bits());
one |= oneHalf;
int32_t oneScaled = 0;
oneScaled |= (one << 16);
int32_t oneone = 0;
oneone |= (one | oneScaled);
return oneone;
}

int32_t GetZeroZeroPacked() {
int32_t zero = 0;
uint16_t const zeroHalf =
reinterpret_cast<uint16_t>(GfHalf(0.0f).bits());
zero |= zeroHalf;
int32_t zerozero = 0;
zerozero |= (zero << 16) | zero;
return zerozero;
}

HdSt_BasisCurvesIndexBuilderComputation::HdSt_BasisCurvesIndexBuilderComputation(
HdBasisCurvesTopology *topology, bool forceLines)
Expand Down Expand Up @@ -60,6 +83,8 @@ HdSt_BasisCurvesIndexBuilderComputation::GetBufferSpecs(
// XXX: we currently create it even when the curve has no uniform primvars
specs->emplace_back(HdTokens->primitiveParam,
HdTupleType{HdTypeInt32, 1});
specs->emplace_back(HdTokens->tessFactors,
HdTupleType{HdTypeInt32Vec3, 1});
}

HdSt_BasisCurvesIndexBuilderComputation::IndexAndPrimIndex
Expand Down Expand Up @@ -108,12 +133,24 @@ HdSt_BasisCurvesIndexBuilderComputation::_BuildLinesIndexArray()
}
}

VtVec3iArray finalTessFactors(finalIndices.size());
int32_t oneone = GetOneOnePacked();
int32_t zerozero = GetZeroZeroPacked();
for (size_t i = 0; i < indices.size(); i++) {
finalTessFactors[i][0] = oneone;
finalTessFactors[i][1] = oneone;
finalTessFactors[i][2] = zerozero;
}


VtIntArray finalPrimIndices(primIndices.size());
std::copy( primIndices.begin(),
primIndices.end(),
finalPrimIndices.begin());

return IndexAndPrimIndex(VtValue(finalIndices), VtValue(finalPrimIndices));
return IndexAndPrimIndex(VtValue(finalIndices),
VtValue(finalPrimIndices),
VtValue(finalTessFactors));
}

HdSt_BasisCurvesIndexBuilderComputation::IndexAndPrimIndex
Expand Down Expand Up @@ -181,12 +218,24 @@ HdSt_BasisCurvesIndexBuilderComputation::_BuildLineSegmentIndexArray()
}
}

VtVec3iArray finalTessFactors(finalIndices.size());
int32_t oneone = GetOneOnePacked();
int32_t zerozero = GetZeroZeroPacked();
for (size_t i = 0; i < indices.size(); i++) {
finalTessFactors[i][0] = oneone;
finalTessFactors[i][1] = oneone;
finalTessFactors[i][2] = zerozero;
}


VtIntArray finalPrimIndices(primIndices.size());
std::copy( primIndices.begin(),
primIndices.end(),
finalPrimIndices.begin());

return IndexAndPrimIndex(VtValue(finalIndices), VtValue(finalPrimIndices));
return IndexAndPrimIndex(VtValue(finalIndices),
VtValue(finalPrimIndices),
VtValue(finalTessFactors));
}

HdSt_BasisCurvesIndexBuilderComputation::IndexAndPrimIndex
Expand Down Expand Up @@ -384,10 +433,23 @@ HdSt_BasisCurvesIndexBuilderComputation::_BuildCubicIndexArray()
}
}

VtVec3iArray finalTessFactors(finalIndices.size());
int32_t oneone = GetOneOnePacked();
int32_t zerozero = GetZeroZeroPacked();
for (size_t i = 0; i < indices.size(); i++) {
finalTessFactors[i][0] = oneone;
finalTessFactors[i][1] = oneone;
finalTessFactors[i][2] = zerozero;
}

VtIntArray finalPrimIndices(primIndices.size());
std::copy(primIndices.begin(), primIndices.end(), finalPrimIndices.begin());
std::copy(primIndices.begin(), primIndices.end(), finalPrimIndices.begin());

return IndexAndPrimIndex(
VtValue(finalIndices),
VtValue(finalPrimIndices),
VtValue(finalTessFactors));

return IndexAndPrimIndex(VtValue(finalIndices), VtValue(finalPrimIndices));
}

bool
Expand All @@ -413,6 +475,10 @@ HdSt_BasisCurvesIndexBuilderComputation::Resolve()
HdTokens->indices,
VtValue(result._indices)));

_tessFactorsParam.reset(new HdVtBufferSource(
HdTokens->tessFactors,
VtValue(result._tessFactors)));

// the primitive param buffer is used only when the basis curve
// has uniform primvars.
// XXX: we currently create it even when the curve has no uniform primvars
Expand All @@ -439,7 +505,7 @@ HdSt_BasisCurvesIndexBuilderComputation::HasChainedBuffer() const
HdBufferSourceSharedPtrVector
HdSt_BasisCurvesIndexBuilderComputation::GetChainedBuffers() const
{
return { _primitiveParam };
return { _primitiveParam, _tessFactorsParam };
}


Expand Down
14 changes: 10 additions & 4 deletions pxr/imaging/hdSt/basisCurvesComputations.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,21 @@ class HdSt_BasisCurvesIndexBuilderComputation : public HdComputedBufferSource {
virtual bool _CheckValid() const override;

public:
// For building index and primitive index arrays
// For building index, primitive index and tessFactor arrays
struct IndexAndPrimIndex {
// default constructor results in empty VtValue's
IndexAndPrimIndex() {}

IndexAndPrimIndex(VtValue indices, VtValue primIndices) :
_indices(indices), _primIndices(primIndices) {}
IndexAndPrimIndex(VtValue indices,
VtValue primIndices,
VtValue tessFactors) :
_indices(indices),
_primIndices(primIndices),
_tessFactors(tessFactors) {}

VtValue _indices;
VtValue _primIndices;
VtValue _tessFactors;
};
private:
IndexAndPrimIndex _BuildLinesIndexArray();
Expand All @@ -80,7 +85,8 @@ class HdSt_BasisCurvesIndexBuilderComputation : public HdComputedBufferSource {
HdBasisCurvesTopology *_topology;
bool _forceLines;

HdBufferSourceSharedPtr _primitiveParam;
HdBufferSourceSharedPtr _primitiveParam;
HdBufferSourceSharedPtr _tessFactorsParam;
};


Expand Down
Loading