-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[HLSL][RootSignature] Add parsing of filter enum for StaticSampler #140294
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
Conversation
@llvm/pr-subscribers-clang Author: Finn Plummer (inbelic) Changes
Part 5 of #126574 Full diff: https://github.com/llvm/llvm-project/pull/140294.diff 6 Files Affected:
diff --git a/clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def b/clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def
index 9b47ec57f541b..9515bc7d847fa 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
@@ -104,10 +107,11 @@ KEYWORD(numDescriptors)
KEYWORD(offset)
// StaticSampler Keywords:
-KEYWORD(mipLODBias)
+KEYWORD(filter)
KEYWORD(addressU)
KEYWORD(addressV)
KEYWORD(addressW)
+KEYWORD(mipLODBias)
KEYWORD(maxAnisotropy)
KEYWORD(minLOD)
KEYWORD(maxLOD)
@@ -154,6 +158,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")
@@ -162,6 +204,7 @@ TEXTURE_ADDRESS_MODE_ENUM(Border, "TEXTURE_ADDRESS_BORDER")
TEXTURE_ADDRESS_MODE_ENUM(MirrorOnce, "TEXTURE_ADDRESS_MIRRORONCE")
#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 9fb542ac7f163..c31b80ad696c3 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::Filter> 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<float> MinLOD;
std::optional<float> MaxLOD;
@@ -128,6 +129,7 @@ class RootSignatureParser {
/// Parsing methods of various enums
std::optional<llvm::hlsl::rootsig::ShaderVisibility> parseShaderVisibility();
+ std::optional<llvm::hlsl::rootsig::Filter> parseFilter();
std::optional<llvm::hlsl::rootsig::TextureAddressMode>
parseTextureAddressMode();
std::optional<llvm::hlsl::rootsig::RootDescriptorFlags>
diff --git a/clang/lib/Parse/ParseHLSLRootSignature.cpp b/clang/lib/Parse/ParseHLSLRootSignature.cpp
index 0268426133e5f..f77e2d4ce6981 100644
--- a/clang/lib/Parse/ParseHLSLRootSignature.cpp
+++ b/clang/lib/Parse/ParseHLSLRootSignature.cpp
@@ -381,6 +381,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();
@@ -688,6 +691,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 = parseFilter();
+ if (!Filter.has_value())
+ return std::nullopt;
+ Params.Filter = Filter;
+ }
+
// `addressU` `=` TEXTURE_ADDRESS
if (tryConsumeExpectedToken(TokenKind::kw_addressU)) {
if (Params.AddressU.has_value()) {
@@ -909,6 +929,31 @@ RootSignatureParser::parseShaderVisibility() {
return std::nullopt;
}
+std::optional<llvm::hlsl::rootsig::Filter> RootSignatureParser::parseFilter() {
+ 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 Filter::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 f0f22ccc29e9f..39872ea6b0a3e 100644
--- a/clang/unittests/Lex/LexHLSLRootSignatureTest.cpp
+++ b/clang/unittests/Lex/LexHLSLRootSignatureTest.cpp
@@ -136,8 +136,8 @@ TEST_F(LexHLSLRootSignatureTest, ValidLexAllTokensTest) {
space visibility flags
numDescriptors offset
- mipLODBias addressU addressV addressW
- maxAnisotropy minLOD maxLOD
+ filter addressU addressV addressW
+ mipLODBias maxAnisotropy minLOD maxLOD
unbounded
DESCRIPTOR_RANGE_OFFSET_APPEND
@@ -170,6 +170,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 9c0dcbd94798a..e40dd042dbdf5 100644
--- a/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp
+++ b/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp
@@ -230,6 +230,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
)
)cc";
@@ -254,6 +255,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, Filter::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);
@@ -267,6 +269,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,
+ Filter::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 bb790c022d66c..f5fa19a8fa6e9 100644
--- a/llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h
+++ b/llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h
@@ -76,6 +76,45 @@ enum class ShaderVisibility {
Mesh = 7,
};
+enum class Filter {
+ 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,
@@ -168,6 +207,7 @@ struct DescriptorTableClause {
struct StaticSampler {
Register Reg;
+ Filter Filter = Filter::Anisotropic;
TextureAddressMode AddressU = TextureAddressMode::Wrap;
TextureAddressMode AddressV = TextureAddressMode::Wrap;
TextureAddressMode AddressW = TextureAddressMode::Wrap;
|
@llvm/pr-subscribers-hlsl Author: Finn Plummer (inbelic) Changes
Part 5 of #126574 Full diff: https://github.com/llvm/llvm-project/pull/140294.diff 6 Files Affected:
diff --git a/clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def b/clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def
index 9b47ec57f541b..9515bc7d847fa 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
@@ -104,10 +107,11 @@ KEYWORD(numDescriptors)
KEYWORD(offset)
// StaticSampler Keywords:
-KEYWORD(mipLODBias)
+KEYWORD(filter)
KEYWORD(addressU)
KEYWORD(addressV)
KEYWORD(addressW)
+KEYWORD(mipLODBias)
KEYWORD(maxAnisotropy)
KEYWORD(minLOD)
KEYWORD(maxLOD)
@@ -154,6 +158,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")
@@ -162,6 +204,7 @@ TEXTURE_ADDRESS_MODE_ENUM(Border, "TEXTURE_ADDRESS_BORDER")
TEXTURE_ADDRESS_MODE_ENUM(MirrorOnce, "TEXTURE_ADDRESS_MIRRORONCE")
#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 9fb542ac7f163..c31b80ad696c3 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::Filter> 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<float> MinLOD;
std::optional<float> MaxLOD;
@@ -128,6 +129,7 @@ class RootSignatureParser {
/// Parsing methods of various enums
std::optional<llvm::hlsl::rootsig::ShaderVisibility> parseShaderVisibility();
+ std::optional<llvm::hlsl::rootsig::Filter> parseFilter();
std::optional<llvm::hlsl::rootsig::TextureAddressMode>
parseTextureAddressMode();
std::optional<llvm::hlsl::rootsig::RootDescriptorFlags>
diff --git a/clang/lib/Parse/ParseHLSLRootSignature.cpp b/clang/lib/Parse/ParseHLSLRootSignature.cpp
index 0268426133e5f..f77e2d4ce6981 100644
--- a/clang/lib/Parse/ParseHLSLRootSignature.cpp
+++ b/clang/lib/Parse/ParseHLSLRootSignature.cpp
@@ -381,6 +381,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();
@@ -688,6 +691,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 = parseFilter();
+ if (!Filter.has_value())
+ return std::nullopt;
+ Params.Filter = Filter;
+ }
+
// `addressU` `=` TEXTURE_ADDRESS
if (tryConsumeExpectedToken(TokenKind::kw_addressU)) {
if (Params.AddressU.has_value()) {
@@ -909,6 +929,31 @@ RootSignatureParser::parseShaderVisibility() {
return std::nullopt;
}
+std::optional<llvm::hlsl::rootsig::Filter> RootSignatureParser::parseFilter() {
+ 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 Filter::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 f0f22ccc29e9f..39872ea6b0a3e 100644
--- a/clang/unittests/Lex/LexHLSLRootSignatureTest.cpp
+++ b/clang/unittests/Lex/LexHLSLRootSignatureTest.cpp
@@ -136,8 +136,8 @@ TEST_F(LexHLSLRootSignatureTest, ValidLexAllTokensTest) {
space visibility flags
numDescriptors offset
- mipLODBias addressU addressV addressW
- maxAnisotropy minLOD maxLOD
+ filter addressU addressV addressW
+ mipLODBias maxAnisotropy minLOD maxLOD
unbounded
DESCRIPTOR_RANGE_OFFSET_APPEND
@@ -170,6 +170,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 9c0dcbd94798a..e40dd042dbdf5 100644
--- a/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp
+++ b/clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp
@@ -230,6 +230,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
)
)cc";
@@ -254,6 +255,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, Filter::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);
@@ -267,6 +269,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,
+ Filter::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 bb790c022d66c..f5fa19a8fa6e9 100644
--- a/llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h
+++ b/llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h
@@ -76,6 +76,45 @@ enum class ShaderVisibility {
Mesh = 7,
};
+enum class Filter {
+ 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,
@@ -168,6 +207,7 @@ struct DescriptorTableClause {
struct StaticSampler {
Register Reg;
+ Filter Filter = Filter::Anisotropic;
TextureAddressMode AddressU = TextureAddressMode::Wrap;
TextureAddressMode AddressV = TextureAddressMode::Wrap;
TextureAddressMode AddressW = TextureAddressMode::Wrap;
|
KEYWORD(mipLODBias) | ||
KEYWORD(filter) | ||
KEYWORD(addressU) | ||
KEYWORD(addressV) | ||
KEYWORD(addressW) | ||
KEYWORD(mipLODBias) | ||
KEYWORD(maxAnisotropy) | ||
KEYWORD(minLOD) | ||
KEYWORD(maxLOD) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is this list sorted? Does the order matter? If not, please just alphabetize it to simplify future additions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opted to sort them in the same order as presented in the documentation here.
Ordering doesn't matter. I will create a small separate clean-up pr to go through all the token sub-groups in this file and ensure they are ordered alphabetically. There are inconsistencies of this for the other parameter kinds.
3c9e4c2
to
4b0bcc8
Compare
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/144/builds/26427 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/181/builds/20711 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/123/builds/20377 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/10/builds/6334 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/140/builds/24085 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/133/builds/16991 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/137/builds/19469 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/33/builds/17398 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/204/builds/10849 Here is the relevant piece of the build log for the reference
|
…or StaticSampler" (#142053) The current naming of the `enum class Filter` and the Filter struct member causes ambiguity. This change will be reverted to be addressed by renaming the variable. Reverts llvm/llvm-project#140294
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/205/builds/10826 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/203/builds/12036 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/180/builds/18477 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/160/builds/18334 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/92/builds/19697 Here is the relevant piece of the build log for the reference
|
filter
Filter
enumparseFilter
Part 5 of #126574