summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--source/slang/slang-emit-spirv.cpp3
-rw-r--r--source/slang/slang-ir-util.cpp18
-rw-r--r--tests/spirv/small-int-texture.slang17
3 files changed, 35 insertions, 3 deletions
diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp
index cb9eb0ae9..23eaa4435 100644
--- a/source/slang/slang-emit-spirv.cpp
+++ b/source/slang/slang-emit-spirv.cpp
@@ -6423,11 +6423,12 @@ struct SPIRVEmitContext
// If the component types are not the same, convert them to be so.
if (!isTypeEqual(getVectorElementType(toType), fromElementType))
{
+ SpvOp convertOp = isIntegralType(fromElementType) ? (isSignedType(fromElementType) ? SpvOpSConvert : SpvOpUConvert) : SpvOpFConvert;
auto newFromType = replaceVectorElementType(fromType, getVectorElementType(toType));
fromSpvInst = emitInstCustomOperandFunc(
parent,
nullptr,
- SpvOpFConvert,
+ convertOp,
[&]() {
emitOperand(newFromType);
emitOperand(kResultID),
diff --git a/source/slang/slang-ir-util.cpp b/source/slang/slang-ir-util.cpp
index 8294cd533..e030b6d24 100644
--- a/source/slang/slang-ir-util.cpp
+++ b/source/slang/slang-ir-util.cpp
@@ -1557,10 +1557,24 @@ void hoistInstOutOfASMBlocks(IRBlock* block)
IRType* getSPIRVSampledElementType(IRInst* sampledType)
{
auto sampledElementType = getVectorElementType((IRType*)sampledType);
- if (sampledElementType->getOp() == kIROp_HalfType)
+
+ IRBuilder builder(sampledType);
+ switch (sampledElementType->getOp())
{
- IRBuilder builder(sampledType);
+ case kIROp_HalfType:
sampledElementType = builder.getBasicType(BaseType::Float);
+ break;
+ case kIROp_UInt16Type:
+ case kIROp_UInt8Type:
+ case kIROp_CharType:
+ sampledElementType = builder.getBasicType(BaseType::UInt);
+ break;
+ case kIROp_Int8Type:
+ case kIROp_Int16Type:
+ sampledElementType = builder.getBasicType(BaseType::Int);
+ break;
+ default:
+ break;
}
return sampledElementType;
}
diff --git a/tests/spirv/small-int-texture.slang b/tests/spirv/small-int-texture.slang
new file mode 100644
index 000000000..b20ae35fe
--- /dev/null
+++ b/tests/spirv/small-int-texture.slang
@@ -0,0 +1,17 @@
+// Test that we can translate textures whose element type is a small integer type to valid spirv.
+
+//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-vk -compute -output-using-type -emit-spirv-directly
+
+//TEST_INPUT: RWTexture2D(format=R8_UINT, size=4, content = one, mipMaps = 1):name g_Image
+RWTexture2D<uint8_t> g_Image;
+
+//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
+RWStructuredBuffer<int> outputBuffer;
+
+[numthreads(1, 1, 1)]
+void computeMain(int id: SV_DispatchThreadID) {
+ g_Image[id] = uint8_t(23);
+ AllMemoryBarrier();
+ // CHECK: 23
+ outputBuffer[0] = g_Image[id];
+} \ No newline at end of file