ソースを参照

Add 16bit integers to Any IntrinsicCompTypes and for existing UInt3264 comp types. (#913)

Young Kim 7 年 前
コミット
bf911b1d22

+ 7 - 2
tools/clang/lib/Sema/SemaHLSL.cpp

@@ -858,7 +858,9 @@ static const ArBasicKind g_UIntCT[] =
 
 static const ArBasicKind g_AnyIntCT[] =
 {
+  AR_BASIC_INT16,
   AR_BASIC_INT32,
+  AR_BASIC_UINT16,
   AR_BASIC_UINT32,
   AR_BASIC_INT64,
   AR_BASIC_UINT64,
@@ -947,7 +949,9 @@ static const ArBasicKind g_NumericCT[] =
   AR_BASIC_MIN10FLOAT,
   AR_BASIC_MIN16FLOAT,
   AR_BASIC_LITERAL_INT,
+  AR_BASIC_INT16,
   AR_BASIC_INT32,
+  AR_BASIC_UINT16,
   AR_BASIC_UINT32,
   AR_BASIC_MIN12INT,
   AR_BASIC_MIN16INT,
@@ -1061,9 +1065,10 @@ static const ArBasicKind g_UInt64CT[] =
   AR_BASIC_UNKNOWN
 };
 
-static const ArBasicKind g_UInt3264CT[] =
+static const ArBasicKind g_UInt163264CT[] =
 {
   AR_BASIC_UINT32,
+  AR_BASIC_UINT16,
   AR_BASIC_UINT64,
   AR_BASIC_LITERAL_INT,
   AR_BASIC_UNKNOWN
@@ -1130,7 +1135,7 @@ const ArBasicKind* g_LegalIntrinsicCompTypes[] =
   g_StringCT,           // LICOMPTYPE_STRING
   g_WaveCT,             // LICOMPTYPE_WAVE
   g_UInt64CT,           // LICOMPTYPE_UINT64
-  g_UInt3264CT,         // LICOMPTYPE_UINT32_64
+  g_UInt163264CT,       // LICOMPTYPE_UINT16_32_64
   g_Float16CT,          // LICOMPTYPE_FLOAT16
   g_Int16CT,            // LICOMPTYPE_INT16
   g_UInt16CT,           // LICOMPTYPE_UINT16

+ 23 - 0
tools/clang/test/CodeGenHLSL/int16Op.hlsl

@@ -0,0 +1,23 @@
+// RUN: %dxc -E main -T cs_6_2 -enable-16bit-types %s | FileCheck %s
+
+// CHECK: @dx.op.binary.i16
+// CHECK: @dx.op.unaryBits.i16
+// CHECK: @dx.op.unaryBits.i16
+// CHECK: sub i16
+
+struct SUnaryUintOp {
+    uint16_t input1;
+    uint16_t input2;
+    uint16_t output;
+};
+RWStructuredBuffer<SUnaryUintOp> g_buf;
+[numthreads(8,8,1)]
+void main(uint GI : SV_GroupIndex) {
+    SUnaryUintOp l = g_buf[GI];
+    int16_t output = min(l.input1,l.input2);
+    output += firstbithigh(l.input1);
+    output += firstbitlow(l.input1);
+    output += l.input1 - l.input2;
+    l.output = output;
+    g_buf[GI] = l;
+};

+ 6 - 0
tools/clang/unittests/HLSL/CompilerTest.cpp

@@ -602,6 +602,7 @@ public:
   TEST_METHOD(CodeGenInput1)
   TEST_METHOD(CodeGenInput2)
   TEST_METHOD(CodeGenInput3)
+  TEST_METHOD(CodeGenInt16Op)
   TEST_METHOD(CodeGenIntrinsic1)
   TEST_METHOD(CodeGenIntrinsic1Minprec)
   TEST_METHOD(CodeGenIntrinsic2)
@@ -3585,6 +3586,11 @@ TEST_F(CompilerTest, CodeGenInput3) {
   CodeGenTest(L"..\\CodeGenHLSL\\input3.hlsl");
 }
 
+TEST_F(CompilerTest, CodeGenInt16Op) {
+  if (m_ver.SkipDxilVersion(1, 2)) return;
+  CodeGenTestCheck(L"..\\CodeGenHLSL\\int16Op.hlsl");
+}
+
 TEST_F(CompilerTest, CodeGenIntrinsic1) {
   CodeGenTestCheck(L"..\\CodeGenHLSL\\intrinsic1.hlsl");
 }

+ 4 - 4
utils/hct/gen_intrin_main.txt

@@ -34,7 +34,7 @@
 //
 // Basic types are bool, int, uint, u64, float, sampler1d, sampler2d,
 // sampler3d, sampler_cube, sampler_cmp, sampler, wave and void.
-// There are meta-types too: any_int, u32_64, uint_only, numeric and any.
+// There are meta-types too: any_int, u16_32_64, uint_only, numeric and any.
 //
 // Along with a type and layout you can also give relations
 // between types in an intrinsic.  The types of an intrinsic
@@ -105,7 +105,7 @@ $type1 [[rn,unsigned_op=uclamp]] clamp(in numeric<> x, in $type1 min, in $type1
 void [[]] clip(in float<> x);
 $type1 [[rn]] cos(in float_like<> x);
 $type1 [[rn]] cosh(in float_like<> x);
-$match<1, 0> uint<> [[rn]] countbits(in u32_64<> x);
+$match<1, 0> uint<> [[rn]] countbits(in u16_32_64<> x);
 $type1 [[rn]] cross(in float_like<3> a, in $type1 b);
 $type1 [[rn]] ddx(in float_like<> x);
 $type1 [[rn]] ddx_coarse(in float_like<> x);
@@ -132,7 +132,7 @@ float<> [[rn]] f16tof32(in uint<> x);
 uint<> [[rn]] f32tof16(in float<> x);
 $type1 [[rn]] faceforward(in float_like<c> N, in $type1 I, in $type1 Ng);
 $match<1, 0> uint<> [[rn,unsigned_op=ufirstbithigh,overload=0]] firstbithigh(in any_int<> x);
-$match<1, 0> uint<> [[rn]] firstbitlow(in u32_64<> x);
+$match<1, 0> uint<> [[rn]] firstbitlow(in u16_32_64<> x);
 $type1 [[rn]] floor(in float_like<> x);
 $type1 [[rn]] fma(in double_only<> a, in $type1 b, in $type1 c);
 $type1 [[rn]] fmod(in float_like<> a, in $type1 b);
@@ -197,7 +197,7 @@ $type1 [[rn]] radians(in float_like<> x);
 $type1 [[rn]] rcp(in any_float<> x) : rcp_approx;
 $type1 [[rn]] reflect(in float_like<c> i, in $type1 n);
 $type1 [[rn]] refract(in float_like<c> i, in $type1 n, in float_like ri);
-$type1 [[rn]] reversebits(in u32_64<> x);
+$type1 [[rn]] reversebits(in u16_32_64<> x);
 $type1 [[rn]] round(in float_like<> x);
 $type1 [[rn]] rsqrt(in float_like<> x);
 $type1 [[rn]] saturate(in any_float<> x);

+ 1 - 1
utils/hct/hctdb.py

@@ -1933,7 +1933,7 @@ class db_hlsl(object):
             "uint": "LICOMPTYPE_UINT",
             "uint16_t": "LICOMPTYPE_UINT16",
             "u64": "LICOMPTYPE_UINT64",
-            "u32_64": "LICOMPTYPE_UINT32_64",
+            "u16_32_64": "LICOMPTYPE_UINT16_32_64",
             "any_int": "LICOMPTYPE_ANY_INT",
             "any_int32": "LICOMPTYPE_ANY_INT32",
             "uint_only": "LICOMPTYPE_UINT_ONLY",