From 6a802cd3e436385ae086b32f9608270cddc45b3f Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Fri, 9 Apr 2021 17:28:18 +0000 Subject: [PATCH] writer/hlsl: Move the renamer into the sanitizer transform The renamer logic in the HLSL writer was inconsistent, and actually broke some valid shaders. Change-Id: I8fbddc7e657f5509b18435fdf352a39d83c1b89c Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47224 Commit-Queue: Ben Clayton Reviewed-by: James Price --- src/BUILD.gn | 2 - src/CMakeLists.txt | 3 - src/transform/hlsl.cc | 570 ++++++++++++++ src/transform/hlsl_test.cc | 635 ++++++++++++++++ src/transform/msl.cc | 1 + src/writer/hlsl/generator_impl.cc | 42 +- src/writer/hlsl/generator_impl.h | 5 - .../hlsl/generator_impl_alias_type_test.cc | 13 +- .../hlsl/generator_impl_function_test.cc | 30 +- .../hlsl/generator_impl_identifier_test.cc | 10 - .../generator_impl_intrinsic_texture_test.cc | 210 +++--- .../hlsl/generator_impl_sanitizer_test.cc | 8 +- src/writer/hlsl/generator_impl_test.cc | 20 +- src/writer/hlsl/generator_impl_type_test.cc | 43 +- src/writer/hlsl/namer.cc | 694 ------------------ src/writer/hlsl/namer.h | 63 -- src/writer/hlsl/namer_test.cc | 665 ----------------- test/BUILD.gn | 1 - 18 files changed, 1373 insertions(+), 1642 deletions(-) delete mode 100644 src/writer/hlsl/namer.cc delete mode 100644 src/writer/hlsl/namer.h delete mode 100644 src/writer/hlsl/namer_test.cc diff --git a/src/BUILD.gn b/src/BUILD.gn index 8c197e2113..2e27469581 100644 --- a/src/BUILD.gn +++ b/src/BUILD.gn @@ -646,8 +646,6 @@ source_set("libtint_hlsl_writer_src") { "writer/hlsl/generator.h", "writer/hlsl/generator_impl.cc", "writer/hlsl/generator_impl.h", - "writer/hlsl/namer.cc", - "writer/hlsl/namer.h", ] configs += [ ":tint_common_config" ] diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 91567fc546..4852f949e0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -383,8 +383,6 @@ if(${TINT_BUILD_HLSL_WRITER}) writer/hlsl/generator.h writer/hlsl/generator_impl.cc writer/hlsl/generator_impl.h - writer/hlsl/namer.cc - writer/hlsl/namer.h ) endif() @@ -812,7 +810,6 @@ if(${TINT_BUILD_TESTS}) writer/hlsl/generator_impl_unary_op_test.cc writer/hlsl/generator_impl_variable_decl_statement_test.cc writer/hlsl/generator_impl_workgroup_var_test.cc - writer/hlsl/namer_test.cc writer/hlsl/test_helper.cc writer/hlsl/test_helper.h ) diff --git a/src/transform/hlsl.cc b/src/transform/hlsl.cc index d2af5059b5..0da3013e4d 100644 --- a/src/transform/hlsl.cc +++ b/src/transform/hlsl.cc @@ -30,6 +30,575 @@ 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; @@ -47,6 +616,7 @@ 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 75f2390f32..fc5567e96c 100644 --- a/src/transform/hlsl_test.cc +++ b/src/transform/hlsl_test.cc @@ -14,6 +14,8 @@ #include "src/transform/hlsl.h" +#include + #include "src/transform/test_helper.h" namespace tint { @@ -291,6 +293,639 @@ fn _tint_unused_entry_point() { 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)); +} +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 48cebce7c0..3624b5d688 100644 --- a/src/transform/msl.cc +++ b/src/transform/msl.cc @@ -23,6 +23,7 @@ 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", diff --git a/src/writer/hlsl/generator_impl.cc b/src/writer/hlsl/generator_impl.cc index 9c1b179489..c569d510d8 100644 --- a/src/writer/hlsl/generator_impl.cc +++ b/src/writer/hlsl/generator_impl.cc @@ -176,14 +176,18 @@ void GeneratorImpl::register_global(ast::Variable* global) { } std::string GeneratorImpl::generate_name(const std::string& prefix) { - std::string name = prefix; - uint32_t i = 0; - while (namer_.IsMapped(name) || namer_.IsRemapped(name)) { - name = prefix + "_" + std::to_string(i); - ++i; + if (!builder_.Symbols().Get(prefix).IsValid()) { + builder_.Symbols().Register(prefix); + return prefix; + } + for (uint32_t i = 0;; i++) { + std::string name = prefix + "_" + std::to_string(i); + if (builder_.Symbols().Get(name).IsValid()) { + continue; + } + builder_.Symbols().Register(name); + return name; } - namer_.RegisterRemappedName(name); - return name; } std::string GeneratorImpl::current_ep_var_name(VarType type) { @@ -225,8 +229,8 @@ bool GeneratorImpl::EmitConstructedType(std::ostream& out, if (!EmitType(out, alias->type(), ast::StorageClass::kNone, "")) { return false; } - out << " " << namer_.NameFor(builder_.Symbols().NameFor(alias->symbol())) - << ";" << std::endl; + out << " " << builder_.Symbols().NameFor(alias->symbol()) << ";" + << std::endl; } else if (auto* str = ty->As()) { if (!EmitStructType(out, str, builder_.Symbols().NameFor(str->symbol()))) { return false; @@ -1428,7 +1432,7 @@ bool GeneratorImpl::EmitIdentifier(std::ostream&, } } - out << namer_.NameFor(builder_.Symbols().NameFor(ident->symbol())); + out << builder_.Symbols().NameFor(ident->symbol()); return true; } @@ -1604,8 +1608,7 @@ bool GeneratorImpl::EmitFunctionInternal(std::ostream& out, builder_.Symbols().NameFor(ep_sym)); ep_func_name_remapped_[ep_name + "_" + func_name] = name; } else { - // TODO(dsinclair): this should be updated to a remapped name - name = namer_.NameFor(builder_.Symbols().NameFor(func->symbol())); + name = builder_.Symbols().NameFor(func->symbol()); } out << name << "("; @@ -1905,7 +1908,7 @@ bool GeneratorImpl::EmitEntryPointData( if (!EmitType(out, var->Type(), var->StorageClass(), "")) { return false; } - out << " " << namer_.NameFor(builder_.Symbols().NameFor(decl->symbol())); + out << " " << builder_.Symbols().NameFor(decl->symbol()); const char* register_space = nullptr; @@ -2003,8 +2006,7 @@ bool GeneratorImpl::EmitEntryPointFunction(std::ostream& out, out << func->return_type()->FriendlyName(builder_.Symbols()); } // TODO(dsinclair): This should output the remapped name - out << " " << namer_.NameFor(builder_.Symbols().NameFor(current_ep_sym_)) - << "("; + out << " " << builder_.Symbols().NameFor(current_ep_sym_) << "("; bool first = true; // TODO(crbug.com/tint/697): Remove this. @@ -2144,8 +2146,8 @@ bool GeneratorImpl::EmitZeroValue(std::ostream& out, type::Type* type) { bool GeneratorImpl::EmitLoop(std::ostream& out, ast::LoopStatement* stmt) { loop_emission_counter_++; - std::string guard = namer_.NameFor("tint_hlsl_is_first_" + - std::to_string(loop_emission_counter_)); + std::string guard = generate_name("tint_hlsl_is_first_" + + std::to_string(loop_emission_counter_)); if (stmt->has_continuing()) { make_indent(out); @@ -2385,7 +2387,7 @@ bool GeneratorImpl::EmitType(std::ostream& out, } if (auto* alias = type->As()) { - out << namer_.NameFor(builder_.Symbols().NameFor(alias->symbol())); + out << builder_.Symbols().NameFor(alias->symbol()); } else if (auto* ary = type->As()) { type::Type* base_type = ary; std::vector sizes; @@ -2403,7 +2405,7 @@ bool GeneratorImpl::EmitType(std::ostream& out, return false; } if (!name.empty()) { - out << " " << namer_.NameFor(name); + out << " " << name; } for (uint32_t size : sizes) { out << "[" << size << "]"; @@ -2557,7 +2559,7 @@ bool GeneratorImpl::EmitStructType(std::ostream& out, } // Array member name will be output with the type if (!mem->type()->Is()) { - out << " " << namer_.NameFor(builder_.Symbols().NameFor(mem->symbol())); + out << " " << builder_.Symbols().NameFor(mem->symbol()); } for (auto* deco : mem->decorations()) { diff --git a/src/writer/hlsl/generator_impl.h b/src/writer/hlsl/generator_impl.h index 08d844f552..7961c21683 100644 --- a/src/writer/hlsl/generator_impl.h +++ b/src/writer/hlsl/generator_impl.h @@ -31,7 +31,6 @@ #include "src/ast/unary_op_expression.h" #include "src/program_builder.h" #include "src/scope_stack.h" -#include "src/writer/hlsl/namer.h" #include "src/writer/text_generator.h" namespace tint { @@ -358,9 +357,6 @@ class GeneratorImpl : public TextGenerator { /// @returns true if an input or output struct is required. bool has_referenced_var_needing_struct(const semantic::Function* func); - /// @returns the namer for testing - Namer* namer_for_testing() { return &namer_; } - /// Generate a unique name /// @param prefix the name prefix /// @returns a unique name @@ -383,7 +379,6 @@ class GeneratorImpl : public TextGenerator { return builder_.TypeOf(expr); } - Namer namer_; ProgramBuilder builder_; Symbol current_ep_sym_; bool generating_entry_point_ = false; diff --git a/src/writer/hlsl/generator_impl_alias_type_test.cc b/src/writer/hlsl/generator_impl_alias_type_test.cc index 8a2470197a..2d53286573 100644 --- a/src/writer/hlsl/generator_impl_alias_type_test.cc +++ b/src/writer/hlsl/generator_impl_alias_type_test.cc @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "gmock/gmock.h" #include "src/writer/hlsl/test_helper.h" namespace tint { @@ -19,6 +20,8 @@ namespace writer { namespace hlsl { namespace { +using ::testing::HasSubstr; + using HlslGeneratorImplTest_Alias = TestHelper; TEST_F(HlslGeneratorImplTest_Alias, EmitAlias_F32) { @@ -32,13 +35,13 @@ TEST_F(HlslGeneratorImplTest_Alias, EmitAlias_F32) { } TEST_F(HlslGeneratorImplTest_Alias, EmitAlias_NameCollision) { - auto* alias = ty.alias("float", ty.f32()); + AST().AddConstructedType(ty.alias("float", ty.f32())); - GeneratorImpl& gen = Build(); + GeneratorImpl& gen = SanitizeAndBuild(); - ASSERT_TRUE(gen.EmitConstructedType(out, alias)) << gen.error(); - EXPECT_EQ(result(), R"(typedef float float_tint_0; -)"); + ASSERT_TRUE(gen.Generate(out)) << gen.error(); + EXPECT_THAT(result(), HasSubstr(R"(typedef float _tint_float; +)")); } TEST_F(HlslGeneratorImplTest_Alias, EmitAlias_Struct) { diff --git a/src/writer/hlsl/generator_impl_function_test.cc b/src/writer/hlsl/generator_impl_function_test.cc index ea23929875..525ce1f15a 100644 --- a/src/writer/hlsl/generator_impl_function_test.cc +++ b/src/writer/hlsl/generator_impl_function_test.cc @@ -55,16 +55,14 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Function_Name_Collision) { }, ast::DecorationList{}); - GeneratorImpl& gen = Build(); + GeneratorImpl& gen = SanitizeAndBuild(); gen.increment_indent(); ASSERT_TRUE(gen.Generate(out)) << gen.error(); - EXPECT_EQ(result(), R"( void GeometryShader_tint_0() { + EXPECT_THAT(result(), HasSubstr(R"( void _tint_GeometryShader() { return; - } - -)"); + })")); } TEST_F(HlslGeneratorImplTest_Function, Emit_Function_WithParams) { @@ -121,15 +119,15 @@ TEST_F(HlslGeneratorImplTest_Function, GeneratorImpl& gen = SanitizeAndBuild(); ASSERT_TRUE(gen.Generate(out)) << gen.error(); - EXPECT_EQ(result(), R"(struct tint_symbol_5 { + EXPECT_EQ(result(), R"(struct tint_symbol_1 { float foo : TEXCOORD0; }; struct tint_symbol_2 { float value : SV_Target1; }; -tint_symbol_2 frag_main(tint_symbol_5 tint_symbol_7) { - const float foo = tint_symbol_7.foo; +tint_symbol_2 frag_main(tint_symbol_1 tint_symbol_6) { + const float foo = tint_symbol_6.foo; const tint_symbol_2 tint_symbol_1 = {foo}; return tint_symbol_1; } @@ -155,15 +153,15 @@ TEST_F(HlslGeneratorImplTest_Function, GeneratorImpl& gen = SanitizeAndBuild(); ASSERT_TRUE(gen.Generate(out)) << gen.error(); - EXPECT_EQ(result(), R"(struct tint_symbol_6 { + EXPECT_EQ(result(), R"(struct tint_symbol_1 { float4 coord : SV_Position; }; struct tint_symbol_2 { float value : SV_Depth; }; -tint_symbol_2 frag_main(tint_symbol_6 tint_symbol_8) { - const float4 coord = tint_symbol_8.coord; +tint_symbol_2 frag_main(tint_symbol_1 tint_symbol_6) { + const float4 coord = tint_symbol_6.coord; const tint_symbol_2 tint_symbol_1 = {coord.x}; return tint_symbol_1; } @@ -216,7 +214,7 @@ struct tint_symbol_2 { float col1 : TEXCOORD1; float col2 : TEXCOORD2; }; -struct tint_symbol_8 { +struct tint_symbol_7 { float col1 : TEXCOORD1; float col2 : TEXCOORD2; }; @@ -227,8 +225,8 @@ tint_symbol_2 vert_main() { return tint_symbol_1; } -void frag_main(tint_symbol_8 tint_symbol_10) { - const Interface colors = {tint_symbol_10.col1, tint_symbol_10.col2}; +void frag_main(tint_symbol_7 tint_symbol_9) { + const Interface colors = {tint_symbol_9.col1, tint_symbol_9.col2}; const float r = colors.col1; const float g = colors.col2; return; @@ -876,10 +874,10 @@ TEST_F(HlslGeneratorImplTest_Function, create(ast::PipelineStage::kFragment), }); - GeneratorImpl& gen = Build(); + GeneratorImpl& gen = SanitizeAndBuild(); ASSERT_TRUE(gen.Generate(out)) << gen.error(); - EXPECT_EQ(result(), R"(void GeometryShader_tint_0() { + EXPECT_EQ(result(), R"(void _tint_GeometryShader() { return; } diff --git a/src/writer/hlsl/generator_impl_identifier_test.cc b/src/writer/hlsl/generator_impl_identifier_test.cc index 536f5c0e4e..1faa7ae834 100644 --- a/src/writer/hlsl/generator_impl_identifier_test.cc +++ b/src/writer/hlsl/generator_impl_identifier_test.cc @@ -30,16 +30,6 @@ TEST_F(HlslGeneratorImplTest_Identifier, EmitIdentifierExpression) { EXPECT_EQ(result(), "foo"); } -TEST_F(HlslGeneratorImplTest_Identifier, - EmitIdentifierExpression_Single_WithCollision) { - auto* i = Expr("virtual"); - - GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.EmitExpression(pre, out, i)) << gen.error(); - EXPECT_EQ(result(), "virtual_tint_0"); -} - } // namespace } // namespace hlsl } // namespace writer diff --git a/src/writer/hlsl/generator_impl_intrinsic_texture_test.cc b/src/writer/hlsl/generator_impl_intrinsic_texture_test.cc index d6aaa84221..6fdab582e0 100644 --- a/src/writer/hlsl/generator_impl_intrinsic_texture_test.cc +++ b/src/writer/hlsl/generator_impl_intrinsic_texture_test.cc @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "gmock/gmock.h" #include "src/ast/call_statement.h" #include "src/ast/intrinsic_texture_helper_test.h" #include "src/ast/stage_decoration.h" @@ -22,6 +23,8 @@ namespace writer { namespace hlsl { namespace { +using ::testing::HasSubstr; + struct ExpectedResult { ExpectedResult(const char* o) : out(o) {} // NOLINT ExpectedResult(const char* p, const char* o) : pre(p), out(o) {} @@ -39,7 +42,7 @@ ExpectedResult expected_texture_overload( case ValidTextureOverload::kDimensionsStorageWO1d: return { R"(int _tint_tmp; -texture_tint_0.GetDimensions(_tint_tmp); + _tint_texture.GetDimensions(_tint_tmp); )", "_tint_tmp", }; @@ -49,14 +52,14 @@ texture_tint_0.GetDimensions(_tint_tmp); case ValidTextureOverload::kDimensionsStorageWO2d: return { R"(int2 _tint_tmp; -texture_tint_0.GetDimensions(_tint_tmp.x, _tint_tmp.y); + _tint_texture.GetDimensions(_tint_tmp.x, _tint_tmp.y); )", "_tint_tmp", }; case ValidTextureOverload::kDimensionsMultisampled2d: return { R"(int3 _tint_tmp; -texture_tint_0.GetDimensions(_tint_tmp.x, _tint_tmp.y, _tint_tmp.z); + _tint_texture.GetDimensions(_tint_tmp.x, _tint_tmp.y, _tint_tmp.z); )", "_tint_tmp.xy", }; @@ -67,14 +70,14 @@ texture_tint_0.GetDimensions(_tint_tmp.x, _tint_tmp.y, _tint_tmp.z); case ValidTextureOverload::kDimensionsStorageWO2dArray: return { R"(int3 _tint_tmp; -texture_tint_0.GetDimensions(_tint_tmp.x, _tint_tmp.y, _tint_tmp.z); + _tint_texture.GetDimensions(_tint_tmp.x, _tint_tmp.y, _tint_tmp.z); )", "_tint_tmp.xy", }; case ValidTextureOverload::kDimensionsMultisampled2dArray: return { R"(int4 _tint_tmp; -texture_tint_0.GetDimensions(_tint_tmp.x, _tint_tmp.y, _tint_tmp.z, _tint_tmp.w); + _tint_texture.GetDimensions(_tint_tmp.x, _tint_tmp.y, _tint_tmp.z, _tint_tmp.w); )", "_tint_tmp.xy", }; @@ -83,22 +86,23 @@ texture_tint_0.GetDimensions(_tint_tmp.x, _tint_tmp.y, _tint_tmp.z, _tint_tmp.w) case ValidTextureOverload::kDimensionsStorageWO3d: return { R"(int3 _tint_tmp; -texture_tint_0.GetDimensions(_tint_tmp.x, _tint_tmp.y, _tint_tmp.z); + _tint_texture.GetDimensions(_tint_tmp.x, _tint_tmp.y, _tint_tmp.z); )", "_tint_tmp", }; case ValidTextureOverload::kDimensionsCube: case ValidTextureOverload::kDimensionsDepthCube: return { - "int2 _tint_tmp;\n" - "texture_tint_0.GetDimensions(_tint_tmp.x, _tint_tmp.y);\n", + R"(int2 _tint_tmp; + _tint_texture.GetDimensions(_tint_tmp.x, _tint_tmp.y); +)", "_tint_tmp.xyy", }; case ValidTextureOverload::kDimensionsCubeArray: case ValidTextureOverload::kDimensionsDepthCubeArray: return { R"(int3 _tint_tmp; -texture_tint_0.GetDimensions(_tint_tmp.x, _tint_tmp.y, _tint_tmp.z); + _tint_texture.GetDimensions(_tint_tmp.x, _tint_tmp.y, _tint_tmp.z); )", "_tint_tmp.xyy", }; @@ -106,7 +110,7 @@ texture_tint_0.GetDimensions(_tint_tmp.x, _tint_tmp.y, _tint_tmp.z); case ValidTextureOverload::kDimensionsDepth2dLevel: return { R"(int3 _tint_tmp; -texture_tint_0.GetDimensions(1, _tint_tmp.x, _tint_tmp.y, _tint_tmp.z); + _tint_texture.GetDimensions(1, _tint_tmp.x, _tint_tmp.y, _tint_tmp.z); )", "_tint_tmp.xy", }; @@ -114,14 +118,14 @@ texture_tint_0.GetDimensions(1, _tint_tmp.x, _tint_tmp.y, _tint_tmp.z); case ValidTextureOverload::kDimensionsDepth2dArrayLevel: return { R"(int4 _tint_tmp; -texture_tint_0.GetDimensions(1, _tint_tmp.x, _tint_tmp.y, _tint_tmp.z, _tint_tmp.w); + _tint_texture.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; -texture_tint_0.GetDimensions(1, _tint_tmp.x, _tint_tmp.y, _tint_tmp.z, _tint_tmp.w); + _tint_texture.GetDimensions(1, _tint_tmp.x, _tint_tmp.y, _tint_tmp.z, _tint_tmp.w); )", "_tint_tmp.xyz", }; @@ -129,7 +133,7 @@ texture_tint_0.GetDimensions(1, _tint_tmp.x, _tint_tmp.y, _tint_tmp.z, _tint_tmp case ValidTextureOverload::kDimensionsDepthCubeLevel: return { R"(int3 _tint_tmp; -texture_tint_0.GetDimensions(1, _tint_tmp.x, _tint_tmp.y, _tint_tmp.z); + _tint_texture.GetDimensions(1, _tint_tmp.x, _tint_tmp.y, _tint_tmp.z); )", "_tint_tmp.xyy", }; @@ -137,7 +141,7 @@ texture_tint_0.GetDimensions(1, _tint_tmp.x, _tint_tmp.y, _tint_tmp.z); case ValidTextureOverload::kDimensionsDepthCubeArrayLevel: return { R"(int4 _tint_tmp; -texture_tint_0.GetDimensions(1, _tint_tmp.x, _tint_tmp.y, _tint_tmp.z, _tint_tmp.w); + _tint_texture.GetDimensions(1, _tint_tmp.x, _tint_tmp.y, _tint_tmp.z, _tint_tmp.w); )", "_tint_tmp.xyy", }; @@ -148,14 +152,14 @@ texture_tint_0.GetDimensions(1, _tint_tmp.x, _tint_tmp.y, _tint_tmp.z, _tint_tmp case ValidTextureOverload::kNumLayersStorageWO2dArray: return { R"(int3 _tint_tmp; -texture_tint_0.GetDimensions(_tint_tmp.x, _tint_tmp.y, _tint_tmp.z); + _tint_texture.GetDimensions(_tint_tmp.x, _tint_tmp.y, _tint_tmp.z); )", "_tint_tmp.z", }; case ValidTextureOverload::kNumLayersMultisampled2dArray: return { R"(int4 _tint_tmp; -texture_tint_0.GetDimensions(_tint_tmp.x, _tint_tmp.y, _tint_tmp.z, _tint_tmp.w); + _tint_texture.GetDimensions(_tint_tmp.x, _tint_tmp.y, _tint_tmp.z, _tint_tmp.w); )", "_tint_tmp.z", }; @@ -166,7 +170,7 @@ texture_tint_0.GetDimensions(_tint_tmp.x, _tint_tmp.y, _tint_tmp.z, _tint_tmp.w) case ValidTextureOverload::kNumLevelsDepthCube: return { R"(int3 _tint_tmp; -texture_tint_0.GetDimensions(0, _tint_tmp.x, _tint_tmp.y, _tint_tmp.z); + _tint_texture.GetDimensions(0, _tint_tmp.x, _tint_tmp.y, _tint_tmp.z); )", "_tint_tmp.z", }; @@ -177,168 +181,168 @@ texture_tint_0.GetDimensions(0, _tint_tmp.x, _tint_tmp.y, _tint_tmp.z); case ValidTextureOverload::kNumLevelsDepthCubeArray: return { R"(int4 _tint_tmp; -texture_tint_0.GetDimensions(0, _tint_tmp.x, _tint_tmp.y, _tint_tmp.z, _tint_tmp.w); + _tint_texture.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; -texture_tint_0.GetDimensions(_tint_tmp.x, _tint_tmp.y, _tint_tmp.z); + _tint_texture.GetDimensions(_tint_tmp.x, _tint_tmp.y, _tint_tmp.z); )", "_tint_tmp.z", }; case ValidTextureOverload::kNumSamplesMultisampled2dArray: return { R"(int4 _tint_tmp; -texture_tint_0.GetDimensions(_tint_tmp.x, _tint_tmp.y, _tint_tmp.z, _tint_tmp.w); + _tint_texture.GetDimensions(_tint_tmp.x, _tint_tmp.y, _tint_tmp.z, _tint_tmp.w); )", "_tint_tmp.w", }; case ValidTextureOverload::kSample1dF32: - return R"(texture_tint_0.Sample(sampler_tint_0, 1.0f))"; + return R"(_tint_texture.Sample(_tint_sampler, 1.0f))"; case ValidTextureOverload::kSample2dF32: - return R"(texture_tint_0.Sample(sampler_tint_0, float2(1.0f, 2.0f)))"; + return R"(_tint_texture.Sample(_tint_sampler, float2(1.0f, 2.0f)))"; case ValidTextureOverload::kSample2dOffsetF32: - return R"(texture_tint_0.Sample(sampler_tint_0, float2(1.0f, 2.0f), int2(3, 4)))"; + return R"(_tint_texture.Sample(_tint_sampler, float2(1.0f, 2.0f), int2(3, 4)))"; case ValidTextureOverload::kSample2dArrayF32: - return R"(texture_tint_0.Sample(sampler_tint_0, float3(1.0f, 2.0f, float(3))))"; + return R"(_tint_texture.Sample(_tint_sampler, float3(1.0f, 2.0f, float(3))))"; case ValidTextureOverload::kSample2dArrayOffsetF32: - return R"(texture_tint_0.Sample(sampler_tint_0, float3(1.0f, 2.0f, float(3)), int2(4, 5)))"; + return R"(_tint_texture.Sample(_tint_sampler, float3(1.0f, 2.0f, float(3)), int2(4, 5)))"; case ValidTextureOverload::kSample3dF32: - return R"(texture_tint_0.Sample(sampler_tint_0, float3(1.0f, 2.0f, 3.0f)))"; + return R"(_tint_texture.Sample(_tint_sampler, float3(1.0f, 2.0f, 3.0f)))"; case ValidTextureOverload::kSample3dOffsetF32: - return R"(texture_tint_0.Sample(sampler_tint_0, float3(1.0f, 2.0f, 3.0f), int3(4, 5, 6)))"; + return R"(_tint_texture.Sample(_tint_sampler, float3(1.0f, 2.0f, 3.0f), int3(4, 5, 6)))"; case ValidTextureOverload::kSampleCubeF32: - return R"(texture_tint_0.Sample(sampler_tint_0, float3(1.0f, 2.0f, 3.0f)))"; + return R"(_tint_texture.Sample(_tint_sampler, float3(1.0f, 2.0f, 3.0f)))"; case ValidTextureOverload::kSampleCubeArrayF32: - return R"(texture_tint_0.Sample(sampler_tint_0, float4(1.0f, 2.0f, 3.0f, float(4))))"; + return R"(_tint_texture.Sample(_tint_sampler, float4(1.0f, 2.0f, 3.0f, float(4))))"; case ValidTextureOverload::kSampleDepth2dF32: - return R"(texture_tint_0.Sample(sampler_tint_0, float2(1.0f, 2.0f)))"; + return R"(_tint_texture.Sample(_tint_sampler, float2(1.0f, 2.0f)))"; case ValidTextureOverload::kSampleDepth2dOffsetF32: - return R"(texture_tint_0.Sample(sampler_tint_0, float2(1.0f, 2.0f), int2(3, 4)))"; + return R"(_tint_texture.Sample(_tint_sampler, float2(1.0f, 2.0f), int2(3, 4)))"; case ValidTextureOverload::kSampleDepth2dArrayF32: - return R"(texture_tint_0.Sample(sampler_tint_0, float3(1.0f, 2.0f, float(3))))"; + return R"(_tint_texture.Sample(_tint_sampler, float3(1.0f, 2.0f, float(3))))"; case ValidTextureOverload::kSampleDepth2dArrayOffsetF32: - return R"(texture_tint_0.Sample(sampler_tint_0, float3(1.0f, 2.0f, float(3)), int2(4, 5)))"; + return R"(_tint_texture.Sample(_tint_sampler, float3(1.0f, 2.0f, float(3)), int2(4, 5)))"; case ValidTextureOverload::kSampleDepthCubeF32: - return R"(texture_tint_0.Sample(sampler_tint_0, float3(1.0f, 2.0f, 3.0f)))"; + return R"(_tint_texture.Sample(_tint_sampler, float3(1.0f, 2.0f, 3.0f)))"; case ValidTextureOverload::kSampleDepthCubeArrayF32: - return R"(texture_tint_0.Sample(sampler_tint_0, float4(1.0f, 2.0f, 3.0f, float(4))))"; + return R"(_tint_texture.Sample(_tint_sampler, float4(1.0f, 2.0f, 3.0f, float(4))))"; case ValidTextureOverload::kSampleBias2dF32: - return R"(texture_tint_0.SampleBias(sampler_tint_0, float2(1.0f, 2.0f), 3.0f))"; + return R"(_tint_texture.SampleBias(_tint_sampler, float2(1.0f, 2.0f), 3.0f))"; case ValidTextureOverload::kSampleBias2dOffsetF32: - return R"(texture_tint_0.SampleBias(sampler_tint_0, float2(1.0f, 2.0f), 3.0f, int2(4, 5)))"; + return R"(_tint_texture.SampleBias(_tint_sampler, float2(1.0f, 2.0f), 3.0f, int2(4, 5)))"; case ValidTextureOverload::kSampleBias2dArrayF32: - return R"(texture_tint_0.SampleBias(sampler_tint_0, float3(1.0f, 2.0f, float(4)), 3.0f))"; + return R"(_tint_texture.SampleBias(_tint_sampler, float3(1.0f, 2.0f, float(4)), 3.0f))"; case ValidTextureOverload::kSampleBias2dArrayOffsetF32: - return R"(texture_tint_0.SampleBias(sampler_tint_0, float3(1.0f, 2.0f, float(3)), 4.0f, int2(5, 6)))"; + return R"(_tint_texture.SampleBias(_tint_sampler, float3(1.0f, 2.0f, float(3)), 4.0f, int2(5, 6)))"; case ValidTextureOverload::kSampleBias3dF32: - return R"(texture_tint_0.SampleBias(sampler_tint_0, float3(1.0f, 2.0f, 3.0f), 4.0f))"; + return R"(_tint_texture.SampleBias(_tint_sampler, float3(1.0f, 2.0f, 3.0f), 4.0f))"; case ValidTextureOverload::kSampleBias3dOffsetF32: - return R"(texture_tint_0.SampleBias(sampler_tint_0, float3(1.0f, 2.0f, 3.0f), 4.0f, int3(5, 6, 7)))"; + return R"(_tint_texture.SampleBias(_tint_sampler, float3(1.0f, 2.0f, 3.0f), 4.0f, int3(5, 6, 7)))"; case ValidTextureOverload::kSampleBiasCubeF32: - return R"(texture_tint_0.SampleBias(sampler_tint_0, float3(1.0f, 2.0f, 3.0f), 4.0f))"; + return R"(_tint_texture.SampleBias(_tint_sampler, float3(1.0f, 2.0f, 3.0f), 4.0f))"; case ValidTextureOverload::kSampleBiasCubeArrayF32: - return R"(texture_tint_0.SampleBias(sampler_tint_0, float4(1.0f, 2.0f, 3.0f, float(3)), 4.0f))"; + return R"(_tint_texture.SampleBias(_tint_sampler, float4(1.0f, 2.0f, 3.0f, float(3)), 4.0f))"; case ValidTextureOverload::kSampleLevel2dF32: - return R"(texture_tint_0.SampleLevel(sampler_tint_0, float2(1.0f, 2.0f), 3.0f))"; + return R"(_tint_texture.SampleLevel(_tint_sampler, float2(1.0f, 2.0f), 3.0f))"; case ValidTextureOverload::kSampleLevel2dOffsetF32: - return R"(texture_tint_0.SampleLevel(sampler_tint_0, float2(1.0f, 2.0f), 3.0f, int2(4, 5)))"; + return R"(_tint_texture.SampleLevel(_tint_sampler, float2(1.0f, 2.0f), 3.0f, int2(4, 5)))"; case ValidTextureOverload::kSampleLevel2dArrayF32: - return R"(texture_tint_0.SampleLevel(sampler_tint_0, float3(1.0f, 2.0f, float(3)), 4.0f))"; + return R"(_tint_texture.SampleLevel(_tint_sampler, float3(1.0f, 2.0f, float(3)), 4.0f))"; case ValidTextureOverload::kSampleLevel2dArrayOffsetF32: - return R"(texture_tint_0.SampleLevel(sampler_tint_0, float3(1.0f, 2.0f, float(3)), 4.0f, int2(5, 6)))"; + return R"(_tint_texture.SampleLevel(_tint_sampler, float3(1.0f, 2.0f, float(3)), 4.0f, int2(5, 6)))"; case ValidTextureOverload::kSampleLevel3dF32: - return R"(texture_tint_0.SampleLevel(sampler_tint_0, float3(1.0f, 2.0f, 3.0f), 4.0f))"; + return R"(_tint_texture.SampleLevel(_tint_sampler, float3(1.0f, 2.0f, 3.0f), 4.0f))"; case ValidTextureOverload::kSampleLevel3dOffsetF32: - return R"(texture_tint_0.SampleLevel(sampler_tint_0, float3(1.0f, 2.0f, 3.0f), 4.0f, int3(5, 6, 7)))"; + return R"(_tint_texture.SampleLevel(_tint_sampler, float3(1.0f, 2.0f, 3.0f), 4.0f, int3(5, 6, 7)))"; case ValidTextureOverload::kSampleLevelCubeF32: - return R"(texture_tint_0.SampleLevel(sampler_tint_0, float3(1.0f, 2.0f, 3.0f), 4.0f))"; + return R"(_tint_texture.SampleLevel(_tint_sampler, float3(1.0f, 2.0f, 3.0f), 4.0f))"; case ValidTextureOverload::kSampleLevelCubeArrayF32: - return R"(texture_tint_0.SampleLevel(sampler_tint_0, float4(1.0f, 2.0f, 3.0f, float(4)), 5.0f))"; + return R"(_tint_texture.SampleLevel(_tint_sampler, float4(1.0f, 2.0f, 3.0f, float(4)), 5.0f))"; case ValidTextureOverload::kSampleLevelDepth2dF32: - return R"(texture_tint_0.SampleLevel(sampler_tint_0, float2(1.0f, 2.0f), 3))"; + return R"(_tint_texture.SampleLevel(_tint_sampler, float2(1.0f, 2.0f), 3))"; case ValidTextureOverload::kSampleLevelDepth2dOffsetF32: - return R"(texture_tint_0.SampleLevel(sampler_tint_0, float2(1.0f, 2.0f), 3, int2(4, 5)))"; + return R"(_tint_texture.SampleLevel(_tint_sampler, float2(1.0f, 2.0f), 3, int2(4, 5)))"; case ValidTextureOverload::kSampleLevelDepth2dArrayF32: - return R"(texture_tint_0.SampleLevel(sampler_tint_0, float3(1.0f, 2.0f, float(3)), 4))"; + return R"(_tint_texture.SampleLevel(_tint_sampler, float3(1.0f, 2.0f, float(3)), 4))"; case ValidTextureOverload::kSampleLevelDepth2dArrayOffsetF32: - return R"(texture_tint_0.SampleLevel(sampler_tint_0, float3(1.0f, 2.0f, float(3)), 4, int2(5, 6)))"; + return R"(_tint_texture.SampleLevel(_tint_sampler, float3(1.0f, 2.0f, float(3)), 4, int2(5, 6)))"; case ValidTextureOverload::kSampleLevelDepthCubeF32: - return R"(texture_tint_0.SampleLevel(sampler_tint_0, float3(1.0f, 2.0f, 3.0f), 4))"; + return R"(_tint_texture.SampleLevel(_tint_sampler, float3(1.0f, 2.0f, 3.0f), 4))"; case ValidTextureOverload::kSampleLevelDepthCubeArrayF32: - return R"(texture_tint_0.SampleLevel(sampler_tint_0, float4(1.0f, 2.0f, 3.0f, float(4)), 5))"; + return R"(_tint_texture.SampleLevel(_tint_sampler, float4(1.0f, 2.0f, 3.0f, float(4)), 5))"; case ValidTextureOverload::kSampleGrad2dF32: - return R"(texture_tint_0.SampleGrad(sampler_tint_0, float2(1.0f, 2.0f), float2(3.0f, 4.0f), float2(5.0f, 6.0f)))"; + return R"(_tint_texture.SampleGrad(_tint_sampler, float2(1.0f, 2.0f), float2(3.0f, 4.0f), float2(5.0f, 6.0f)))"; case ValidTextureOverload::kSampleGrad2dOffsetF32: - return R"(texture_tint_0.SampleGrad(sampler_tint_0, float2(1.0f, 2.0f), float2(3.0f, 4.0f), float2(5.0f, 6.0f), int2(7, 8)))"; + 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)))"; case ValidTextureOverload::kSampleGrad2dArrayF32: - return R"(texture_tint_0.SampleGrad(sampler_tint_0, float3(1.0f, 2.0f, float(3)), float2(4.0f, 5.0f), float2(6.0f, 7.0f)))"; + return R"(_tint_texture.SampleGrad(_tint_sampler, float3(1.0f, 2.0f, float(3)), float2(4.0f, 5.0f), float2(6.0f, 7.0f)))"; case ValidTextureOverload::kSampleGrad2dArrayOffsetF32: - return R"(texture_tint_0.SampleGrad(sampler_tint_0, float3(1.0f, 2.0f, float(3)), float2(4.0f, 5.0f), float2(6.0f, 7.0f), int2(8, 9)))"; + 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)))"; case ValidTextureOverload::kSampleGrad3dF32: - return R"(texture_tint_0.SampleGrad(sampler_tint_0, float3(1.0f, 2.0f, 3.0f), float3(4.0f, 5.0f, 6.0f), float3(7.0f, 8.0f, 9.0f)))"; + 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)))"; case ValidTextureOverload::kSampleGrad3dOffsetF32: - return R"(texture_tint_0.SampleGrad(sampler_tint_0, 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_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)))"; case ValidTextureOverload::kSampleGradCubeF32: - return R"(texture_tint_0.SampleGrad(sampler_tint_0, float3(1.0f, 2.0f, 3.0f), float3(4.0f, 5.0f, 6.0f), float3(7.0f, 8.0f, 9.0f)))"; + 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)))"; case ValidTextureOverload::kSampleGradCubeArrayF32: - return R"(texture_tint_0.SampleGrad(sampler_tint_0, 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_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)))"; case ValidTextureOverload::kSampleCompareDepth2dF32: - return R"(texture_tint_0.SampleCmp(sampler_tint_0, float2(1.0f, 2.0f), 3.0f))"; + return R"(_tint_texture.SampleCmp(_tint_sampler, float2(1.0f, 2.0f), 3.0f))"; case ValidTextureOverload::kSampleCompareDepth2dOffsetF32: - return R"(texture_tint_0.SampleCmp(sampler_tint_0, float2(1.0f, 2.0f), 3.0f, int2(4, 5)))"; + return R"(_tint_texture.SampleCmp(_tint_sampler, float2(1.0f, 2.0f), 3.0f, int2(4, 5)))"; case ValidTextureOverload::kSampleCompareDepth2dArrayF32: - return R"(texture_tint_0.SampleCmp(sampler_tint_0, float3(1.0f, 2.0f, float(4)), 3.0f))"; + return R"(_tint_texture.SampleCmp(_tint_sampler, float3(1.0f, 2.0f, float(4)), 3.0f))"; case ValidTextureOverload::kSampleCompareDepth2dArrayOffsetF32: - return R"(texture_tint_0.SampleCmp(sampler_tint_0, float3(1.0f, 2.0f, float(4)), 3.0f, int2(5, 6)))"; + return R"(_tint_texture.SampleCmp(_tint_sampler, float3(1.0f, 2.0f, float(4)), 3.0f, int2(5, 6)))"; case ValidTextureOverload::kSampleCompareDepthCubeF32: - return R"(texture_tint_0.SampleCmp(sampler_tint_0, float3(1.0f, 2.0f, 3.0f), 4.0f))"; + return R"(_tint_texture.SampleCmp(_tint_sampler, float3(1.0f, 2.0f, 3.0f), 4.0f))"; case ValidTextureOverload::kSampleCompareDepthCubeArrayF32: - return R"(texture_tint_0.SampleCmp(sampler_tint_0, float4(1.0f, 2.0f, 3.0f, float(4)), 5.0f))"; + return R"(_tint_texture.SampleCmp(_tint_sampler, float4(1.0f, 2.0f, 3.0f, float(4)), 5.0f))"; case ValidTextureOverload::kLoad1dLevelF32: - return R"(texture_tint_0.Load(int2(1, 0), 3))"; + return R"(_tint_texture.Load(int2(1, 0), 3))"; case ValidTextureOverload::kLoad1dLevelU32: - return R"(texture_tint_0.Load(int2(1, 0), 3))"; + return R"(_tint_texture.Load(int2(1, 0), 3))"; case ValidTextureOverload::kLoad1dLevelI32: - return R"(texture_tint_0.Load(int2(1, 0), 3))"; + return R"(_tint_texture.Load(int2(1, 0), 3))"; case ValidTextureOverload::kLoad2dLevelF32: - return R"(texture_tint_0.Load(int3(1, 2, 0), 3))"; + return R"(_tint_texture.Load(int3(1, 2, 0), 3))"; case ValidTextureOverload::kLoad2dLevelU32: - return R"(texture_tint_0.Load(int3(1, 2, 0), 3))"; + return R"(_tint_texture.Load(int3(1, 2, 0), 3))"; case ValidTextureOverload::kLoad2dLevelI32: - return R"(texture_tint_0.Load(int3(1, 2, 0), 3))"; + return R"(_tint_texture.Load(int3(1, 2, 0), 3))"; case ValidTextureOverload::kLoad2dArrayLevelF32: - return R"(texture_tint_0.Load(int4(1, 2, 3, 0), 4))"; + return R"(_tint_texture.Load(int4(1, 2, 3, 0), 4))"; case ValidTextureOverload::kLoad2dArrayLevelU32: - return R"(texture_tint_0.Load(int4(1, 2, 3, 0), 4))"; + return R"(_tint_texture.Load(int4(1, 2, 3, 0), 4))"; case ValidTextureOverload::kLoad2dArrayLevelI32: - return R"(texture_tint_0.Load(int4(1, 2, 3, 0), 4))"; + return R"(_tint_texture.Load(int4(1, 2, 3, 0), 4))"; case ValidTextureOverload::kLoad3dLevelF32: - return R"(texture_tint_0.Load(int4(1, 2, 3, 0), 4))"; + return R"(_tint_texture.Load(int4(1, 2, 3, 0), 4))"; case ValidTextureOverload::kLoad3dLevelU32: - return R"(texture_tint_0.Load(int4(1, 2, 3, 0), 4))"; + return R"(_tint_texture.Load(int4(1, 2, 3, 0), 4))"; case ValidTextureOverload::kLoad3dLevelI32: - return R"(texture_tint_0.Load(int4(1, 2, 3, 0), 4))"; + return R"(_tint_texture.Load(int4(1, 2, 3, 0), 4))"; case ValidTextureOverload::kLoadMultisampled2dF32: - return R"(texture_tint_0.Load(int3(1, 2, 0), 3))"; + return R"(_tint_texture.Load(int3(1, 2, 0), 3))"; case ValidTextureOverload::kLoadMultisampled2dU32: - return R"(texture_tint_0.Load(int3(1, 2, 0), 3))"; + return R"(_tint_texture.Load(int3(1, 2, 0), 3))"; case ValidTextureOverload::kLoadMultisampled2dI32: - return R"(texture_tint_0.Load(int3(1, 2, 0), 3))"; + return R"(_tint_texture.Load(int3(1, 2, 0), 3))"; case ValidTextureOverload::kLoadMultisampled2dArrayF32: - return R"(texture_tint_0.Load(int4(1, 2, 3, 0), 4))"; + return R"(_tint_texture.Load(int4(1, 2, 3, 0), 4))"; case ValidTextureOverload::kLoadMultisampled2dArrayU32: - return R"(texture_tint_0.Load(int4(1, 2, 3, 0), 4))"; + return R"(_tint_texture.Load(int4(1, 2, 3, 0), 4))"; case ValidTextureOverload::kLoadMultisampled2dArrayI32: - return R"(texture_tint_0.Load(int4(1, 2, 3, 0), 4))"; + return R"(_tint_texture.Load(int4(1, 2, 3, 0), 4))"; case ValidTextureOverload::kLoadDepth2dLevelF32: - return R"(texture_tint_0.Load(int3(1, 2, 0), 3))"; + return R"(_tint_texture.Load(int3(1, 2, 0), 3))"; case ValidTextureOverload::kLoadDepth2dArrayLevelF32: - return R"(texture_tint_0.Load(int4(1, 2, 3, 0), 4))"; + return R"(_tint_texture.Load(int4(1, 2, 3, 0), 4))"; case ValidTextureOverload::kLoadStorageRO1dRgba32float: - return R"(texture_tint_0.Load(int2(1, 0)))"; + return R"(_tint_texture.Load(int2(1, 0)))"; case ValidTextureOverload::kLoadStorageRO2dRgba8unorm: case ValidTextureOverload::kLoadStorageRO2dRgba8snorm: case ValidTextureOverload::kLoadStorageRO2dRgba8uint: @@ -355,19 +359,19 @@ texture_tint_0.GetDimensions(_tint_tmp.x, _tint_tmp.y, _tint_tmp.z, _tint_tmp.w) case ValidTextureOverload::kLoadStorageRO2dRgba32uint: case ValidTextureOverload::kLoadStorageRO2dRgba32sint: case ValidTextureOverload::kLoadStorageRO2dRgba32float: - return R"(texture_tint_0.Load(int3(1, 2, 0)))"; + return R"(_tint_texture.Load(int3(1, 2, 0)))"; case ValidTextureOverload::kLoadStorageRO2dArrayRgba32float: - return R"(texture_tint_0.Load(int4(1, 2, 3, 0)))"; + return R"(_tint_texture.Load(int4(1, 2, 3, 0)))"; case ValidTextureOverload::kLoadStorageRO3dRgba32float: - return R"(texture_tint_0.Load(int4(1, 2, 3, 0)))"; + return R"(_tint_texture.Load(int4(1, 2, 3, 0)))"; case ValidTextureOverload::kStoreWO1dRgba32float: - return R"(texture_tint_0[1] = float4(2.0f, 3.0f, 4.0f, 5.0f))"; + return R"(_tint_texture[1] = float4(2.0f, 3.0f, 4.0f, 5.0f))"; case ValidTextureOverload::kStoreWO2dRgba32float: - return R"(texture_tint_0[int2(1, 2)] = float4(3.0f, 4.0f, 5.0f, 6.0f))"; + return R"(_tint_texture[int2(1, 2)] = float4(3.0f, 4.0f, 5.0f, 6.0f))"; case ValidTextureOverload::kStoreWO2dArrayRgba32float: - return R"(texture_tint_0[int3(1, 2, 3)] = float4(4.0f, 5.0f, 6.0f, 7.0f))"; + return R"(_tint_texture[int3(1, 2, 3)] = float4(4.0f, 5.0f, 6.0f, 7.0f))"; case ValidTextureOverload::kStoreWO3dRgba32float: - return R"(texture_tint_0[int3(1, 2, 3)] = float4(4.0f, 5.0f, 6.0f, 7.0f))"; + return R"(_tint_texture[int3(1, 2, 3)] = float4(4.0f, 5.0f, 6.0f, 7.0f))"; } return ""; } // NOLINT - Ignore the length of this function @@ -391,14 +395,14 @@ TEST_P(HlslGeneratorIntrinsicTextureTest, Call) { create(ast::PipelineStage::kFragment), }); - GeneratorImpl& gen = Build(); + GeneratorImpl& gen = SanitizeAndBuild(); - ASSERT_TRUE(gen.EmitExpression(pre, out, call)) << gen.error(); + ASSERT_TRUE(gen.Generate(out)) << gen.error(); auto expected = expected_texture_overload(param.overload); - EXPECT_EQ(expected.pre, pre_result()); - EXPECT_EQ(expected.out, result()); + EXPECT_THAT(result(), HasSubstr(expected.pre)); + EXPECT_THAT(result(), HasSubstr(expected.out)); Validate(); } diff --git a/src/writer/hlsl/generator_impl_sanitizer_test.cc b/src/writer/hlsl/generator_impl_sanitizer_test.cc index 229931d0fc..48fbb063d6 100644 --- a/src/writer/hlsl/generator_impl_sanitizer_test.cc +++ b/src/writer/hlsl/generator_impl_sanitizer_test.cc @@ -62,10 +62,10 @@ TEST_F(HlslSanitizerTest, ArrayLength) { ByteAddressBuffer sb : register(t0, space1); void main() { - uint tint_symbol_9 = 0u; - sb.GetDimensions(tint_symbol_9); - const uint tint_symbol_10 = ((tint_symbol_9 - 16u) / 16u); - uint len = tint_symbol_10; + uint tint_symbol_7 = 0u; + sb.GetDimensions(tint_symbol_7); + const uint tint_symbol_9 = ((tint_symbol_7 - 16u) / 16u); + uint len = tint_symbol_9; return; } diff --git a/src/writer/hlsl/generator_impl_test.cc b/src/writer/hlsl/generator_impl_test.cc index f800f0ec8f..a47cd9ef68 100644 --- a/src/writer/hlsl/generator_impl_test.cc +++ b/src/writer/hlsl/generator_impl_test.cc @@ -41,23 +41,15 @@ TEST_F(HlslGeneratorImplTest, InputStructName) { } TEST_F(HlslGeneratorImplTest, InputStructName_ConflictWithExisting) { - // Register the struct name as existing. + Symbols().Register("func_main_out_1"); + Symbols().Register("func_main_out_2"); + GeneratorImpl& gen = Build(); - auto* namer = gen.namer_for_testing(); - namer->NameFor("func_main_out"); - + ASSERT_EQ(gen.generate_name("func_main_out"), "func_main_out"); ASSERT_EQ(gen.generate_name("func_main_out"), "func_main_out_0"); -} - -TEST_F(HlslGeneratorImplTest, NameConflictWith_InputStructName) { - auto* expr = Expr("func_main_in"); - - GeneratorImpl& gen = Build(); - - ASSERT_EQ(gen.generate_name("func_main_in"), "func_main_in"); - ASSERT_TRUE(gen.EmitIdentifier(pre, out, expr)); - EXPECT_EQ(result(), "func_main_in_0"); + ASSERT_EQ(gen.generate_name("func_main_out"), "func_main_out_3"); + ASSERT_EQ(gen.generate_name("func_main_out"), "func_main_out_4"); } struct HlslBuiltinData { diff --git a/src/writer/hlsl/generator_impl_type_test.cc b/src/writer/hlsl/generator_impl_type_test.cc index fb871e4c0c..bb64ba4475 100644 --- a/src/writer/hlsl/generator_impl_type_test.cc +++ b/src/writer/hlsl/generator_impl_type_test.cc @@ -42,16 +42,6 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Alias) { EXPECT_EQ(result(), "alias"); } -TEST_F(HlslGeneratorImplTest_Type, EmitType_Alias_NameCollision) { - auto* alias = ty.alias("bool", ty.f32()); - - GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.EmitType(out, alias, ast::StorageClass::kNone, "")) - << gen.error(); - EXPECT_EQ(result(), "bool_tint_0"); -} - TEST_F(HlslGeneratorImplTest_Type, EmitType_Array) { auto* arr = ty.array(); @@ -94,16 +84,6 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_ArrayOfArrayOfArray) { EXPECT_EQ(result(), "bool ary[6][5][4]"); } -TEST_F(HlslGeneratorImplTest_Type, EmitType_Array_NameCollision) { - auto* arr = ty.array(); - - GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.EmitType(out, arr, ast::StorageClass::kNone, "bool")) - << gen.error(); - EXPECT_EQ(result(), "bool bool_tint_0[4]"); -} - TEST_F(HlslGeneratorImplTest_Type, EmitType_Array_WithoutName) { auto* arr = ty.array(); @@ -124,17 +104,6 @@ TEST_F(HlslGeneratorImplTest_Type, DISABLED_EmitType_RuntimeArray) { EXPECT_EQ(result(), "bool ary[]"); } -TEST_F(HlslGeneratorImplTest_Type, - DISABLED_EmitType_RuntimeArray_NameCollision) { - auto* arr = ty.array(); - - GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.EmitType(out, arr, ast::StorageClass::kNone, "double")) - << gen.error(); - EXPECT_EQ(result(), "bool double_tint_0[]"); -} - TEST_F(HlslGeneratorImplTest_Type, EmitType_Bool) { auto* bool_ = ty.bool_(); @@ -263,14 +232,14 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Struct_NameCollision) { }); Global("g", s, ast::StorageClass::kPrivate); - GeneratorImpl& gen = Build(); + GeneratorImpl& gen = SanitizeAndBuild(); - ASSERT_TRUE(gen.EmitStructType(out, s, "S")) << gen.error(); - EXPECT_EQ(result(), R"(struct S { - int double_tint_0; - float float_tint_0; + ASSERT_TRUE(gen.Generate(out)) << gen.error(); + EXPECT_THAT(result(), HasSubstr(R"(struct S { + int _tint_double; + float _tint_float; }; -)"); +)")); } // TODO(dsinclair): How to translate [[block]] diff --git a/src/writer/hlsl/namer.cc b/src/writer/hlsl/namer.cc deleted file mode 100644 index 79e4975222..0000000000 --- a/src/writer/hlsl/namer.cc +++ /dev/null @@ -1,694 +0,0 @@ -// Copyright 2020 The Tint Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "src/writer/hlsl/namer.h" - -#include - -namespace tint { -namespace writer { -namespace hlsl { -namespace { - -// This list is used for a binary search and must be kept in sorted order. -const char* kNames[] = {"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", - "acos", - "all", - "allow_uav_condition", - "any", - "asdouble", - "asfloat", - "asin", - "asint", - "asm", - "asm_fragment", - "asuint", - "atan", - "atan2", - "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", - "ceil", - "centroid", - "char", - "clamp", - "class", - "clip", - "column_major", - "compile_fragment", - "const", - "const_cast", - "continue", - "cos", - "cosh", - "countbits", - "cross", - "ddx", - "ddx_coarse", - "ddx_fine", - "ddy", - "ddy_coarse", - "ddy_fine", - "degrees", - "delete", - "determinant", - "discard", - "distance", - "do", - "dot", - "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", - "exp", - "exp2", - "explicit", - "export", - "extern", - "f16to32", - "f32tof16", - "faceforward", - "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", - "floor", - "fma", - "fmod", - "for", - "forcecase", - "frac", - "frexp", - "friend", - "fwidth", - "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", - "ldexp", - "length", - "lerp", - "lineadj", - "linear", - "lit", - "log", - "log10", - "log2", - "long", - "loop", - "mad", - "matrix", - "max", - "min", - "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", - "msad4", - "mul", - "mutable", - "namespace", - "new", - "nointerpolation", - "noise", - "noperspective", - "normalize", - "numthreads", - "operator", - "out", - "packoffset", - "pass", - "pixelfragment", - "pixelshader", - "point", - "pow", - "precise", - "printf", - "private", - "protected", - "public", - "radians", - "rcp", - "reflect", - "refract", - "register", - "reinterpret_cast", - "return", - "reversebits", - "round", - "row_major", - "rsqrt", - "sample", - "sampler", - "sampler1D", - "sampler2D", - "sampler3D", - "samplerCUBE", - "sampler_state", - "saturate", - "shared", - "short", - "sign", - "signed", - "sin", - "sincos", - "sinh", - "sizeof", - "smoothstep", - "snorm", - "sqrt", - "stateblock", - "stateblock_state", - "static", - "static_cast", - "step", - "string", - "struct", - "switch", - "tan", - "tanh", - "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", - "trunc", - "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 - -Namer::Namer() = default; - -Namer::~Namer() = default; - -std::string Namer::NameFor(const std::string& name) { - // If it's in the name map we can just return it. There are no shadow names - // in WGSL so this has to be unique in the WGSL names, and we've already - // checked the name collisions with HLSL. - auto it = name_map_.find(name); - if (it != name_map_.end()) { - return it->second; - } - - std::string ret_name = name; - if (std::binary_search(std::begin(kNames), std::end(kNames), ret_name)) { - uint32_t i = 0; - // Make sure there wasn't already a tint variable with the new name we've - // now created. - while (true) { - ret_name = name + "_tint_" + std::to_string(i); - it = name_map_.find(ret_name); - if (it == name_map_.end()) { - break; - } - i++; - } - RegisterRemappedName(ret_name); - } else { - uint32_t i = 0; - // Make sure the ident name wasn't assigned by a remapping. - while (true) { - if (!IsRemapped(ret_name)) { - break; - } - ret_name = name + "_" + std::to_string(i); - i++; - } - RegisterRemappedName(ret_name); - } - - name_map_[name] = ret_name; - return ret_name; -} - -bool Namer::IsMapped(const std::string& name) { - auto it = name_map_.find(name); - return it != name_map_.end(); -} - -bool Namer::IsRemapped(const std::string& name) { - auto it = remapped_names_.find(name); - return it != remapped_names_.end(); -} - -void Namer::RegisterRemappedName(const std::string& name) { - remapped_names_.insert(name); -} - -} // namespace hlsl -} // namespace writer -} // namespace tint diff --git a/src/writer/hlsl/namer.h b/src/writer/hlsl/namer.h deleted file mode 100644 index c067e2230a..0000000000 --- a/src/writer/hlsl/namer.h +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright 2020 The Tint Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef SRC_WRITER_HLSL_NAMER_H_ -#define SRC_WRITER_HLSL_NAMER_H_ - -#include -#include -#include - -namespace tint { -namespace writer { -namespace hlsl { - -/// Remaps maps names to avoid reserved words and collisions for HLSL. -class Namer { - public: - /// Constructor - Namer(); - ~Namer(); - - /// Returns a sanitized version of `name` - /// @param name the name to sanitize - /// @returns the sanitized version of `name` - std::string NameFor(const std::string& name); - - /// Registers a remapped name. - /// @param name the name to register - void RegisterRemappedName(const std::string& name); - - /// Returns if the given name has been mapped already - /// @param name the name to check - /// @returns true if the name has been mapped - bool IsMapped(const std::string& name); - - /// Returns if the given name has been remapped already - /// @param name the name to check - /// @returns true if the name has been remapped - bool IsRemapped(const std::string& name); - - private: - /// Map of original name to new name. The two names may be the same. - std::unordered_map name_map_; - // The list of names taken by the remapper - std::unordered_set remapped_names_; -}; - -} // namespace hlsl -} // namespace writer -} // namespace tint - -#endif // SRC_WRITER_HLSL_NAMER_H_ diff --git a/src/writer/hlsl/namer_test.cc b/src/writer/hlsl/namer_test.cc deleted file mode 100644 index a714cb9217..0000000000 --- a/src/writer/hlsl/namer_test.cc +++ /dev/null @@ -1,665 +0,0 @@ -// Copyright 2020 The Tint Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "src/writer/hlsl/namer.h" - -#include "gtest/gtest.h" - -namespace tint { -namespace writer { -namespace hlsl { -namespace { - -using HlslNamerTest = testing::Test; - -TEST_F(HlslNamerTest, ReturnsName) { - Namer n; - EXPECT_EQ("my_name", n.NameFor("my_name")); - EXPECT_EQ("my_name", n.NameFor("my_name")); -} - -TEST_F(HlslNamerTest, HandlesConflictWithRenamedReservedWordAfterIdentSeen) { - Namer n; - EXPECT_EQ("float_tint_0", n.NameFor("float_tint_0")); - EXPECT_EQ("float_tint_1", n.NameFor("float")); - EXPECT_EQ("float_tint_0", n.NameFor("float_tint_0")); -} - -TEST_F(HlslNamerTest, HandlesConflictWithRenamedReservedWordBeforeIdentSeen) { - Namer n; - EXPECT_EQ("float_tint_0", n.NameFor("float")); - EXPECT_EQ("float_tint_0_0", n.NameFor("float_tint_0")); - EXPECT_EQ("float_tint_0_0_0", n.NameFor("float_tint_0_0")); - EXPECT_EQ("float_tint_0_0", n.NameFor("float_tint_0")); -} - -using HlslReservedNameTest = testing::TestWithParam; -TEST_P(HlslReservedNameTest, Emit) { - auto name = GetParam(); - - Namer n; - EXPECT_EQ(name + "_tint_0", n.NameFor(name)); -} -INSTANTIATE_TEST_SUITE_P(HlslNamerTest, - HlslReservedNameTest, - 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", - "acos", - "all", - "allow_uav_condition", - "any", - "asdouble", - "asfloat", - "asin", - "asint", - "asm", - "asm_fragment", - "asuint", - "atan", - "atan2", - "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", - "ceil", - "centroid", - "char", - "clamp", - "class", - "clip", - "column_major", - "compile_fragment", - "const", - "const_cast", - "continue", - "cos", - "cosh", - "countbits", - "cross", - "ddx", - "ddx_coarse", - "ddx_fine", - "ddy", - "ddy_coarse", - "ddy_fine", - "degrees", - "delete", - "determinant", - "discard", - "distance", - "do", - "dot", - "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", - "exp", - "exp2", - "explicit", - "export", - "extern", - "f16to32", - "f32tof16", - "faceforward", - "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", - "floor", - "fma", - "fmod", - "for", - "forcecase", - "frac", - "frexp", - "friend", - "fwidth", - "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", - "ldexp", - "length", - "lerp", - "lineadj", - "linear", - "lit", - "log", - "log10", - "log2", - "long", - "loop", - "mad", - "matrix", - "max", - "min", - "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", - "msad4", - "mul", - "mutable", - "namespace", - "new", - "nointerpolation", - "noise", - "noperspective", - "normalize", - "numthreads", - "operator", - "out", - "packoffset", - "pass", - "pixelfragment", - "pixelshader", - "point", - "pow", - "precise", - "printf", - "private", - "protected", - "public", - "radians", - "rcp", - "reflect", - "refract", - "register", - "reinterpret_cast", - "return", - "reversebits", - "round", - "row_major", - "rsqrt", - "sample", - "sampler1D", - "sampler2D", - "sampler3D", - "samplerCUBE", - "sampler_state", - "saturate", - "shared", - "short", - "sign", - "signed", - "sin", - "sincos", - "sinh", - "sizeof", - "smoothstep", - "snorm", - "sqrt", - "stateblock", - "stateblock_state", - "static", - "static_cast", - "step", - "string", - "struct", - "switch", - "tan", - "tanh", - "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", - "trunc", - "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 -} // namespace hlsl -} // namespace writer -} // namespace tint diff --git a/test/BUILD.gn b/test/BUILD.gn index 6827f4b54b..43e014bdfe 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -591,7 +591,6 @@ source_set("tint_unittests_hlsl_writer_src") { "../src/writer/hlsl/generator_impl_unary_op_test.cc", "../src/writer/hlsl/generator_impl_variable_decl_statement_test.cc", "../src/writer/hlsl/generator_impl_workgroup_var_test.cc", - "../src/writer/hlsl/namer_test.cc", "../src/writer/hlsl/test_helper.cc", "../src/writer/hlsl/test_helper.h", ]