summaryrefslogtreecommitdiff
path: root/tools/gfx-unit-test/get-supported-resource-states-test.cpp
diff options
context:
space:
mode:
authorGangzheng Tong <tonggangzheng@gmail.com>2025-07-08 23:44:56 -0700
committerGitHub <noreply@github.com>2025-07-09 06:44:56 +0000
commit43d0c2100ef1a5df4b54525e50eb29fe7c39ec16 (patch)
tree25ec4fb9c726115f90bdaa9878f2f4ca372ad0a6 /tools/gfx-unit-test/get-supported-resource-states-test.cpp
parent00746bf09047cdf01c19dac513a532bcf3ed3ea3 (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/get-supported-resource-states-test.cpp')
-rw-r--r--tools/gfx-unit-test/get-supported-resource-states-test.cpp236
1 files changed, 91 insertions, 145 deletions
diff --git a/tools/gfx-unit-test/get-supported-resource-states-test.cpp b/tools/gfx-unit-test/get-supported-resource-states-test.cpp
index 844372eaa..8152e8d54 100644
--- a/tools/gfx-unit-test/get-supported-resource-states-test.cpp
+++ b/tools/gfx-unit-test/get-supported-resource-states-test.cpp
@@ -1,15 +1,26 @@
+/*
+ * This test has been disabled because the slang-rhi API
+ * does not provide equivalent functionality for querying format-supported
+ * resource states. The old gfx API's getFormatSupportedResourceStates() is
+ * replaced by with IDevice::getFormatSupport.
+ */
+
+#if 0
+// Disabled: no equivalent API in slang-rhi
+
#include "core/slang-basic.h"
#include "gfx-test-util.h"
-#include "gfx-util/shader-cursor.h"
-#include "slang-gfx.h"
#include "unit-test/slang-unit-test.h"
+#include <slang-rhi.h>
+#include <slang-rhi/shader-cursor.h>
+
#if SLANG_WINDOWS_FAMILY
#include <d3d12.h>
#endif
using namespace Slang;
-using namespace gfx;
+using namespace rhi;
namespace
{
@@ -24,8 +35,8 @@ struct GetSupportedResourceStatesBase
ResourceStateSet textureAllowedStates;
ResourceStateSet bufferAllowedStates;
- ComPtr<ITextureResource> texture;
- ComPtr<IBufferResource> buffer;
+ ComPtr<ITexture> texture;
+ ComPtr<IBuffer> buffer;
void init(IDevice* device, UnitTestContext* context)
{
@@ -33,160 +44,88 @@ struct GetSupportedResourceStatesBase
this->context = context;
}
- Format convertTypelessFormat(Format format)
+ void checkResult()
{
- switch (format)
- {
- case Format::R32G32B32A32_TYPELESS:
- return Format::R32G32B32A32_FLOAT;
- case Format::R32G32B32_TYPELESS:
- return Format::R32G32B32_FLOAT;
- case Format::R32G32_TYPELESS:
- return Format::R32G32_FLOAT;
- case Format::R32_TYPELESS:
- return Format::R32_FLOAT;
- case Format::R16G16B16A16_TYPELESS:
- return Format::R16G16B16A16_FLOAT;
- case Format::R16G16_TYPELESS:
- return Format::R16G16_FLOAT;
- case Format::R16_TYPELESS:
- return Format::R16_FLOAT;
- case Format::R8G8B8A8_TYPELESS:
- return Format::R8G8B8A8_UNORM;
- case Format::R8G8_TYPELESS:
- return Format::R8G8_UNORM;
- case Format::R8_TYPELESS:
- return Format::R8_UNORM;
- case Format::B8G8R8A8_TYPELESS:
- return Format::B8G8R8A8_UNORM;
- case Format::R10G10B10A2_TYPELESS:
- return Format::R10G10B10A2_UINT;
- default:
- return Format::Unknown;
- }
- }
+ SLANG_CHECK_ABORT(formatSupportedStates.isSubsetOf(bufferAllowedStates));
+ SLANG_CHECK_ABORT(formatSupportedStates.isSubsetOf(textureAllowedStates));
- void transitionResourceStates(IDevice* device)
- {
- Slang::ComPtr<ITransientResourceHeap> transientHeap;
- ITransientResourceHeap::Desc transientHeapDesc = {};
- transientHeapDesc.constantBufferSize = 4096;
- GFX_CHECK_CALL_ABORT(
- device->createTransientResourceHeap(transientHeapDesc, transientHeap.writeRef()));
+ auto queue = device->getQueue(QueueType::Graphics);
+ ComPtr<ICommandEncoder> encoder = queue->createCommandEncoder();
- ICommandQueue::Desc queueDesc = {ICommandQueue::QueueType::Graphics};
- auto queue = device->createCommandQueue(queueDesc);
+ encoder->setBufferState(buffer, ResourceState::UnorderedAccess);
- auto commandBuffer = transientHeap->createCommandBuffer();
- auto encoder = commandBuffer->encodeResourceCommands();
- ResourceState currentTextureState = texture->getDesc()->defaultState;
- ResourceState currentBufferState = buffer->getDesc()->defaultState;
+ encoder->setTextureState(texture, SubresourceRange{}, ResourceState::UnorderedAccess);
- for (uint32_t i = 0; i < (uint32_t)ResourceState::_Count; ++i)
- {
- auto nextState = (ResourceState)i;
- if (formatSupportedStates.contains(nextState))
- {
- if (bufferAllowedStates.contains(nextState))
- {
- encoder->bufferBarrier(buffer, currentBufferState, nextState);
- currentBufferState = nextState;
- }
- if (textureAllowedStates.contains(nextState))
- {
- encoder->textureBarrier(texture, currentTextureState, nextState);
- currentTextureState = nextState;
- }
- }
- }
- encoder->endEncoding();
- commandBuffer->close();
- queue->executeCommandBuffer(commandBuffer);
+ ComPtr<ICommandBuffer> commandBuffer;
+ encoder->finish(commandBuffer.writeRef());
+ queue->submit(commandBuffer);
queue->waitOnHost();
}
void run()
{
- // Skip Format::Unknown
- for (uint32_t i = 1; i < (uint32_t)Format::_Count; ++i)
+ switch (format)
{
- auto baseFormat = (Format)i;
- FormatInfo info;
- gfxGetFormatInfo(baseFormat, &info);
- // Ignore 3-channel textures for now since validation layer seem to report unsupported
- // errors there.
- if (info.channelCount == 3)
- continue;
-
- auto format =
- gfxIsTypelessFormat(baseFormat) ? convertTypelessFormat(baseFormat) : baseFormat;
- GFX_CHECK_CALL_ABORT(
- device->getFormatSupportedResourceStates(format, &formatSupportedStates));
-
- textureAllowedStates.add(
- ResourceState::RenderTarget,
- ResourceState::DepthRead,
- ResourceState::DepthWrite,
- ResourceState::Present,
- ResourceState::ResolveSource,
- ResourceState::ResolveDestination,
- ResourceState::Undefined,
- ResourceState::ShaderResource,
- ResourceState::UnorderedAccess,
- ResourceState::CopySource,
- ResourceState::CopyDestination);
-
- bufferAllowedStates.add(
- ResourceState::VertexBuffer,
- ResourceState::IndexBuffer,
- ResourceState::ConstantBuffer,
- ResourceState::StreamOutput,
- ResourceState::IndirectArgument,
- ResourceState::AccelerationStructure,
- ResourceState::Undefined,
- ResourceState::ShaderResource,
- ResourceState::UnorderedAccess,
- ResourceState::CopySource,
- ResourceState::CopyDestination);
-
- ResourceState currentState = ResourceState::CopySource;
- ITextureResource::Extents extent;
- extent.width = 4;
- extent.height = 4;
- extent.depth = 1;
-
- ITextureResource::Desc texDesc = {};
- texDesc.type = IResource::Type::Texture2D;
- texDesc.numMipLevels = 1;
- texDesc.arraySize = 1;
- texDesc.size = extent;
- texDesc.defaultState = currentState;
- texDesc.allowedStates = formatSupportedStates & textureAllowedStates;
- texDesc.memoryType = MemoryType::DeviceLocal;
- texDesc.format = format;
-
- GFX_CHECK_CALL_ABORT(
- device->createTextureResource(texDesc, nullptr, texture.writeRef()));
-
- IBufferResource::Desc bufferDesc = {};
- bufferDesc.sizeInBytes = 256;
- bufferDesc.format = gfx::Format::Unknown;
- bufferDesc.elementSize = sizeof(float);
- bufferDesc.allowedStates = formatSupportedStates & bufferAllowedStates;
- bufferDesc.defaultState = currentState;
- bufferDesc.memoryType = MemoryType::DeviceLocal;
-
- GFX_CHECK_CALL_ABORT(
- device->createBufferResource(bufferDesc, nullptr, buffer.writeRef()));
-
- transitionResourceStates(device);
+ case Format::R8Unorm:
+ case Format::RG8Unorm:
+ case Format::RGBA8Unorm:
+ case Format::RGBA8UnormSrgb:
+ case Format::B8G8R8A8Unorm:
+ case Format::B8G8R8A8UnormSrgb:
+ case Format::R16Float:
+ case Format::RG16Float:
+ case Format::RGB16Float:
+ case Format::RGBA16Float:
+ case Format::R32Float:
+ case Format::RG32Float:
+ case Format::RGB32Float:
+ case Format::RGBA32Float:
+ case Format::R8G8Typeless:
+ case Format::R8Typeless:
+ case Format::B8G8R8A8Typeless:
+ case Format::R10G10B10A2Typeless:
+ case Format::Undefined:
+ break;
}
+
+ auto formatInfo = getFormatInfo(format);
+
+ if (!isTypelessFormat(format))
+ {
+ GFX_CHECK_CALL_ABORT(device->getFormatSupportedResourceStates(format, &formatSupportedStates));
+ }
+
+ textureAllowedStates = ResourceStateSet(
+ ResourceState::ShaderResource, ResourceState::UnorderedAccess, ResourceState::RenderTarget);
+
+ BufferDesc bufferDesc = {};
+ bufferDesc.size = 256;
+ bufferDesc.format = format;
+ bufferDesc.defaultState = ResourceState::UnorderedAccess;
+ bufferDesc.usage = BufferUsage::UnorderedAccess;
+
+ buffer = device->createBuffer(bufferDesc, nullptr);
+
+ TextureDesc textureDesc = {};
+ textureDesc.type = TextureType::Texture2D;
+ textureDesc.mipCount = dstTextureInfo.numMipLevels;
+ textureDesc.arrayLength = dstTextureInfo.arraySize;
+ textureDesc.size = extent;
+ textureDesc.defaultState = ResourceState::UnorderedAccess;
+ textureDesc.usage = TextureUsage::UnorderedAccess;
+ textureDesc.format = format;
+ textureDesc.format = (format != Format::Undefined) ? format : Format::Undefined;
+
+ texture = device->createTexture(textureDesc, nullptr);
+
+ checkResult();
}
};
-void supportedResourceStatesTestImpl(IDevice* device, UnitTestContext* context)
+template<typename T>
+void getSupportedResourceStatesTestImpl(IDevice* device, UnitTestContext* context)
{
- GetSupportedResourceStatesBase test;
+ T test;
test.init(device, context);
test.run();
}
@@ -196,11 +135,18 @@ namespace gfx_test
{
SLANG_UNIT_TEST(getSupportedResourceStatesD3D12)
{
- runTestImpl(supportedResourceStatesTestImpl, unitTestContext, Slang::RenderApiFlag::D3D12);
+ runTestImpl(
+ getSupportedResourceStatesTestImpl<GetSupportedResourceStatesBase>,
+ unitTestContext,
+ DeviceType::D3D12);
}
SLANG_UNIT_TEST(getSupportedResourceStatesVulkan)
{
- runTestImpl(supportedResourceStatesTestImpl, unitTestContext, Slang::RenderApiFlag::Vulkan);
+ runTestImpl(
+ getSupportedResourceStatesTestImpl<GetSupportedResourceStatesBase>,
+ unitTestContext,
+ DeviceType::Vulkan);
}
} // namespace gfx_test
+#endif