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

Make C++ operator overload for enums not happen for HLSL #386

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
2 changes: 2 additions & 0 deletions include/spirv/unified1/spirv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2825,6 +2825,7 @@ inline void HasResultAndType(Op opcode, bool *hasResult, bool *hasResultType) {
}
#endif /* SPV_ENABLE_UTILITY_CODE */

#ifndef __HLSL_VERSION
// Overload bitwise operators for mask bit combining

inline ImageOperandsMask operator|(ImageOperandsMask a, ImageOperandsMask b) { return ImageOperandsMask(unsigned(a) | unsigned(b)); }
Expand Down Expand Up @@ -2871,6 +2872,7 @@ inline CooperativeMatrixOperandsMask operator|(CooperativeMatrixOperandsMask a,
inline CooperativeMatrixOperandsMask operator&(CooperativeMatrixOperandsMask a, CooperativeMatrixOperandsMask b) { return CooperativeMatrixOperandsMask(unsigned(a) & unsigned(b)); }
inline CooperativeMatrixOperandsMask operator^(CooperativeMatrixOperandsMask a, CooperativeMatrixOperandsMask b) { return CooperativeMatrixOperandsMask(unsigned(a) ^ unsigned(b)); }
inline CooperativeMatrixOperandsMask operator~(CooperativeMatrixOperandsMask a) { return CooperativeMatrixOperandsMask(~unsigned(a)); }
#endif

} // end namespace spv

Expand Down
2 changes: 2 additions & 0 deletions include/spirv/unified1/spirv.hpp11
Original file line number Diff line number Diff line change
Expand Up @@ -2825,6 +2825,7 @@ inline void HasResultAndType(Op opcode, bool *hasResult, bool *hasResultType) {
}
#endif /* SPV_ENABLE_UTILITY_CODE */

#ifndef __HLSL_VERSION
// Overload bitwise operators for mask bit combining

constexpr ImageOperandsMask operator|(ImageOperandsMask a, ImageOperandsMask b) { return ImageOperandsMask(unsigned(a) | unsigned(b)); }
Expand Down Expand Up @@ -2871,6 +2872,7 @@ constexpr CooperativeMatrixOperandsMask operator|(CooperativeMatrixOperandsMask
constexpr CooperativeMatrixOperandsMask operator&(CooperativeMatrixOperandsMask a, CooperativeMatrixOperandsMask b) { return CooperativeMatrixOperandsMask(unsigned(a) & unsigned(b)); }
constexpr CooperativeMatrixOperandsMask operator^(CooperativeMatrixOperandsMask a, CooperativeMatrixOperandsMask b) { return CooperativeMatrixOperandsMask(unsigned(a) ^ unsigned(b)); }
constexpr CooperativeMatrixOperandsMask operator~(CooperativeMatrixOperandsMask a) { return CooperativeMatrixOperandsMask(~unsigned(a)); }
#endif

} // end namespace spv

Expand Down
2 changes: 2 additions & 0 deletions tools/buildHeaders/header.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,7 @@ namespace {
void printMaskOperators(std::ostream& out, const std::string& specifiers) const {
const Json::Value& enums = spvRoot["spv"]["enum"];

out << "#ifndef __HLSL_VERSION\n";
out << "// Overload bitwise operators for mask bit combining\n\n";

for (auto opClass = enums.begin(); opClass != enums.end(); ++opClass) {
Expand All @@ -601,6 +602,7 @@ namespace {
typeName << "(~unsigned(a)); }\n";
}
}
out << "#endif\n";
}
private:
void printPrologue(std::ostream& out) const override {
Expand Down