Skip to content

Commit

Permalink
[OGSMOD-2694] cherry-pick 71e55a12 from adsk/feature/text. [OGSMOD-25…
Browse files Browse the repository at this point in the history
…74] Add the support for input/output qualifiers (PixarAnimationStudios#208)

### Description of Change(s)
Add the support for input/output qualifiers.
Currently only "flat" qualifier is supported.

### Fixes Issue(s)
OGSMOD-2574: Input/output layout doesn't support qualifiers
For example, you can not add "flat", "smooth" or "noperspective" to an input.

(cherry picked from commit 6bcb00af841f3abfc8353c32338e54c44a71a2f0)

Co-authored-by: Pierre Wang <[email protected]>
  • Loading branch information
2 people authored and GitHub Enterprise committed Jan 4, 2023
1 parent 925d419 commit f32338c
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 7 deletions.
9 changes: 7 additions & 2 deletions pxr/imaging/hdSt/codeGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,7 @@ _ResourceGenerator::_GenerateHgiResources(
HgiShaderFunctionParamBlockDesc::Member paramMember;
paramMember.name = member.name;
paramMember.type = _ConvertBoolType(member.dataType);
paramMember.qualifiers = member.qualifiers;
paramBlock.members.push_back(paramMember);
}
if (element.inOut == InOut::STAGE_IN) {
Expand Down Expand Up @@ -925,8 +926,12 @@ _ResourceGenerator::_GenerateGLSLResources(
}
str << element.aggregateName << " {\n";
for (auto const & member : element.members) {
str << " " << member.dataType << " "
<< member.name;
str << " ";
// Only check flat qualifier, because the Element class also only check flat.
if (member.qualifiers == _tokens->flat) {
str << "flat ";
}
str << member.dataType << " " << member.name;
if (member.arraySize.IsEmpty()) {
str << ";\n";
} else {
Expand Down
10 changes: 7 additions & 3 deletions pxr/imaging/hdSt/resourceLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,15 @@ _ParseMembers(InputValueVector const & input, int fromElement)
MemberVector result;
for (auto const & inputValue : input) {
InputValueVector memberInput = _GetInputValueVector(inputValue);
if (memberInput.size() != 2 && memberInput.size() != 3) continue;
if (memberInput.size() != 2 && memberInput.size() != 3 && memberInput.size() != 4) continue;
result.emplace_back(/*dataType=*/_Token(memberInput[0]),
/*name=*/_Token(memberInput[1]));
if (input.size() == 3) {
result.back().arraySize = _Token(input[2]);
if (memberInput.size() == 3) {
result.back().arraySize = _Token(memberInput[2]);
}
// The support for member qualifiers.
if (memberInput.size() == 4) {
result.back().qualifiers = _Token(memberInput[3]);
}
}
return result;
Expand Down
4 changes: 3 additions & 1 deletion pxr/imaging/hdSt/resourceLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,16 @@ class HdSt_ResourceLayout
struct Member {
Member(TfToken const & dataType,
TfToken const & name,
TfToken const & arraySize = TfToken())
TfToken const & arraySize = TfToken(),
TfToken qualifiers = TfToken())
: dataType(dataType)
, name(name)
, arraySize(arraySize)
{ }
TfToken dataType;
TfToken name;
TfToken arraySize;
TfToken qualifiers;
};
using MemberVector = std::vector<Member>;

Expand Down
1 change: 1 addition & 0 deletions pxr/imaging/hgi/shaderFunctionDesc.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ struct HgiShaderFunctionParamBlockDesc
struct Member {
std::string name;
std::string type;
std::string qualifiers;
};
using MemberVector = std::vector<Member>;

Expand Down
23 changes: 23 additions & 0 deletions pxr/imaging/hgiMetal/shaderGenerator.mm
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,21 @@
(textureBindings)
);


// Convert the qualifiers to the interpolation string in MSL.
std::string _GetInterpolationString(std::string const & qualifiers)
{
if (qualifiers == "flat") {
return qualifiers;
}
else if(qualifiers == "noperspective") {
return "center_no_perspective";
}
else {
return "";
}
}

template<typename SectionType, typename ...T>
SectionType *
HgiMetalShaderGenerator::CreateShaderSection(T && ...t)
Expand Down Expand Up @@ -644,6 +659,8 @@ void _Init(
HgiShaderStage stage,
bool iterateAttrs)
{
// Currently we don't add qualifiers for function parameters.
const static std::string emptyQualifiers("");
HgiMetalShaderSectionPtrVector stageShaderSections;
//only some roles have an index
if(!iterateAttrs) {
Expand Down Expand Up @@ -695,6 +712,7 @@ void _Init(
HgiMetalMemberShaderSection>(
p.nameInShader,
p.type,
emptyQualifiers,
attributes,
p.arraySize);
stageShaderSections.push_back(section);
Expand All @@ -719,6 +737,7 @@ void _Init(
HgiMetalMemberShaderSection>(
p.nameInShader,
p.type,
emptyQualifiers,
attributes,
p.arraySize);
stageShaderSections.push_back(section);
Expand Down Expand Up @@ -750,6 +769,7 @@ void _Init(
HgiMetalMemberShaderSection>(
m.name,
m.type,
_GetInterpolationString(m.qualifiers),
attributes,
std::string(),
p.instanceName);
Expand Down Expand Up @@ -1340,12 +1360,15 @@ void _Init(
: HgiShaderGenerator(descriptor)
, _generatorShaderSections(_BuildShaderStageEntryPoints(descriptor))
{
// Currently we don't add qualifiers for global uniforms.
const static std::string emptyQualifiers("");
for (const auto &member: descriptor.stageGlobalMembers) {
HgiShaderSectionAttributeVector attrs;
CreateShaderSection<
HgiMetalMemberShaderSection>(
member.nameInShader,
member.type,
emptyQualifiers,
attrs,
member.arraySize);
}
Expand Down
4 changes: 4 additions & 0 deletions pxr/imaging/hgiMetal/shaderSection.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ class HgiMetalMemberShaderSection final : public HgiMetalShaderSection
HgiMetalMemberShaderSection(
const std::string &identifier,
const std::string &type,
const std::string &qualifiers,
const HgiShaderSectionAttributeVector &attributes = {},
const std::string arraySize = std::string(),
const std::string &blockInstanceIdentifier = std::string());
Expand All @@ -130,12 +131,15 @@ class HgiMetalMemberShaderSection final : public HgiMetalShaderSection

HGIMETAL_API
void WriteType(std::ostream &ss) const override;
HGIMETAL_API
void WriteParameter(std::ostream& ss) const override;

HGIMETAL_API
bool VisitScopeMemberDeclarations(std::ostream &ss) override;

private:
const std::string _type;
const std::string _qualifiers;
};

/// \class HgiMetalSamplerShaderSection
Expand Down
16 changes: 15 additions & 1 deletion pxr/imaging/hgiMetal/shaderSection.mm
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,14 @@
HgiMetalMemberShaderSection::HgiMetalMemberShaderSection(
const std::string &identifier,
const std::string &type,
const std::string &qualifiers,
const HgiShaderSectionAttributeVector &attributes,
const std::string arraySize,
const std::string &blockInstanceIdentifier)
: HgiMetalShaderSection(identifier, attributes,
std::string(), arraySize,
blockInstanceIdentifier)
, _type{type}
, _type{ type }, _qualifiers{qualifiers}
{
}

Expand All @@ -122,6 +123,19 @@
ss << _type;
}

void
HgiMetalMemberShaderSection::WriteParameter(std::ostream& ss) const
{
WriteType(ss);
ss << " ";
WriteIdentifier(ss);
// Write the qualifiers, such as "flat" and "center_no_perspective".
if (!_qualifiers.empty())
{
ss << " [[" << _qualifiers << "]]";
}
}

bool
HgiMetalMemberShaderSection::VisitScopeMemberDeclarations(std::ostream &ss)
{
Expand Down

0 comments on commit f32338c

Please sign in to comment.