From 579df478de078f0a22f72f499c13ce442b4cd290 Mon Sep 17 00:00:00 2001 From: Yong He Date: Mon, 13 Sep 2021 00:27:13 -0700 Subject: Bug fix in 16bit type emit, vk validation error fix. (#1936) + Implement bit_cast between float16 and uint16 in GLSL. + Enable pack-any-value-16bit test on vk. Co-authored-by: Yong He --- source/slang/slang-emit-glsl.cpp | 43 ++++++++++++++++++++++++++++- source/slang/slang-emit-hlsl.cpp | 14 +--------- tests/compute/half-texture.slang.1.expected | 14 +++++----- tests/compute/pack-any-value-16bit.slang | 5 ++-- tools/gfx/vulkan/render-vk.cpp | 4 ++- 5 files changed, 55 insertions(+), 25 deletions(-) diff --git a/source/slang/slang-emit-glsl.cpp b/source/slang/slang-emit-glsl.cpp index 82804c6b5..634067ab7 100644 --- a/source/slang/slang-emit-glsl.cpp +++ b/source/slang/slang-emit-glsl.cpp @@ -1432,7 +1432,48 @@ bool GLSLSourceEmitter::tryEmitInstExprImpl(IRInst* inst, const EmitOpInfo& inOu emitType(inst->getDataType()); } break; - + case BaseType::UInt16: + if (fromType == BaseType::Half) + { + m_writer->emit("uint16_t(packHalf2x16(vec2("); + emitOperand(inst->getOperand(0), getInfo(EmitOp::General)); + m_writer->emit(", 0.0)))"); + return true; + } + else + { + emitType(inst->getDataType()); + } + break; + case BaseType::Int16: + if (fromType == BaseType::Half) + { + m_writer->emit("int16_t(packHalf2x16(vec2("); + emitOperand(inst->getOperand(0), getInfo(EmitOp::General)); + m_writer->emit(", 0.0)))"); + return true; + } + else + { + emitType(inst->getDataType()); + } + break; + case BaseType::Half: + switch (fromType) + { + case BaseType::Int16: + case BaseType::UInt16: + case BaseType::Int: + case BaseType::UInt: + m_writer->emit("float16_t(unpackHalf2x16(uint("); + emitOperand(inst->getOperand(0), getInfo(EmitOp::General)); + m_writer->emit(")).x)"); + return true; + default: + emitType(inst->getDataType()); + break; + } + break; case BaseType::Float: switch (fromType) { diff --git a/source/slang/slang-emit-hlsl.cpp b/source/slang/slang-emit-hlsl.cpp index 2fda8ab99..dc58b7507 100644 --- a/source/slang/slang-emit-hlsl.cpp +++ b/source/slang/slang-emit-hlsl.cpp @@ -766,23 +766,11 @@ void HLSLSourceEmitter::emitSimpleTypeImpl(IRType* type) case kIROp_UInt64Type: case kIROp_FloatType: case kIROp_DoubleType: - { - m_writer->emit(getDefaultBuiltinTypeName(type->getOp())); - return; - } case kIROp_Int16Type: - { - m_writer->emit("min16int"); - return; - } case kIROp_UInt16Type: { - m_writer->emit("min16uint"); - return; - } case kIROp_HalfType: - { - m_writer->emit("min16float"); + m_writer->emit(getDefaultBuiltinTypeName(type->getOp())); return; } case kIROp_StructType: diff --git a/tests/compute/half-texture.slang.1.expected b/tests/compute/half-texture.slang.1.expected index cd1f1e4f7..7dd96403f 100644 --- a/tests/compute/half-texture.slang.1.expected +++ b/tests/compute/half-texture.slang.1.expected @@ -5,11 +5,11 @@ standard output = { #pragma pack_matrix(column_major) #line 8 "tests/compute/half-texture.slang" -RWTexture2D halfTexture_0 : register(u1); +RWTexture2D halfTexture_0 : register(u1); -RWTexture2D > halfTexture2_0 : register(u2); +RWTexture2D > halfTexture2_0 : register(u2); -RWTexture2D > halfTexture4_0 : register(u3); +RWTexture2D > halfTexture4_0 : register(u3); #line 5 @@ -27,15 +27,15 @@ void computeMain(vector dispatchThreadID_0 : SV_DISPATCHTHREADID) vector pos2_0 = vector(int(3) - pos_0.y, int(3) - pos_0.x); #line 29 - min16float h_0 = halfTexture_0[(vector) pos2_0]; - vector h2_0 = halfTexture2_0[(vector) pos2_0]; - vector h4_0 = halfTexture4_0[(vector) pos2_0]; + half h_0 = halfTexture_0[(vector) pos2_0]; + vector h2_0 = halfTexture2_0[(vector) pos2_0]; + vector h4_0 = halfTexture4_0[(vector) pos2_0]; halfTexture_0[(vector) pos_0] = h2_0.x + h2_0.y; halfTexture2_0[(vector) pos_0] = h4_0.xy; - halfTexture4_0[(vector) pos_0] = vector(h2_0, h_0, h_0); + halfTexture4_0[(vector) pos_0] = vector(h2_0, h_0, h_0); int index_0 = pos_0.x + pos_0.y * int(4); outputBuffer_0[(uint) index_0] = index_0; diff --git a/tests/compute/pack-any-value-16bit.slang b/tests/compute/pack-any-value-16bit.slang index b4f41bb94..1a7c96a16 100644 --- a/tests/compute/pack-any-value-16bit.slang +++ b/tests/compute/pack-any-value-16bit.slang @@ -1,9 +1,8 @@ // Test anyvalue packing of 16bit types. -//TEST_DISABLED(compute):COMPARE_COMPUTE_EX:-slang -compute -vk -output-using-type //TEST_DISABLED(compute):COMPARE_COMPUTE_EX:-slang -compute -cuda -output-using-type -//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -profile sm_6_0 -use-dxil -output-using-type -//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx11 -profile sm_5_0 -output-using-type +//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -output-using-type -render-feature int16,half +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -profile sm_6_2 -use-dxil -output-using-type [anyValueSize(32)] interface IInterface diff --git a/tools/gfx/vulkan/render-vk.cpp b/tools/gfx/vulkan/render-vk.cpp index f56a21d20..847eaec90 100644 --- a/tools/gfx/vulkan/render-vk.cpp +++ b/tools/gfx/vulkan/render-vk.cpp @@ -4083,7 +4083,9 @@ public: VK_PIPELINE_STAGE_ACCELERATION_STRUCTURE_BUILD_BIT_KHR | VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, VK_PIPELINE_STAGE_ACCELERATION_STRUCTURE_BUILD_BIT_KHR | - VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT | VK_PIPELINE_STAGE_TRANSFER_BIT, + VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT | VK_PIPELINE_STAGE_TRANSFER_BIT | + VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | + VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT | VK_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR, 0, 0, nullptr, -- cgit v1.2.3