diff options
| author | Ellie Hermaszewska <ellieh@nvidia.com> | 2024-10-29 14:49:26 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-29 14:49:26 +0800 |
| commit | f65d756bff8d4c5cbc15bd0322a2ae8e6b896a21 (patch) | |
| tree | ea1d61342cd29368e19135000ec2948813096205 /tools/gfx-unit-test/clear-texture-test.cpp | |
| parent | a729c15e9dce9f5116a38afc66329ab2ca4cea54 (diff) | |
format
* format
* Minor test fixes
* enable checking cpp format in ci
Diffstat (limited to 'tools/gfx-unit-test/clear-texture-test.cpp')
| -rw-r--r-- | tools/gfx-unit-test/clear-texture-test.cpp | 141 |
1 files changed, 72 insertions, 69 deletions
diff --git a/tools/gfx-unit-test/clear-texture-test.cpp b/tools/gfx-unit-test/clear-texture-test.cpp index 4ad82f313..ed9d12f0d 100644 --- a/tools/gfx-unit-test/clear-texture-test.cpp +++ b/tools/gfx-unit-test/clear-texture-test.cpp @@ -1,89 +1,92 @@ -#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 Slang; using namespace gfx; namespace gfx_test { - void clearTextureTestImpl(IDevice* device, UnitTestContext* context) - { - Slang::ComPtr<ITransientResourceHeap> transientHeap; - ITransientResourceHeap::Desc transientHeapDesc = {}; - transientHeapDesc.constantBufferSize = 4096; - GFX_CHECK_CALL_ABORT( - device->createTransientResourceHeap(transientHeapDesc, transientHeap.writeRef())); +void clearTextureTestImpl(IDevice* device, UnitTestContext* context) +{ + Slang::ComPtr<ITransientResourceHeap> transientHeap; + ITransientResourceHeap::Desc transientHeapDesc = {}; + transientHeapDesc.constantBufferSize = 4096; + GFX_CHECK_CALL_ABORT( + device->createTransientResourceHeap(transientHeapDesc, transientHeap.writeRef())); - ITextureResource::Desc srcTexDesc = {}; - srcTexDesc.type = IResource::Type::Texture2D; - srcTexDesc.numMipLevels = 1; - srcTexDesc.arraySize = 1; - srcTexDesc.size.width = 4; - srcTexDesc.size.height = 4; - srcTexDesc.size.depth = 1; - srcTexDesc.defaultState = ResourceState::RenderTarget; - srcTexDesc.allowedStates = ResourceStateSet( - ResourceState::RenderTarget, - ResourceState::CopySource, - ResourceState::CopyDestination); - srcTexDesc.format = Format::R32G32B32A32_FLOAT; + ITextureResource::Desc srcTexDesc = {}; + srcTexDesc.type = IResource::Type::Texture2D; + srcTexDesc.numMipLevels = 1; + srcTexDesc.arraySize = 1; + srcTexDesc.size.width = 4; + srcTexDesc.size.height = 4; + srcTexDesc.size.depth = 1; + srcTexDesc.defaultState = ResourceState::RenderTarget; + srcTexDesc.allowedStates = ResourceStateSet( + ResourceState::RenderTarget, + ResourceState::CopySource, + ResourceState::CopyDestination); + srcTexDesc.format = Format::R32G32B32A32_FLOAT; - Slang::ComPtr<ITextureResource> srcTexture; - GFX_CHECK_CALL_ABORT(device->createTextureResource( - srcTexDesc, nullptr, srcTexture.writeRef())); + Slang::ComPtr<ITextureResource> srcTexture; + GFX_CHECK_CALL_ABORT(device->createTextureResource(srcTexDesc, nullptr, srcTexture.writeRef())); - Slang::ComPtr<IResourceView> rtv; - IResourceView::Desc rtvDesc = {}; - rtvDesc.type = IResourceView::Type::RenderTarget; - rtvDesc.format = Format::R32G32B32A32_FLOAT; - rtvDesc.renderTarget.shape = IResource::Type::Texture2D; - rtvDesc.subresourceRange.layerCount = 1; - rtvDesc.subresourceRange.mipLevelCount = 1; - rtv = device->createTextureView(srcTexture, rtvDesc); + Slang::ComPtr<IResourceView> rtv; + IResourceView::Desc rtvDesc = {}; + rtvDesc.type = IResourceView::Type::RenderTarget; + rtvDesc.format = Format::R32G32B32A32_FLOAT; + rtvDesc.renderTarget.shape = IResource::Type::Texture2D; + rtvDesc.subresourceRange.layerCount = 1; + rtvDesc.subresourceRange.mipLevelCount = 1; + rtv = device->createTextureView(srcTexture, rtvDesc); - { - ICommandQueue::Desc queueDesc = {ICommandQueue::QueueType::Graphics}; - auto queue = device->createCommandQueue(queueDesc); + { + ICommandQueue::Desc queueDesc = {ICommandQueue::QueueType::Graphics}; + auto queue = device->createCommandQueue(queueDesc); - auto commandBuffer = transientHeap->createCommandBuffer(); - auto resourceEncoder = commandBuffer->encodeResourceCommands(); - ClearValue clearValue = {}; - clearValue.color.floatValues[0] = 0.5f; - clearValue.color.floatValues[1] = 1.0f; - clearValue.color.floatValues[2] = 0.2f; - clearValue.color.floatValues[3] = 0.1f; - resourceEncoder->clearResourceView(rtv, &clearValue, ClearResourceViewFlags::FloatClearValues); - resourceEncoder->textureBarrier( - srcTexture, ResourceState::RenderTarget, ResourceState::CopySource); - resourceEncoder->endEncoding(); + auto commandBuffer = transientHeap->createCommandBuffer(); + auto resourceEncoder = commandBuffer->encodeResourceCommands(); + ClearValue clearValue = {}; + clearValue.color.floatValues[0] = 0.5f; + clearValue.color.floatValues[1] = 1.0f; + clearValue.color.floatValues[2] = 0.2f; + clearValue.color.floatValues[3] = 0.1f; + resourceEncoder->clearResourceView( + rtv, + &clearValue, + ClearResourceViewFlags::FloatClearValues); + resourceEncoder->textureBarrier( + srcTexture, + ResourceState::RenderTarget, + ResourceState::CopySource); + resourceEncoder->endEncoding(); - commandBuffer->close(); - queue->executeCommandBuffer(commandBuffer); + commandBuffer->close(); + queue->executeCommandBuffer(commandBuffer); - queue->waitOnHost(); + queue->waitOnHost(); - Slang::ComPtr<ISlangBlob> blob; - size_t rowPitch, pixelSize; - device->readTextureResource( - srcTexture, - ResourceState::CopySource, - blob.writeRef(), - &rowPitch, - &pixelSize); - float* data = (float*)blob->getBufferPointer(); - for (int i = 0; i < 4; i++) - { - SLANG_CHECK(data[i] == clearValue.color.floatValues[i]); - } + Slang::ComPtr<ISlangBlob> blob; + size_t rowPitch, pixelSize; + device->readTextureResource( + srcTexture, + ResourceState::CopySource, + blob.writeRef(), + &rowPitch, + &pixelSize); + float* data = (float*)blob->getBufferPointer(); + for (int i = 0; i < 4; i++) + { + SLANG_CHECK(data[i] == clearValue.color.floatValues[i]); } } +} - SLANG_UNIT_TEST(clearTextureTestVulkan) - { - runTestImpl(clearTextureTestImpl, unitTestContext, Slang::RenderApiFlag::Vulkan); - } +SLANG_UNIT_TEST(clearTextureTestVulkan) +{ + runTestImpl(clearTextureTestImpl, unitTestContext, Slang::RenderApiFlag::Vulkan); } +} // namespace gfx_test |
