diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2021-04-30 11:36:42 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-30 11:36:42 -0700 |
| commit | c45f368ae404798db67a601749c6e0047fba75ef (patch) | |
| tree | 2ac8f53f4bffa8ff760e051714bb6f3044947fe3 /tools/gfx/d3d11/render-d3d11.cpp | |
| parent | 37a341775e410c02df5072244becdc416fd15c86 (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/d3d11/render-d3d11.cpp')
| -rw-r--r-- | tools/gfx/d3d11/render-d3d11.cpp | 39 |
1 files changed, 31 insertions, 8 deletions
diff --git a/tools/gfx/d3d11/render-d3d11.cpp b/tools/gfx/d3d11/render-d3d11.cpp index 415e0b833..6f6ba4faf 100644 --- a/tools/gfx/d3d11/render-d3d11.cpp +++ b/tools/gfx/d3d11/render-d3d11.cpp @@ -550,6 +550,18 @@ protected: } } + /// Create an offset based on size/stride information in the given Slang `typeLayout` + SimpleBindingOffset(slang::TypeLayoutReflection* typeLayout) + { + if(typeLayout) + { + cbv = (uint32_t) typeLayout->getSize(SLANG_PARAMETER_CATEGORY_CONSTANT_BUFFER); + srv = (uint32_t) typeLayout->getSize(SLANG_PARAMETER_CATEGORY_SHADER_RESOURCE); + uav = (uint32_t) typeLayout->getSize(SLANG_PARAMETER_CATEGORY_UNORDERED_ACCESS); + sampler = (uint32_t) typeLayout->getSize(SLANG_PARAMETER_CATEGORY_SAMPLER_STATE); + } + } + /// Add any values in the given `offset` void operator+=(SimpleBindingOffset const& offset) { @@ -594,6 +606,12 @@ protected: , pending(varLayout->getPendingDataLayout()) {} + /// Create an offset based on size/stride information in the given Slang `typeLayout` + BindingOffset(slang::TypeLayoutReflection* typeLayout) + : SimpleBindingOffset(typeLayout) + , pending(typeLayout->getPendingDataTypeLayout()) + {} + /// Add any values in the given `offset` void operator+=(SimpleBindingOffset const& offset) { @@ -673,16 +691,17 @@ protected: }; /// Stride information for a sub-object range - struct SubObjectRangeStride + struct SubObjectRangeStride : BindingOffset { SubObjectRangeStride() {} SubObjectRangeStride(slang::TypeLayoutReflection* typeLayout) + : BindingOffset(typeLayout) { if(auto pendingLayout = typeLayout->getPendingDataTypeLayout()) { - pendingOrdinaryData = (uint32_t) pendingLayout->getSize(SLANG_PARAMETER_CATEGORY_UNIFORM); + pendingOrdinaryData = (uint32_t) typeLayout->getStride(); } } @@ -1747,6 +1766,11 @@ protected: BindingOffset rangeOffset = offset; rangeOffset += subObjectRange.offset; + // Similarly, the "stride" between consecutive objects in + // the range was also pre-computed. + // + BindingOffset rangeStride = subObjectRange.stride; + switch(bindingRange.bindingType) { // For D3D11-compatible compilation targets, the Slang compiler @@ -1765,8 +1789,7 @@ protected: // subObject->bindAsConstantBuffer(context, objOffset, subObjectLayout); - // TODO: We need to update `objOffset` by the stride for - // this range. + objOffset += rangeStride; } } break; @@ -1782,15 +1805,15 @@ protected: // As a result, the offset for the first object in the range // will come from the `pending` part of the range's offset. // - BindingOffset objOffset = BindingOffset(rangeOffset.pending); + SimpleBindingOffset objOffset = rangeOffset.pending; + SimpleBindingOffset objStride = rangeStride.pending; for(Index i = 0; i < count; ++i) { auto subObject = m_objects[ baseIndex + i ]; - subObject->bindAsValue(context, objOffset, subObjectLayout); + subObject->bindAsValue(context, BindingOffset(objOffset), subObjectLayout); - // TODO: We need to update `objOffset` by the stride for - // this range. + objOffset += objStride; } } break; |
