yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Gangzheng TongConvert gfx unit tests and examples to use slang-rhi (#7577)43d0c2100

master
4.2 KiB152 linesraw
1/*
2 * This test has been disabled because the slang-rhi API
3 * does not provide equivalent functionality for querying format-supported
4 * resource states. The old gfx API's getFormatSupportedResourceStates() is
5 * replaced by with IDevice::getFormatSupport.
6 */
7
8#if 0
9// Disabled: no equivalent API in slang-rhi
10
11#include "core/slang-basic.h"
12#include "gfx-test-util.h"
13#include "unit-test/slang-unit-test.h"
14
15#include <slang-rhi.h>
16#include <slang-rhi/shader-cursor.h>
17
18#if SLANG_WINDOWS_FAMILY
19#include <d3d12.h>
20#endif
21
22using namespace Slang;
23using namespace rhi;
24
25namespace
26{
27using namespace gfx_test;
28
29struct GetSupportedResourceStatesBase
30{
31    IDevice* device;
32    UnitTestContext* context;
33
34    ResourceStateSet formatSupportedStates;
35    ResourceStateSet textureAllowedStates;
36    ResourceStateSet bufferAllowedStates;
37
38    ComPtr<ITexture> texture;
39    ComPtr<IBuffer> buffer;
40
41    void init(IDevice* device, UnitTestContext* context)
42    {
43        this->device = device;
44        this->context = context;
45    }
46
47    void checkResult()
48    {
49        SLANG_CHECK_ABORT(formatSupportedStates.isSubsetOf(bufferAllowedStates));
50        SLANG_CHECK_ABORT(formatSupportedStates.isSubsetOf(textureAllowedStates));
51
52        auto queue = device->getQueue(QueueType::Graphics);
53        ComPtr<ICommandEncoder> encoder = queue->createCommandEncoder();
54
55        encoder->setBufferState(buffer, ResourceState::UnorderedAccess);
56
57        encoder->setTextureState(texture, SubresourceRange{}, ResourceState::UnorderedAccess);
58
59        ComPtr<ICommandBuffer> commandBuffer;
60        encoder->finish(commandBuffer.writeRef());
61        queue->submit(commandBuffer);
62        queue->waitOnHost();
63    }
64
65    void run()
66    {
67        switch (format)
68        {
69        case Format::R8Unorm:
70        case Format::RG8Unorm:
71        case Format::RGBA8Unorm:
72        case Format::RGBA8UnormSrgb:
73        case Format::B8G8R8A8Unorm:
74        case Format::B8G8R8A8UnormSrgb:
75        case Format::R16Float:
76        case Format::RG16Float:
77        case Format::RGB16Float:
78        case Format::RGBA16Float:
79        case Format::R32Float:
80        case Format::RG32Float:
81        case Format::RGB32Float:
82        case Format::RGBA32Float:
83        case Format::R8G8Typeless:
84        case Format::R8Typeless:
85        case Format::B8G8R8A8Typeless:
86        case Format::R10G10B10A2Typeless:
87        case Format::Undefined:
88            break;
89        }
90
91        auto formatInfo = getFormatInfo(format);
92
93        if (!isTypelessFormat(format))
94        {
95            GFX_CHECK_CALL_ABORT(device->getFormatSupportedResourceStates(format, &formatSupportedStates));
96        }
97
98        textureAllowedStates = ResourceStateSet(
99            ResourceState::ShaderResource, ResourceState::UnorderedAccess, ResourceState::RenderTarget);
100
101        BufferDesc bufferDesc = {};
102        bufferDesc.size = 256;
103        bufferDesc.format = format;
104        bufferDesc.defaultState = ResourceState::UnorderedAccess;
105        bufferDesc.usage = BufferUsage::UnorderedAccess;
106
107        buffer = device->createBuffer(bufferDesc, nullptr);
108
109        TextureDesc textureDesc = {};
110        textureDesc.type = TextureType::Texture2D;
111        textureDesc.mipCount = dstTextureInfo.numMipLevels;
112        textureDesc.arrayLength = dstTextureInfo.arraySize;
113        textureDesc.size = extent;
114        textureDesc.defaultState = ResourceState::UnorderedAccess;
115        textureDesc.usage = TextureUsage::UnorderedAccess;
116        textureDesc.format = format;
117        textureDesc.format = (format != Format::Undefined) ? format : Format::Undefined;
118
119        texture = device->createTexture(textureDesc, nullptr);
120
121        checkResult();
122    }
123};
124
125template<typename T>
126void getSupportedResourceStatesTestImpl(IDevice* device, UnitTestContext* context)
127{
128    T test;
129    test.init(device, context);
130    test.run();
131}
132} // namespace
133
134namespace gfx_test
135{
136SLANG_UNIT_TEST(getSupportedResourceStatesD3D12)
137{
138    runTestImpl(
139        getSupportedResourceStatesTestImpl<GetSupportedResourceStatesBase>,
140        unitTestContext,
141        DeviceType::D3D12);
142}
143
144SLANG_UNIT_TEST(getSupportedResourceStatesVulkan)
145{
146    runTestImpl(
147        getSupportedResourceStatesTestImpl<GetSupportedResourceStatesBase>,
148        unitTestContext,
149        DeviceType::Vulkan);
150}
151} // namespace gfx_test
152#endif