2
0
Эх сурвалжийг харах

[spirv] Add half as allowed (RW)Buffer element type (#1678)

Fixes https://github.com/Microsoft/DirectXShaderCompiler/issues/1672
Lei Zhang 6 жил өмнө
parent
commit
ee00dc18d6

+ 1 - 0
tools/clang/lib/SPIRV/TypeTranslator.cpp

@@ -1490,6 +1490,7 @@ TypeTranslator::translateSampledTypeToImageFormat(QualType sampledType) {
                               : elemCount == 2 ? spv::ImageFormat::Rg32ui
                                                : spv::ImageFormat::Rgba32ui;
       case BuiltinType::Float:
+      case BuiltinType::HalfFloat:
         return elemCount == 1 ? spv::ImageFormat::R32f
                               : elemCount == 2 ? spv::ImageFormat::Rg32f
                                                : spv::ImageFormat::Rgba32f;

+ 13 - 0
tools/clang/test/CodeGenSPIRV/type.rwbuffer.half.hlsl

@@ -0,0 +1,13 @@
+// Run: %dxc -T cs_6_0 -E main
+
+// CHECK: %type_buffer_image = OpTypeImage %float Buffer 2 0 0 2 Rgba32f
+// CHECK: %_ptr_UniformConstant_type_buffer_image = OpTypePointer UniformConstant %type_buffer_image
+// CHECK: %HalfBuffer = OpVariable %_ptr_UniformConstant_type_buffer_image UniformConstant
+
+RWBuffer<half4> HalfBuffer;
+
+void main()
+{
+    HalfBuffer[0] = 1.0;
+}
+

+ 3 - 0
tools/clang/unittests/SPIRV/CodeGenSPIRVTest.cpp

@@ -72,6 +72,9 @@ TEST_F(FileTest, BufferTypeStructError2) {
 TEST_F(FileTest, BufferTypeStructError3) {
   runFileTest("type.buffer.struct.error3.hlsl", Expect::Failure);
 }
+TEST_F(FileTest, RWBufferTypeHalfElementType) {
+  runFileTest("type.rwbuffer.half.hlsl");
+}
 TEST_F(FileTest, RWBufferTypeStructError) {
   runFileTest("type.rwbuffer.struct.error.hlsl", Expect::Failure);
 }