summaryrefslogtreecommitdiffstats
path: root/source/slang/type-layout.cpp
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2017-07-13 10:31:09 -0700
committerGitHub <noreply@github.com>2017-07-13 10:31:09 -0700
commit4bc59f896c9df970ec27a57c397977fc4721d3cd (patch)
tree2c41633b9ba7d63754bc2acfbe1d90468131f06c /source/slang/type-layout.cpp
parentc963b44aa48a4349e20a0afcd423b55b1996d2fa (diff)
parentbb8ebb4e75db0a19ed7643876bf646bdacb2726e (diff)
Merge pull request #86 from tfoleyNV/resource-array-layout-fix
An array of resources in Vulkan only consumes one binding
Diffstat (limited to 'source/slang/type-layout.cpp')
-rw-r--r--source/slang/type-layout.cpp22
1 files changed, 21 insertions, 1 deletions
diff --git a/source/slang/type-layout.cpp b/source/slang/type-layout.cpp
index 9bc001e88..2977ee9b8 100644
--- a/source/slang/type-layout.cpp
+++ b/source/slang/type-layout.cpp
@@ -1053,10 +1053,30 @@ SimpleLayoutInfo GetLayoutImpl(
// The uniform case was already handled above
if( elementResourceInfo.kind == LayoutResourceKind::Uniform )
continue;
+
+ // In almost all cases, the resources consumed by an array
+ // will be its element count times the resources consumed
+ // by its element type. The one exception to this is
+ // arrays of resources in Vulkan GLSL, where an entire array
+ // only consumes a single descriptor-table slot.
+ //
+ // Note: We extend this logic to arbitrary arrays-of-structs,
+ // under the assumption that downstream legalization will
+ // turn those into scalarized structs-of-arrays and this
+ // logic will work out.
+ UInt arrayResourceCount = 0;
+ if (elementResourceInfo.kind == LayoutResourceKind::DescriptorTableSlot)
+ {
+ arrayResourceCount = elementResourceInfo.count;
+ }
+ else
+ {
+ arrayResourceCount = elementResourceInfo.count * elementCount;
+ }
typeLayout->addResourceUsage(
elementResourceInfo.kind,
- elementResourceInfo.count * elementCount);
+ arrayResourceCount);
}
}
return arrayUniformInfo;