diff options
| author | Gangzheng Tong <tonggangzheng@gmail.com> | 2025-07-08 23:44:56 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-09 06:44:56 +0000 |
| commit | 43d0c2100ef1a5df4b54525e50eb29fe7c39ec16 (patch) | |
| tree | 25ec4fb9c726115f90bdaa9878f2f4ca372ad0a6 /tools/gfx-unit-test/link-time-constant-array-size.cpp | |
| parent | 00746bf09047cdf01c19dac513a532bcf3ed3ea3 (diff) | |
Convert gfx unit tests and examples to use slang-rhi (#7577)
* Port first gfx unit test to slang-rhi
* port triangle example to use slang-rhi
* port platform-test to slang-rhi
* Update platform-test to throttle mouse move events
* port gpu-printing example to use slang-rhi
* port model-viewer example to use slang-rhi
* port ray-tracing example to use slang-rhi
* port ray-tracing pipeline example to use slang-rhi
* port reflection parameter blocks example to use slang-rhi
* port shader-object example to use slang-rhi
* port shader-toy example to use slang-rhi
* Port most of tests to slang-rhi
* port link-time-constant-array-size to use slang-rhi
* Fix tests and find matching tests in slang-rhi
* port autodiff-texture
* remove gfx target; port nv-aftermath-example
* update include path for shader-cursor.h
* Disabled 2 more ported tests
* fix build error
* remove gfx test
* put slang-rhi (static-lib) before slang (shared)
* format code (#7621)
Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
* add debug callback
* format code (#7649)
Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
* Address review comments; revert back to use SLANG_CHECK_MSG
---------
Co-authored-by: slangbot <ellieh+slangbot@nvidia.com>
Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
Diffstat (limited to 'tools/gfx-unit-test/link-time-constant-array-size.cpp')
| -rw-r--r-- | tools/gfx-unit-test/link-time-constant-array-size.cpp | 85 |
1 files changed, 31 insertions, 54 deletions
diff --git a/tools/gfx-unit-test/link-time-constant-array-size.cpp b/tools/gfx-unit-test/link-time-constant-array-size.cpp index e67e5636c..0c1c20c1d 100644 --- a/tools/gfx-unit-test/link-time-constant-array-size.cpp +++ b/tools/gfx-unit-test/link-time-constant-array-size.cpp @@ -1,17 +1,18 @@ #include "core/slang-basic.h" #include "core/slang-blob.h" #include "gfx-test-util.h" -#include "gfx-util/shader-cursor.h" -#include "slang-gfx.h" #include "unit-test/slang-unit-test.h" -using namespace gfx; +#include <slang-rhi.h> +#include <slang-rhi/shader-cursor.h> + +using namespace rhi; namespace gfx_test { static Slang::Result loadProgram( - gfx::IDevice* device, - Slang::ComPtr<gfx::IShaderProgram>& outShaderProgram, + IDevice* device, + Slang::ComPtr<IShaderProgram>& outShaderProgram, const char* mainModuleName, const char* libModuleName, const char* entryPointName, @@ -64,10 +65,10 @@ static Slang::Result loadProgram( slangReflection = composedProgram->getLayout(); // Create shader program - gfx::IShaderProgram::Desc programDesc = {}; + ShaderProgramDesc programDesc = {}; programDesc.slangGlobalScope = composedProgram.get(); - auto shaderProgram = device->createProgram(programDesc); + auto shaderProgram = device->createShaderProgram(programDesc); outShaderProgram = shaderProgram; return SLANG_OK; @@ -80,20 +81,18 @@ static void validateArraySizeInStruct( int expectedSize) { // Check reflection is available - SLANG_CHECK(slangReflection != nullptr); + SLANG_CHECK_ABORT(slangReflection != nullptr); // Get the global scope layout auto globalScope = slangReflection->getGlobalParamsVarLayout(); - SLANG_CHECK_MSG(globalScope != nullptr, "Could not get global scope layout"); + SLANG_CHECK_ABORT(globalScope != nullptr); auto typeLayout = globalScope->getTypeLayout(); - SLANG_CHECK_MSG(typeLayout != nullptr, "Global scope has no type layout"); + SLANG_CHECK_ABORT(typeLayout != nullptr); // Check if the global scope is a struct type auto kind = typeLayout->getKind(); - SLANG_CHECK_MSG( - kind == slang::TypeReflection::Kind::Struct, - "Global scope is not a struct type"); + SLANG_CHECK_ABORT(kind == slang::TypeReflection::Kind::Struct); // Find the buffer resource 'b' bool foundBuffer = false; @@ -117,7 +116,6 @@ static void validateArraySizeInStruct( SLANG_CHECK_MSG( elementTypeLayout != nullptr, "Structured buffer has no element type layout"); - // Check if it's a struct type auto elementKind = elementTypeLayout->getKind(); SLANG_CHECK_MSG( @@ -176,13 +174,6 @@ static void validateArraySizeInStruct( void linkTimeConstantArraySizeTestImpl(IDevice* device, UnitTestContext* context) { - // Create transient heap - Slang::ComPtr<ITransientResourceHeap> transientHeap; - ITransientResourceHeap::Desc transientHeapDesc = {}; - transientHeapDesc.constantBufferSize = 4096; - GFX_CHECK_CALL_ABORT( - device->createTransientResourceHeap(transientHeapDesc, transientHeap.writeRef())); - // Load and link program ComPtr<IShaderProgram> shaderProgram; slang::ProgramLayout* slangReflection; @@ -200,70 +191,56 @@ void linkTimeConstantArraySizeTestImpl(IDevice* device, UnitTestContext* context validateArraySizeInStruct(context, slangReflection, N); // Create compute pipeline - ComputePipelineStateDesc pipelineDesc = {}; + ComputePipelineDesc pipelineDesc = {}; pipelineDesc.program = shaderProgram.get(); - ComPtr<gfx::IPipelineState> pipelineState; - GFX_CHECK_CALL_ABORT( - device->createComputePipelineState(pipelineDesc, pipelineState.writeRef())); + ComPtr<IComputePipeline> pipelineState; + GFX_CHECK_CALL_ABORT(device->createComputePipeline(pipelineDesc, pipelineState.writeRef())); // Create buffer for struct S with array of size N int32_t initialData[] = {1, 2, 3, 4}; - IBufferResource::Desc bufferDesc = {}; - bufferDesc.sizeInBytes = N * sizeof(int32_t); - bufferDesc.format = gfx::Format::Unknown; + BufferDesc bufferDesc = {}; + bufferDesc.size = N * sizeof(int32_t); + bufferDesc.format = Format::Undefined; bufferDesc.elementSize = sizeof(int32_t); - bufferDesc.allowedStates = ResourceStateSet( - ResourceState::ShaderResource, - ResourceState::UnorderedAccess, - ResourceState::CopyDestination, - ResourceState::CopySource); + bufferDesc.usage = BufferUsage::ShaderResource | BufferUsage::UnorderedAccess | + BufferUsage::CopyDestination | BufferUsage::CopySource; bufferDesc.defaultState = ResourceState::UnorderedAccess; bufferDesc.memoryType = MemoryType::DeviceLocal; - ComPtr<IBufferResource> numbersBuffer; - GFX_CHECK_CALL_ABORT( - device->createBufferResource(bufferDesc, (void*)initialData, numbersBuffer.writeRef())); - - ComPtr<IResourceView> bufferView; - IResourceView::Desc viewDesc = {}; - viewDesc.type = IResourceView::Type::UnorderedAccess; - viewDesc.format = Format::Unknown; + ComPtr<IBuffer> numbersBuffer; GFX_CHECK_CALL_ABORT( - device->createBufferView(numbersBuffer, nullptr, viewDesc, bufferView.writeRef())); + device->createBuffer(bufferDesc, (void*)initialData, numbersBuffer.writeRef())); // Record and execute command buffer { - ICommandQueue::Desc queueDesc = {ICommandQueue::QueueType::Graphics}; - auto queue = device->createCommandQueue(queueDesc); - - auto commandBuffer = transientHeap->createCommandBuffer(); - auto encoder = commandBuffer->encodeComputeCommands(); + auto queue = device->getQueue(QueueType::Graphics); + auto commandEncoder = queue->createCommandEncoder(); + auto encoder = commandEncoder->beginComputePass(); auto rootObject = encoder->bindPipeline(pipelineState); ShaderCursor rootCursor(rootObject); - rootCursor.getPath("b").setResource(bufferView); + rootCursor.getPath("b").setBinding(Binding(numbersBuffer)); encoder->dispatchCompute(1, 1, 1); - encoder->endEncoding(); - commandBuffer->close(); - queue->executeCommandBuffer(commandBuffer); + encoder->end(); + queue->submit(commandEncoder->finish()); queue->waitOnHost(); } // Expected results: each element is input * N // With N=4 and inputs [1,2,3,4], expected output is [4,8,12,16] - compareComputeResult(device, numbersBuffer, Slang::makeArray<int>(4, 8, 12, 16)); + compareComputeResult(device, numbersBuffer, std::array{4, 8, 12, 16}); } SLANG_UNIT_TEST(linkTimeConstantArraySizeD3D12) { - runTestImpl(linkTimeConstantArraySizeTestImpl, unitTestContext, Slang::RenderApiFlag::D3D12); + runTestImpl(linkTimeConstantArraySizeTestImpl, unitTestContext, DeviceType::D3D12); } SLANG_UNIT_TEST(linkTimeConstantArraySizeVulkan) { - runTestImpl(linkTimeConstantArraySizeTestImpl, unitTestContext, Slang::RenderApiFlag::Vulkan); + runTestImpl(linkTimeConstantArraySizeTestImpl, unitTestContext, DeviceType::Vulkan); } } // namespace gfx_test |
