diff options
| author | Ellie Hermaszewska <ellieh@nvidia.com> | 2023-10-18 06:26:00 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-17 15:26:00 -0700 |
| commit | 7826afcaad78cc33c976bb3db3cdc9eada4c77e8 (patch) | |
| tree | 7a89a54512a4cbab6165d2c4b7906f88a032bbee /tools/render-test | |
| parent | 0a3683dd39fc04d15937b8a4700d477f9492c257 (diff) | |
Type layouts for structured buffers with counters (#3269)
* More tests for append structured buffer
* Append and Consume structured buffer tests for DX12
* neaten
* test wobble
* Add counter layout information to append/consume structured buffers
* add getRWStructuredBufferType
* Correct definition of get size for append/consume structured buffers
* tweak append structured buffer test
* Allow initializing counter buffer in render test
* vulkan test for consume structured buffer
* Handle null counterVarLayout in getExplicitCounterBindingRangeOffset
* remove dead code
* Implement atomic counter increment/decrement for spirv
* explicit spirv test
* Add missing check on result
* Hold on to counter resources
---------
Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'tools/render-test')
| -rw-r--r-- | tools/render-test/render-test-main.cpp | 42 | ||||
| -rw-r--r-- | tools/render-test/shader-input-layout.cpp | 5 | ||||
| -rw-r--r-- | tools/render-test/shader-input-layout.h | 4 |
3 files changed, 49 insertions, 2 deletions
diff --git a/tools/render-test/render-test-main.cpp b/tools/render-test/render-test-main.cpp index 3bdcdba07..1f2b3a5ae 100644 --- a/tools/render-test/render-test-main.cpp +++ b/tools/render-test/render-test-main.cpp @@ -209,11 +209,49 @@ struct AssignValsFromLayoutContext ComPtr<IBufferResource> bufferResource; SLANG_RETURN_ON_FAIL(ShaderRendererUtil::createBufferResource(srcBuffer, /*entry.isOutput,*/ bufferSize, bufferData.getBuffer(), device, bufferResource)); + ComPtr<IBufferResource> counterResource; + const auto explicitCounterCursor = dstCursor.getExplicitCounter(); + if(srcBuffer.counter != ~0u) + { + if(explicitCounterCursor.isValid()) + { + // If this cursor has a full buffer object associated with the + // resource, then assign to that. + ShaderInputLayout::BufferVal counterVal; + counterVal.bufferData.add(srcBuffer.counter); + assignBuffer(explicitCounterCursor, &counterVal); + } + else + { + // Otherwise, this API (D3D) must be handling the buffer object + // specially, in which case create the buffer resource to pass + // into `createBufferView` + const InputBufferDesc& counterBufferDesc{ + InputBufferType::StorageBuffer, + sizeof(uint32_t), + Format::Unknown, + }; + SLANG_RETURN_ON_FAIL(ShaderRendererUtil::createBufferResource( + counterBufferDesc, + sizeof(srcBuffer.counter), + &srcBuffer.counter, + device, + counterResource + )); + } + } + else if(explicitCounterCursor.isValid()) + { + // If we know we require a counter for this resource but haven't + // been given one, error + return SLANG_E_INVALID_ARG; + } + IResourceView::Desc viewDesc = {}; viewDesc.type = IResourceView::Type::UnorderedAccess; viewDesc.format = srcBuffer.format; viewDesc.bufferElementSize = srcVal->bufferDesc.stride; - auto bufferView = device->createBufferView(bufferResource, nullptr, viewDesc); + auto bufferView = device->createBufferView(bufferResource, counterResource, viewDesc); dstCursor.setResource(bufferView); maybeAddOutput(dstCursor, srcVal, bufferResource); @@ -977,7 +1015,7 @@ Result RenderTestApp::writeBindingOutput(const String& fileName) m_transientHeap->finish(); m_transientHeap->synchronizeAndReset(); - m_device->readBufferResource(stagingBuffer, 0, bufferSize, blob.writeRef()); + SLANG_RETURN_ON_FAIL(m_device->readBufferResource(stagingBuffer, 0, bufferSize, blob.writeRef())); } if (!blob) diff --git a/tools/render-test/shader-input-layout.cpp b/tools/render-test/shader-input-layout.cpp index b8c505607..80ce4e316 100644 --- a/tools/render-test/shader-input-layout.cpp +++ b/tools/render-test/shader-input-layout.cpp @@ -203,6 +203,11 @@ namespace renderer_test parser.Read("="); val->bufferDesc.stride = parser.ReadInt(); } + else if (word == "counter") + { + parser.Read("="); + val->bufferDesc.counter = parser.ReadInt(); + } else if (word == "random") { parser.Read("("); diff --git a/tools/render-test/shader-input-layout.h b/tools/render-test/shader-input-layout.h index 78d545114..2803d1915 100644 --- a/tools/render-test/shader-input-layout.h +++ b/tools/render-test/shader-input-layout.h @@ -58,6 +58,10 @@ struct InputBufferDesc InputBufferType type = InputBufferType::StorageBuffer; int stride = 0; // stride == 0 indicates an unstructured buffer. Format format = Format::Unknown; + // For RWStructuredBuffer, AppendStructuredBuffer, ConsumeStructuredBuffer + // the default value of 0xffffffff indicates that a counter buffer should + // not be assigned + uint32_t counter = ~0u; }; struct InputSamplerDesc |
