diff --git a/samples/main.cc b/samples/main.cc index 17acb9ae57..056508e589 100644 --- a/samples/main.cc +++ b/samples/main.cc @@ -85,6 +85,7 @@ const char kUsage[] = R"(Usage: tint [options] bound_array_accessors emit_vertex_point_size first_index_offset + renamer --parse-only -- Stop after parsing the input --dump-ast -- Dump the generated AST to stdout --dawn-validation -- SPIRV outputs are validated with the same flags @@ -688,6 +689,8 @@ int main(int argc, const char** argv) { } else if (name == "first_index_offset") { transform_manager.append( std::make_unique(0, 0)); + } else if (name == "renamer") { + transform_manager.append(std::make_unique()); } else { std::cerr << "Unknown transform name: " << name << std::endl; return 1; @@ -702,14 +705,24 @@ int main(int argc, const char** argv) { break; #endif // TINT_BUILD_SPV_WRITER #if TINT_BUILD_MSL_WRITER - case Format::kMsl: + case Format::kMsl: { + tint::transform::Renamer::Config renamer_config{ + tint::transform::Renamer::Target::kMslKeywords}; + transform_manager.append( + std::make_unique(renamer_config)); transform_manager.append(std::make_unique()); break; + } #endif // TINT_BUILD_MSL_WRITER #if TINT_BUILD_HLSL_WRITER - case Format::kHlsl: + case Format::kHlsl: { + tint::transform::Renamer::Config renamer_config{ + tint::transform::Renamer::Target::kHlslKeywords}; + transform_manager.append( + std::make_unique(renamer_config)); transform_manager.append(std::make_unique()); break; + } #endif // TINT_BUILD_HLSL_WRITER default: break; diff --git a/src/transform/hlsl.cc b/src/transform/hlsl.cc index 5972a829e5..3b4bb8008e 100644 --- a/src/transform/hlsl.cc +++ b/src/transform/hlsl.cc @@ -30,575 +30,6 @@ namespace tint { namespace transform { -namespace { - -// This list is used for a binary search and must be kept in sorted order. -const char* kReservedKeywords[] = {"AddressU", - "AddressV", - "AddressW", - "AllMemoryBarrier", - "AllMemoryBarrierWithGroupSync", - "AppendStructuredBuffer", - "BINORMAL", - "BLENDINDICES", - "BLENDWEIGHT", - "BlendState", - "BorderColor", - "Buffer", - "ByteAddressBuffer", - "COLOR", - "CheckAccessFullyMapped", - "ComparisonFunc", - "CompileShader", - "ComputeShader", - "ConsumeStructuredBuffer", - "D3DCOLORtoUBYTE4", - "DEPTH", - "DepthStencilState", - "DepthStencilView", - "DeviceMemoryBarrier", - "DeviceMemroyBarrierWithGroupSync", - "DomainShader", - "EvaluateAttributeAtCentroid", - "EvaluateAttributeAtSample", - "EvaluateAttributeSnapped", - "FOG", - "Filter", - "GeometryShader", - "GetRenderTargetSampleCount", - "GetRenderTargetSamplePosition", - "GroupMemoryBarrier", - "GroupMemroyBarrierWithGroupSync", - "Hullshader", - "InputPatch", - "InterlockedAdd", - "InterlockedAnd", - "InterlockedCompareExchange", - "InterlockedCompareStore", - "InterlockedExchange", - "InterlockedMax", - "InterlockedMin", - "InterlockedOr", - "InterlockedXor", - "LineStream", - "MaxAnisotropy", - "MaxLOD", - "MinLOD", - "MipLODBias", - "NORMAL", - "NULL", - "Normal", - "OutputPatch", - "POSITION", - "POSITIONT", - "PSIZE", - "PixelShader", - "PointStream", - "Process2DQuadTessFactorsAvg", - "Process2DQuadTessFactorsMax", - "Process2DQuadTessFactorsMin", - "ProcessIsolineTessFactors", - "ProcessQuadTessFactorsAvg", - "ProcessQuadTessFactorsMax", - "ProcessQuadTessFactorsMin", - "ProcessTriTessFactorsAvg", - "ProcessTriTessFactorsMax", - "ProcessTriTessFactorsMin", - "RWBuffer", - "RWByteAddressBuffer", - "RWStructuredBuffer", - "RWTexture1D", - "RWTexture2D", - "RWTexture2DArray", - "RWTexture3D", - "RasterizerState", - "RenderTargetView", - "SV_ClipDistance", - "SV_Coverage", - "SV_CullDistance", - "SV_Depth", - "SV_DepthGreaterEqual", - "SV_DepthLessEqual", - "SV_DispatchThreadID", - "SV_DomainLocation", - "SV_GSInstanceID", - "SV_GroupID", - "SV_GroupIndex", - "SV_GroupThreadID", - "SV_InnerCoverage", - "SV_InsideTessFactor", - "SV_InstanceID", - "SV_IsFrontFace", - "SV_OutputControlPointID", - "SV_Position", - "SV_PrimitiveID", - "SV_RenderTargetArrayIndex", - "SV_SampleIndex", - "SV_StencilRef", - "SV_Target", - "SV_TessFactor", - "SV_VertexArrayIndex", - "SV_VertexID", - "Sampler", - "Sampler1D", - "Sampler2D", - "Sampler3D", - "SamplerCUBE", - "StructuredBuffer", - "TANGENT", - "TESSFACTOR", - "TEXCOORD", - "Texcoord", - "Texture", - "Texture1D", - "Texture2D", - "Texture2DArray", - "Texture2DMS", - "Texture2DMSArray", - "Texture3D", - "TextureCube", - "TextureCubeArray", - "TriangleStream", - "VFACE", - "VPOS", - "VertexShader", - "abort", - "allow_uav_condition", - "asdouble", - "asfloat", - "asint", - "asm", - "asm_fragment", - "asuint", - "auto", - "bool", - "bool1", - "bool1x1", - "bool1x2", - "bool1x3", - "bool1x4", - "bool2", - "bool2x1", - "bool2x2", - "bool2x3", - "bool2x4", - "bool3", - "bool3x1", - "bool3x2", - "bool3x3", - "bool3x4", - "bool4", - "bool4x1", - "bool4x2", - "bool4x3", - "bool4x4", - "branch", - "break", - "call", - "case", - "catch", - "cbuffer", - "centroid", - "char", - "class", - "clip", - "column_major", - "compile_fragment", - "const", - "const_cast", - "continue", - "countbits", - "ddx", - "ddx_coarse", - "ddx_fine", - "ddy", - "ddy_coarse", - "ddy_fine", - "degrees", - "delete", - "discard", - "do", - "double", - "double1", - "double1x1", - "double1x2", - "double1x3", - "double1x4", - "double2", - "double2x1", - "double2x2", - "double2x3", - "double2x4", - "double3", - "double3x1", - "double3x2", - "double3x3", - "double3x4", - "double4", - "double4x1", - "double4x2", - "double4x3", - "double4x4", - "dst", - "dword", - "dword1", - "dword1x1", - "dword1x2", - "dword1x3", - "dword1x4", - "dword2", - "dword2x1", - "dword2x2", - "dword2x3", - "dword2x4", - "dword3", - "dword3x1", - "dword3x2", - "dword3x3", - "dword3x4", - "dword4", - "dword4x1", - "dword4x2", - "dword4x3", - "dword4x4", - "dynamic_cast", - "else", - "enum", - "errorf", - "explicit", - "export", - "extern", - "f16to32", - "f32tof16", - "false", - "fastopt", - "firstbithigh", - "firstbitlow", - "flatten", - "float", - "float1", - "float1x1", - "float1x2", - "float1x3", - "float1x4", - "float2", - "float2x1", - "float2x2", - "float2x3", - "float2x4", - "float3", - "float3x1", - "float3x2", - "float3x3", - "float3x4", - "float4", - "float4x1", - "float4x2", - "float4x3", - "float4x4", - "fmod", - "for", - "forcecase", - "frac", - "friend", - "fxgroup", - "goto", - "groupshared", - "half", - "half1", - "half1x1", - "half1x2", - "half1x3", - "half1x4", - "half2", - "half2x1", - "half2x2", - "half2x3", - "half2x4", - "half3", - "half3x1", - "half3x2", - "half3x3", - "half3x4", - "half4", - "half4x1", - "half4x2", - "half4x3", - "half4x4", - "if", - "in", - "inline", - "inout", - "int", - "int1", - "int1x1", - "int1x2", - "int1x3", - "int1x4", - "int2", - "int2x1", - "int2x2", - "int2x3", - "int2x4", - "int3", - "int3x1", - "int3x2", - "int3x3", - "int3x4", - "int4", - "int4x1", - "int4x2", - "int4x3", - "int4x4", - "interface", - "isfinite", - "isinf", - "isnan", - "lerp", - "lineadj", - "linear", - "lit", - "log10", - "long", - "loop", - "mad", - "matrix", - "min10float", - "min10float1", - "min10float1x1", - "min10float1x2", - "min10float1x3", - "min10float1x4", - "min10float2", - "min10float2x1", - "min10float2x2", - "min10float2x3", - "min10float2x4", - "min10float3", - "min10float3x1", - "min10float3x2", - "min10float3x3", - "min10float3x4", - "min10float4", - "min10float4x1", - "min10float4x2", - "min10float4x3", - "min10float4x4", - "min12int", - "min12int1", - "min12int1x1", - "min12int1x2", - "min12int1x3", - "min12int1x4", - "min12int2", - "min12int2x1", - "min12int2x2", - "min12int2x3", - "min12int2x4", - "min12int3", - "min12int3x1", - "min12int3x2", - "min12int3x3", - "min12int3x4", - "min12int4", - "min12int4x1", - "min12int4x2", - "min12int4x3", - "min12int4x4", - "min16float", - "min16float1", - "min16float1x1", - "min16float1x2", - "min16float1x3", - "min16float1x4", - "min16float2", - "min16float2x1", - "min16float2x2", - "min16float2x3", - "min16float2x4", - "min16float3", - "min16float3x1", - "min16float3x2", - "min16float3x3", - "min16float3x4", - "min16float4", - "min16float4x1", - "min16float4x2", - "min16float4x3", - "min16float4x4", - "min16int", - "min16int1", - "min16int1x1", - "min16int1x2", - "min16int1x3", - "min16int1x4", - "min16int2", - "min16int2x1", - "min16int2x2", - "min16int2x3", - "min16int2x4", - "min16int3", - "min16int3x1", - "min16int3x2", - "min16int3x3", - "min16int3x4", - "min16int4", - "min16int4x1", - "min16int4x2", - "min16int4x3", - "min16int4x4", - "min16uint", - "min16uint1", - "min16uint1x1", - "min16uint1x2", - "min16uint1x3", - "min16uint1x4", - "min16uint2", - "min16uint2x1", - "min16uint2x2", - "min16uint2x3", - "min16uint2x4", - "min16uint3", - "min16uint3x1", - "min16uint3x2", - "min16uint3x3", - "min16uint3x4", - "min16uint4", - "min16uint4x1", - "min16uint4x2", - "min16uint4x3", - "min16uint4x4", - "msad4", - "mul", - "mutable", - "namespace", - "new", - "nointerpolation", - "noise", - "noperspective", - "numthreads", - "operator", - "out", - "packoffset", - "pass", - "pixelfragment", - "pixelshader", - "point", - "precise", - "printf", - "private", - "protected", - "public", - "radians", - "rcp", - "refract", - "register", - "reinterpret_cast", - "return", - "row_major", - "rsqrt", - "sample", - "sampler", - "sampler1D", - "sampler2D", - "sampler3D", - "samplerCUBE", - "sampler_state", - "saturate", - "shared", - "short", - "signed", - "sincos", - "sizeof", - "snorm", - "stateblock", - "stateblock_state", - "static", - "static_cast", - "string", - "struct", - "switch", - "tbuffer", - "technique", - "technique10", - "technique11", - "template", - "tex1D", - "tex1Dbias", - "tex1Dgrad", - "tex1Dlod", - "tex1Dproj", - "tex2D", - "tex2Dbias", - "tex2Dgrad", - "tex2Dlod", - "tex2Dproj", - "tex3D", - "tex3Dbias", - "tex3Dgrad", - "tex3Dlod", - "tex3Dproj", - "texCUBE", - "texCUBEbias", - "texCUBEgrad", - "texCUBElod", - "texCUBEproj", - "texture", - "texture1D", - "texture1DArray", - "texture2D", - "texture2DArray", - "texture2DMS", - "texture2DMSArray", - "texture3D", - "textureCube", - "textureCubeArray", - "this", - "throw", - "transpose", - "triangle", - "triangleadj", - "true", - "try", - "typedef", - "typename", - "uint", - "uint1", - "uint1x1", - "uint1x2", - "uint1x3", - "uint1x4", - "uint2", - "uint2x1", - "uint2x2", - "uint2x3", - "uint2x4", - "uint3", - "uint3x1", - "uint3x2", - "uint3x3", - "uint3x4", - "uint4", - "uint4x1", - "uint4x2", - "uint4x3", - "uint4x4", - "uniform", - "union", - "unorm", - "unroll", - "unsigned", - "using", - "vector", - "vertexfragment", - "vertexshader", - "virtual", - "void", - "volatile", - "while"}; - -} // namespace - Hlsl::Hlsl() = default; Hlsl::~Hlsl() = default; @@ -616,7 +47,6 @@ Transform::Output Hlsl::Run(const Program* in, const DataMap& data) { CloneContext ctx(&builder, &out.program); PromoteInitializersToConstVar(ctx); AddEmptyEntryPoint(ctx); - RenameReservedKeywords(&ctx, kReservedKeywords); ctx.Clone(); return Output{Program(std::move(builder))}; } diff --git a/src/transform/hlsl_test.cc b/src/transform/hlsl_test.cc index 1f1515bb29..1f97e4682b 100644 --- a/src/transform/hlsl_test.cc +++ b/src/transform/hlsl_test.cc @@ -14,8 +14,6 @@ #include "src/transform/hlsl.h" -#include - #include "src/transform/test_helper.h" namespace tint { @@ -291,686 +289,8 @@ fn tint_unused_entry_point() { auto got = Run(src); EXPECT_EQ(expect, str(got)); + } - -using HlslReservedKeywordTest = TransformTestWithParam; - -TEST_P(HlslReservedKeywordTest, Keywords) { - auto keyword = GetParam(); - - auto src = R"( -[[stage(fragment)]] -fn main() { - var )" + keyword + - R"( : i32; -} -)"; - - auto expect = R"( -[[stage(fragment)]] -fn main() { - var tint_)" + keyword + - R"( : i32; -} -)"; - - auto got = Run(src); - - EXPECT_EQ(expect, str(got)); -} - -TEST_P(HlslReservedKeywordTest, AttemptSymbolCollision) { - auto keyword = GetParam(); - - auto src = R"( -[[stage(fragment)]] -fn main() { - var tint_)" + - keyword + - R"( : i32; - var tint_)" + - keyword + - R"(_1 : i32; - var )" + keyword + - R"( : i32; - var tint_)" + - keyword + - R"(_2 : i32; - var tint_)" + - keyword + - R"(_3 : i32; -} -)"; - - auto expect = R"( -[[stage(fragment)]] -fn main() { - var tint_)" + keyword + - R"( : i32; - var tint_)" + keyword + - R"(_1 : i32; - var tint_)" + keyword + - R"(_2 : i32; - var tint_)" + keyword + - R"(_2_1 : i32; - var tint_)" + keyword + - R"(_3 : i32; -} -)"; - - auto got = Run(src); - - EXPECT_EQ(expect, str(got)); -} - -INSTANTIATE_TEST_SUITE_P(HlslReservedKeywordTest, - HlslReservedKeywordTest, - testing::Values("AddressU", - "AddressV", - "AddressW", - "AllMemoryBarrier", - "AllMemoryBarrierWithGroupSync", - "AppendStructuredBuffer", - "BINORMAL", - "BLENDINDICES", - "BLENDWEIGHT", - "BlendState", - "BorderColor", - "Buffer", - "ByteAddressBuffer", - "COLOR", - "CheckAccessFullyMapped", - "ComparisonFunc", - "CompileShader", - "ComputeShader", - "ConsumeStructuredBuffer", - "D3DCOLORtoUBYTE4", - "DEPTH", - "DepthStencilState", - "DepthStencilView", - "DeviceMemoryBarrier", - "DeviceMemroyBarrierWithGroupSync", - "DomainShader", - "EvaluateAttributeAtCentroid", - "EvaluateAttributeAtSample", - "EvaluateAttributeSnapped", - "FOG", - "Filter", - "GeometryShader", - "GetRenderTargetSampleCount", - "GetRenderTargetSamplePosition", - "GroupMemoryBarrier", - "GroupMemroyBarrierWithGroupSync", - "Hullshader", - "InputPatch", - "InterlockedAdd", - "InterlockedAnd", - "InterlockedCompareExchange", - "InterlockedCompareStore", - "InterlockedExchange", - "InterlockedMax", - "InterlockedMin", - "InterlockedOr", - "InterlockedXor", - "LineStream", - "MaxAnisotropy", - "MaxLOD", - "MinLOD", - "MipLODBias", - "NORMAL", - "NULL", - "Normal", - "OutputPatch", - "POSITION", - "POSITIONT", - "PSIZE", - "PixelShader", - "PointStream", - "Process2DQuadTessFactorsAvg", - "Process2DQuadTessFactorsMax", - "Process2DQuadTessFactorsMin", - "ProcessIsolineTessFactors", - "ProcessQuadTessFactorsAvg", - "ProcessQuadTessFactorsMax", - "ProcessQuadTessFactorsMin", - "ProcessTriTessFactorsAvg", - "ProcessTriTessFactorsMax", - "ProcessTriTessFactorsMin", - "RWBuffer", - "RWByteAddressBuffer", - "RWStructuredBuffer", - "RWTexture1D", - "RWTexture2D", - "RWTexture2DArray", - "RWTexture3D", - "RasterizerState", - "RenderTargetView", - "SV_ClipDistance", - "SV_Coverage", - "SV_CullDistance", - "SV_Depth", - "SV_DepthGreaterEqual", - "SV_DepthLessEqual", - "SV_DispatchThreadID", - "SV_DomainLocation", - "SV_GSInstanceID", - "SV_GroupID", - "SV_GroupIndex", - "SV_GroupThreadID", - "SV_InnerCoverage", - "SV_InsideTessFactor", - "SV_InstanceID", - "SV_IsFrontFace", - "SV_OutputControlPointID", - "SV_Position", - "SV_PrimitiveID", - "SV_RenderTargetArrayIndex", - "SV_SampleIndex", - "SV_StencilRef", - "SV_Target", - "SV_TessFactor", - "SV_VertexArrayIndex", - "SV_VertexID", - "Sampler", - "Sampler1D", - "Sampler2D", - "Sampler3D", - "SamplerCUBE", - "StructuredBuffer", - "TANGENT", - "TESSFACTOR", - "TEXCOORD", - "Texcoord", - "Texture", - "Texture1D", - "Texture2D", - "Texture2DArray", - "Texture2DMS", - "Texture2DMSArray", - "Texture3D", - "TextureCube", - "TextureCubeArray", - "TriangleStream", - "VFACE", - "VPOS", - "VertexShader", - "abort", - // "abs", // WGSL intrinsic - // "acos", // WGSL intrinsic - // "all", // WGSL intrinsic - "allow_uav_condition", - // "any", // WGSL intrinsic - "asdouble", - "asfloat", - // "asin", // WGSL intrinsic - "asint", - // "asm", // WGSL keyword - "asm_fragment", - "asuint", - // "atan", // WGSL intrinsic - // "atan2", // WGSL intrinsic - "auto", - // "bool", // WGSL keyword - "bool1", - "bool1x1", - "bool1x2", - "bool1x3", - "bool1x4", - "bool2", - "bool2x1", - "bool2x2", - "bool2x3", - "bool2x4", - "bool3", - "bool3x1", - "bool3x2", - "bool3x3", - "bool3x4", - "bool4", - "bool4x1", - "bool4x2", - "bool4x3", - "bool4x4", - "branch", - // "break", // WGSL keyword - // "call", // WGSL intrinsic - // "case", // WGSL keyword - "catch", - "cbuffer", - // "ceil", // WGSL intrinsic - "centroid", - "char", - // "clamp", // WGSL intrinsic - "class", - "clip", - "column_major", - "compile_fragment", - // "const", // WGSL keyword - "const_cast", - // "continue", // WGSL keyword - // "cos", // WGSL intrinsic - // "cosh", // WGSL intrinsic - "countbits", - // "cross", // WGSL intrinsic - "ddx", - "ddx_coarse", - "ddx_fine", - "ddy", - "ddy_coarse", - "ddy_fine", - "degrees", - "delete", - // "determinant", // WGSL intrinsic - // "discard", // WGSL keyword - // "distance", // WGSL intrinsic - // "do", // WGSL keyword - // "dot", // WGSL intrinsic - "double", - "double1", - "double1x1", - "double1x2", - "double1x3", - "double1x4", - "double2", - "double2x1", - "double2x2", - "double2x3", - "double2x4", - "double3", - "double3x1", - "double3x2", - "double3x3", - "double3x4", - "double4", - "double4x1", - "double4x2", - "double4x3", - "double4x4", - "dst", - "dword", - "dword1", - "dword1x1", - "dword1x2", - "dword1x3", - "dword1x4", - "dword2", - "dword2x1", - "dword2x2", - "dword2x3", - "dword2x4", - "dword3", - "dword3x1", - "dword3x2", - "dword3x3", - "dword3x4", - "dword4", - "dword4x1", - "dword4x2", - "dword4x3", - "dword4x4", - "dynamic_cast", - // "else", // WGSL keyword - // "enum", // WGSL keyword - "errorf", - // "exp", // WGSL intrinsic - // "exp2", // WGSL intrinsic - "explicit", - "export", - "extern", - "f16to32", - "f32tof16", - // "faceforward", // WGSL intrinsic - // "false", // WGSL keyword - "fastopt", - "firstbithigh", - "firstbitlow", - "flatten", - "float", - "float1", - "float1x1", - "float1x2", - "float1x3", - "float1x4", - "float2", - "float2x1", - "float2x2", - "float2x3", - "float2x4", - "float3", - "float3x1", - "float3x2", - "float3x3", - "float3x4", - "float4", - "float4x1", - "float4x2", - "float4x3", - "float4x4", - // "floor", // WGSL intrinsic - // "fma", // WGSL intrinsic - "fmod", - // "for", // WGSL keyword - "forcecase", - "frac", - // "frexp", // WGSL intrinsic - "friend", - // "fwidth", // WGSL intrinsic - "fxgroup", - "goto", - "groupshared", - "half", - "half1", - "half1x1", - "half1x2", - "half1x3", - "half1x4", - "half2", - "half2x1", - "half2x2", - "half2x3", - "half2x4", - "half3", - "half3x1", - "half3x2", - "half3x3", - "half3x4", - "half4", - "half4x1", - "half4x2", - "half4x3", - "half4x4", - // "if", // WGSL keyword - // "in", // WGSL keyword - "inline", - "inout", - "int", - "int1", - "int1x1", - "int1x2", - "int1x3", - "int1x4", - "int2", - "int2x1", - "int2x2", - "int2x3", - "int2x4", - "int3", - "int3x1", - "int3x2", - "int3x3", - "int3x4", - "int4", - "int4x1", - "int4x2", - "int4x3", - "int4x4", - "interface", - "isfinite", - "isinf", - "isnan", - // "ldexp", // WGSL intrinsic - // "length", // WGSL intrinsic - "lerp", - "lineadj", - "linear", - "lit", - // "log", // WGSL intrinsic - "log10", - // "log2", // WGSL intrinsic - "long", - // "loop", // WGSL keyword - "mad", - "matrix", - // "max", // WGSL intrinsic - // "min", // WGSL intrinsic - "min10float", - "min10float1", - "min10float1x1", - "min10float1x2", - "min10float1x3", - "min10float1x4", - "min10float2", - "min10float2x1", - "min10float2x2", - "min10float2x3", - "min10float2x4", - "min10float3", - "min10float3x1", - "min10float3x2", - "min10float3x3", - "min10float3x4", - "min10float4", - "min10float4x1", - "min10float4x2", - "min10float4x3", - "min10float4x4", - "min12int", - "min12int1", - "min12int1x1", - "min12int1x2", - "min12int1x3", - "min12int1x4", - "min12int2", - "min12int2x1", - "min12int2x2", - "min12int2x3", - "min12int2x4", - "min12int3", - "min12int3x1", - "min12int3x2", - "min12int3x3", - "min12int3x4", - "min12int4", - "min12int4x1", - "min12int4x2", - "min12int4x3", - "min12int4x4", - "min16float", - "min16float1", - "min16float1x1", - "min16float1x2", - "min16float1x3", - "min16float1x4", - "min16float2", - "min16float2x1", - "min16float2x2", - "min16float2x3", - "min16float2x4", - "min16float3", - "min16float3x1", - "min16float3x2", - "min16float3x3", - "min16float3x4", - "min16float4", - "min16float4x1", - "min16float4x2", - "min16float4x3", - "min16float4x4", - "min16int", - "min16int1", - "min16int1x1", - "min16int1x2", - "min16int1x3", - "min16int1x4", - "min16int2", - "min16int2x1", - "min16int2x2", - "min16int2x3", - "min16int2x4", - "min16int3", - "min16int3x1", - "min16int3x2", - "min16int3x3", - "min16int3x4", - "min16int4", - "min16int4x1", - "min16int4x2", - "min16int4x3", - "min16int4x4", - "min16uint", - "min16uint1", - "min16uint1x1", - "min16uint1x2", - "min16uint1x3", - "min16uint1x4", - "min16uint2", - "min16uint2x1", - "min16uint2x2", - "min16uint2x3", - "min16uint2x4", - "min16uint3", - "min16uint3x1", - "min16uint3x2", - "min16uint3x3", - "min16uint3x4", - "min16uint4", - "min16uint4x1", - "min16uint4x2", - "min16uint4x3", - "min16uint4x4", - // "modf", // WGSL intrinsic - "msad4", - "mul", - "mutable", - "namespace", - "new", - "nointerpolation", - "noise", - "noperspective", - // "normalize", // WGSL intrinsic - "numthreads", - "operator", - // "out", // WGSL keyword - "packoffset", - "pass", - "pixelfragment", - "pixelshader", - "point", - // "pow", // WGSL intrinsic - "precise", - "printf", - // "private", // WGSL keyword - "protected", - "public", - "radians", - "rcp", - // "reflect", // WGSL intrinsic - "refract", - "register", - "reinterpret_cast", - // "return", // WGSL keyword - // "reversebits", // WGSL intrinsic - // "round", // WGSL intrinsic - "row_major", - "rsqrt", - "sample", - "sampler1D", - "sampler2D", - "sampler3D", - "samplerCUBE", - "sampler_state", - "saturate", - "shared", - "short", - // "sign", // WGSL intrinsic - "signed", - // "sin", // WGSL intrinsic - "sincos", - // "sinh", // WGSL intrinsic - "sizeof", - // "smoothstep", // WGSL intrinsic - "snorm", - // "sqrt", // WGSL intrinsic - "stateblock", - "stateblock_state", - "static", - "static_cast", - // "step", // WGSL intrinsic - "string", - // "struct", // WGSL keyword - // "switch", // WGSL keyword - // "tan", // WGSL intrinsic - // "tanh", // WGSL intrinsic - "tbuffer", - "technique", - "technique10", - "technique11", - "template", - "tex1D", - "tex1Dbias", - "tex1Dgrad", - "tex1Dlod", - "tex1Dproj", - "tex2D", - "tex2Dbias", - "tex2Dgrad", - "tex2Dlod", - "tex2Dproj", - "tex3D", - "tex3Dbias", - "tex3Dgrad", - "tex3Dlod", - "tex3Dproj", - "texCUBE", - "texCUBEbias", - "texCUBEgrad", - "texCUBElod", - "texCUBEproj", - "texture", - "texture1D", - "texture1DArray", - "texture2D", - "texture2DArray", - "texture2DMS", - "texture2DMSArray", - "texture3D", - "textureCube", - "textureCubeArray", - "this", - "throw", - "transpose", - "triangle", - "triangleadj", - // "true", // WGSL keyword - // "trunc", // WGSL intrinsic - "try", - // "typedef", // WGSL keyword - "typename", - "uint", - "uint1", - "uint1x1", - "uint1x2", - "uint1x3", - "uint1x4", - "uint2", - "uint2x1", - "uint2x2", - "uint2x3", - "uint2x4", - "uint3", - "uint3x1", - "uint3x2", - "uint3x3", - "uint3x4", - "uint4", - "uint4x1", - "uint4x2", - "uint4x3", - "uint4x4", - // "uniform", // WGSL keyword - "union", - "unorm", - "unroll", - "unsigned", - "using", - "vector", - "vertexfragment", - "vertexshader", - "virtual", - // "void", // WGSL keyword - "volatile", - "while")); - } // namespace } // namespace transform } // namespace tint diff --git a/src/transform/msl.cc b/src/transform/msl.cc index 3624b5d688..5f01358b90 100644 --- a/src/transform/msl.cc +++ b/src/transform/msl.cc @@ -16,251 +16,11 @@ #include -#include "src/program_builder.h" #include "src/transform/canonicalize_entry_point_io.h" #include "src/transform/manager.h" namespace tint { namespace transform { -namespace { -// This list is used for a binary search and must be kept in sorted order. -const char* kReservedKeywords[] = {"access", - "alignas", - "alignof", - "and", - "and_eq", - "array", - "array_ref", - "as_type", - "asm", - "atomic", - "atomic_bool", - "atomic_int", - "atomic_uint", - "auto", - "bitand", - "bitor", - "bool", - "bool2", - "bool3", - "bool4", - "break", - "buffer", - "case", - "catch", - "char", - "char16_t", - "char2", - "char3", - "char32_t", - "char4", - "class", - "compl", - "const", - "const_cast", - "const_reference", - "constant", - "constexpr", - "continue", - "decltype", - "default", - "delete", - "depth2d", - "depth2d_array", - "depth2d_ms", - "depth2d_ms_array", - "depthcube", - "depthcube_array", - "device", - "discard_fragment", - "do", - "double", - "dynamic_cast", - "else", - "enum", - "explicit", - "extern", - "false", - "final", - "float", - "float2", - "float2x2", - "float2x3", - "float2x4", - "float3", - "float3x2", - "float3x3", - "float3x4", - "float4", - "float4x2", - "float4x3", - "float4x4", - "for", - "fragment", - "friend", - "goto", - "half", - "half2", - "half2x2", - "half2x3", - "half2x4", - "half3", - "half3x2", - "half3x3", - "half3x4", - "half4", - "half4x2", - "half4x3", - "half4x4", - "if", - "imageblock", - "inline", - "int", - "int16_t", - "int2", - "int3", - "int32_t", - "int4", - "int64_t", - "int8_t", - "kernel", - "long", - "long2", - "long3", - "long4", - "main", - "metal", - "mutable", - "namespace", - "new", - "noexcept", - "not", - "not_eq", - "nullptr", - "operator", - "or", - "or_eq", - "override", - "packed_bool2", - "packed_bool3", - "packed_bool4", - "packed_char2", - "packed_char3", - "packed_char4", - "packed_float2", - "packed_float3", - "packed_float4", - "packed_half2", - "packed_half3", - "packed_half4", - "packed_int2", - "packed_int3", - "packed_int4", - "packed_short2", - "packed_short3", - "packed_short4", - "packed_uchar2", - "packed_uchar3", - "packed_uchar4", - "packed_uint2", - "packed_uint3", - "packed_uint4", - "packed_ushort2", - "packed_ushort3", - "packed_ushort4", - "patch_control_point", - "private", - "protected", - "ptrdiff_t", - "public", - "r16snorm", - "r16unorm", - "r8unorm", - "reference", - "register", - "reinterpret_cast", - "return", - "rg11b10f", - "rg16snorm", - "rg16unorm", - "rg8snorm", - "rg8unorm", - "rgb10a2", - "rgb9e5", - "rgba16snorm", - "rgba16unorm", - "rgba8snorm", - "rgba8unorm", - "sampler", - "short", - "short2", - "short3", - "short4", - "signed", - "size_t", - "sizeof", - "srgba8unorm", - "static", - "static_assert", - "static_cast", - "struct", - "switch", - "template", - "texture", - "texture1d", - "texture1d_array", - "texture2d", - "texture2d_array", - "texture2d_ms", - "texture2d_ms_array", - "texture3d", - "texture_buffer", - "texturecube", - "texturecube_array", - "this", - "thread", - "thread_local", - "threadgroup", - "threadgroup_imageblock", - "throw", - "true", - "try", - "typedef", - "typeid", - "typename", - "uchar", - "uchar2", - "uchar3", - "uchar4", - "uint", - "uint16_t", - "uint2", - "uint3", - "uint32_t", - "uint4", - "uint64_t", - "uint8_t", - "ulong2", - "ulong3", - "ulong4", - "uniform", - "union", - "unsigned", - "ushort", - "ushort2", - "ushort3", - "ushort4", - "using", - "vec", - "vertex", - "virtual", - "void", - "volatile", - "wchar_t", - "while", - "xor", - "xor_eq"}; -} // namespace Msl::Msl() = default; Msl::~Msl() = default; @@ -272,12 +32,7 @@ Transform::Output Msl::Run(const Program* in, const DataMap& data) { if (!out.program.IsValid()) { return out; } - - ProgramBuilder builder; - CloneContext ctx(&builder, &out.program); - RenameReservedKeywords(&ctx, kReservedKeywords); - ctx.Clone(); - return Output{Program(std::move(builder))}; + return Output{Program(std::move(out.program))}; } } // namespace transform diff --git a/src/transform/msl_test.cc b/src/transform/msl_test.cc index a93df302f2..d257b2bddd 100644 --- a/src/transform/msl_test.cc +++ b/src/transform/msl_test.cc @@ -14,363 +14,12 @@ #include "src/transform/msl.h" -#include - #include "src/transform/test_helper.h" namespace tint { namespace transform { namespace { -using MslReservedKeywordTest = TransformTestWithParam; - -TEST_F(MslReservedKeywordTest, Basic) { - auto* src = R"( -struct class { - delete : i32; -}; - -[[stage(fragment)]] -fn main() { - var foo : i32; - var half : f32; - var half1 : f32; - var half2 : f32; - var tint_half2 : f32; -} -)"; - - auto* expect = R"( -struct tint_class { - tint_delete : i32; -}; - -[[stage(fragment)]] -fn tint_main() { - var foo : i32; - var tint_half : f32; - var half1 : f32; - var tint_half2 : f32; - var tint_half2_1 : f32; -} -)"; - - auto got = Run(src); - - EXPECT_EQ(expect, str(got)); -} - -TEST_P(MslReservedKeywordTest, Keywords) { - auto keyword = GetParam(); - - auto src = R"( -[[stage(fragment)]] -fn main() { - var )" + keyword + - R"( : i32; -} -)"; - - auto expect = R"( -[[stage(fragment)]] -fn tint_main() { - var tint_)" + keyword + - R"( : i32; -} -)"; - - auto got = Run(src); - - EXPECT_EQ(expect, str(got)); -} - -TEST_P(MslReservedKeywordTest, AttemptSymbolCollision) { - auto keyword = GetParam(); - - auto src = R"( -[[stage(fragment)]] -fn frag_main() { - var tint_)" + - keyword + - R"( : i32; - var tint_)" + - keyword + - R"(_1 : i32; - var )" + keyword + - R"( : i32; - var tint_)" + - keyword + - R"(_2 : i32; - var tint_)" + - keyword + - R"(_3 : i32; -} -)"; - - auto expect = R"( -[[stage(fragment)]] -fn frag_main() { - var tint_)" + keyword + - R"( : i32; - var tint_)" + keyword + - R"(_1 : i32; - var tint_)" + keyword + - R"(_2 : i32; - var tint_)" + keyword + - R"(_2_1 : i32; - var tint_)" + keyword + - R"(_3 : i32; -} -)"; - - auto got = Run(src); - - EXPECT_EQ(expect, str(got)); -} - -INSTANTIATE_TEST_SUITE_P(MslReservedKeywordTest, - MslReservedKeywordTest, - testing::Values( - // c++14 spec - "alignas", - "alignof", - "and", - "and_eq", - // "asm", // Also reserved in WGSL - "auto", - "bitand", - "bitor", - // "bool", // Also used in WGSL - // "break", // Also used in WGSL - // "case", // Also used in WGSL - "catch", - "char", - "char16_t", - "char32_t", - "class", - "compl", - // "const", // Also used in WGSL - "const_cast", - "constexpr", - // "continue", // Also used in WGSL - "decltype", - // "default", // Also used in WGSL - "delete", - // "do", // Also used in WGSL - "double", - "dynamic_cast", - // "else", // Also used in WGSL - // "enum", // Also used in WGSL - "explicit", - "extern", - // "false", // Also used in WGSL - "final", - "float", - // "for", // Also used in WGSL - "friend", - "goto", - // "if", // Also used in WGSL - "inline", - "int", - "long", - "mutable", - "namespace", - "new", - "noexcept", - "not", - "not_eq", - "nullptr", - "operator", - "or", - "or_eq", - "override", - // "private", // Also used in WGSL - "protected", - "public", - "register", - "reinterpret_cast", - // "return", // Also used in WGSL - "short", - "signed", - "sizeof", - "static", - "static_assert", - "static_cast", - // "struct", // Also used in WGSL - // "switch", // Also used in WGSL - "template", - "this", - "thread_local", - "throw", - // "true", // Also used in WGSL - "try", - // "typedef", // Also used in WGSL - "typeid", - "typename", - "union", - "unsigned", - "using", - "virtual", - // "void", // Also used in WGSL - "volatile", - "wchar_t", - "while", - "xor", - "xor_eq", - - // Metal Spec - "access", - // "array", // Also used in WGSL - "array_ref", - "as_type", - "atomic", - "atomic_bool", - "atomic_int", - "atomic_uint", - "bool2", - "bool3", - "bool4", - "buffer", - "char2", - "char3", - "char4", - "const_reference", - "constant", - "depth2d", - "depth2d_array", - "depth2d_ms", - "depth2d_ms_array", - "depthcube", - "depthcube_array", - "device", - "discard_fragment", - "float2", - "float2x2", - "float2x3", - "float2x4", - "float3", - "float3x2", - "float3x3", - "float3x4", - "float4", - "float4x2", - "float4x3", - "float4x4", - "fragment", - "half", - "half2", - "half2x2", - "half2x3", - "half2x4", - "half3", - "half3x2", - "half3x3", - "half3x4", - "half4", - "half4x2", - "half4x3", - "half4x4", - "imageblock", - "int16_t", - "int2", - "int3", - "int32_t", - "int4", - "int64_t", - "int8_t", - "kernel", - "long2", - "long3", - "long4", - "main", // No functions called main - "metal", // The namespace - "packed_bool2", - "packed_bool3", - "packed_bool4", - "packed_char2", - "packed_char3", - "packed_char4", - "packed_float2", - "packed_float3", - "packed_float4", - "packed_half2", - "packed_half3", - "packed_half4", - "packed_int2", - "packed_int3", - "packed_int4", - "packed_short2", - "packed_short3", - "packed_short4", - "packed_uchar2", - "packed_uchar3", - "packed_uchar4", - "packed_uint2", - "packed_uint3", - "packed_uint4", - "packed_ushort2", - "packed_ushort3", - "packed_ushort4", - "patch_control_point", - "ptrdiff_t", - "r16snorm", - "r16unorm", - // "r8unorm", // Also used in WGSL - "reference", - "rg11b10f", - "rg16snorm", - "rg16unorm", - // "rg8snorm", // Also used in WGSL - // "rg8unorm", // Also used in WGSL - "rgb10a2", - "rgb9e5", - "rgba16snorm", - "rgba16unorm", - // "rgba8snorm", // Also used in WGSL - // "rgba8unorm", // Also used in WGSL - // "sampler", // Also used in WGSL - "short2", - "short3", - "short4", - "size_t", - "srgba8unorm", - "texture", - "texture1d", - "texture1d_array", - "texture2d", - "texture2d_array", - "texture2d_ms", - "texture2d_ms_array", - "texture3d", - "texture_buffer", - "texturecube", - "texturecube_array", - "thread", - "threadgroup", - "threadgroup_imageblock", - "uchar", - "uchar2", - "uchar3", - "uchar4", - "uint", - "uint16_t", - "uint2", - "uint3", - "uint32_t", - "uint4", - "uint64_t", - "uint8_t", - "ulong2", - "ulong3", - "ulong4", - // "uniform", // Also used in WGSL - "ushort", - "ushort2", - "ushort3", - "ushort4", - "vec", - "vertex")); - } // namespace } // namespace transform } // namespace tint diff --git a/src/transform/renamer.cc b/src/transform/renamer.cc index b707010578..07f773d264 100644 --- a/src/transform/renamer.cc +++ b/src/transform/renamer.cc @@ -27,6 +27,813 @@ TINT_INSTANTIATE_TYPEINFO(tint::transform::Renamer::Data); namespace tint { namespace transform { +namespace { + +// This list is used for a binary search and must be kept in sorted order. +const char* kReservedKeywordsHLSL[] = {"AddressU", + "AddressV", + "AddressW", + "AllMemoryBarrier", + "AllMemoryBarrierWithGroupSync", + "AppendStructuredBuffer", + "BINORMAL", + "BLENDINDICES", + "BLENDWEIGHT", + "BlendState", + "BorderColor", + "Buffer", + "ByteAddressBuffer", + "COLOR", + "CheckAccessFullyMapped", + "ComparisonFunc", + "CompileShader", + "ComputeShader", + "ConsumeStructuredBuffer", + "D3DCOLORtoUBYTE4", + "DEPTH", + "DepthStencilState", + "DepthStencilView", + "DeviceMemoryBarrier", + "DeviceMemroyBarrierWithGroupSync", + "DomainShader", + "EvaluateAttributeAtCentroid", + "EvaluateAttributeAtSample", + "EvaluateAttributeSnapped", + "FOG", + "Filter", + "GeometryShader", + "GetRenderTargetSampleCount", + "GetRenderTargetSamplePosition", + "GroupMemoryBarrier", + "GroupMemroyBarrierWithGroupSync", + "Hullshader", + "InputPatch", + "InterlockedAdd", + "InterlockedAnd", + "InterlockedCompareExchange", + "InterlockedCompareStore", + "InterlockedExchange", + "InterlockedMax", + "InterlockedMin", + "InterlockedOr", + "InterlockedXor", + "LineStream", + "MaxAnisotropy", + "MaxLOD", + "MinLOD", + "MipLODBias", + "NORMAL", + "NULL", + "Normal", + "OutputPatch", + "POSITION", + "POSITIONT", + "PSIZE", + "PixelShader", + "PointStream", + "Process2DQuadTessFactorsAvg", + "Process2DQuadTessFactorsMax", + "Process2DQuadTessFactorsMin", + "ProcessIsolineTessFactors", + "ProcessQuadTessFactorsAvg", + "ProcessQuadTessFactorsMax", + "ProcessQuadTessFactorsMin", + "ProcessTriTessFactorsAvg", + "ProcessTriTessFactorsMax", + "ProcessTriTessFactorsMin", + "RWBuffer", + "RWByteAddressBuffer", + "RWStructuredBuffer", + "RWTexture1D", + "RWTexture2D", + "RWTexture2DArray", + "RWTexture3D", + "RasterizerState", + "RenderTargetView", + "SV_ClipDistance", + "SV_Coverage", + "SV_CullDistance", + "SV_Depth", + "SV_DepthGreaterEqual", + "SV_DepthLessEqual", + "SV_DispatchThreadID", + "SV_DomainLocation", + "SV_GSInstanceID", + "SV_GroupID", + "SV_GroupIndex", + "SV_GroupThreadID", + "SV_InnerCoverage", + "SV_InsideTessFactor", + "SV_InstanceID", + "SV_IsFrontFace", + "SV_OutputControlPointID", + "SV_Position", + "SV_PrimitiveID", + "SV_RenderTargetArrayIndex", + "SV_SampleIndex", + "SV_StencilRef", + "SV_Target", + "SV_TessFactor", + "SV_VertexArrayIndex", + "SV_VertexID", + "Sampler", + "Sampler1D", + "Sampler2D", + "Sampler3D", + "SamplerCUBE", + "StructuredBuffer", + "TANGENT", + "TESSFACTOR", + "TEXCOORD", + "Texcoord", + "Texture", + "Texture1D", + "Texture2D", + "Texture2DArray", + "Texture2DMS", + "Texture2DMSArray", + "Texture3D", + "TextureCube", + "TextureCubeArray", + "TriangleStream", + "VFACE", + "VPOS", + "VertexShader", + "abort", + "allow_uav_condition", + "asdouble", + "asfloat", + "asint", + "asm", + "asm_fragment", + "asuint", + "auto", + "bool", + "bool1", + "bool1x1", + "bool1x2", + "bool1x3", + "bool1x4", + "bool2", + "bool2x1", + "bool2x2", + "bool2x3", + "bool2x4", + "bool3", + "bool3x1", + "bool3x2", + "bool3x3", + "bool3x4", + "bool4", + "bool4x1", + "bool4x2", + "bool4x3", + "bool4x4", + "branch", + "break", + "call", + "case", + "catch", + "cbuffer", + "centroid", + "char", + "class", + "clip", + "column_major", + "compile_fragment", + "const", + "const_cast", + "continue", + "countbits", + "ddx", + "ddx_coarse", + "ddx_fine", + "ddy", + "ddy_coarse", + "ddy_fine", + "degrees", + "delete", + "discard", + "do", + "double", + "double1", + "double1x1", + "double1x2", + "double1x3", + "double1x4", + "double2", + "double2x1", + "double2x2", + "double2x3", + "double2x4", + "double3", + "double3x1", + "double3x2", + "double3x3", + "double3x4", + "double4", + "double4x1", + "double4x2", + "double4x3", + "double4x4", + "dst", + "dword", + "dword1", + "dword1x1", + "dword1x2", + "dword1x3", + "dword1x4", + "dword2", + "dword2x1", + "dword2x2", + "dword2x3", + "dword2x4", + "dword3", + "dword3x1", + "dword3x2", + "dword3x3", + "dword3x4", + "dword4", + "dword4x1", + "dword4x2", + "dword4x3", + "dword4x4", + "dynamic_cast", + "else", + "enum", + "errorf", + "explicit", + "export", + "extern", + "f16to32", + "f32tof16", + "false", + "fastopt", + "firstbithigh", + "firstbitlow", + "flatten", + "float", + "float1", + "float1x1", + "float1x2", + "float1x3", + "float1x4", + "float2", + "float2x1", + "float2x2", + "float2x3", + "float2x4", + "float3", + "float3x1", + "float3x2", + "float3x3", + "float3x4", + "float4", + "float4x1", + "float4x2", + "float4x3", + "float4x4", + "fmod", + "for", + "forcecase", + "frac", + "friend", + "fxgroup", + "goto", + "groupshared", + "half", + "half1", + "half1x1", + "half1x2", + "half1x3", + "half1x4", + "half2", + "half2x1", + "half2x2", + "half2x3", + "half2x4", + "half3", + "half3x1", + "half3x2", + "half3x3", + "half3x4", + "half4", + "half4x1", + "half4x2", + "half4x3", + "half4x4", + "if", + "in", + "inline", + "inout", + "int", + "int1", + "int1x1", + "int1x2", + "int1x3", + "int1x4", + "int2", + "int2x1", + "int2x2", + "int2x3", + "int2x4", + "int3", + "int3x1", + "int3x2", + "int3x3", + "int3x4", + "int4", + "int4x1", + "int4x2", + "int4x3", + "int4x4", + "interface", + "isfinite", + "isinf", + "isnan", + "lerp", + "lineadj", + "linear", + "lit", + "log10", + "long", + "loop", + "mad", + "matrix", + "min10float", + "min10float1", + "min10float1x1", + "min10float1x2", + "min10float1x3", + "min10float1x4", + "min10float2", + "min10float2x1", + "min10float2x2", + "min10float2x3", + "min10float2x4", + "min10float3", + "min10float3x1", + "min10float3x2", + "min10float3x3", + "min10float3x4", + "min10float4", + "min10float4x1", + "min10float4x2", + "min10float4x3", + "min10float4x4", + "min12int", + "min12int1", + "min12int1x1", + "min12int1x2", + "min12int1x3", + "min12int1x4", + "min12int2", + "min12int2x1", + "min12int2x2", + "min12int2x3", + "min12int2x4", + "min12int3", + "min12int3x1", + "min12int3x2", + "min12int3x3", + "min12int3x4", + "min12int4", + "min12int4x1", + "min12int4x2", + "min12int4x3", + "min12int4x4", + "min16float", + "min16float1", + "min16float1x1", + "min16float1x2", + "min16float1x3", + "min16float1x4", + "min16float2", + "min16float2x1", + "min16float2x2", + "min16float2x3", + "min16float2x4", + "min16float3", + "min16float3x1", + "min16float3x2", + "min16float3x3", + "min16float3x4", + "min16float4", + "min16float4x1", + "min16float4x2", + "min16float4x3", + "min16float4x4", + "min16int", + "min16int1", + "min16int1x1", + "min16int1x2", + "min16int1x3", + "min16int1x4", + "min16int2", + "min16int2x1", + "min16int2x2", + "min16int2x3", + "min16int2x4", + "min16int3", + "min16int3x1", + "min16int3x2", + "min16int3x3", + "min16int3x4", + "min16int4", + "min16int4x1", + "min16int4x2", + "min16int4x3", + "min16int4x4", + "min16uint", + "min16uint1", + "min16uint1x1", + "min16uint1x2", + "min16uint1x3", + "min16uint1x4", + "min16uint2", + "min16uint2x1", + "min16uint2x2", + "min16uint2x3", + "min16uint2x4", + "min16uint3", + "min16uint3x1", + "min16uint3x2", + "min16uint3x3", + "min16uint3x4", + "min16uint4", + "min16uint4x1", + "min16uint4x2", + "min16uint4x3", + "min16uint4x4", + "msad4", + "mul", + "mutable", + "namespace", + "new", + "nointerpolation", + "noise", + "noperspective", + "numthreads", + "operator", + "out", + "packoffset", + "pass", + "pixelfragment", + "pixelshader", + "point", + "precise", + "printf", + "private", + "protected", + "public", + "radians", + "rcp", + "refract", + "register", + "reinterpret_cast", + "return", + "row_major", + "rsqrt", + "sample", + "sampler", + "sampler1D", + "sampler2D", + "sampler3D", + "samplerCUBE", + "sampler_state", + "saturate", + "shared", + "short", + "signed", + "sincos", + "sizeof", + "snorm", + "stateblock", + "stateblock_state", + "static", + "static_cast", + "string", + "struct", + "switch", + "tbuffer", + "technique", + "technique10", + "technique11", + "template", + "tex1D", + "tex1Dbias", + "tex1Dgrad", + "tex1Dlod", + "tex1Dproj", + "tex2D", + "tex2Dbias", + "tex2Dgrad", + "tex2Dlod", + "tex2Dproj", + "tex3D", + "tex3Dbias", + "tex3Dgrad", + "tex3Dlod", + "tex3Dproj", + "texCUBE", + "texCUBEbias", + "texCUBEgrad", + "texCUBElod", + "texCUBEproj", + "texture", + "texture1D", + "texture1DArray", + "texture2D", + "texture2DArray", + "texture2DMS", + "texture2DMSArray", + "texture3D", + "textureCube", + "textureCubeArray", + "this", + "throw", + "transpose", + "triangle", + "triangleadj", + "true", + "try", + "typedef", + "typename", + "uint", + "uint1", + "uint1x1", + "uint1x2", + "uint1x3", + "uint1x4", + "uint2", + "uint2x1", + "uint2x2", + "uint2x3", + "uint2x4", + "uint3", + "uint3x1", + "uint3x2", + "uint3x3", + "uint3x4", + "uint4", + "uint4x1", + "uint4x2", + "uint4x3", + "uint4x4", + "uniform", + "union", + "unorm", + "unroll", + "unsigned", + "using", + "vector", + "vertexfragment", + "vertexshader", + "virtual", + "void", + "volatile", + "while"}; + +// This list is used for a binary search and must be kept in sorted order. +const char* kReservedKeywordsMSL[] = {"access", + "alignas", + "alignof", + "and", + "and_eq", + "array", + "array_ref", + "as_type", + "asm", + "atomic", + "atomic_bool", + "atomic_int", + "atomic_uint", + "auto", + "bitand", + "bitor", + "bool", + "bool2", + "bool3", + "bool4", + "break", + "buffer", + "case", + "catch", + "char", + "char16_t", + "char2", + "char3", + "char32_t", + "char4", + "class", + "compl", + "const", + "const_cast", + "const_reference", + "constant", + "constexpr", + "continue", + "decltype", + "default", + "delete", + "depth2d", + "depth2d_array", + "depth2d_ms", + "depth2d_ms_array", + "depthcube", + "depthcube_array", + "device", + "discard_fragment", + "do", + "double", + "dynamic_cast", + "else", + "enum", + "explicit", + "extern", + "false", + "final", + "float", + "float2", + "float2x2", + "float2x3", + "float2x4", + "float3", + "float3x2", + "float3x3", + "float3x4", + "float4", + "float4x2", + "float4x3", + "float4x4", + "for", + "fragment", + "friend", + "goto", + "half", + "half2", + "half2x2", + "half2x3", + "half2x4", + "half3", + "half3x2", + "half3x3", + "half3x4", + "half4", + "half4x2", + "half4x3", + "half4x4", + "if", + "imageblock", + "inline", + "int", + "int16_t", + "int2", + "int3", + "int32_t", + "int4", + "int64_t", + "int8_t", + "kernel", + "long", + "long2", + "long3", + "long4", + "main", + "metal", + "mutable", + "namespace", + "new", + "noexcept", + "not", + "not_eq", + "nullptr", + "operator", + "or", + "or_eq", + "override", + "packed_bool2", + "packed_bool3", + "packed_bool4", + "packed_char2", + "packed_char3", + "packed_char4", + "packed_float2", + "packed_float3", + "packed_float4", + "packed_half2", + "packed_half3", + "packed_half4", + "packed_int2", + "packed_int3", + "packed_int4", + "packed_short2", + "packed_short3", + "packed_short4", + "packed_uchar2", + "packed_uchar3", + "packed_uchar4", + "packed_uint2", + "packed_uint3", + "packed_uint4", + "packed_ushort2", + "packed_ushort3", + "packed_ushort4", + "patch_control_point", + "private", + "protected", + "ptrdiff_t", + "public", + "r16snorm", + "r16unorm", + "r8unorm", + "reference", + "register", + "reinterpret_cast", + "return", + "rg11b10f", + "rg16snorm", + "rg16unorm", + "rg8snorm", + "rg8unorm", + "rgb10a2", + "rgb9e5", + "rgba16snorm", + "rgba16unorm", + "rgba8snorm", + "rgba8unorm", + "sampler", + "short", + "short2", + "short3", + "short4", + "signed", + "size_t", + "sizeof", + "srgba8unorm", + "static", + "static_assert", + "static_cast", + "struct", + "switch", + "template", + "texture", + "texture1d", + "texture1d_array", + "texture2d", + "texture2d_array", + "texture2d_ms", + "texture2d_ms_array", + "texture3d", + "texture_buffer", + "texturecube", + "texturecube_array", + "this", + "thread", + "thread_local", + "threadgroup", + "threadgroup_imageblock", + "throw", + "true", + "try", + "typedef", + "typeid", + "typename", + "uchar", + "uchar2", + "uchar3", + "uchar4", + "uint", + "uint16_t", + "uint2", + "uint3", + "uint32_t", + "uint4", + "uint64_t", + "uint8_t", + "ulong2", + "ulong3", + "ulong4", + "uniform", + "union", + "unsigned", + "ushort", + "ushort2", + "ushort3", + "ushort4", + "using", + "vec", + "vertex", + "virtual", + "void", + "volatile", + "wchar_t", + "while", + "xor", + "xor_eq"}; + +} // namespace + Renamer::Data::Data(Remappings&& r) : remappings(std::move(r)) {} Renamer::Data::Data(const Data&) = default; @@ -70,28 +877,50 @@ Transform::Output Renamer::Run(const Program* in, const DataMap&) { Data::Remappings remappings; - switch (cfg_.method) { - case Method::kMonotonic: - ctx.ReplaceAll([&](Symbol sym_in) { - auto sym_out = ctx.dst->Symbols().New(); - remappings.emplace(ctx.src->Symbols().NameFor(sym_in), - ctx.dst->Symbols().NameFor(sym_out)); - return sym_out; - }); + ctx.ReplaceAll([&](Symbol sym_in) { + auto name_in = ctx.src->Symbols().NameFor(sym_in); + switch (cfg_.target) { + case Target::kAll: + // Always rename. + break; + case Target::kHlslKeywords: + if (!std::binary_search( + kReservedKeywordsHLSL, + kReservedKeywordsHLSL + + sizeof(kReservedKeywordsHLSL) / sizeof(const char*), + name_in)) { + // No match, just reuse the original name. + return ctx.dst->Symbols().New(name_in); + } + break; + case Target::kMslKeywords: + if (!std::binary_search( + kReservedKeywordsMSL, + kReservedKeywordsMSL + + sizeof(kReservedKeywordsMSL) / sizeof(const char*), + name_in)) { + // No match, just reuse the original name. + return ctx.dst->Symbols().New(name_in); + } + break; + } - ctx.ReplaceAll( - [&](ast::IdentifierExpression* ident) -> ast::IdentifierExpression* { - if (preserve.count(ident)) { - auto sym_in = ident->symbol(); - auto str = in->Symbols().NameFor(sym_in); - auto sym_out = out.Symbols().Register(str); - return ctx.dst->create( - ctx.Clone(ident->source()), sym_out); - } - return nullptr; // Clone ident. Uses the symbol remapping above. - }); - break; - } + auto sym_out = ctx.dst->Symbols().New(); + remappings.emplace(name_in, ctx.dst->Symbols().NameFor(sym_out)); + return sym_out; + }); + + ctx.ReplaceAll( + [&](ast::IdentifierExpression* ident) -> ast::IdentifierExpression* { + if (preserve.count(ident)) { + auto sym_in = ident->symbol(); + auto str = in->Symbols().NameFor(sym_in); + auto sym_out = out.Symbols().Register(str); + return ctx.dst->create( + ctx.Clone(ident->source()), sym_out); + } + return nullptr; // Clone ident. Uses the symbol remapping above. + }); ctx.Clone(); return Output(Program(std::move(out)), diff --git a/src/transform/renamer.h b/src/transform/renamer.h index 4670482846..55cf5dcd2e 100644 --- a/src/transform/renamer.h +++ b/src/transform/renamer.h @@ -46,17 +46,20 @@ class Renamer : public Transform { Remappings const remappings; }; - /// Method is an enumerator of renaming methods that can be used - enum class Method { - /// Every symbol will be replaced with an identifier containing a - /// monotonically incrementing integer. - kMonotonic, + /// Target is an enumerator of rename targets that can be used + enum class Target { + /// Rename every symbol. + kAll, + /// Only rename symbols that are reserved keywords in HLSL. + kHlslKeywords, + /// Only rename symbols that are reserved keywords in MSL. + kMslKeywords, }; /// Configuration options for the transform struct Config { - /// The method used for renaming symbols - Method method = Method::kMonotonic; + /// The targets to rename + Target target = Target::kAll; }; /// Constructor using a default configuration diff --git a/src/transform/renamer_test.cc b/src/transform/renamer_test.cc index 02f6378b39..e840e874bb 100644 --- a/src/transform/renamer_test.cc +++ b/src/transform/renamer_test.cc @@ -14,6 +14,8 @@ #include "src/transform/renamer.h" +#include + #include "gmock/gmock.h" #include "src/transform/test_helper.h" @@ -185,6 +187,908 @@ fn tint_symbol() -> [[builtin(position)]] vec4 { EXPECT_THAT(data->remappings, ContainerEq(expected_remappings)); } +using RenamerTestHlsl = TransformTestWithParam; +using RenamerTestMsl = TransformTestWithParam; + +TEST_P(RenamerTestHlsl, Keywords) { + auto keyword = GetParam(); + + auto src = R"( +[[stage(fragment)]] +fn frag_main() { + var )" + keyword + + R"( : i32; +} +)"; + + auto* expect = R"( +[[stage(fragment)]] +fn frag_main() { + var tint_symbol : i32; +} +)"; + + Renamer::Config config{Renamer::Target::kHlslKeywords}; + auto got = Run(src, std::make_unique(config)); + + EXPECT_EQ(expect, str(got)); +} + +TEST_P(RenamerTestMsl, Keywords) { + auto keyword = GetParam(); + + auto src = R"( +[[stage(fragment)]] +fn frag_main() { + var )" + keyword + + R"( : i32; +} +)"; + + auto* expect = R"( +[[stage(fragment)]] +fn frag_main() { + var tint_symbol : i32; +} +)"; + + Renamer::Config config{Renamer::Target::kMslKeywords}; + auto got = Run(src, std::make_unique(config)); + + EXPECT_EQ(expect, str(got)); +} + +INSTANTIATE_TEST_SUITE_P(RenamerTestHlsl, + RenamerTestHlsl, + testing::Values("AddressU", + "AddressV", + "AddressW", + "AllMemoryBarrier", + "AllMemoryBarrierWithGroupSync", + "AppendStructuredBuffer", + "BINORMAL", + "BLENDINDICES", + "BLENDWEIGHT", + "BlendState", + "BorderColor", + "Buffer", + "ByteAddressBuffer", + "COLOR", + "CheckAccessFullyMapped", + "ComparisonFunc", + "CompileShader", + "ComputeShader", + "ConsumeStructuredBuffer", + "D3DCOLORtoUBYTE4", + "DEPTH", + "DepthStencilState", + "DepthStencilView", + "DeviceMemoryBarrier", + "DeviceMemroyBarrierWithGroupSync", + "DomainShader", + "EvaluateAttributeAtCentroid", + "EvaluateAttributeAtSample", + "EvaluateAttributeSnapped", + "FOG", + "Filter", + "GeometryShader", + "GetRenderTargetSampleCount", + "GetRenderTargetSamplePosition", + "GroupMemoryBarrier", + "GroupMemroyBarrierWithGroupSync", + "Hullshader", + "InputPatch", + "InterlockedAdd", + "InterlockedAnd", + "InterlockedCompareExchange", + "InterlockedCompareStore", + "InterlockedExchange", + "InterlockedMax", + "InterlockedMin", + "InterlockedOr", + "InterlockedXor", + "LineStream", + "MaxAnisotropy", + "MaxLOD", + "MinLOD", + "MipLODBias", + "NORMAL", + "NULL", + "Normal", + "OutputPatch", + "POSITION", + "POSITIONT", + "PSIZE", + "PixelShader", + "PointStream", + "Process2DQuadTessFactorsAvg", + "Process2DQuadTessFactorsMax", + "Process2DQuadTessFactorsMin", + "ProcessIsolineTessFactors", + "ProcessQuadTessFactorsAvg", + "ProcessQuadTessFactorsMax", + "ProcessQuadTessFactorsMin", + "ProcessTriTessFactorsAvg", + "ProcessTriTessFactorsMax", + "ProcessTriTessFactorsMin", + "RWBuffer", + "RWByteAddressBuffer", + "RWStructuredBuffer", + "RWTexture1D", + "RWTexture2D", + "RWTexture2DArray", + "RWTexture3D", + "RasterizerState", + "RenderTargetView", + "SV_ClipDistance", + "SV_Coverage", + "SV_CullDistance", + "SV_Depth", + "SV_DepthGreaterEqual", + "SV_DepthLessEqual", + "SV_DispatchThreadID", + "SV_DomainLocation", + "SV_GSInstanceID", + "SV_GroupID", + "SV_GroupIndex", + "SV_GroupThreadID", + "SV_InnerCoverage", + "SV_InsideTessFactor", + "SV_InstanceID", + "SV_IsFrontFace", + "SV_OutputControlPointID", + "SV_Position", + "SV_PrimitiveID", + "SV_RenderTargetArrayIndex", + "SV_SampleIndex", + "SV_StencilRef", + "SV_Target", + "SV_TessFactor", + "SV_VertexArrayIndex", + "SV_VertexID", + "Sampler", + "Sampler1D", + "Sampler2D", + "Sampler3D", + "SamplerCUBE", + "StructuredBuffer", + "TANGENT", + "TESSFACTOR", + "TEXCOORD", + "Texcoord", + "Texture", + "Texture1D", + "Texture2D", + "Texture2DArray", + "Texture2DMS", + "Texture2DMSArray", + "Texture3D", + "TextureCube", + "TextureCubeArray", + "TriangleStream", + "VFACE", + "VPOS", + "VertexShader", + "abort", + // "abs", // WGSL intrinsic + // "acos", // WGSL intrinsic + // "all", // WGSL intrinsic + "allow_uav_condition", + // "any", // WGSL intrinsic + "asdouble", + "asfloat", + // "asin", // WGSL intrinsic + "asint", + // "asm", // WGSL keyword + "asm_fragment", + "asuint", + // "atan", // WGSL intrinsic + // "atan2", // WGSL intrinsic + "auto", + // "bool", // WGSL keyword + "bool1", + "bool1x1", + "bool1x2", + "bool1x3", + "bool1x4", + "bool2", + "bool2x1", + "bool2x2", + "bool2x3", + "bool2x4", + "bool3", + "bool3x1", + "bool3x2", + "bool3x3", + "bool3x4", + "bool4", + "bool4x1", + "bool4x2", + "bool4x3", + "bool4x4", + "branch", + // "break", // WGSL keyword + // "call", // WGSL intrinsic + // "case", // WGSL keyword + "catch", + "cbuffer", + // "ceil", // WGSL intrinsic + "centroid", + "char", + // "clamp", // WGSL intrinsic + "class", + "clip", + "column_major", + "compile_fragment", + // "const", // WGSL keyword + "const_cast", + // "continue", // WGSL keyword + // "cos", // WGSL intrinsic + // "cosh", // WGSL intrinsic + "countbits", + // "cross", // WGSL intrinsic + "ddx", + "ddx_coarse", + "ddx_fine", + "ddy", + "ddy_coarse", + "ddy_fine", + "degrees", + "delete", + // "determinant", // WGSL intrinsic + // "discard", // WGSL keyword + // "distance", // WGSL intrinsic + // "do", // WGSL keyword + // "dot", // WGSL intrinsic + "double", + "double1", + "double1x1", + "double1x2", + "double1x3", + "double1x4", + "double2", + "double2x1", + "double2x2", + "double2x3", + "double2x4", + "double3", + "double3x1", + "double3x2", + "double3x3", + "double3x4", + "double4", + "double4x1", + "double4x2", + "double4x3", + "double4x4", + "dst", + "dword", + "dword1", + "dword1x1", + "dword1x2", + "dword1x3", + "dword1x4", + "dword2", + "dword2x1", + "dword2x2", + "dword2x3", + "dword2x4", + "dword3", + "dword3x1", + "dword3x2", + "dword3x3", + "dword3x4", + "dword4", + "dword4x1", + "dword4x2", + "dword4x3", + "dword4x4", + "dynamic_cast", + // "else", // WGSL keyword + // "enum", // WGSL keyword + "errorf", + // "exp", // WGSL intrinsic + // "exp2", // WGSL intrinsic + "explicit", + "export", + "extern", + "f16to32", + "f32tof16", + // "faceforward", // WGSL intrinsic + // "false", // WGSL keyword + "fastopt", + "firstbithigh", + "firstbitlow", + "flatten", + "float", + "float1", + "float1x1", + "float1x2", + "float1x3", + "float1x4", + "float2", + "float2x1", + "float2x2", + "float2x3", + "float2x4", + "float3", + "float3x1", + "float3x2", + "float3x3", + "float3x4", + "float4", + "float4x1", + "float4x2", + "float4x3", + "float4x4", + // "floor", // WGSL intrinsic + // "fma", // WGSL intrinsic + "fmod", + // "for", // WGSL keyword + "forcecase", + "frac", + // "frexp", // WGSL intrinsic + "friend", + // "fwidth", // WGSL intrinsic + "fxgroup", + "goto", + "groupshared", + "half", + "half1", + "half1x1", + "half1x2", + "half1x3", + "half1x4", + "half2", + "half2x1", + "half2x2", + "half2x3", + "half2x4", + "half3", + "half3x1", + "half3x2", + "half3x3", + "half3x4", + "half4", + "half4x1", + "half4x2", + "half4x3", + "half4x4", + // "if", // WGSL keyword + // "in", // WGSL keyword + "inline", + "inout", + "int", + "int1", + "int1x1", + "int1x2", + "int1x3", + "int1x4", + "int2", + "int2x1", + "int2x2", + "int2x3", + "int2x4", + "int3", + "int3x1", + "int3x2", + "int3x3", + "int3x4", + "int4", + "int4x1", + "int4x2", + "int4x3", + "int4x4", + "interface", + "isfinite", + "isinf", + "isnan", + // "ldexp", // WGSL intrinsic + // "length", // WGSL intrinsic + "lerp", + "lineadj", + "linear", + "lit", + // "log", // WGSL intrinsic + "log10", + // "log2", // WGSL intrinsic + "long", + // "loop", // WGSL keyword + "mad", + "matrix", + // "max", // WGSL intrinsic + // "min", // WGSL intrinsic + "min10float", + "min10float1", + "min10float1x1", + "min10float1x2", + "min10float1x3", + "min10float1x4", + "min10float2", + "min10float2x1", + "min10float2x2", + "min10float2x3", + "min10float2x4", + "min10float3", + "min10float3x1", + "min10float3x2", + "min10float3x3", + "min10float3x4", + "min10float4", + "min10float4x1", + "min10float4x2", + "min10float4x3", + "min10float4x4", + "min12int", + "min12int1", + "min12int1x1", + "min12int1x2", + "min12int1x3", + "min12int1x4", + "min12int2", + "min12int2x1", + "min12int2x2", + "min12int2x3", + "min12int2x4", + "min12int3", + "min12int3x1", + "min12int3x2", + "min12int3x3", + "min12int3x4", + "min12int4", + "min12int4x1", + "min12int4x2", + "min12int4x3", + "min12int4x4", + "min16float", + "min16float1", + "min16float1x1", + "min16float1x2", + "min16float1x3", + "min16float1x4", + "min16float2", + "min16float2x1", + "min16float2x2", + "min16float2x3", + "min16float2x4", + "min16float3", + "min16float3x1", + "min16float3x2", + "min16float3x3", + "min16float3x4", + "min16float4", + "min16float4x1", + "min16float4x2", + "min16float4x3", + "min16float4x4", + "min16int", + "min16int1", + "min16int1x1", + "min16int1x2", + "min16int1x3", + "min16int1x4", + "min16int2", + "min16int2x1", + "min16int2x2", + "min16int2x3", + "min16int2x4", + "min16int3", + "min16int3x1", + "min16int3x2", + "min16int3x3", + "min16int3x4", + "min16int4", + "min16int4x1", + "min16int4x2", + "min16int4x3", + "min16int4x4", + "min16uint", + "min16uint1", + "min16uint1x1", + "min16uint1x2", + "min16uint1x3", + "min16uint1x4", + "min16uint2", + "min16uint2x1", + "min16uint2x2", + "min16uint2x3", + "min16uint2x4", + "min16uint3", + "min16uint3x1", + "min16uint3x2", + "min16uint3x3", + "min16uint3x4", + "min16uint4", + "min16uint4x1", + "min16uint4x2", + "min16uint4x3", + "min16uint4x4", + // "modf", // WGSL intrinsic + "msad4", + "mul", + "mutable", + "namespace", + "new", + "nointerpolation", + "noise", + "noperspective", + // "normalize", // WGSL intrinsic + "numthreads", + "operator", + // "out", // WGSL keyword + "packoffset", + "pass", + "pixelfragment", + "pixelshader", + "point", + // "pow", // WGSL intrinsic + "precise", + "printf", + // "private", // WGSL keyword + "protected", + "public", + "radians", + "rcp", + // "reflect", // WGSL intrinsic + "refract", + "register", + "reinterpret_cast", + // "return", // WGSL keyword + // "reversebits", // WGSL intrinsic + // "round", // WGSL intrinsic + "row_major", + "rsqrt", + "sample", + "sampler1D", + "sampler2D", + "sampler3D", + "samplerCUBE", + "sampler_state", + "saturate", + "shared", + "short", + // "sign", // WGSL intrinsic + "signed", + // "sin", // WGSL intrinsic + "sincos", + // "sinh", // WGSL intrinsic + "sizeof", + // "smoothstep", // WGSL intrinsic + "snorm", + // "sqrt", // WGSL intrinsic + "stateblock", + "stateblock_state", + "static", + "static_cast", + // "step", // WGSL intrinsic + "string", + // "struct", // WGSL keyword + // "switch", // WGSL keyword + // "tan", // WGSL intrinsic + // "tanh", // WGSL intrinsic + "tbuffer", + "technique", + "technique10", + "technique11", + "template", + "tex1D", + "tex1Dbias", + "tex1Dgrad", + "tex1Dlod", + "tex1Dproj", + "tex2D", + "tex2Dbias", + "tex2Dgrad", + "tex2Dlod", + "tex2Dproj", + "tex3D", + "tex3Dbias", + "tex3Dgrad", + "tex3Dlod", + "tex3Dproj", + "texCUBE", + "texCUBEbias", + "texCUBEgrad", + "texCUBElod", + "texCUBEproj", + "texture", + "texture1D", + "texture1DArray", + "texture2D", + "texture2DArray", + "texture2DMS", + "texture2DMSArray", + "texture3D", + "textureCube", + "textureCubeArray", + "this", + "throw", + "transpose", + "triangle", + "triangleadj", + // "true", // WGSL keyword + // "trunc", // WGSL intrinsic + "try", + // "typedef", // WGSL keyword + "typename", + "uint", + "uint1", + "uint1x1", + "uint1x2", + "uint1x3", + "uint1x4", + "uint2", + "uint2x1", + "uint2x2", + "uint2x3", + "uint2x4", + "uint3", + "uint3x1", + "uint3x2", + "uint3x3", + "uint3x4", + "uint4", + "uint4x1", + "uint4x2", + "uint4x3", + "uint4x4", + // "uniform", // WGSL keyword + "union", + "unorm", + "unroll", + "unsigned", + "using", + "vector", + "vertexfragment", + "vertexshader", + "virtual", + // "void", // WGSL keyword + "volatile", + "while")); + +INSTANTIATE_TEST_SUITE_P(RenamerTestMsl, + RenamerTestMsl, + testing::Values( + // c++14 spec + "alignas", + "alignof", + "and", + "and_eq", + // "asm", // Also reserved in WGSL + "auto", + "bitand", + "bitor", + // "bool", // Also used in WGSL + // "break", // Also used in WGSL + // "case", // Also used in WGSL + "catch", + "char", + "char16_t", + "char32_t", + "class", + "compl", + // "const", // Also used in WGSL + "const_cast", + "constexpr", + // "continue", // Also used in WGSL + "decltype", + // "default", // Also used in WGSL + "delete", + // "do", // Also used in WGSL + "double", + "dynamic_cast", + // "else", // Also used in WGSL + // "enum", // Also used in WGSL + "explicit", + "extern", + // "false", // Also used in WGSL + "final", + "float", + // "for", // Also used in WGSL + "friend", + "goto", + // "if", // Also used in WGSL + "inline", + "int", + "long", + "mutable", + "namespace", + "new", + "noexcept", + "not", + "not_eq", + "nullptr", + "operator", + "or", + "or_eq", + "override", + // "private", // Also used in WGSL + "protected", + "public", + "register", + "reinterpret_cast", + // "return", // Also used in WGSL + "short", + "signed", + "sizeof", + "static", + "static_assert", + "static_cast", + // "struct", // Also used in WGSL + // "switch", // Also used in WGSL + "template", + "this", + "thread_local", + "throw", + // "true", // Also used in WGSL + "try", + // "typedef", // Also used in WGSL + "typeid", + "typename", + "union", + "unsigned", + "using", + "virtual", + // "void", // Also used in WGSL + "volatile", + "wchar_t", + "while", + "xor", + "xor_eq", + + // Metal Spec + "access", + // "array", // Also used in WGSL + "array_ref", + "as_type", + "atomic", + "atomic_bool", + "atomic_int", + "atomic_uint", + "bool2", + "bool3", + "bool4", + "buffer", + "char2", + "char3", + "char4", + "const_reference", + "constant", + "depth2d", + "depth2d_array", + "depth2d_ms", + "depth2d_ms_array", + "depthcube", + "depthcube_array", + "device", + "discard_fragment", + "float2", + "float2x2", + "float2x3", + "float2x4", + "float3", + "float3x2", + "float3x3", + "float3x4", + "float4", + "float4x2", + "float4x3", + "float4x4", + "fragment", + "half", + "half2", + "half2x2", + "half2x3", + "half2x4", + "half3", + "half3x2", + "half3x3", + "half3x4", + "half4", + "half4x2", + "half4x3", + "half4x4", + "imageblock", + "int16_t", + "int2", + "int3", + "int32_t", + "int4", + "int64_t", + "int8_t", + "kernel", + "long2", + "long3", + "long4", + "main", // No functions called main + "metal", // The namespace + "packed_bool2", + "packed_bool3", + "packed_bool4", + "packed_char2", + "packed_char3", + "packed_char4", + "packed_float2", + "packed_float3", + "packed_float4", + "packed_half2", + "packed_half3", + "packed_half4", + "packed_int2", + "packed_int3", + "packed_int4", + "packed_short2", + "packed_short3", + "packed_short4", + "packed_uchar2", + "packed_uchar3", + "packed_uchar4", + "packed_uint2", + "packed_uint3", + "packed_uint4", + "packed_ushort2", + "packed_ushort3", + "packed_ushort4", + "patch_control_point", + "ptrdiff_t", + "r16snorm", + "r16unorm", + // "r8unorm", // Also used in WGSL + "reference", + "rg11b10f", + "rg16snorm", + "rg16unorm", + // "rg8snorm", // Also used in WGSL + // "rg8unorm", // Also used in WGSL + "rgb10a2", + "rgb9e5", + "rgba16snorm", + "rgba16unorm", + // "rgba8snorm", // Also used in WGSL + // "rgba8unorm", // Also used in WGSL + // "sampler", // Also used in WGSL + "short2", + "short3", + "short4", + "size_t", + "srgba8unorm", + "texture", + "texture1d", + "texture1d_array", + "texture2d", + "texture2d_array", + "texture2d_ms", + "texture2d_ms_array", + "texture3d", + "texture_buffer", + "texturecube", + "texturecube_array", + "thread", + "threadgroup", + "threadgroup_imageblock", + "uchar", + "uchar2", + "uchar3", + "uchar4", + "uint", + "uint16_t", + "uint2", + "uint3", + "uint32_t", + "uint4", + "uint64_t", + "uint8_t", + "ulong2", + "ulong3", + "ulong4", + // "uniform", // Also used in WGSL + "ushort", + "ushort2", + "ushort3", + "ushort4", + "vec", + "vertex")); + } // namespace } // namespace transform } // namespace tint diff --git a/src/transform/transform.cc b/src/transform/transform.cc index 04bac75f5e..a9c3816174 100644 --- a/src/transform/transform.cc +++ b/src/transform/transform.cc @@ -57,18 +57,6 @@ ast::Function* Transform::CloneWithStatementsAtStart( body, decos, ret_decos); } -void Transform::RenameReservedKeywords(CloneContext* ctx, - const char* names[], - size_t count) { - ctx->ReplaceAll([=](Symbol in) { - auto name_in = ctx->src->Symbols().NameFor(in); - if (std::binary_search(names, names + count, name_in)) { - return ctx->dst->Symbols().New("tint_" + name_in); - } - return ctx->dst->Symbols().New(name_in); - }); -} - ast::DecorationList Transform::RemoveDecorations( CloneContext* ctx, const ast::DecorationList& in, diff --git a/src/transform/transform.h b/src/transform/transform.h index 2c96b27db9..21e9f10012 100644 --- a/src/transform/transform.h +++ b/src/transform/transform.h @@ -165,25 +165,6 @@ class Transform { ast::Function* in, ast::StatementList statements); - /// Registers a symbol renamer on `ctx` for any symbol that is found in the - /// list of reserved identifiers. - /// @param ctx the clone context - /// @param names the lexicographically sorted list of reserved identifiers - /// @param count the number of identifiers in the array `names` - static void RenameReservedKeywords(CloneContext* ctx, - const char* names[], - size_t count); - - /// Registers a symbol renamer on `ctx` for any symbol that is found in the - /// list of reserved identifiers. - /// @param ctx the clone context - /// @param names the lexicographically sorted list of reserved identifiers - template - static void RenameReservedKeywords(CloneContext* ctx, - const char* (&names)[N]) { - RenameReservedKeywords(ctx, names, N); - } - /// Clones the decoration list `in`, removing decorations based on a filter. /// @param ctx the clone context /// @param in the decorations to clone diff --git a/src/writer/hlsl/generator_impl_alias_type_test.cc b/src/writer/hlsl/generator_impl_alias_type_test.cc index cc17869af7..3837cde078 100644 --- a/src/writer/hlsl/generator_impl_alias_type_test.cc +++ b/src/writer/hlsl/generator_impl_alias_type_test.cc @@ -40,7 +40,7 @@ TEST_F(HlslGeneratorImplTest_Alias, EmitAlias_NameCollision) { GeneratorImpl& gen = SanitizeAndBuild(); ASSERT_TRUE(gen.Generate(out)) << gen.error(); - EXPECT_THAT(result(), HasSubstr(R"(typedef float tint_float; + EXPECT_THAT(result(), HasSubstr(R"(typedef float tint_symbol; )")); } diff --git a/src/writer/hlsl/generator_impl_function_test.cc b/src/writer/hlsl/generator_impl_function_test.cc index 37af244020..0bbd4028ab 100644 --- a/src/writer/hlsl/generator_impl_function_test.cc +++ b/src/writer/hlsl/generator_impl_function_test.cc @@ -60,7 +60,7 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Function_Name_Collision) { gen.increment_indent(); ASSERT_TRUE(gen.Generate(out)) << gen.error(); - EXPECT_THAT(result(), HasSubstr(R"( void tint_GeometryShader() { + EXPECT_THAT(result(), HasSubstr(R"( void tint_symbol() { return; })")); } @@ -877,7 +877,7 @@ TEST_F(HlslGeneratorImplTest_Function, GeneratorImpl& gen = SanitizeAndBuild(); ASSERT_TRUE(gen.Generate(out)) << gen.error(); - EXPECT_EQ(result(), R"(void tint_GeometryShader() { + EXPECT_EQ(result(), R"(void tint_symbol() { return; } diff --git a/src/writer/hlsl/generator_impl_intrinsic_texture_test.cc b/src/writer/hlsl/generator_impl_intrinsic_texture_test.cc index 063392988c..88d9eedd11 100644 --- a/src/writer/hlsl/generator_impl_intrinsic_texture_test.cc +++ b/src/writer/hlsl/generator_impl_intrinsic_texture_test.cc @@ -42,7 +42,7 @@ ExpectedResult expected_texture_overload( case ValidTextureOverload::kDimensionsStorageWO1d: return { R"(int tint_tmp; - tint_texture.GetDimensions(tint_tmp); + tint_symbol.GetDimensions(tint_tmp); )", "tint_tmp", }; @@ -52,14 +52,14 @@ ExpectedResult expected_texture_overload( case ValidTextureOverload::kDimensionsStorageWO2d: return { R"(int2 tint_tmp; - tint_texture.GetDimensions(tint_tmp.x, tint_tmp.y); + tint_symbol.GetDimensions(tint_tmp.x, tint_tmp.y); )", "tint_tmp", }; case ValidTextureOverload::kDimensionsMultisampled2d: return { R"(int3 tint_tmp; - tint_texture.GetDimensions(tint_tmp.x, tint_tmp.y, tint_tmp.z); + tint_symbol.GetDimensions(tint_tmp.x, tint_tmp.y, tint_tmp.z); )", "tint_tmp.xy", }; @@ -70,14 +70,14 @@ ExpectedResult expected_texture_overload( case ValidTextureOverload::kDimensionsStorageWO2dArray: return { R"(int3 tint_tmp; - tint_texture.GetDimensions(tint_tmp.x, tint_tmp.y, tint_tmp.z); + tint_symbol.GetDimensions(tint_tmp.x, tint_tmp.y, tint_tmp.z); )", "tint_tmp.xy", }; case ValidTextureOverload::kDimensionsMultisampled2dArray: return { R"(int4 tint_tmp; - tint_texture.GetDimensions(tint_tmp.x, tint_tmp.y, tint_tmp.z, tint_tmp.w); + tint_symbol.GetDimensions(tint_tmp.x, tint_tmp.y, tint_tmp.z, tint_tmp.w); )", "tint_tmp.xy", }; @@ -86,7 +86,7 @@ ExpectedResult expected_texture_overload( case ValidTextureOverload::kDimensionsStorageWO3d: return { R"(int3 tint_tmp; - tint_texture.GetDimensions(tint_tmp.x, tint_tmp.y, tint_tmp.z); + tint_symbol.GetDimensions(tint_tmp.x, tint_tmp.y, tint_tmp.z); )", "tint_tmp", }; @@ -94,7 +94,7 @@ ExpectedResult expected_texture_overload( case ValidTextureOverload::kDimensionsDepthCube: return { R"(int2 tint_tmp; - tint_texture.GetDimensions(tint_tmp.x, tint_tmp.y); + tint_symbol.GetDimensions(tint_tmp.x, tint_tmp.y); )", "tint_tmp.xyy", }; @@ -102,7 +102,7 @@ ExpectedResult expected_texture_overload( case ValidTextureOverload::kDimensionsDepthCubeArray: return { R"(int3 tint_tmp; - tint_texture.GetDimensions(tint_tmp.x, tint_tmp.y, tint_tmp.z); + tint_symbol.GetDimensions(tint_tmp.x, tint_tmp.y, tint_tmp.z); )", "tint_tmp.xyy", }; @@ -110,7 +110,7 @@ ExpectedResult expected_texture_overload( case ValidTextureOverload::kDimensionsDepth2dLevel: return { R"(int3 tint_tmp; - tint_texture.GetDimensions(1, tint_tmp.x, tint_tmp.y, tint_tmp.z); + tint_symbol.GetDimensions(1, tint_tmp.x, tint_tmp.y, tint_tmp.z); )", "tint_tmp.xy", }; @@ -118,14 +118,14 @@ ExpectedResult expected_texture_overload( case ValidTextureOverload::kDimensionsDepth2dArrayLevel: return { R"(int4 tint_tmp; - tint_texture.GetDimensions(1, tint_tmp.x, tint_tmp.y, tint_tmp.z, tint_tmp.w); + tint_symbol.GetDimensions(1, tint_tmp.x, tint_tmp.y, tint_tmp.z, tint_tmp.w); )", "tint_tmp.xy", }; case ValidTextureOverload::kDimensions3dLevel: return { R"(int4 tint_tmp; - tint_texture.GetDimensions(1, tint_tmp.x, tint_tmp.y, tint_tmp.z, tint_tmp.w); + tint_symbol.GetDimensions(1, tint_tmp.x, tint_tmp.y, tint_tmp.z, tint_tmp.w); )", "tint_tmp.xyz", }; @@ -133,7 +133,7 @@ ExpectedResult expected_texture_overload( case ValidTextureOverload::kDimensionsDepthCubeLevel: return { R"(int3 tint_tmp; - tint_texture.GetDimensions(1, tint_tmp.x, tint_tmp.y, tint_tmp.z); + tint_symbol.GetDimensions(1, tint_tmp.x, tint_tmp.y, tint_tmp.z); )", "tint_tmp.xyy", }; @@ -141,7 +141,7 @@ ExpectedResult expected_texture_overload( case ValidTextureOverload::kDimensionsDepthCubeArrayLevel: return { R"(int4 tint_tmp; - tint_texture.GetDimensions(1, tint_tmp.x, tint_tmp.y, tint_tmp.z, tint_tmp.w); + tint_symbol.GetDimensions(1, tint_tmp.x, tint_tmp.y, tint_tmp.z, tint_tmp.w); )", "tint_tmp.xyy", }; @@ -152,14 +152,14 @@ ExpectedResult expected_texture_overload( case ValidTextureOverload::kNumLayersStorageWO2dArray: return { R"(int3 tint_tmp; - tint_texture.GetDimensions(tint_tmp.x, tint_tmp.y, tint_tmp.z); + tint_symbol.GetDimensions(tint_tmp.x, tint_tmp.y, tint_tmp.z); )", "tint_tmp.z", }; case ValidTextureOverload::kNumLayersMultisampled2dArray: return { R"(int4 tint_tmp; - tint_texture.GetDimensions(tint_tmp.x, tint_tmp.y, tint_tmp.z, tint_tmp.w); + tint_symbol.GetDimensions(tint_tmp.x, tint_tmp.y, tint_tmp.z, tint_tmp.w); )", "tint_tmp.z", }; @@ -170,7 +170,7 @@ ExpectedResult expected_texture_overload( case ValidTextureOverload::kNumLevelsDepthCube: return { R"(int3 tint_tmp; - tint_texture.GetDimensions(0, tint_tmp.x, tint_tmp.y, tint_tmp.z); + tint_symbol.GetDimensions(0, tint_tmp.x, tint_tmp.y, tint_tmp.z); )", "tint_tmp.z", }; @@ -181,168 +181,168 @@ ExpectedResult expected_texture_overload( case ValidTextureOverload::kNumLevelsDepthCubeArray: return { R"(int4 tint_tmp; - tint_texture.GetDimensions(0, tint_tmp.x, tint_tmp.y, tint_tmp.z, tint_tmp.w); + tint_symbol.GetDimensions(0, tint_tmp.x, tint_tmp.y, tint_tmp.z, tint_tmp.w); )", "tint_tmp.w", }; case ValidTextureOverload::kNumSamplesMultisampled2d: return { R"(int3 tint_tmp; - tint_texture.GetDimensions(tint_tmp.x, tint_tmp.y, tint_tmp.z); + tint_symbol.GetDimensions(tint_tmp.x, tint_tmp.y, tint_tmp.z); )", "tint_tmp.z", }; case ValidTextureOverload::kNumSamplesMultisampled2dArray: return { R"(int4 tint_tmp; - tint_texture.GetDimensions(tint_tmp.x, tint_tmp.y, tint_tmp.z, tint_tmp.w); + tint_symbol.GetDimensions(tint_tmp.x, tint_tmp.y, tint_tmp.z, tint_tmp.w); )", "tint_tmp.w", }; case ValidTextureOverload::kSample1dF32: - return R"(tint_texture.Sample(tint_sampler, 1.0f))"; + return R"(tint_symbol.Sample(tint_symbol_1, 1.0f))"; case ValidTextureOverload::kSample2dF32: - return R"(tint_texture.Sample(tint_sampler, float2(1.0f, 2.0f)))"; + return R"(tint_symbol.Sample(tint_symbol_1, float2(1.0f, 2.0f)))"; case ValidTextureOverload::kSample2dOffsetF32: - return R"(tint_texture.Sample(tint_sampler, float2(1.0f, 2.0f), int2(3, 4)))"; + return R"(tint_symbol.Sample(tint_symbol_1, float2(1.0f, 2.0f), int2(3, 4)))"; case ValidTextureOverload::kSample2dArrayF32: - return R"(tint_texture.Sample(tint_sampler, float3(1.0f, 2.0f, float(3))))"; + return R"(tint_symbol.Sample(tint_symbol_1, float3(1.0f, 2.0f, float(3))))"; case ValidTextureOverload::kSample2dArrayOffsetF32: - return R"(tint_texture.Sample(tint_sampler, float3(1.0f, 2.0f, float(3)), int2(4, 5)))"; + return R"(tint_symbol.Sample(tint_symbol_1, float3(1.0f, 2.0f, float(3)), int2(4, 5)))"; case ValidTextureOverload::kSample3dF32: - return R"(tint_texture.Sample(tint_sampler, float3(1.0f, 2.0f, 3.0f)))"; + return R"(tint_symbol.Sample(tint_symbol_1, float3(1.0f, 2.0f, 3.0f)))"; case ValidTextureOverload::kSample3dOffsetF32: - return R"(tint_texture.Sample(tint_sampler, float3(1.0f, 2.0f, 3.0f), int3(4, 5, 6)))"; + return R"(tint_symbol.Sample(tint_symbol_1, float3(1.0f, 2.0f, 3.0f), int3(4, 5, 6)))"; case ValidTextureOverload::kSampleCubeF32: - return R"(tint_texture.Sample(tint_sampler, float3(1.0f, 2.0f, 3.0f)))"; + return R"(tint_symbol.Sample(tint_symbol_1, float3(1.0f, 2.0f, 3.0f)))"; case ValidTextureOverload::kSampleCubeArrayF32: - return R"(tint_texture.Sample(tint_sampler, float4(1.0f, 2.0f, 3.0f, float(4))))"; + return R"(tint_symbol.Sample(tint_symbol_1, float4(1.0f, 2.0f, 3.0f, float(4))))"; case ValidTextureOverload::kSampleDepth2dF32: - return R"(tint_texture.Sample(tint_sampler, float2(1.0f, 2.0f)))"; + return R"(tint_symbol.Sample(tint_symbol_1, float2(1.0f, 2.0f)))"; case ValidTextureOverload::kSampleDepth2dOffsetF32: - return R"(tint_texture.Sample(tint_sampler, float2(1.0f, 2.0f), int2(3, 4)))"; + return R"(tint_symbol.Sample(tint_symbol_1, float2(1.0f, 2.0f), int2(3, 4)))"; case ValidTextureOverload::kSampleDepth2dArrayF32: - return R"(tint_texture.Sample(tint_sampler, float3(1.0f, 2.0f, float(3))))"; + return R"(tint_symbol.Sample(tint_symbol_1, float3(1.0f, 2.0f, float(3))))"; case ValidTextureOverload::kSampleDepth2dArrayOffsetF32: - return R"(tint_texture.Sample(tint_sampler, float3(1.0f, 2.0f, float(3)), int2(4, 5)))"; + return R"(tint_symbol.Sample(tint_symbol_1, float3(1.0f, 2.0f, float(3)), int2(4, 5)))"; case ValidTextureOverload::kSampleDepthCubeF32: - return R"(tint_texture.Sample(tint_sampler, float3(1.0f, 2.0f, 3.0f)))"; + return R"(tint_symbol.Sample(tint_symbol_1, float3(1.0f, 2.0f, 3.0f)))"; case ValidTextureOverload::kSampleDepthCubeArrayF32: - return R"(tint_texture.Sample(tint_sampler, float4(1.0f, 2.0f, 3.0f, float(4))))"; + return R"(tint_symbol.Sample(tint_symbol_1, float4(1.0f, 2.0f, 3.0f, float(4))))"; case ValidTextureOverload::kSampleBias2dF32: - return R"(tint_texture.SampleBias(tint_sampler, float2(1.0f, 2.0f), 3.0f))"; + return R"(tint_symbol.SampleBias(tint_symbol_1, float2(1.0f, 2.0f), 3.0f))"; case ValidTextureOverload::kSampleBias2dOffsetF32: - return R"(tint_texture.SampleBias(tint_sampler, float2(1.0f, 2.0f), 3.0f, int2(4, 5)))"; + return R"(tint_symbol.SampleBias(tint_symbol_1, float2(1.0f, 2.0f), 3.0f, int2(4, 5)))"; case ValidTextureOverload::kSampleBias2dArrayF32: - return R"(tint_texture.SampleBias(tint_sampler, float3(1.0f, 2.0f, float(4)), 3.0f))"; + return R"(tint_symbol.SampleBias(tint_symbol_1, float3(1.0f, 2.0f, float(4)), 3.0f))"; case ValidTextureOverload::kSampleBias2dArrayOffsetF32: - return R"(tint_texture.SampleBias(tint_sampler, float3(1.0f, 2.0f, float(3)), 4.0f, int2(5, 6)))"; + return R"(tint_symbol.SampleBias(tint_symbol_1, float3(1.0f, 2.0f, float(3)), 4.0f, int2(5, 6)))"; case ValidTextureOverload::kSampleBias3dF32: - return R"(tint_texture.SampleBias(tint_sampler, float3(1.0f, 2.0f, 3.0f), 4.0f))"; + return R"(tint_symbol.SampleBias(tint_symbol_1, float3(1.0f, 2.0f, 3.0f), 4.0f))"; case ValidTextureOverload::kSampleBias3dOffsetF32: - return R"(tint_texture.SampleBias(tint_sampler, float3(1.0f, 2.0f, 3.0f), 4.0f, int3(5, 6, 7)))"; + return R"(tint_symbol.SampleBias(tint_symbol_1, float3(1.0f, 2.0f, 3.0f), 4.0f, int3(5, 6, 7)))"; case ValidTextureOverload::kSampleBiasCubeF32: - return R"(tint_texture.SampleBias(tint_sampler, float3(1.0f, 2.0f, 3.0f), 4.0f))"; + return R"(tint_symbol.SampleBias(tint_symbol_1, float3(1.0f, 2.0f, 3.0f), 4.0f))"; case ValidTextureOverload::kSampleBiasCubeArrayF32: - return R"(tint_texture.SampleBias(tint_sampler, float4(1.0f, 2.0f, 3.0f, float(3)), 4.0f))"; + return R"(tint_symbol.SampleBias(tint_symbol_1, float4(1.0f, 2.0f, 3.0f, float(3)), 4.0f))"; case ValidTextureOverload::kSampleLevel2dF32: - return R"(tint_texture.SampleLevel(tint_sampler, float2(1.0f, 2.0f), 3.0f))"; + return R"(tint_symbol.SampleLevel(tint_symbol_1, float2(1.0f, 2.0f), 3.0f))"; case ValidTextureOverload::kSampleLevel2dOffsetF32: - return R"(tint_texture.SampleLevel(tint_sampler, float2(1.0f, 2.0f), 3.0f, int2(4, 5)))"; + return R"(tint_symbol.SampleLevel(tint_symbol_1, float2(1.0f, 2.0f), 3.0f, int2(4, 5)))"; case ValidTextureOverload::kSampleLevel2dArrayF32: - return R"(tint_texture.SampleLevel(tint_sampler, float3(1.0f, 2.0f, float(3)), 4.0f))"; + return R"(tint_symbol.SampleLevel(tint_symbol_1, float3(1.0f, 2.0f, float(3)), 4.0f))"; case ValidTextureOverload::kSampleLevel2dArrayOffsetF32: - return R"(tint_texture.SampleLevel(tint_sampler, float3(1.0f, 2.0f, float(3)), 4.0f, int2(5, 6)))"; + return R"(tint_symbol.SampleLevel(tint_symbol_1, float3(1.0f, 2.0f, float(3)), 4.0f, int2(5, 6)))"; case ValidTextureOverload::kSampleLevel3dF32: - return R"(tint_texture.SampleLevel(tint_sampler, float3(1.0f, 2.0f, 3.0f), 4.0f))"; + return R"(tint_symbol.SampleLevel(tint_symbol_1, float3(1.0f, 2.0f, 3.0f), 4.0f))"; case ValidTextureOverload::kSampleLevel3dOffsetF32: - return R"(tint_texture.SampleLevel(tint_sampler, float3(1.0f, 2.0f, 3.0f), 4.0f, int3(5, 6, 7)))"; + return R"(tint_symbol.SampleLevel(tint_symbol_1, float3(1.0f, 2.0f, 3.0f), 4.0f, int3(5, 6, 7)))"; case ValidTextureOverload::kSampleLevelCubeF32: - return R"(tint_texture.SampleLevel(tint_sampler, float3(1.0f, 2.0f, 3.0f), 4.0f))"; + return R"(tint_symbol.SampleLevel(tint_symbol_1, float3(1.0f, 2.0f, 3.0f), 4.0f))"; case ValidTextureOverload::kSampleLevelCubeArrayF32: - return R"(tint_texture.SampleLevel(tint_sampler, float4(1.0f, 2.0f, 3.0f, float(4)), 5.0f))"; + return R"(tint_symbol.SampleLevel(tint_symbol_1, float4(1.0f, 2.0f, 3.0f, float(4)), 5.0f))"; case ValidTextureOverload::kSampleLevelDepth2dF32: - return R"(tint_texture.SampleLevel(tint_sampler, float2(1.0f, 2.0f), 3))"; + return R"(tint_symbol.SampleLevel(tint_symbol_1, float2(1.0f, 2.0f), 3))"; case ValidTextureOverload::kSampleLevelDepth2dOffsetF32: - return R"(tint_texture.SampleLevel(tint_sampler, float2(1.0f, 2.0f), 3, int2(4, 5)))"; + return R"(tint_symbol.SampleLevel(tint_symbol_1, float2(1.0f, 2.0f), 3, int2(4, 5)))"; case ValidTextureOverload::kSampleLevelDepth2dArrayF32: - return R"(tint_texture.SampleLevel(tint_sampler, float3(1.0f, 2.0f, float(3)), 4))"; + return R"(tint_symbol.SampleLevel(tint_symbol_1, float3(1.0f, 2.0f, float(3)), 4))"; case ValidTextureOverload::kSampleLevelDepth2dArrayOffsetF32: - return R"(tint_texture.SampleLevel(tint_sampler, float3(1.0f, 2.0f, float(3)), 4, int2(5, 6)))"; + return R"(tint_symbol.SampleLevel(tint_symbol_1, float3(1.0f, 2.0f, float(3)), 4, int2(5, 6)))"; case ValidTextureOverload::kSampleLevelDepthCubeF32: - return R"(tint_texture.SampleLevel(tint_sampler, float3(1.0f, 2.0f, 3.0f), 4))"; + return R"(tint_symbol.SampleLevel(tint_symbol_1, float3(1.0f, 2.0f, 3.0f), 4))"; case ValidTextureOverload::kSampleLevelDepthCubeArrayF32: - return R"(tint_texture.SampleLevel(tint_sampler, float4(1.0f, 2.0f, 3.0f, float(4)), 5))"; + return R"(tint_symbol.SampleLevel(tint_symbol_1, float4(1.0f, 2.0f, 3.0f, float(4)), 5))"; case ValidTextureOverload::kSampleGrad2dF32: - return R"(tint_texture.SampleGrad(tint_sampler, float2(1.0f, 2.0f), float2(3.0f, 4.0f), float2(5.0f, 6.0f)))"; + return R"(tint_symbol.SampleGrad(tint_symbol_1, float2(1.0f, 2.0f), float2(3.0f, 4.0f), float2(5.0f, 6.0f)))"; case ValidTextureOverload::kSampleGrad2dOffsetF32: - return R"(tint_texture.SampleGrad(tint_sampler, float2(1.0f, 2.0f), float2(3.0f, 4.0f), float2(5.0f, 6.0f), int2(7, 8)))"; + return R"(tint_symbol.SampleGrad(tint_symbol_1, float2(1.0f, 2.0f), float2(3.0f, 4.0f), float2(5.0f, 6.0f), int2(7, 8)))"; case ValidTextureOverload::kSampleGrad2dArrayF32: - return R"(tint_texture.SampleGrad(tint_sampler, float3(1.0f, 2.0f, float(3)), float2(4.0f, 5.0f), float2(6.0f, 7.0f)))"; + return R"(tint_symbol.SampleGrad(tint_symbol_1, float3(1.0f, 2.0f, float(3)), float2(4.0f, 5.0f), float2(6.0f, 7.0f)))"; case ValidTextureOverload::kSampleGrad2dArrayOffsetF32: - return R"(tint_texture.SampleGrad(tint_sampler, float3(1.0f, 2.0f, float(3)), float2(4.0f, 5.0f), float2(6.0f, 7.0f), int2(8, 9)))"; + return R"(tint_symbol.SampleGrad(tint_symbol_1, float3(1.0f, 2.0f, float(3)), float2(4.0f, 5.0f), float2(6.0f, 7.0f), int2(8, 9)))"; case ValidTextureOverload::kSampleGrad3dF32: - return R"(tint_texture.SampleGrad(tint_sampler, float3(1.0f, 2.0f, 3.0f), float3(4.0f, 5.0f, 6.0f), float3(7.0f, 8.0f, 9.0f)))"; + return R"(tint_symbol.SampleGrad(tint_symbol_1, float3(1.0f, 2.0f, 3.0f), float3(4.0f, 5.0f, 6.0f), float3(7.0f, 8.0f, 9.0f)))"; case ValidTextureOverload::kSampleGrad3dOffsetF32: - return R"(tint_texture.SampleGrad(tint_sampler, float3(1.0f, 2.0f, 3.0f), float3(4.0f, 5.0f, 6.0f), float3(7.0f, 8.0f, 9.0f), int3(10, 11, 12)))"; + return R"(tint_symbol.SampleGrad(tint_symbol_1, float3(1.0f, 2.0f, 3.0f), float3(4.0f, 5.0f, 6.0f), float3(7.0f, 8.0f, 9.0f), int3(10, 11, 12)))"; case ValidTextureOverload::kSampleGradCubeF32: - return R"(tint_texture.SampleGrad(tint_sampler, float3(1.0f, 2.0f, 3.0f), float3(4.0f, 5.0f, 6.0f), float3(7.0f, 8.0f, 9.0f)))"; + return R"(tint_symbol.SampleGrad(tint_symbol_1, float3(1.0f, 2.0f, 3.0f), float3(4.0f, 5.0f, 6.0f), float3(7.0f, 8.0f, 9.0f)))"; case ValidTextureOverload::kSampleGradCubeArrayF32: - return R"(tint_texture.SampleGrad(tint_sampler, float4(1.0f, 2.0f, 3.0f, float(4)), float3(5.0f, 6.0f, 7.0f), float3(8.0f, 9.0f, 10.0f)))"; + return R"(tint_symbol.SampleGrad(tint_symbol_1, float4(1.0f, 2.0f, 3.0f, float(4)), float3(5.0f, 6.0f, 7.0f), float3(8.0f, 9.0f, 10.0f)))"; case ValidTextureOverload::kSampleCompareDepth2dF32: - return R"(tint_texture.SampleCmpLevelZero(tint_sampler, float2(1.0f, 2.0f), 3.0f))"; + return R"(tint_symbol.SampleCmpLevelZero(tint_symbol_1, float2(1.0f, 2.0f), 3.0f))"; case ValidTextureOverload::kSampleCompareDepth2dOffsetF32: - return R"(tint_texture.SampleCmpLevelZero(tint_sampler, float2(1.0f, 2.0f), 3.0f, int2(4, 5)))"; + return R"(tint_symbol.SampleCmpLevelZero(tint_symbol_1, float2(1.0f, 2.0f), 3.0f, int2(4, 5)))"; case ValidTextureOverload::kSampleCompareDepth2dArrayF32: - return R"(tint_texture.SampleCmpLevelZero(tint_sampler, float3(1.0f, 2.0f, float(4)), 3.0f))"; + return R"(tint_symbol.SampleCmpLevelZero(tint_symbol_1, float3(1.0f, 2.0f, float(4)), 3.0f))"; case ValidTextureOverload::kSampleCompareDepth2dArrayOffsetF32: - return R"(tint_texture.SampleCmpLevelZero(tint_sampler, float3(1.0f, 2.0f, float(4)), 3.0f, int2(5, 6)))"; + return R"(tint_symbol.SampleCmpLevelZero(tint_symbol_1, float3(1.0f, 2.0f, float(4)), 3.0f, int2(5, 6)))"; case ValidTextureOverload::kSampleCompareDepthCubeF32: - return R"(tint_texture.SampleCmpLevelZero(tint_sampler, float3(1.0f, 2.0f, 3.0f), 4.0f))"; + return R"(tint_symbol.SampleCmpLevelZero(tint_symbol_1, float3(1.0f, 2.0f, 3.0f), 4.0f))"; case ValidTextureOverload::kSampleCompareDepthCubeArrayF32: - return R"(tint_texture.SampleCmpLevelZero(tint_sampler, float4(1.0f, 2.0f, 3.0f, float(4)), 5.0f))"; + return R"(tint_symbol.SampleCmpLevelZero(tint_symbol_1, float4(1.0f, 2.0f, 3.0f, float(4)), 5.0f))"; case ValidTextureOverload::kLoad1dLevelF32: - return R"(tint_texture.Load(int2(1, 0), 3))"; + return R"(tint_symbol.Load(int2(1, 0), 3))"; case ValidTextureOverload::kLoad1dLevelU32: - return R"(tint_texture.Load(int2(1, 0), 3))"; + return R"(tint_symbol.Load(int2(1, 0), 3))"; case ValidTextureOverload::kLoad1dLevelI32: - return R"(tint_texture.Load(int2(1, 0), 3))"; + return R"(tint_symbol.Load(int2(1, 0), 3))"; case ValidTextureOverload::kLoad2dLevelF32: - return R"(tint_texture.Load(int3(1, 2, 0), 3))"; + return R"(tint_symbol.Load(int3(1, 2, 0), 3))"; case ValidTextureOverload::kLoad2dLevelU32: - return R"(tint_texture.Load(int3(1, 2, 0), 3))"; + return R"(tint_symbol.Load(int3(1, 2, 0), 3))"; case ValidTextureOverload::kLoad2dLevelI32: - return R"(tint_texture.Load(int3(1, 2, 0), 3))"; + return R"(tint_symbol.Load(int3(1, 2, 0), 3))"; case ValidTextureOverload::kLoad2dArrayLevelF32: - return R"(tint_texture.Load(int4(1, 2, 3, 0), 4))"; + return R"(tint_symbol.Load(int4(1, 2, 3, 0), 4))"; case ValidTextureOverload::kLoad2dArrayLevelU32: - return R"(tint_texture.Load(int4(1, 2, 3, 0), 4))"; + return R"(tint_symbol.Load(int4(1, 2, 3, 0), 4))"; case ValidTextureOverload::kLoad2dArrayLevelI32: - return R"(tint_texture.Load(int4(1, 2, 3, 0), 4))"; + return R"(tint_symbol.Load(int4(1, 2, 3, 0), 4))"; case ValidTextureOverload::kLoad3dLevelF32: - return R"(tint_texture.Load(int4(1, 2, 3, 0), 4))"; + return R"(tint_symbol.Load(int4(1, 2, 3, 0), 4))"; case ValidTextureOverload::kLoad3dLevelU32: - return R"(tint_texture.Load(int4(1, 2, 3, 0), 4))"; + return R"(tint_symbol.Load(int4(1, 2, 3, 0), 4))"; case ValidTextureOverload::kLoad3dLevelI32: - return R"(tint_texture.Load(int4(1, 2, 3, 0), 4))"; + return R"(tint_symbol.Load(int4(1, 2, 3, 0), 4))"; case ValidTextureOverload::kLoadMultisampled2dF32: - return R"(tint_texture.Load(int3(1, 2, 0), 3))"; + return R"(tint_symbol.Load(int3(1, 2, 0), 3))"; case ValidTextureOverload::kLoadMultisampled2dU32: - return R"(tint_texture.Load(int3(1, 2, 0), 3))"; + return R"(tint_symbol.Load(int3(1, 2, 0), 3))"; case ValidTextureOverload::kLoadMultisampled2dI32: - return R"(tint_texture.Load(int3(1, 2, 0), 3))"; + return R"(tint_symbol.Load(int3(1, 2, 0), 3))"; case ValidTextureOverload::kLoadMultisampled2dArrayF32: - return R"(tint_texture.Load(int4(1, 2, 3, 0), 4))"; + return R"(tint_symbol.Load(int4(1, 2, 3, 0), 4))"; case ValidTextureOverload::kLoadMultisampled2dArrayU32: - return R"(tint_texture.Load(int4(1, 2, 3, 0), 4))"; + return R"(tint_symbol.Load(int4(1, 2, 3, 0), 4))"; case ValidTextureOverload::kLoadMultisampled2dArrayI32: - return R"(tint_texture.Load(int4(1, 2, 3, 0), 4))"; + return R"(tint_symbol.Load(int4(1, 2, 3, 0), 4))"; case ValidTextureOverload::kLoadDepth2dLevelF32: - return R"(tint_texture.Load(int3(1, 2, 0), 3))"; + return R"(tint_symbol.Load(int3(1, 2, 0), 3))"; case ValidTextureOverload::kLoadDepth2dArrayLevelF32: - return R"(tint_texture.Load(int4(1, 2, 3, 0), 4))"; + return R"(tint_symbol.Load(int4(1, 2, 3, 0), 4))"; case ValidTextureOverload::kLoadStorageRO1dRgba32float: - return R"(tint_texture.Load(int2(1, 0)))"; + return R"(tint_symbol.Load(int2(1, 0)))"; case ValidTextureOverload::kLoadStorageRO2dRgba8unorm: case ValidTextureOverload::kLoadStorageRO2dRgba8snorm: case ValidTextureOverload::kLoadStorageRO2dRgba8uint: @@ -359,19 +359,19 @@ ExpectedResult expected_texture_overload( case ValidTextureOverload::kLoadStorageRO2dRgba32uint: case ValidTextureOverload::kLoadStorageRO2dRgba32sint: case ValidTextureOverload::kLoadStorageRO2dRgba32float: - return R"(tint_texture.Load(int3(1, 2, 0)))"; + return R"(tint_symbol.Load(int3(1, 2, 0)))"; case ValidTextureOverload::kLoadStorageRO2dArrayRgba32float: - return R"(tint_texture.Load(int4(1, 2, 3, 0)))"; + return R"(tint_symbol.Load(int4(1, 2, 3, 0)))"; case ValidTextureOverload::kLoadStorageRO3dRgba32float: - return R"(tint_texture.Load(int4(1, 2, 3, 0)))"; + return R"(tint_symbol.Load(int4(1, 2, 3, 0)))"; case ValidTextureOverload::kStoreWO1dRgba32float: - return R"(tint_texture[1] = float4(2.0f, 3.0f, 4.0f, 5.0f))"; + return R"(tint_symbol[1] = float4(2.0f, 3.0f, 4.0f, 5.0f))"; case ValidTextureOverload::kStoreWO2dRgba32float: - return R"(tint_texture[int2(1, 2)] = float4(3.0f, 4.0f, 5.0f, 6.0f))"; + return R"(tint_symbol[int2(1, 2)] = float4(3.0f, 4.0f, 5.0f, 6.0f))"; case ValidTextureOverload::kStoreWO2dArrayRgba32float: - return R"(tint_texture[int3(1, 2, 3)] = float4(4.0f, 5.0f, 6.0f, 7.0f))"; + return R"(tint_symbol[int3(1, 2, 3)] = float4(4.0f, 5.0f, 6.0f, 7.0f))"; case ValidTextureOverload::kStoreWO3dRgba32float: - return R"(tint_texture[int3(1, 2, 3)] = float4(4.0f, 5.0f, 6.0f, 7.0f))"; + return R"(tint_symbol[int3(1, 2, 3)] = float4(4.0f, 5.0f, 6.0f, 7.0f))"; } return ""; } // NOLINT - Ignore the length of this function diff --git a/src/writer/hlsl/generator_impl_type_test.cc b/src/writer/hlsl/generator_impl_type_test.cc index d46ec56151..920434fe64 100644 --- a/src/writer/hlsl/generator_impl_type_test.cc +++ b/src/writer/hlsl/generator_impl_type_test.cc @@ -236,8 +236,8 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Struct_NameCollision) { ASSERT_TRUE(gen.Generate(out)) << gen.error(); EXPECT_THAT(result(), HasSubstr(R"(struct S { - int tint_double; - float tint_float; + int tint_symbol; + float tint_symbol_1; }; )")); } diff --git a/src/writer/hlsl/test_helper.h b/src/writer/hlsl/test_helper.h index de6611c362..8b3604ee95 100644 --- a/src/writer/hlsl/test_helper.h +++ b/src/writer/hlsl/test_helper.h @@ -21,6 +21,8 @@ #include "gtest/gtest.h" #include "src/transform/hlsl.h" +#include "src/transform/manager.h" +#include "src/transform/renamer.h" #include "src/writer/hlsl/generator_impl.h" namespace tint { @@ -99,7 +101,13 @@ class TestHelperBase : public BODY, public ProgramBuilder { << formatter.format(program->Diagnostics()); }(); - auto result = transform::Hlsl().Run(program.get()); + transform::Manager transform_manager; + transform::Renamer::Config renamer_config{ + transform::Renamer::Target::kHlslKeywords}; + transform_manager.append( + std::make_unique(renamer_config)); + transform_manager.append(std::make_unique()); + auto result = transform_manager.Run(program.get()); [&]() { ASSERT_TRUE(result.program.IsValid()) << formatter.format(result.program.Diagnostics());