summaryrefslogtreecommitdiffstats
path: root/tools/gfx/vulkan/render-vk.cpp
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2021-04-30 11:36:42 -0700
committerGitHub <noreply@github.com>2021-04-30 11:36:42 -0700
commitc45f368ae404798db67a601749c6e0047fba75ef (patch)
tree2ac8f53f4bffa8ff760e051714bb6f3044947fe3 /tools/gfx/vulkan/render-vk.cpp
parent37a341775e410c02df5072244becdc416fd15c86 (diff)
Clean up the way we stride over sub-object ranges for D3D11 and Vulkan (#1829)
This change applies to the case where we have a sub-object range with more than one object in it (so arrays of constant buffers, parameter blocks, or existentials). It is worth noting that we don't really seem to have any tests covering this case right now, so it is entirely possible that things are busted already, and/or that this change doesn't work the way I think it does. When we go to actually bind the state from a sub-object range into the pipeline, we care about: * The offset to where the first object should be written * The "stride" between consecutive objects We were already capturing the offset information from Slang reflection data, and the same was true for the part of the offset that pertains to "pending" ordinary data. For other cases, though, we were manually incrementing the offset by values computed manually in `gfx` for Vulkan, and we were just skipping the offsetting step entirely for D3D11. With this change we extract more complete stride information from the Slang reflection data and use that instead of ad hoc computations. Hopefully this data is correct, and if it isn't we can consider whether it needs fixing at the Slang reflection level rather than in `gfx`. This change doesn't apply to the OpenGL back-end (which hasn't been updated to match the new approach to static specialization at all) or to the D3D12 back end (which has been updated a bit, but probably needs other cleanup work to be done first to bring it in line).
Diffstat (limited to 'tools/gfx/vulkan/render-vk.cpp')
-rw-r--r--tools/gfx/vulkan/render-vk.cpp32
1 files changed, 11 insertions, 21 deletions
diff --git a/tools/gfx/vulkan/render-vk.cpp b/tools/gfx/vulkan/render-vk.cpp
index a0860f0e5..f330d95a8 100644
--- a/tools/gfx/vulkan/render-vk.cpp
+++ b/tools/gfx/vulkan/render-vk.cpp
@@ -853,7 +853,7 @@ public:
};
/// Stride information for a sub-object range
- struct SubObjectRangeStride
+ struct SubObjectRangeStride : BindingOffset
{
SubObjectRangeStride()
{}
@@ -862,7 +862,7 @@ public:
{
if(auto pendingLayout = typeLayout->getPendingDataTypeLayout())
{
- pendingOrdinaryData = (uint32_t) pendingLayout->getSize(SLANG_PARAMETER_CATEGORY_UNIFORM);
+ pendingOrdinaryData = (uint32_t) pendingLayout->getStride();
}
}
@@ -3095,6 +3095,8 @@ public:
BindingOffset rangeOffset = offset;
rangeOffset += subObjectRange.offset;
+ BindingOffset rangeStride = subObjectRange.stride;
+
switch( bindingRangeInfo.bindingType )
{
case slang::BindingType::ConstantBuffer:
@@ -3114,12 +3116,7 @@ public:
// sure to increment the offset for each subsequent object
// by the appropriate stride.
//
- // TODO: We should pre-compute these and simply have
- // `subObjectRange.stride` to go with `subObjectRange.offset`.
- //
- objOffset.binding += subObjectLayout->getTotalBindingCount();
- objOffset.childSet += subObjectLayout->getChildDescriptorSetCount();
- objOffset.pushConstantRange += subObjectLayout->getTotalPushConstantRangeCount();
+ objOffset += rangeStride;
}
}
break;
@@ -3135,12 +3132,7 @@ public:
ShaderObjectImpl* subObject = m_objects[baseIndex + i];
subObject->bindAsParameterBlock(encoder, context, objOffset, subObjectLayout);
- // The logic for striding from one sub-object to another is also
- // different, given the differences in how constant buffers and
- // parameter blocks are allocated.
- //
- objOffset.childSet += subObjectLayout->getChildDescriptorSetCount();
- objOffset.pushConstantRange += subObjectLayout->getTotalPushConstantRangeCount();
+ objOffset += rangeStride;
}
}
break;
@@ -3153,14 +3145,15 @@ public:
//
if( subObjectLayout )
{
- // Second, the offset where we want to start bindign for existential-type
+ // Second, the offset where we want to start binding for existential-type
// ranges is a bit different, because we don't wnat to bind at the "primary"
// offset that got passed down, but instead at the "pending" offset.
//
// For the purposes of nested binding, what used to be the pending offset
// will now be used as the primary offset.
//
- BindingOffset objOffset = BindingOffset(rangeOffset.pending);
+ SimpleBindingOffset objOffset = rangeOffset.pending;
+ SimpleBindingOffset objStride = rangeStride.pending;
for (uint32_t i = 0; i < count; ++i)
{
// An existential-type sub-object is always bound just as a value,
@@ -3170,11 +3163,8 @@ public:
// already.
//
ShaderObjectImpl* subObject = m_objects[baseIndex + i];
- subObject->bindAsValue(encoder, context, objOffset, subObjectLayout);
-
- objOffset.binding += subObjectLayout->getTotalBindingCount();
- objOffset.childSet += subObjectLayout->getChildDescriptorSetCount();
- objOffset.pushConstantRange += subObjectLayout->getTotalPushConstantRangeCount();
+ subObject->bindAsValue(encoder, context, BindingOffset(objOffset), subObjectLayout);
+ objOffset += objStride;
}
}
break;