From d39c94c56f897f8e1b9b5070b527471ce2baa1a3 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Wed, 3 Jan 2018 10:13:04 -0500 Subject: [PATCH] [spirv] Emit warning for packoffset (#951) We do not support packoffset right now. Emit warning and ignore it. --- docs/SPIR-V.rst | 6 +++++- tools/clang/lib/SPIRV/SPIRVEmitter.cpp | 7 ++++++- .../CodeGenSPIRV/vk.layout.cbuffer.packoffset.hlsl | 14 ++++++++++++++ tools/clang/unittests/SPIRV/CodeGenSPIRVTest.cpp | 4 ++++ 4 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 tools/clang/test/CodeGenSPIRV/vk.layout.cbuffer.packoffset.hlsl diff --git a/docs/SPIR-V.rst b/docs/SPIR-V.rst index c1e3f5d73..b4e73450a 100644 --- a/docs/SPIR-V.rst +++ b/docs/SPIR-V.rst @@ -2348,4 +2348,8 @@ either because of no Vulkan equivalents at the moment, or because of deprecation only allowed to be applied to members of structures. A warning will be issued by the compiler. * The Hull shader ``partitioning`` attribute may not have the ``pow2`` value. The compiler will emit an error. Other attribute values are supported and described in the - `Hull Entry Point Attributes`_ section. \ No newline at end of file + `Hull Entry Point Attributes`_ section. +* ``cbuffer``/``tbuffer`` member initializer: no Vulkan equivalent. The compiler + will emit an warning and ignore it. +* ``:packoffset()``: Not supported right now. The compiler will emit an warning + and ignore it. diff --git a/tools/clang/lib/SPIRV/SPIRVEmitter.cpp b/tools/clang/lib/SPIRV/SPIRVEmitter.cpp index ec5b1e62b..31e4a9c3c 100644 --- a/tools/clang/lib/SPIRV/SPIRVEmitter.cpp +++ b/tools/clang/lib/SPIRV/SPIRVEmitter.cpp @@ -883,12 +883,17 @@ void SPIRVEmitter::doHLSLBufferDecl(const HLSLBufferDecl *bufferDecl) { // Check and emit warnings for member intializers which are not // supported in Vulkan for (const auto *member : bufferDecl->decls()) { - if (const auto *varMember = dyn_cast(member)) + if (const auto *varMember = dyn_cast(member)) { if (const auto *init = varMember->getInit()) emitWarning("%select{tbuffer|cbuffer}0 member initializer " "ignored since no equivalent in Vulkan", init->getExprLoc()) << bufferDecl->isCBuffer() << init->getSourceRange(); + + for (const auto *annotation : varMember->getUnusualAnnotations()) + if (const auto *packing = dyn_cast(annotation)) + emitWarning("packoffset ignored since not supported", packing->Loc); + } } validateVKAttributes(bufferDecl); (void)declIdMapper.createCTBuffer(bufferDecl); diff --git a/tools/clang/test/CodeGenSPIRV/vk.layout.cbuffer.packoffset.hlsl b/tools/clang/test/CodeGenSPIRV/vk.layout.cbuffer.packoffset.hlsl new file mode 100644 index 000000000..16a083def --- /dev/null +++ b/tools/clang/test/CodeGenSPIRV/vk.layout.cbuffer.packoffset.hlsl @@ -0,0 +1,14 @@ +// Run: %dxc -T vs_6_0 -E main + +cbuffer MyCBuffer { + float4 data1; + float4 data2 : packoffset(c1); + float data3 : packoffset(c2.y); +} + +float4 main() : A { + return data1 + data2 + data3; +} + +// CHECK: :5:20: warning: packoffset ignored since not supported +// CHECK: :6:20: warning: packoffset ignored since not supported diff --git a/tools/clang/unittests/SPIRV/CodeGenSPIRVTest.cpp b/tools/clang/unittests/SPIRV/CodeGenSPIRVTest.cpp index 5ac91eb69..cc6b11958 100644 --- a/tools/clang/unittests/SPIRV/CodeGenSPIRVTest.cpp +++ b/tools/clang/unittests/SPIRV/CodeGenSPIRVTest.cpp @@ -1091,6 +1091,10 @@ TEST_F(FileTest, VulkanLayoutPushConstantStd430) { runFileTest("vk.layout.push-constant.std430.hlsl"); } +TEST_F(FileTest, VulkanLayoutCBufferPackOffset) { + runFileTest("vk.layout.cbuffer.packoffset.hlsl", Expect::Warning); +} + // HS: for different Patch Constant Functions TEST_F(FileTest, HullShaderPCFVoid) { runFileTest("hs.pcf.void.hlsl"); } TEST_F(FileTest, HullShaderPCFTakesInputPatch) {