From f65d756bff8d4c5cbc15bd0322a2ae8e6b896a21 Mon Sep 17 00:00:00 2001 From: Ellie Hermaszewska Date: Tue, 29 Oct 2024 14:49:26 +0800 Subject: format * format * Minor test fixes * enable checking cpp format in ci --- tools/gfx-unit-test/sampler-array.cpp | 261 +++++++++++++++++----------------- 1 file changed, 131 insertions(+), 130 deletions(-) (limited to 'tools/gfx-unit-test/sampler-array.cpp') diff --git a/tools/gfx-unit-test/sampler-array.cpp b/tools/gfx-unit-test/sampler-array.cpp index 945c31b07..720aa0a2c 100644 --- a/tools/gfx-unit-test/sampler-array.cpp +++ b/tools/gfx-unit-test/sampler-array.cpp @@ -1,159 +1,160 @@ -#include "tools/unit-test/slang-unit-test.h" - -#include "slang-gfx.h" #include "gfx-test-util.h" -#include "tools/gfx-util/shader-cursor.h" +#include "slang-gfx.h" #include "source/core/slang-basic.h" +#include "tools/gfx-util/shader-cursor.h" +#include "tools/unit-test/slang-unit-test.h" using namespace gfx; namespace gfx_test { - static ComPtr createBuffer(IDevice* device, uint32_t content) - { - ComPtr buffer; - IBufferResource::Desc bufferDesc = {}; - bufferDesc.sizeInBytes = sizeof(uint32_t); - 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.memoryType = MemoryType::DeviceLocal; - - ComPtr numbersBuffer; - GFX_CHECK_CALL_ABORT( - device->createBufferResource(bufferDesc, (void*)&content, buffer.writeRef())); +static ComPtr createBuffer(IDevice* device, uint32_t content) +{ + ComPtr buffer; + IBufferResource::Desc bufferDesc = {}; + bufferDesc.sizeInBytes = sizeof(uint32_t); + 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.memoryType = MemoryType::DeviceLocal; + + ComPtr numbersBuffer; + GFX_CHECK_CALL_ABORT( + device->createBufferResource(bufferDesc, (void*)&content, buffer.writeRef())); + + return buffer; +} +void samplerArrayTestImpl(IDevice* device, UnitTestContext* context) +{ + Slang::ComPtr transientHeap; + ITransientResourceHeap::Desc transientHeapDesc = {}; + transientHeapDesc.constantBufferSize = 4096; + GFX_CHECK_CALL_ABORT( + device->createTransientResourceHeap(transientHeapDesc, transientHeap.writeRef())); + + ComPtr shaderProgram; + slang::ProgramLayout* slangReflection; + GFX_CHECK_CALL_ABORT( + loadComputeProgram(device, shaderProgram, "sampler-array", "computeMain", slangReflection)); + + ComputePipelineStateDesc pipelineDesc = {}; + pipelineDesc.program = shaderProgram.get(); + ComPtr pipelineState; + GFX_CHECK_CALL_ABORT( + device->createComputePipelineState(pipelineDesc, pipelineState.writeRef())); + + Slang::List> samplers; + Slang::List> srvs; + ComPtr uav; + ComPtr texture; + ComPtr buffer = createBuffer(device, 0); - return buffer; + { + IResourceView::Desc viewDesc = {}; + viewDesc.type = IResourceView::Type::UnorderedAccess; + viewDesc.format = Format::Unknown; + GFX_CHECK_CALL_ABORT(device->createBufferView(buffer, nullptr, viewDesc, uav.writeRef())); } - void samplerArrayTestImpl(IDevice* device, UnitTestContext* context) { - Slang::ComPtr transientHeap; - ITransientResourceHeap::Desc transientHeapDesc = {}; - transientHeapDesc.constantBufferSize = 4096; + ITextureResource::Desc textureDesc = {}; + textureDesc.type = IResource::Type::Texture2D; + textureDesc.format = Format::R8G8B8A8_UNORM; + textureDesc.size.width = 2; + textureDesc.size.height = 2; + textureDesc.size.depth = 1; + textureDesc.numMipLevels = 2; + textureDesc.memoryType = MemoryType::DeviceLocal; + textureDesc.defaultState = ResourceState::ShaderResource; + textureDesc.allowedStates.add(ResourceState::CopyDestination); + uint32_t data[] = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF}; + ITextureResource::SubresourceData subResourceData[2] = {{data, 8, 16}, {data, 8, 16}}; GFX_CHECK_CALL_ABORT( - device->createTransientResourceHeap(transientHeapDesc, transientHeap.writeRef())); + device->createTextureResource(textureDesc, subResourceData, texture.writeRef())); + } + for (uint32_t i = 0; i < 32; i++) + { + ComPtr srv; + IResourceView::Desc viewDesc = {}; + viewDesc.type = IResourceView::Type::ShaderResource; + viewDesc.format = Format::R8G8B8A8_UNORM; + viewDesc.subresourceRange.layerCount = 1; + viewDesc.subresourceRange.mipLevelCount = 1; + GFX_CHECK_CALL_ABORT(device->createTextureView(texture, viewDesc, srv.writeRef())); + srvs.add(srv); + } - ComPtr shaderProgram; - slang::ProgramLayout* slangReflection; - GFX_CHECK_CALL_ABORT(loadComputeProgram(device, shaderProgram, "sampler-array", "computeMain", slangReflection)); + for (uint32_t i = 0; i < 32; i++) + { + ISamplerState::Desc desc = {}; + ComPtr sampler; + GFX_CHECK_CALL_ABORT(device->createSamplerState(desc, sampler.writeRef())); + samplers.add(sampler); + } - ComputePipelineStateDesc pipelineDesc = {}; - pipelineDesc.program = shaderProgram.get(); - ComPtr pipelineState; - GFX_CHECK_CALL_ABORT( - device->createComputePipelineState(pipelineDesc, pipelineState.writeRef())); + ComPtr rootObject; + device->createMutableRootShaderObject(shaderProgram, rootObject.writeRef()); - Slang::List> samplers; - Slang::List> srvs; - ComPtr uav; - ComPtr texture; - ComPtr buffer = createBuffer(device, 0); + ComPtr g; + device->createMutableShaderObject( + slangReflection->findTypeByName("S0"), + ShaderObjectContainerType::None, + g.writeRef()); - { - IResourceView::Desc viewDesc = {}; - viewDesc.type = IResourceView::Type::UnorderedAccess; - viewDesc.format = Format::Unknown; - GFX_CHECK_CALL_ABORT( - device->createBufferView(buffer, nullptr, viewDesc, uav.writeRef())); - } - { - ITextureResource::Desc textureDesc = {}; - textureDesc.type = IResource::Type::Texture2D; - textureDesc.format = Format::R8G8B8A8_UNORM; - textureDesc.size.width = 2; - textureDesc.size.height = 2; - textureDesc.size.depth = 1; - textureDesc.numMipLevels = 2; - textureDesc.memoryType = MemoryType::DeviceLocal; - textureDesc.defaultState = ResourceState::ShaderResource; - textureDesc.allowedStates.add(ResourceState::CopyDestination); - uint32_t data[] = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF}; - ITextureResource::SubresourceData subResourceData[2] = {{data, 8, 16}, {data, 8, 16}}; - GFX_CHECK_CALL_ABORT( - device->createTextureResource(textureDesc, subResourceData, texture.writeRef())); - } - for (uint32_t i = 0; i < 32; i++) - { - ComPtr srv; - IResourceView::Desc viewDesc = {}; - viewDesc.type = IResourceView::Type::ShaderResource; - viewDesc.format = Format::R8G8B8A8_UNORM; - viewDesc.subresourceRange.layerCount = 1; - viewDesc.subresourceRange.mipLevelCount = 1; - GFX_CHECK_CALL_ABORT( - device->createTextureView(texture, viewDesc, srv.writeRef())); - srvs.add(srv); - } + ComPtr s1; + device->createMutableShaderObject( + slangReflection->findTypeByName("S1"), + ShaderObjectContainerType::None, + s1.writeRef()); + { + auto cursor = ShaderCursor(s1); for (uint32_t i = 0; i < 32; i++) { - ISamplerState::Desc desc = {}; - ComPtr sampler; - GFX_CHECK_CALL_ABORT(device->createSamplerState(desc, sampler.writeRef())); - samplers.add(sampler); + cursor["samplers"][i].setSampler(samplers[i]); + cursor["tex"][i].setResource(srvs[i]); } + cursor["data"].setData(1.0f); + } - ComPtr rootObject; - device->createMutableRootShaderObject(shaderProgram, rootObject.writeRef()); - - ComPtr g; - device->createMutableShaderObject( - slangReflection->findTypeByName("S0"), ShaderObjectContainerType::None, g.writeRef()); - - ComPtr s1; - device->createMutableShaderObject( - slangReflection->findTypeByName("S1"), ShaderObjectContainerType::None, s1.writeRef()); - - { - auto cursor = ShaderCursor(s1); - for (uint32_t i = 0; i < 32; i++) - { - cursor["samplers"][i].setSampler(samplers[i]); - cursor["tex"][i].setResource(srvs[i]); - } - cursor["data"].setData(1.0f); - } + { + auto cursor = ShaderCursor(g); + cursor["s"].setObject(s1); + cursor["data"].setData(2.0f); + } - { - auto cursor = ShaderCursor(g); - cursor["s"].setObject(s1); - cursor["data"].setData(2.0f); - } + { + auto cursor = ShaderCursor(rootObject); + cursor["g"].setObject(g); + cursor["buffer"].setResource(uav); + } - { - auto cursor = ShaderCursor(rootObject); - cursor["g"].setObject(g); - cursor["buffer"].setResource(uav); - } + { + ICommandQueue::Desc queueDesc = {ICommandQueue::QueueType::Graphics}; + auto queue = device->createCommandQueue(queueDesc); + auto commandBuffer = transientHeap->createCommandBuffer(); { - ICommandQueue::Desc queueDesc = { ICommandQueue::QueueType::Graphics }; - auto queue = device->createCommandQueue(queueDesc); - - auto commandBuffer = transientHeap->createCommandBuffer(); - { - auto encoder = commandBuffer->encodeComputeCommands(); - encoder->bindPipelineWithRootObject(pipelineState, rootObject); - encoder->dispatchCompute(1, 1, 1); - encoder->endEncoding(); - } - - commandBuffer->close(); - queue->executeCommandBuffer(commandBuffer); - queue->waitOnHost(); + auto encoder = commandBuffer->encodeComputeCommands(); + encoder->bindPipelineWithRootObject(pipelineState, rootObject); + encoder->dispatchCompute(1, 1, 1); + encoder->endEncoding(); } - compareComputeResult( - device, buffer, Slang::makeArray(4.0f)); + commandBuffer->close(); + queue->executeCommandBuffer(commandBuffer); + queue->waitOnHost(); } - SLANG_UNIT_TEST(samplerArrayVulkan) - { - runTestImpl(samplerArrayTestImpl, unitTestContext, Slang::RenderApiFlag::Vulkan); - } + compareComputeResult(device, buffer, Slang::makeArray(4.0f)); +} + +SLANG_UNIT_TEST(samplerArrayVulkan) +{ + runTestImpl(samplerArrayTestImpl, unitTestContext, Slang::RenderApiFlag::Vulkan); } +} // namespace gfx_test -- cgit v1.2.3