1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
/*
* 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 "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 rhi;
namespace
{
using namespace gfx_test;
struct GetSupportedResourceStatesBase
{
IDevice* device;
UnitTestContext* context;
ResourceStateSet formatSupportedStates;
ResourceStateSet textureAllowedStates;
ResourceStateSet bufferAllowedStates;
ComPtr<ITexture> texture;
ComPtr<IBuffer> buffer;
void init(IDevice* device, UnitTestContext* context)
{
this->device = device;
this->context = context;
}
void checkResult()
{
SLANG_CHECK_ABORT(formatSupportedStates.isSubsetOf(bufferAllowedStates));
SLANG_CHECK_ABORT(formatSupportedStates.isSubsetOf(textureAllowedStates));
auto queue = device->getQueue(QueueType::Graphics);
ComPtr<ICommandEncoder> encoder = queue->createCommandEncoder();
encoder->setBufferState(buffer, ResourceState::UnorderedAccess);
encoder->setTextureState(texture, SubresourceRange{}, ResourceState::UnorderedAccess);
ComPtr<ICommandBuffer> commandBuffer;
encoder->finish(commandBuffer.writeRef());
queue->submit(commandBuffer);
queue->waitOnHost();
}
void run()
{
switch (format)
{
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();
}
};
template<typename T>
void getSupportedResourceStatesTestImpl(IDevice* device, UnitTestContext* context)
{
T test;
test.init(device, context);
test.run();
}
} // namespace
namespace gfx_test
{
SLANG_UNIT_TEST(getSupportedResourceStatesD3D12)
{
runTestImpl(
getSupportedResourceStatesTestImpl<GetSupportedResourceStatesBase>,
unitTestContext,
DeviceType::D3D12);
}
SLANG_UNIT_TEST(getSupportedResourceStatesVulkan)
{
runTestImpl(
getSupportedResourceStatesTestImpl<GetSupportedResourceStatesBase>,
unitTestContext,
DeviceType::Vulkan);
}
} // namespace gfx_test
#endif
|