Browse Source

Fixup of noticed problem about DXC build regarding math operations on enum types. Added casts in emission.

Signed-off-by: Vivien Oddou <[email protected]>
Vivien Oddou 2 năm trước cách đây
mục cha
commit
5dd04c4332
2 tập tin đã thay đổi với 6 bổ sung2 xóa
  1. 4 2
      src/AzslcEmitter.cpp
  2. 2 0
      tests/Emission/option-range.azsl

+ 4 - 2
src/AzslcEmitter.cpp

@@ -1187,7 +1187,7 @@ namespace AZ::ShaderCompiler
                 else
                 {
                     // add the value of the first enumerator (by emitting its name)
-                    m_out << " + " << GetTranslatedName(enumerators.front(), UsageContext::ReferenceSite);  // we can access front with no defense because keySize would be 0 if there are no enumerators.
+                    m_out << " + (uint)" << GetTranslatedName(enumerators.front(), UsageContext::ReferenceSite);  // we can access front with no defense because keySize would be 0 if there are no enumerators.
                 }
             }
             m_out << ";\n";
@@ -1199,7 +1199,9 @@ namespace AZ::ShaderCompiler
             // and this if-branch will be taken. if the programmer specified no initializer clause,
             // this would produce unbuildable HLSL and error in generatored code. We really don't want that
             // as it would be hard to diagnose for users. As a reasonable behavior, we can emit val = 0.
-            m_out << "    " << GetTranslatedName(returnType, UsageContext::ReferenceSite) << " val = " << (defaultValue.empty() ? "0" : defaultValue) << ";\n";
+            string typeAsStr = GetTranslatedName(returnType, UsageContext::ReferenceSite);
+            // "<type> val = (cast expr to <type>) 0 or default;"
+            m_out << "    " << typeAsStr << " val = (" << typeAsStr << ")" << (defaultValue.empty() ? "0" : defaultValue) << ";\n";
             m_out << "    return val;\n";
         }
         m_out << "}\n\n";

+ 2 - 0
tests/Emission/option-range.azsl

@@ -17,6 +17,8 @@ option enum class F { v = 10, v2 } o_s3;
 
 option enum G { gv, gv2 = 4, gv3 } o_s4;
 
+option enum Empty { } o_y = 1;
+
 float4 MainPS(float2 uv : TEXCOORD0) : SV_Target0
 {
     return o_stuff;