summaryrefslogtreecommitdiffstats
path: root/source/slang/reflection.cpp
diff options
context:
space:
mode:
authorTim Foley <tfoley@nvidia.com>2017-07-13 09:50:27 -0700
committerTim Foley <tfoley@nvidia.com>2017-07-13 09:52:19 -0700
commitbb8ebb4e75db0a19ed7643876bf646bdacb2726e (patch)
tree2c41633b9ba7d63754bc2acfbe1d90468131f06c /source/slang/reflection.cpp
parentc51fd4ee8f478aa3d3b7e6208a3a4e9c00e2413a (diff)
An array of resources in Vulkan only consumes one binding
Fixes #84 - When computing resource usage for an array type, don't multiply the resource usage of the element type by the element count foor descriptor-table-slot resources. - When reporting the "stride" of an array type through reflection, report the stride for descriptor table slots as zero, always.
Diffstat (limited to 'source/slang/reflection.cpp')
-rw-r--r--source/slang/reflection.cpp28
1 files changed, 20 insertions, 8 deletions
diff --git a/source/slang/reflection.cpp b/source/slang/reflection.cpp
index 1beacc21b..3c89194c8 100644
--- a/source/slang/reflection.cpp
+++ b/source/slang/reflection.cpp
@@ -476,16 +476,28 @@ SLANG_API size_t spReflectionTypeLayout_GetElementStride(SlangReflectionTypeLayo
if( auto arrayTypeLayout = dynamic_cast<ArrayTypeLayout*>(typeLayout))
{
- if(category == SLANG_PARAMETER_CATEGORY_UNIFORM)
+ switch (category)
{
+ // We store the stride explictly for the uniform case
+ case SLANG_PARAMETER_CATEGORY_UNIFORM:
return arrayTypeLayout->uniformStride;
- }
- else
- {
- auto elementTypeLayout = arrayTypeLayout->elementTypeLayout;
- auto info = elementTypeLayout->FindResourceInfo(LayoutResourceKind(category));
- if(!info) return 0;
- return info->count;
+
+ // For most other cases (resource registers), the "stride"
+ // of an array is simply the number of resources (if any)
+ // consumed by its element type.
+ default:
+ {
+ auto elementTypeLayout = arrayTypeLayout->elementTypeLayout;
+ auto info = elementTypeLayout->FindResourceInfo(LayoutResourceKind(category));
+ if(!info) return 0;
+ return info->count;
+ }
+
+ // An import special case, though, is Vulkan descriptor-table slots,
+ // where an entire array will use a single `binding`, so that the
+ // effective stride is zero:
+ case SLANG_PARAMETER_CATEGORY_DESCRIPTOR_TABLE_SLOT:
+ return 0;
}
}