Skip to content

Revert "[HLSL][RootSignature] Add parsing of filter enum for StaticSampler" #142053

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

Merged
merged 1 commit into from
May 29, 2025
Merged
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
45 changes: 1 addition & 44 deletions clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@
#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
Expand Down Expand Up @@ -107,11 +104,10 @@ KEYWORD(numDescriptors)
KEYWORD(offset)

// StaticSampler Keywords:
KEYWORD(filter)
KEYWORD(mipLODBias)
KEYWORD(addressU)
KEYWORD(addressV)
KEYWORD(addressW)
KEYWORD(mipLODBias)
KEYWORD(maxAnisotropy)
KEYWORD(minLOD)
KEYWORD(maxLOD)
Expand Down Expand Up @@ -158,44 +154,6 @@ 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")
Expand All @@ -204,7 +162,6 @@ 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
Expand Down
4 changes: 1 addition & 3 deletions clang/include/clang/Parse/ParseHLSLRootSignature.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,10 @@ class RootSignatureParser {

struct ParsedStaticSamplerParams {
std::optional<llvm::hlsl::rootsig::Register> Reg;
std::optional<llvm::hlsl::rootsig::Filter> Filter;
std::optional<float> MipLODBias;
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;
Expand All @@ -129,7 +128,6 @@ 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>
Expand Down
45 changes: 0 additions & 45 deletions clang/lib/Parse/ParseHLSLRootSignature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,6 @@ 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();

Expand Down Expand Up @@ -687,23 +684,6 @@ 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()) {
Expand Down Expand Up @@ -929,31 +909,6 @@ 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 &&
Expand Down
41 changes: 2 additions & 39 deletions clang/unittests/Lex/LexHLSLRootSignatureTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ TEST_F(LexHLSLRootSignatureTest, ValidLexAllTokensTest) {
space visibility flags
numDescriptors offset

filter addressU addressV addressW
mipLODBias maxAnisotropy minLOD maxLOD
mipLODBias addressU addressV addressW
maxAnisotropy minLOD maxLOD

unbounded
DESCRIPTOR_RANGE_OFFSET_APPEND
Expand Down Expand Up @@ -170,43 +170,6 @@ 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
Expand Down
4 changes: 0 additions & 4 deletions clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ 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";
Expand All @@ -255,7 +254,6 @@ 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);
Expand All @@ -269,8 +267,6 @@ 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);
Expand Down
47 changes: 1 addition & 46 deletions llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ class Metadata;
namespace hlsl {
namespace rootsig {

// 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/
// Definition of the various enumerations and flags

enum class RootFlags : uint32_t {
None = 0,
Expand Down Expand Up @@ -79,47 +76,6 @@ enum class ShaderVisibility {
Mesh = 7,
};

// D3D12_FILTER enumeration:
// https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ne-d3d12-d3d12_filter
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,
Expand Down Expand Up @@ -209,7 +165,6 @@ raw_ostream &operator<<(raw_ostream &OS, const DescriptorTableClause &Clause);

struct StaticSampler {
Register Reg;
Filter Filter = Filter::Anisotropic;
TextureAddressMode AddressU = TextureAddressMode::Wrap;
TextureAddressMode AddressV = TextureAddressMode::Wrap;
TextureAddressMode AddressW = TextureAddressMode::Wrap;
Expand Down
Loading