Author: Finn Plummer Date: 2025-06-02T13:22:21-07:00 New Revision: 5628bf5a1e99375065df2b9652069adc9afcd655
URL: https://github.com/llvm/llvm-project/commit/5628bf5a1e99375065df2b9652069adc9afcd655 DIFF: https://github.com/llvm/llvm-project/commit/5628bf5a1e99375065df2b9652069adc9afcd655.diff LOG: Reland "[HLSL][RootSignature] Add parsing of filter enum for StaticSampler" (#142441) This relands https://github.com/llvm/llvm-project/pull/140294. The initial naming of the enum class Filter and the Filter struct member causes ambiguity when compiling with gcc. This change addresses this my renaming `Filter` to `SamplerFilter`. I have confirmed this builds locally using gcc. Resolves https://github.com/llvm/llvm-project/issues/126574. Added: Modified: clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def clang/include/clang/Parse/ParseHLSLRootSignature.h clang/lib/Parse/ParseHLSLRootSignature.cpp clang/unittests/Lex/LexHLSLRootSignatureTest.cpp clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h Removed: ################################################################################ diff --git a/clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def b/clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def index 1814ac4aeae5f..a5cfeb34b2b51 100644 --- a/clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def +++ b/clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def @@ -53,6 +53,9 @@ #ifndef SHADER_VISIBILITY_ENUM #define SHADER_VISIBILITY_ENUM(NAME, LIT) ENUM(NAME, LIT) #endif +#ifndef FILTER_ENUM +#define FILTER_ENUM(NAME, LIT) ENUM(NAME, LIT) +#endif #ifndef TEXTURE_ADDRESS_MODE_ENUM #define TEXTURE_ADDRESS_MODE_ENUM(NAME, LIT) ENUM(NAME, LIT) #endif @@ -110,6 +113,7 @@ KEYWORD(numDescriptors) KEYWORD(offset) // StaticSampler Keywords: +KEYWORD(filter) KEYWORD(mipLODBias) KEYWORD(addressU) KEYWORD(addressV) @@ -162,6 +166,44 @@ SHADER_VISIBILITY_ENUM(Pixel, "SHADER_VISIBILITY_PIXEL") SHADER_VISIBILITY_ENUM(Amplification, "SHADER_VISIBILITY_AMPLIFICATION") SHADER_VISIBILITY_ENUM(Mesh, "SHADER_VISIBILITY_MESH") +// Filter Enums: +FILTER_ENUM(MinMagMipPoint, "FILTER_MIN_MAG_MIP_POINT") +FILTER_ENUM(MinMagPointMipLinear, "FILTER_MIN_MAG_POINT_MIP_LINEAR") +FILTER_ENUM(MinPointMagLinearMipPoint, "FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT") +FILTER_ENUM(MinPointMagMipLinear, "FILTER_MIN_POINT_MAG_MIP_LINEAR") +FILTER_ENUM(MinLinearMagMipPoint, "FILTER_MIN_LINEAR_MAG_MIP_POINT") +FILTER_ENUM(MinLinearMagPointMipLinear, "FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR") +FILTER_ENUM(MinMagLinearMipPoint, "FILTER_MIN_MAG_LINEAR_MIP_POINT") +FILTER_ENUM(MinMagMipLinear, "FILTER_MIN_MAG_MIP_LINEAR") +FILTER_ENUM(Anisotropic, "FILTER_ANISOTROPIC") +FILTER_ENUM(ComparisonMinMagMipPoint, "FILTER_COMPARISON_MIN_MAG_MIP_POINT") +FILTER_ENUM(ComparisonMinMagPointMipLinear, "FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR") +FILTER_ENUM(ComparisonMinPointMagLinearMipPoint, "FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT") +FILTER_ENUM(ComparisonMinPointMagMipLinear, "FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR") +FILTER_ENUM(ComparisonMinLinearMagMipPoint, "FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT") +FILTER_ENUM(ComparisonMinLinearMagPointMipLinear, "FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR") +FILTER_ENUM(ComparisonMinMagLinearMipPoint, "FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT") +FILTER_ENUM(ComparisonMinMagMipLinear, "FILTER_COMPARISON_MIN_MAG_MIP_LINEAR") +FILTER_ENUM(ComparisonAnisotropic, "FILTER_COMPARISON_ANISOTROPIC") +FILTER_ENUM(MinimumMinMagMipPoint, "FILTER_MINIMUM_MIN_MAG_MIP_POINT") +FILTER_ENUM(MinimumMinMagPointMipLinear, "FILTER_MINIMUM_MIN_MAG_POINT_MIP_LINEAR") +FILTER_ENUM(MinimumMinPointMagLinearMipPoint, "FILTER_MINIMUM_MIN_POINT_MAG_LINEAR_MIP_POINT") +FILTER_ENUM(MinimumMinPointMagMipLinear, "FILTER_MINIMUM_MIN_POINT_MAG_MIP_LINEAR") +FILTER_ENUM(MinimumMinLinearMagMipPoint, "FILTER_MINIMUM_MIN_LINEAR_MAG_MIP_POINT") +FILTER_ENUM(MinimumMinLinearMagPointMipLinear, "FILTER_MINIMUM_MIN_LINEAR_MAG_POINT_MIP_LINEAR") +FILTER_ENUM(MinimumMinMagLinearMipPoint, "FILTER_MINIMUM_MIN_MAG_LINEAR_MIP_POINT") +FILTER_ENUM(MinimumMinMagMipLinear, "FILTER_MINIMUM_MIN_MAG_MIP_LINEAR") +FILTER_ENUM(MinimumAnisotropic, "FILTER_MINIMUM_ANISOTROPIC") +FILTER_ENUM(MaximumMinMagMipPoint, "FILTER_MAXIMUM_MIN_MAG_MIP_POINT") +FILTER_ENUM(MaximumMinMagPointMipLinear, "FILTER_MAXIMUM_MIN_MAG_POINT_MIP_LINEAR") +FILTER_ENUM(MaximumMinPointMagLinearMipPoint, "FILTER_MAXIMUM_MIN_POINT_MAG_LINEAR_MIP_POINT") +FILTER_ENUM(MaximumMinPointMagMipLinear, "FILTER_MAXIMUM_MIN_POINT_MAG_MIP_LINEAR") +FILTER_ENUM(MaximumMinLinearMagMipPoint, "FILTER_MAXIMUM_MIN_LINEAR_MAG_MIP_POINT") +FILTER_ENUM(MaximumMinLinearMagPointMipLinear, "FILTER_MAXIMUM_MIN_LINEAR_MAG_POINT_MIP_LINEAR") +FILTER_ENUM(MaximumMinMagLinearMipPoint, "FILTER_MAXIMUM_MIN_MAG_LINEAR_MIP_POINT") +FILTER_ENUM(MaximumMinMagMipLinear, "FILTER_MAXIMUM_MIN_MAG_MIP_LINEAR") +FILTER_ENUM(MaximumAnisotropic, "FILTER_MAXIMUM_ANISOTROPIC") + // Texture Address Mode Enums: TEXTURE_ADDRESS_MODE_ENUM(Wrap, "TEXTURE_ADDRESS_WRAP") TEXTURE_ADDRESS_MODE_ENUM(Mirror, "TEXTURE_ADDRESS_MIRROR") @@ -189,6 +231,7 @@ STATIC_BORDER_COLOR_ENUM(OpaqueWhiteUint, "STATIC_BORDER_COLOR_OPAQUE_WHITE_UINT #undef STATIC_BORDER_COLOR_ENUM #undef COMPARISON_FUNC_ENUM #undef TEXTURE_ADDRESS_MODE_ENUM +#undef FILTER_ENUM #undef SHADER_VISIBILITY_ENUM #undef DESCRIPTOR_RANGE_FLAG_ENUM #undef DESCRIPTOR_RANGE_FLAG_ENUM_OFF diff --git a/clang/include/clang/Parse/ParseHLSLRootSignature.h b/clang/include/clang/Parse/ParseHLSLRootSignature.h index 66a887bc12e64..afa2c4d8cfe50 100644 --- a/clang/include/clang/Parse/ParseHLSLRootSignature.h +++ b/clang/include/clang/Parse/ParseHLSLRootSignature.h @@ -111,10 +111,11 @@ class RootSignatureParser { struct ParsedStaticSamplerParams { std::optional<llvm::hlsl::rootsig::Register> Reg; - std::optional<float> MipLODBias; + std::optional<llvm::hlsl::rootsig::SamplerFilter> Filter; std::optional<llvm::hlsl::rootsig::TextureAddressMode> AddressU; std::optional<llvm::hlsl::rootsig::TextureAddressMode> AddressV; std::optional<llvm::hlsl::rootsig::TextureAddressMode> AddressW; + std::optional<float> MipLODBias; std::optional<uint32_t> MaxAnisotropy; std::optional<llvm::hlsl::rootsig::ComparisonFunc> CompFunc; std::optional<llvm::hlsl::rootsig::StaticBorderColor> BorderColor; @@ -132,6 +133,7 @@ class RootSignatureParser { /// Parsing methods of various enums std::optional<llvm::hlsl::rootsig::ShaderVisibility> parseShaderVisibility(); + std::optional<llvm::hlsl::rootsig::SamplerFilter> parseSamplerFilter(); std::optional<llvm::hlsl::rootsig::TextureAddressMode> parseTextureAddressMode(); std::optional<llvm::hlsl::rootsig::ComparisonFunc> parseComparisonFunc(); diff --git a/clang/lib/Parse/ParseHLSLRootSignature.cpp b/clang/lib/Parse/ParseHLSLRootSignature.cpp index 39a28edee8e2a..e510302c3aae0 100644 --- a/clang/lib/Parse/ParseHLSLRootSignature.cpp +++ b/clang/lib/Parse/ParseHLSLRootSignature.cpp @@ -377,6 +377,9 @@ std::optional<StaticSampler> RootSignatureParser::parseStaticSampler() { Sampler.Reg = Params->Reg.value(); // Fill in optional values + if (Params->Filter.has_value()) + Sampler.Filter = Params->Filter.value(); + if (Params->AddressU.has_value()) Sampler.AddressU = Params->AddressU.value(); @@ -696,6 +699,23 @@ RootSignatureParser::parseStaticSamplerParams() { Params.Reg = Reg; } + // `filter` `=` FILTER + if (tryConsumeExpectedToken(TokenKind::kw_filter)) { + if (Params.Filter.has_value()) { + getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param) + << CurToken.TokKind; + return std::nullopt; + } + + if (consumeExpectedToken(TokenKind::pu_equal)) + return std::nullopt; + + auto Filter = parseSamplerFilter(); + if (!Filter.has_value()) + return std::nullopt; + Params.Filter = Filter; + } + // `addressU` `=` TEXTURE_ADDRESS if (tryConsumeExpectedToken(TokenKind::kw_addressU)) { if (Params.AddressU.has_value()) { @@ -989,6 +1009,32 @@ RootSignatureParser::parseShaderVisibility() { return std::nullopt; } +std::optional<llvm::hlsl::rootsig::SamplerFilter> +RootSignatureParser::parseSamplerFilter() { + assert(CurToken.TokKind == TokenKind::pu_equal && + "Expects to only be invoked starting at given keyword"); + + TokenKind Expected[] = { +#define FILTER_ENUM(NAME, LIT) TokenKind::en_##NAME, +#include "clang/Lex/HLSLRootSignatureTokenKinds.def" + }; + + if (!tryConsumeExpectedToken(Expected)) + return std::nullopt; + + switch (CurToken.TokKind) { +#define FILTER_ENUM(NAME, LIT) \ + case TokenKind::en_##NAME: \ + return SamplerFilter::NAME; \ + break; +#include "clang/Lex/HLSLRootSignatureTokenKinds.def" + default: + llvm_unreachable("Switch for consumed enum token was not provided"); + } + + return std::nullopt; +} + std::optional<llvm::hlsl::rootsig::TextureAddressMode> RootSignatureParser::parseTextureAddressMode() { assert(CurToken.TokKind == TokenKind::pu_equal && diff --git a/clang/unittests/Lex/LexHLSLRootSignatureTest.cpp b/clang/unittests/Lex/LexHLSLRootSignatureTest.cpp index 943a31a08604c..b5bd233c52557 100644 --- a/clang/unittests/Lex/LexHLSLRootSignatureTest.cpp +++ b/clang/unittests/Lex/LexHLSLRootSignatureTest.cpp @@ -136,7 +136,7 @@ TEST_F(LexHLSLRootSignatureTest, ValidLexAllTokensTest) { space visibility flags numDescriptors offset - mipLODBias addressU addressV addressW + filter mipLODBias addressU addressV addressW maxAnisotropy comparisonFunc borderColor minLOD maxLOD @@ -171,6 +171,43 @@ TEST_F(LexHLSLRootSignatureTest, ValidLexAllTokensTest) { shader_visibility_amplification shader_visibility_mesh + FILTER_MIN_MAG_MIP_POINT + FILTER_MIN_MAG_POINT_MIP_LINEAR + FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT + FILTER_MIN_POINT_MAG_MIP_LINEAR + FILTER_MIN_LINEAR_MAG_MIP_POINT + FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR + FILTER_MIN_MAG_LINEAR_MIP_POINT + FILTER_MIN_MAG_MIP_LINEAR + FILTER_ANISOTROPIC + FILTER_COMPARISON_MIN_MAG_MIP_POINT + FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR + FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT + FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR + FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT + FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR + FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT + FILTER_COMPARISON_MIN_MAG_MIP_LINEAR + FILTER_COMPARISON_ANISOTROPIC + FILTER_MINIMUM_MIN_MAG_MIP_POINT + FILTER_MINIMUM_MIN_MAG_POINT_MIP_LINEAR + FILTER_MINIMUM_MIN_POINT_MAG_LINEAR_MIP_POINT + FILTER_MINIMUM_MIN_POINT_MAG_MIP_LINEAR + FILTER_MINIMUM_MIN_LINEAR_MAG_MIP_POINT + FILTER_MINIMUM_MIN_LINEAR_MAG_POINT_MIP_LINEAR + FILTER_MINIMUM_MIN_MAG_LINEAR_MIP_POINT + FILTER_MINIMUM_MIN_MAG_MIP_LINEAR + FILTER_MINIMUM_ANISOTROPIC + FILTER_MAXIMUM_MIN_MAG_MIP_POINT + FILTER_MAXIMUM_MIN_MAG_POINT_MIP_LINEAR + FILTER_MAXIMUM_MIN_POINT_MAG_LINEAR_MIP_POINT + FILTER_MAXIMUM_MIN_POINT_MAG_MIP_LINEAR + FILTER_MAXIMUM_MIN_LINEAR_MAG_MIP_POINT + FILTER_MAXIMUM_MIN_LINEAR_MAG_POINT_MIP_LINEAR + FILTER_MAXIMUM_MIN_MAG_LINEAR_MIP_POINT + FILTER_MAXIMUM_MIN_MAG_MIP_LINEAR + FILTER_MAXIMUM_ANISOTROPIC + TEXTURE_ADDRESS_WRAP TEXTURE_ADDRESS_MIRROR TEXTURE_ADDRESS_CLAMP diff --git a/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp b/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp index d45f99e06c630..1e46ee35d5d49 100644 --- a/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp +++ b/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp @@ -231,6 +231,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseStaticSamplerTest) { minLOD = 4.2f, mipLODBias = 0.23e+3, addressW = TEXTURE_ADDRESS_CLAMP, addressV = TEXTURE_ADDRESS_BORDER, + filter = FILTER_MAXIMUM_MIN_POINT_MAG_LINEAR_MIP_POINT, maxLOD = 9000, addressU = TEXTURE_ADDRESS_MIRROR, comparisonFunc = COMPARISON_NOT_EQUAL, borderColor = STATIC_BORDER_COLOR_OPAQUE_BLACK_UINT @@ -257,6 +258,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseStaticSamplerTest) { ASSERT_TRUE(std::holds_alternative<StaticSampler>(Elem)); ASSERT_EQ(std::get<StaticSampler>(Elem).Reg.ViewType, RegisterType::SReg); ASSERT_EQ(std::get<StaticSampler>(Elem).Reg.Number, 0u); + ASSERT_EQ(std::get<StaticSampler>(Elem).Filter, SamplerFilter::Anisotropic); ASSERT_EQ(std::get<StaticSampler>(Elem).AddressU, TextureAddressMode::Wrap); ASSERT_EQ(std::get<StaticSampler>(Elem).AddressV, TextureAddressMode::Wrap); ASSERT_EQ(std::get<StaticSampler>(Elem).AddressW, TextureAddressMode::Wrap); @@ -275,6 +277,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseStaticSamplerTest) { ASSERT_TRUE(std::holds_alternative<StaticSampler>(Elem)); ASSERT_EQ(std::get<StaticSampler>(Elem).Reg.ViewType, RegisterType::SReg); ASSERT_EQ(std::get<StaticSampler>(Elem).Reg.Number, 0u); + ASSERT_EQ(std::get<StaticSampler>(Elem).Filter, + SamplerFilter::MaximumMinPointMagLinearMipPoint); ASSERT_EQ(std::get<StaticSampler>(Elem).AddressU, TextureAddressMode::Mirror); ASSERT_EQ(std::get<StaticSampler>(Elem).AddressV, TextureAddressMode::Border); ASSERT_EQ(std::get<StaticSampler>(Elem).AddressW, TextureAddressMode::Clamp); diff --git a/llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h b/llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h index 68f3cb97db859..ca383a828b5cc 100644 --- a/llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h +++ b/llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h @@ -28,7 +28,10 @@ class Metadata; namespace hlsl { namespace rootsig { -// Definition of the various enumerations and flags +// Definition of the various enumerations and flags. The definitions of all +// values here correspond to their description in the d3d12.h header and are +// carried over from their values in DXC. For reference: +// https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ enum class RootFlags : uint32_t { None = 0, @@ -77,6 +80,47 @@ enum class ShaderVisibility { Mesh = 7, }; +// D3D12_FILTER enumeration: +// https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ne-d3d12-d3d12_filter +enum class SamplerFilter { + MinMagMipPoint = 0, + MinMagPointMipLinear = 0x1, + MinPointMagLinearMipPoint = 0x4, + MinPointMagMipLinear = 0x5, + MinLinearMagMipPoint = 0x10, + MinLinearMagPointMipLinear = 0x11, + MinMagLinearMipPoint = 0x14, + MinMagMipLinear = 0x15, + Anisotropic = 0x55, + ComparisonMinMagMipPoint = 0x80, + ComparisonMinMagPointMipLinear = 0x81, + ComparisonMinPointMagLinearMipPoint = 0x84, + ComparisonMinPointMagMipLinear = 0x85, + ComparisonMinLinearMagMipPoint = 0x90, + ComparisonMinLinearMagPointMipLinear = 0x91, + ComparisonMinMagLinearMipPoint = 0x94, + ComparisonMinMagMipLinear = 0x95, + ComparisonAnisotropic = 0xd5, + MinimumMinMagMipPoint = 0x100, + MinimumMinMagPointMipLinear = 0x101, + MinimumMinPointMagLinearMipPoint = 0x104, + MinimumMinPointMagMipLinear = 0x105, + MinimumMinLinearMagMipPoint = 0x110, + MinimumMinLinearMagPointMipLinear = 0x111, + MinimumMinMagLinearMipPoint = 0x114, + MinimumMinMagMipLinear = 0x115, + MinimumAnisotropic = 0x155, + MaximumMinMagMipPoint = 0x180, + MaximumMinMagPointMipLinear = 0x181, + MaximumMinPointMagLinearMipPoint = 0x184, + MaximumMinPointMagMipLinear = 0x185, + MaximumMinLinearMagMipPoint = 0x190, + MaximumMinLinearMagPointMipLinear = 0x191, + MaximumMinMagLinearMipPoint = 0x194, + MaximumMinMagMipLinear = 0x195, + MaximumAnisotropic = 0x1d5 +}; + enum class TextureAddressMode { Wrap = 1, Mirror = 2, @@ -186,6 +230,7 @@ LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, struct StaticSampler { Register Reg; + SamplerFilter Filter = SamplerFilter::Anisotropic; TextureAddressMode AddressU = TextureAddressMode::Wrap; TextureAddressMode AddressV = TextureAddressMode::Wrap; TextureAddressMode AddressW = TextureAddressMode::Wrap; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits