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/precompiled-module-cache.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/precompiled-module-cache.cpp')
| -rw-r--r-- | tools/gfx-unit-test/precompiled-module-cache.cpp | 80 |
1 files changed, 30 insertions, 50 deletions
diff --git a/tools/gfx-unit-test/precompiled-module-cache.cpp b/tools/gfx-unit-test/precompiled-module-cache.cpp index 778c68a89..f9ff31070 100644 --- a/tools/gfx-unit-test/precompiled-module-cache.cpp +++ b/tools/gfx-unit-test/precompiled-module-cache.cpp @@ -3,18 +3,18 @@ #include "core/slang-io.h" #include "core/slang-memory-file-system.h" #include "gfx-test-util.h" -#include "gfx-util/shader-cursor.h" -#include "slang-gfx.h" +#include "slang-rhi.h" +#include "slang-rhi/shader-cursor.h" #include "unit-test/slang-unit-test.h" #include <mutex> -using namespace gfx; +using namespace rhi; namespace gfx_test { // Test that precompiled module cache is working. -Slang::ComPtr<slang::ISession> createSession(gfx::IDevice* device, ISlangFileSystemExt* fileSys) +Slang::ComPtr<slang::ISession> createSession(rhi::IDevice* device, ISlangFileSystemExt* fileSys) { static std::mutex m; std::lock_guard<std ::mutex> lock(m); @@ -33,13 +33,13 @@ Slang::ComPtr<slang::ISession> createSession(gfx::IDevice* device, ISlangFileSys entry.value.intValue0 = 1; sessionDesc.compilerOptionEntries = &entry; slang::TargetDesc targetDesc = {}; - switch (device->getDeviceInfo().deviceType) + switch (device->getInfo().deviceType) { - case gfx::DeviceType::DirectX12: + case rhi::DeviceType::D3D12: targetDesc.format = SLANG_DXIL; targetDesc.profile = device->getSlangSession()->getGlobalSession()->findProfile("sm_6_1"); break; - case gfx::DeviceType::Vulkan: + case rhi::DeviceType::Vulkan: targetDesc.format = SLANG_SPIRV; targetDesc.profile = device->getSlangSession()->getGlobalSession()->findProfile("GLSL_460"); break; @@ -52,7 +52,7 @@ Slang::ComPtr<slang::ISession> createSession(gfx::IDevice* device, ISlangFileSys } static Slang::Result precompileProgram( - gfx::IDevice* device, + rhi::IDevice* device, ISlangMutableFileSystem* fileSys, const char* shaderModuleName) { @@ -84,12 +84,6 @@ static Slang::Result precompileProgram( void precompiledModuleCacheTestImpl(IDevice* device, UnitTestContext* context) { - Slang::ComPtr<ITransientResourceHeap> transientHeap; - ITransientResourceHeap::Desc transientHeapDesc = {}; - transientHeapDesc.constantBufferSize = 4096; - GFX_CHECK_CALL_ABORT( - device->createTransientResourceHeap(transientHeapDesc, transientHeap.writeRef())); - // First, Initialize our file system. ComPtr<ISlangMutableFileSystem> memoryFileSystem = ComPtr<ISlangMutableFileSystem>(new Slang::MemoryFileSystem()); @@ -164,61 +158,47 @@ void precompiledModuleCacheTestImpl(IDevice* device, UnitTestContext* context) "computeMain", slangReflection)); - ComputePipelineStateDesc pipelineDesc = {}; + ComputePipelineDesc pipelineDesc = {}; pipelineDesc.program = shaderProgram.get(); - ComPtr<gfx::IPipelineState> pipelineState; - GFX_CHECK_CALL_ABORT( - device->createComputePipelineState(pipelineDesc, pipelineState.writeRef())); + ComPtr<IComputePipeline> computePipeline; + GFX_CHECK_CALL_ABORT(device->createComputePipeline(pipelineDesc, computePipeline.writeRef())); const int numberCount = 4; float initialData[] = {0.0f, 0.0f, 0.0f, 0.0f}; - IBufferResource::Desc bufferDesc = {}; - bufferDesc.sizeInBytes = numberCount * sizeof(float); - bufferDesc.format = gfx::Format::Unknown; - bufferDesc.elementSize = sizeof(float); - bufferDesc.allowedStates = ResourceStateSet( - ResourceState::ShaderResource, - ResourceState::UnorderedAccess, - ResourceState::CopyDestination, - ResourceState::CopySource); - bufferDesc.defaultState = ResourceState::UnorderedAccess; + BufferDesc bufferDesc = {}; + bufferDesc.size = numberCount * sizeof(float); + bufferDesc.usage = BufferUsage::UnorderedAccess | BufferUsage::ShaderResource | + BufferUsage::CopySource | BufferUsage::CopyDestination; 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())); // We have done all the set up work, now it is time to start recording a command buffer for // GPU execution. { - ICommandQueue::Desc queueDesc = {ICommandQueue::QueueType::Graphics}; - auto queue = device->createCommandQueue(queueDesc); + auto queue = device->getQueue(QueueType::Graphics); - auto commandBuffer = transientHeap->createCommandBuffer(); - auto encoder = commandBuffer->encodeComputeCommands(); + auto commandEncoder = queue->createCommandEncoder(); + auto encoder = commandEncoder->beginComputePass(); - auto rootObject = encoder->bindPipeline(pipelineState); + ComPtr<IShaderObject> rootObject; + device->createRootShaderObject(shaderProgram, rootObject.writeRef()); + encoder->bindPipeline(computePipeline, rootObject); ShaderCursor entryPointCursor( rootObject->getEntryPoint(0)); // get a cursor the the first entry-point. - // Bind buffer view to the entry point. - entryPointCursor.getPath("buffer").setResource(bufferView); + // Bind buffer to the entry point. + entryPointCursor.getPath("buffer").setBinding(numbersBuffer); encoder->dispatchCompute(1, 1, 1); - encoder->endEncoding(); - commandBuffer->close(); - queue->executeCommandBuffer(commandBuffer); + encoder->end(); + queue->submit(commandEncoder->finish()); queue->waitOnHost(); } - compareComputeResult(device, numbersBuffer, Slang::makeArray<float>(3.0f, 3.0f, 3.0f, 3.0f)); + compareComputeResult(device, numbersBuffer, std::array{3.0f, 3.0f, 3.0f, 3.0f}); // Now we change the source and check if the precompiled module is still up-to-date. const char* moduleSrc4 = R"( @@ -239,12 +219,12 @@ void precompiledModuleCacheTestImpl(IDevice* device, UnitTestContext* context) SLANG_UNIT_TEST(precompiledModuleCacheD3D12) { - runTestImpl(precompiledModuleCacheTestImpl, unitTestContext, Slang::RenderApiFlag::D3D12); + runTestImpl(precompiledModuleCacheTestImpl, unitTestContext, DeviceType::D3D12, {}); } SLANG_UNIT_TEST(precompiledModuleCacheVulkan) { - runTestImpl(precompiledModuleCacheTestImpl, unitTestContext, Slang::RenderApiFlag::Vulkan); + runTestImpl(precompiledModuleCacheTestImpl, unitTestContext, DeviceType::Vulkan, {}); } } // namespace gfx_test |
