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
51.5 KiB1507 linesraw
1#if 0
2// Duplicated: This test is identical to slang-rhi\tests\test-formats.cpp
3
4#include "core/slang-basic.h"
5#include "gfx-test-util.h"
6#include "slang-gfx.h"
7#include "slang-rhi/shader-cursor.h"
8#include "unit-test/slang-unit-test.h"
9
10using namespace gfx;
11
12namespace gfx_test
13{
14gfx::Format convertTypelessFormat(gfx::Format format)
15{
16    switch (format)
17    {
18    case gfx::Format::R32G32B32A32_TYPELESS:
19        return gfx::Format::R32G32B32A32_FLOAT;
20    case gfx::Format::R32G32B32_TYPELESS:
21        return gfx::Format::R32G32B32_FLOAT;
22    case gfx::Format::R32G32_TYPELESS:
23        return gfx::Format::R32G32_FLOAT;
24    case gfx::Format::R32_TYPELESS:
25        return gfx::Format::R32_FLOAT;
26    case gfx::Format::R16G16B16A16_TYPELESS:
27        return gfx::Format::R16G16B16A16_FLOAT;
28    case gfx::Format::R16G16_TYPELESS:
29        return gfx::Format::R16G16_FLOAT;
30    case gfx::Format::R16_TYPELESS:
31        return gfx::Format::R16_FLOAT;
32    case gfx::Format::R8G8B8A8_TYPELESS:
33        return gfx::Format::R8G8B8A8_UNORM;
34    case gfx::Format::R8G8_TYPELESS:
35        return gfx::Format::R8G8_UNORM;
36    case gfx::Format::R8_TYPELESS:
37        return gfx::Format::R8_UNORM;
38    case gfx::Format::B8G8R8A8_TYPELESS:
39        return gfx::Format::B8G8R8A8_UNORM;
40    case gfx::Format::R10G10B10A2_TYPELESS:
41        return gfx::Format::R10G10B10A2_UINT;
42    default:
43        return gfx::Format::Unknown;
44    }
45}
46
47void setUpAndRunTest(
48    IDevice* device,
49    ComPtr<IResourceView> texView,
50    ComPtr<IResourceView> bufferView,
51    const char* entryPoint,
52    ComPtr<ISamplerState> sampler = nullptr)
53{
54    Slang::ComPtr<ITransientResourceHeap> transientHeap;
55    ITransientResourceHeap::Desc transientHeapDesc = {};
56    transientHeapDesc.constantBufferSize = 4096;
57    GFX_CHECK_CALL_ABORT(
58        device->createTransientResourceHeap(transientHeapDesc, transientHeap.writeRef()));
59
60    ComPtr<IShaderProgram> shaderProgram;
61    slang::ProgramLayout* slangReflection;
62    GFX_CHECK_CALL_ABORT(loadComputeProgram(
63        device,
64        shaderProgram,
65        "format-test-shaders",
66        entryPoint,
67        slangReflection));
68
69    ComputePipelineStateDesc pipelineDesc = {};
70    pipelineDesc.program = shaderProgram.get();
71    ComPtr<gfx::IPipelineState> pipelineState;
72    GFX_CHECK_CALL_ABORT(
73        device->createComputePipelineState(pipelineDesc, pipelineState.writeRef()));
74
75    // We have done all the set up work, now it is time to start recording a command buffer for
76    // GPU execution.
77    {
78        ICommandQueue::Desc queueDesc = {ICommandQueue::QueueType::Graphics};
79        auto queue = device->createCommandQueue(queueDesc);
80
81        auto commandBuffer = transientHeap->createCommandBuffer();
82        auto encoder = commandBuffer->encodeComputeCommands();
83
84        auto rootObject = encoder->bindPipeline(pipelineState);
85
86        ShaderCursor entryPointCursor(
87            rootObject->getEntryPoint(0)); // get a cursor the the first entry-point.
88
89        // Bind texture view to the entry point
90        entryPointCursor.getPath("tex").setResource(texView);
91
92        if (sampler)
93            entryPointCursor.getPath("sampler").setSampler(sampler);
94
95        // Bind buffer view to the entry point.
96        entryPointCursor.getPath("buffer").setResource(bufferView);
97
98        encoder->dispatchCompute(1, 1, 1);
99        encoder->endEncoding();
100        commandBuffer->close();
101        queue->executeCommandBuffer(commandBuffer);
102        queue->waitOnHost();
103    }
104}
105
106ComPtr<IResourceView> createTexView(
107    IDevice* device,
108    ITextureResource::Extents size,
109    gfx::Format format,
110    ITextureResource::SubresourceData* data,
111    int mips = 1)
112{
113    ITextureResource::Desc texDesc = {};
114    texDesc.type = IResource::Type::Texture2D;
115    texDesc.numMipLevels = mips;
116    texDesc.arraySize = 1;
117    texDesc.size = size;
118    texDesc.defaultState = ResourceState::ShaderResource;
119    texDesc.format = format;
120
121    ComPtr<ITextureResource> inTex;
122    GFX_CHECK_CALL_ABORT(device->createTextureResource(texDesc, data, inTex.writeRef()));
123
124    ComPtr<IResourceView> texView;
125    IResourceView::Desc texViewDesc = {};
126    texViewDesc.type = IResourceView::Type::ShaderResource;
127    texViewDesc.format = gfxIsTypelessFormat(format) ? convertTypelessFormat(format) : format;
128    GFX_CHECK_CALL_ABORT(device->createTextureView(inTex, texViewDesc, texView.writeRef()));
129    return texView;
130}
131
132template<typename T>
133ComPtr<IBufferResource> createBuffer(IDevice* device, int size, void* initialData)
134{
135    IBufferResource::Desc bufferDesc = {};
136    bufferDesc.sizeInBytes = size * sizeof(T);
137    bufferDesc.format = gfx::Format::Unknown;
138    bufferDesc.elementSize = sizeof(T);
139    bufferDesc.allowedStates = ResourceStateSet(
140        ResourceState::ShaderResource,
141        ResourceState::UnorderedAccess,
142        ResourceState::CopyDestination,
143        ResourceState::CopySource);
144    bufferDesc.defaultState = ResourceState::UnorderedAccess;
145    bufferDesc.memoryType = MemoryType::DeviceLocal;
146
147    ComPtr<IBufferResource> outBuffer;
148    GFX_CHECK_CALL_ABORT(
149        device->createBufferResource(bufferDesc, initialData, outBuffer.writeRef()));
150    return outBuffer;
151}
152
153ComPtr<IResourceView> createBufferView(IDevice* device, ComPtr<IBufferResource> outBuffer)
154{
155    ComPtr<IResourceView> bufferView;
156    IResourceView::Desc viewDesc = {};
157    viewDesc.type = IResourceView::Type::UnorderedAccess;
158    viewDesc.format = Format::Unknown;
159    GFX_CHECK_CALL_ABORT(
160        device->createBufferView(outBuffer, nullptr, viewDesc, bufferView.writeRef()));
161    return bufferView;
162}
163
164void formatTestsImpl(IDevice* device, UnitTestContext* context)
165{
166    ISamplerState::Desc samplerDesc;
167    auto sampler = device->createSamplerState(samplerDesc);
168
169    float initFloatData[16] = {0.0f};
170    auto floatResults = createBuffer<float>(device, 16, initFloatData);
171    auto floatBufferView = createBufferView(device, floatResults);
172
173    uint32_t initUintData[16] = {0u};
174    auto uintResults = createBuffer<uint32_t>(device, 16, initUintData);
175    auto uintBufferView = createBufferView(device, uintResults);
176
177    int32_t initIntData[16] = {0};
178    auto intResults = createBuffer<uint32_t>(device, 16, initIntData);
179    auto intBufferView = createBufferView(device, intResults);
180
181    ITextureResource::Extents size = {};
182    size.width = 2;
183    size.height = 2;
184    size.depth = 1;
185
186    ITextureResource::Extents bcSize = {};
187    bcSize.width = 4;
188    bcSize.height = 4;
189    bcSize.depth = 1;
190
191    // Note: D32_FLOAT and D16_UNORM are not directly tested as they are only used for raster. These
192    // are the same as R32_FLOAT and R16_UNORM, respectively, when passed to a shader.
193    {
194        float texData[] = {
195            1.0f,
196            0.0f,
197            0.0f,
198            1.0f,
199            0.0f,
200            1.0f,
201            0.0f,
202            1.0f,
203            0.0f,
204            0.0f,
205            1.0f,
206            1.0f,
207            0.5f,
208            0.5f,
209            0.5f,
210            1.0f};
211        ITextureResource::SubresourceData subData = {(void*)texData, 32, 0};
212
213        auto texView = createTexView(device, size, gfx::Format::R32G32B32A32_FLOAT, &subData);
214        setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat4");
215        compareComputeResult(
216            device,
217            floatResults,
218            Slang::makeArray<float>(
219                1.0f,
220                0.0f,
221                0.0f,
222                1.0f,
223                0.0f,
224                1.0f,
225                0.0f,
226                1.0f,
227                0.0f,
228                0.0f,
229                1.0f,
230                1.0f,
231                0.5f,
232                0.5f,
233                0.5f,
234                1.0f));
235
236        texView = createTexView(device, size, gfx::Format::R32G32B32A32_TYPELESS, &subData);
237        setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat4");
238        compareComputeResult(
239            device,
240            floatResults,
241            Slang::makeArray<float>(
242                1.0f,
243                0.0f,
244                0.0f,
245                1.0f,
246                0.0f,
247                1.0f,
248                0.0f,
249                1.0f,
250                0.0f,
251                0.0f,
252                1.0f,
253                1.0f,
254                0.5f,
255                0.5f,
256                0.5f,
257                1.0f));
258    }
259
260    // Ignore this test since it is not supported by swiftshader and nvidia's driver.
261    if (false)
262    {
263        float texData[] = {1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.5f, 0.5f, 0.5f};
264        ITextureResource::SubresourceData subData = {(void*)texData, 24, 0};
265
266        auto texView = createTexView(device, size, gfx::Format::R32G32B32_FLOAT, &subData);
267        setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat3");
268        compareComputeResult(
269            device,
270            floatResults,
271            Slang::makeArray<
272                float>(1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.5f, 0.5f, 0.5f));
273
274        texView = createTexView(device, size, gfx::Format::R32G32B32_TYPELESS, &subData);
275        setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat3");
276        compareComputeResult(
277            device,
278            floatResults,
279            Slang::makeArray<
280                float>(1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.5f, 0.5f, 0.5f));
281    }
282
283    {
284        float texData[] = {1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.5f, 0.5f};
285        ITextureResource::SubresourceData subData = {(void*)texData, 16, 0};
286
287        auto texView = createTexView(device, size, gfx::Format::R32G32_FLOAT, &subData);
288        setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat2");
289        compareComputeResult(
290            device,
291            floatResults,
292            Slang::makeArray<float>(1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.5f, 0.5f));
293
294        texView = createTexView(device, size, gfx::Format::R32G32_TYPELESS, &subData);
295        setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat2");
296        compareComputeResult(
297            device,
298            floatResults,
299            Slang::makeArray<float>(1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.5f, 0.5f));
300    }
301
302    {
303        float texData[] = {1.0f, 0.0f, 0.5f, 0.25f};
304        ITextureResource::SubresourceData subData = {(void*)texData, 8, 0};
305
306        auto texView = createTexView(device, size, gfx::Format::R32_FLOAT, &subData);
307        setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat");
308        compareComputeResult(
309            device,
310            floatResults,
311            Slang::makeArray<float>(1.0f, 0.0f, 0.5f, 0.25f));
312
313        texView = createTexView(device, size, gfx::Format::R32_TYPELESS, &subData);
314        setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat");
315        compareComputeResult(
316            device,
317            floatResults,
318            Slang::makeArray<float>(1.0f, 0.0f, 0.5f, 0.25f));
319    }
320
321    {
322        uint16_t texData[] = {
323            15360u,
324            0u,
325            0u,
326            15360u,
327            0u,
328            15360u,
329            0u,
330            15360u,
331            0u,
332            0u,
333            15360u,
334            15360u,
335            14336u,
336            14336u,
337            14336u,
338            15360u};
339        ITextureResource::SubresourceData subData = {(void*)texData, 16, 0};
340
341        auto texView = createTexView(device, size, gfx::Format::R16G16B16A16_FLOAT, &subData);
342        setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat4");
343        compareComputeResult(
344            device,
345            floatResults,
346            Slang::makeArray<float>(
347                1.0f,
348                0.0f,
349                0.0f,
350                1.0f,
351                0.0f,
352                1.0f,
353                0.0f,
354                1.0f,
355                0.0f,
356                0.0f,
357                1.0f,
358                1.0f,
359                0.5f,
360                0.5f,
361                0.5f,
362                1.0f));
363
364        texView = createTexView(device, size, gfx::Format::R16G16B16A16_TYPELESS, &subData);
365        setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat4");
366        compareComputeResult(
367            device,
368            floatResults,
369            Slang::makeArray<float>(
370                1.0f,
371                0.0f,
372                0.0f,
373                1.0f,
374                0.0f,
375                1.0f,
376                0.0f,
377                1.0f,
378                0.0f,
379                0.0f,
380                1.0f,
381                1.0f,
382                0.5f,
383                0.5f,
384                0.5f,
385                1.0f));
386    }
387
388    {
389        uint16_t texData[] = {15360u, 0u, 0u, 15360u, 15360u, 15360u, 14336u, 14336u};
390        ITextureResource::SubresourceData subData = {(void*)texData, 8, 0};
391
392        auto texView = createTexView(device, size, gfx::Format::R16G16_FLOAT, &subData);
393        setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat2");
394        compareComputeResult(
395            device,
396            floatResults,
397            Slang::makeArray<float>(1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.5f, 0.5f));
398
399        texView = createTexView(device, size, gfx::Format::R16G16_TYPELESS, &subData);
400        setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat2");
401        compareComputeResult(
402            device,
403            floatResults,
404            Slang::makeArray<float>(1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.5f, 0.5f));
405    }
406
407    {
408        uint16_t texData[] = {15360u, 0u, 14336u, 13312u};
409        ITextureResource::SubresourceData subData = {(void*)texData, 4, 0};
410
411        auto texView = createTexView(device, size, gfx::Format::R16_FLOAT, &subData);
412        setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat");
413        compareComputeResult(
414            device,
415            floatResults,
416            Slang::makeArray<float>(1.0f, 0.0f, 0.5f, 0.25f));
417
418        texView = createTexView(device, size, gfx::Format::R16_TYPELESS, &subData);
419        setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat");
420        compareComputeResult(
421            device,
422            floatResults,
423            Slang::makeArray<float>(1.0f, 0.0f, 0.5f, 0.25f));
424    }
425
426    {
427        uint32_t texData[] =
428            {255u, 0u, 0u, 255u, 0u, 255u, 0u, 255u, 0u, 0u, 255u, 255u, 127u, 127u, 127u, 255u};
429        ITextureResource::SubresourceData subData = {(void*)texData, 32, 0};
430
431        auto texView = createTexView(device, size, gfx::Format::R32G32B32A32_UINT, &subData);
432        setUpAndRunTest(device, texView, uintBufferView, "copyTexUint4");
433        compareComputeResult(
434            device,
435            uintResults,
436            Slang::makeArray<uint32_t>(
437                255u,
438                0u,
439                0u,
440                255u,
441                0u,
442                255u,
443                0u,
444                255u,
445                0u,
446                0u,
447                255u,
448                255u,
449                127u,
450                127u,
451                127u,
452                255u));
453    }
454
455    // Ignore this test since validation layer reports that it is unsupported.
456    if (false)
457    {
458        uint32_t texData[] = {255u, 0u, 0u, 0u, 255u, 0u, 0u, 0u, 255u, 127u, 127u, 127u};
459        ITextureResource::SubresourceData subData = {(void*)texData, 24, 0};
460
461        auto texView = createTexView(device, size, gfx::Format::R32G32B32_UINT, &subData);
462        setUpAndRunTest(device, texView, uintBufferView, "copyTexUint3");
463        compareComputeResult(
464            device,
465            uintResults,
466            Slang::makeArray<uint32_t>(255u, 0u, 0u, 0u, 255u, 0u, 0u, 0u, 255u, 127u, 127u, 127u));
467    }
468
469    {
470        uint32_t texData[] = {255u, 0u, 0u, 255u, 255u, 255u, 127u, 127u};
471        ITextureResource::SubresourceData subData = {(void*)texData, 16, 0};
472
473        auto texView = createTexView(device, size, gfx::Format::R32G32_UINT, &subData);
474        setUpAndRunTest(device, texView, uintBufferView, "copyTexUint2");
475        compareComputeResult(
476            device,
477            uintResults,
478            Slang::makeArray<uint32_t>(255u, 0u, 0u, 255u, 255u, 255u, 127u, 127u));
479    }
480
481    {
482        uint32_t texData[] = {255u, 0u, 127u, 73u};
483        ITextureResource::SubresourceData subData = {(void*)texData, 8, 0};
484
485        auto texView = createTexView(device, size, gfx::Format::R32_UINT, &subData);
486        setUpAndRunTest(device, texView, uintBufferView, "copyTexUint");
487        compareComputeResult(device, uintResults, Slang::makeArray<uint32_t>(255u, 0u, 127u, 73u));
488    }
489
490    {
491        uint16_t texData[] =
492            {255u, 0u, 0u, 255u, 0u, 255u, 0u, 255u, 0u, 0u, 255u, 255u, 127u, 127u, 127u, 255u};
493        ITextureResource::SubresourceData subData = {(void*)texData, 16, 0};
494
495        auto texView = createTexView(device, size, gfx::Format::R16G16B16A16_UINT, &subData);
496        setUpAndRunTest(device, texView, uintBufferView, "copyTexUint4");
497        compareComputeResult(
498            device,
499            uintResults,
500            Slang::makeArray<uint32_t>(
501                255u,
502                0u,
503                0u,
504                255u,
505                0u,
506                255u,
507                0u,
508                255u,
509                0u,
510                0u,
511                255u,
512                255u,
513                127u,
514                127u,
515                127u,
516                255u));
517    }
518
519    {
520        uint16_t texData[] = {255u, 0u, 0u, 255u, 255u, 255u, 127u, 127u};
521        ITextureResource::SubresourceData subData = {(void*)texData, 8, 0};
522
523        auto texView = createTexView(device, size, gfx::Format::R16G16_UINT, &subData);
524        setUpAndRunTest(device, texView, uintBufferView, "copyTexUint2");
525        compareComputeResult(
526            device,
527            uintResults,
528            Slang::makeArray<uint32_t>(255u, 0u, 0u, 255u, 255u, 255u, 127u, 127u));
529    }
530
531    {
532        uint16_t texData[] = {255u, 0u, 127u, 73u};
533        ITextureResource::SubresourceData subData = {(void*)texData, 4, 0};
534
535        auto texView = createTexView(device, size, gfx::Format::R16_UINT, &subData);
536        setUpAndRunTest(device, texView, uintBufferView, "copyTexUint");
537        compareComputeResult(device, uintResults, Slang::makeArray<uint32_t>(255u, 0u, 127u, 73u));
538    }
539
540    {
541        uint8_t texData[] =
542            {255u, 0u, 0u, 255u, 0u, 255u, 0u, 255u, 0u, 0u, 255u, 255u, 127u, 127u, 127u, 255u};
543        ITextureResource::SubresourceData subData = {(void*)texData, 8, 0};
544
545        auto texView = createTexView(device, size, gfx::Format::R8G8B8A8_UINT, &subData);
546        setUpAndRunTest(device, texView, uintBufferView, "copyTexUint4");
547        compareComputeResult(
548            device,
549            uintResults,
550            Slang::makeArray<uint32_t>(
551                255u,
552                0u,
553                0u,
554                255u,
555                0u,
556                255u,
557                0u,
558                255u,
559                0u,
560                0u,
561                255u,
562                255u,
563                127u,
564                127u,
565                127u,
566                255u));
567    }
568
569    {
570        uint8_t texData[] = {255u, 0u, 0u, 255u, 255u, 255u, 127u, 127u};
571        ITextureResource::SubresourceData subData = {(void*)texData, 4, 0};
572
573        auto texView = createTexView(device, size, gfx::Format::R8G8_UINT, &subData);
574        setUpAndRunTest(device, texView, uintBufferView, "copyTexUint2");
575        compareComputeResult(
576            device,
577            uintResults,
578            Slang::makeArray<uint32_t>(255u, 0u, 0u, 255u, 255u, 255u, 127u, 127u));
579    }
580
581    {
582        uint8_t texData[] = {255u, 0u, 127u, 73u};
583        ITextureResource::SubresourceData subData = {(void*)texData, 2, 0};
584
585        auto texView = createTexView(device, size, gfx::Format::R8_UINT, &subData);
586        setUpAndRunTest(device, texView, uintBufferView, "copyTexUint");
587        compareComputeResult(device, uintResults, Slang::makeArray<uint32_t>(255u, 0u, 127u, 73u));
588    }
589
590    {
591        int32_t texData[] = {255, 0, 0, 255, 0, 255, 0, 255, 0, 0, 255, 255, 127, 127, 127, 255};
592        ITextureResource::SubresourceData subData = {(void*)texData, 32, 0};
593
594        auto texView = createTexView(device, size, gfx::Format::R32G32B32A32_SINT, &subData);
595        setUpAndRunTest(device, texView, intBufferView, "copyTexInt4");
596        compareComputeResult(
597            device,
598            intResults,
599            Slang::makeArray<
600                int32_t>(255, 0, 0, 255, 0, 255, 0, 255, 0, 0, 255, 255, 127, 127, 127, 255));
601    }
602
603    // Ignore this test on swiftshader. Swiftshader produces unsupported format warnings for this
604    // test.
605    if (false)
606    {
607        int32_t texData[] = {255, 0, 0, 0, 255, 0, 0, 0, 255, 127, 127, 127};
608        ITextureResource::SubresourceData subData = {(void*)texData, 24, 0};
609
610        auto texView = createTexView(device, size, gfx::Format::R32G32B32_SINT, &subData);
611        setUpAndRunTest(device, texView, intBufferView, "copyTexInt3");
612        compareComputeResult(
613            device,
614            intResults,
615            Slang::makeArray<int32_t>(255, 0, 0, 0, 255, 0, 0, 0, 255, 127, 127, 127));
616    }
617
618    {
619        int32_t texData[] = {255, 0, 0, 255, 255, 255, 127, 127};
620        ITextureResource::SubresourceData subData = {(void*)texData, 16, 0};
621
622        auto texView = createTexView(device, size, gfx::Format::R32G32_SINT, &subData);
623        setUpAndRunTest(device, texView, intBufferView, "copyTexInt2");
624        compareComputeResult(
625            device,
626            intResults,
627            Slang::makeArray<int32_t>(255, 0, 0, 255, 255, 255, 127, 127));
628    }
629
630    {
631        int32_t texData[] = {255, 0, 127, 73};
632        ITextureResource::SubresourceData subData = {(void*)texData, 8, 0};
633
634        auto texView = createTexView(device, size, gfx::Format::R32_SINT, &subData);
635        setUpAndRunTest(device, texView, intBufferView, "copyTexInt");
636        compareComputeResult(device, intResults, Slang::makeArray<int32_t>(255, 0, 127, 73));
637    }
638
639    {
640        int16_t texData[] = {255, 0, 0, 255, 0, 255, 0, 255, 0, 0, 255, 255, 127, 127, 127, 255};
641        ITextureResource::SubresourceData subData = {(void*)texData, 16, 0};
642
643        auto texView = createTexView(device, size, gfx::Format::R16G16B16A16_SINT, &subData);
644        setUpAndRunTest(device, texView, intBufferView, "copyTexInt4");
645        compareComputeResult(
646            device,
647            intResults,
648            Slang::makeArray<
649                int32_t>(255, 0, 0, 255, 0, 255, 0, 255, 0, 0, 255, 255, 127, 127, 127, 255));
650    }
651
652    {
653        int16_t texData[] = {255, 0, 0, 255, 255, 255, 127, 127};
654        ITextureResource::SubresourceData subData = {(void*)texData, 8, 0};
655
656        auto texView = createTexView(device, size, gfx::Format::R16G16_SINT, &subData);
657        setUpAndRunTest(device, texView, intBufferView, "copyTexInt2");
658        compareComputeResult(
659            device,
660            intResults,
661            Slang::makeArray<int32_t>(255, 0, 0, 255, 255, 255, 127, 127));
662    }
663
664    {
665        int16_t texData[] = {255, 0, 127, 73};
666        ITextureResource::SubresourceData subData = {(void*)texData, 4, 0};
667
668        auto texView = createTexView(device, size, gfx::Format::R16_SINT, &subData);
669        setUpAndRunTest(device, texView, intBufferView, "copyTexInt");
670        compareComputeResult(device, intResults, Slang::makeArray<int32_t>(255, 0, 127, 73));
671    }
672
673    {
674        int8_t texData[] = {127, 0, 0, 127, 0, 127, 0, 127, 0, 0, 127, 127, 0, 0, 0, 127};
675        ITextureResource::SubresourceData subData = {(void*)texData, 8, 0};
676
677        auto texView = createTexView(device, size, gfx::Format::R8G8B8A8_SINT, &subData);
678        setUpAndRunTest(device, texView, intBufferView, "copyTexInt4");
679        compareComputeResult(
680            device,
681            intResults,
682            Slang::makeArray<
683                int32_t>(127, 0, 0, 127, 0, 127, 0, 127, 0, 0, 127, 127, 0, 0, 0, 127));
684    }
685
686    {
687        int8_t texData[] = {127, 0, 0, 127, 127, 127, 73, 73};
688        ITextureResource::SubresourceData subData = {(void*)texData, 4, 0};
689
690        auto texView = createTexView(device, size, gfx::Format::R8G8_SINT, &subData);
691        setUpAndRunTest(device, texView, intBufferView, "copyTexInt2");
692        compareComputeResult(
693            device,
694            intResults,
695            Slang::makeArray<int32_t>(127, 0, 0, 127, 127, 127, 73, 73));
696    }
697
698    {
699        int8_t texData[] = {127, 0, 73, 25};
700        ITextureResource::SubresourceData subData = {(void*)texData, 2, 0};
701
702        auto texView = createTexView(device, size, gfx::Format::R8_SINT, &subData);
703        setUpAndRunTest(device, texView, intBufferView, "copyTexInt");
704        compareComputeResult(device, intResults, Slang::makeArray<int32_t>(127, 0, 73, 25));
705    }
706
707    {
708        uint16_t texData[] = {
709            65535u,
710            0u,
711            0u,
712            65535u,
713            0u,
714            65535u,
715            0u,
716            65535u,
717            0u,
718            0u,
719            65535u,
720            65535u,
721            32767u,
722            32767u,
723            32767u,
724            32767u};
725        ITextureResource::SubresourceData subData = {(void*)texData, 16, 0};
726
727        auto texView = createTexView(device, size, gfx::Format::R16G16B16A16_UNORM, &subData);
728        setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat4");
729        compareComputeResult(
730            device,
731            floatResults,
732            Slang::makeArray<float>(
733                1.0f,
734                0.0f,
735                0.0f,
736                1.0f,
737                0.0f,
738                1.0f,
739                0.0f,
740                1.0f,
741                0.0f,
742                0.0f,
743                1.0f,
744                1.0f,
745                0.499992371f,
746                0.499992371f,
747                0.499992371f,
748                0.499992371f));
749    }
750
751    {
752        uint16_t texData[] = {65535u, 0u, 0u, 65535u, 65535u, 65535u, 32767u, 32767u};
753        ITextureResource::SubresourceData subData = {(void*)texData, 8, 0};
754
755        auto texView = createTexView(device, size, gfx::Format::R16G16_UNORM, &subData);
756        setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat2");
757        compareComputeResult(
758            device,
759            floatResults,
760            Slang::makeArray<
761                float>(1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.499992371f, 0.499992371f));
762    }
763
764    {
765        uint16_t texData[] = {65535u, 0u, 32767u, 16383u};
766        ITextureResource::SubresourceData subData = {(void*)texData, 4, 0};
767
768        auto texView = createTexView(device, size, gfx::Format::R16_UNORM, &subData);
769        setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat");
770        compareComputeResult(
771            device,
772            floatResults,
773            Slang::makeArray<float>(1.0f, 0.0f, 0.499992371f, 0.249988556f));
774    }
775
776    // Ignore this test on swiftshader. Swiftshader produces different results than expected.
777    if (!Slang::String(device->getDeviceInfo().adapterName).toLower().contains("swiftshader"))
778    {
779        uint8_t texData[] =
780            {0u, 0u, 0u, 255u, 127u, 127u, 127u, 255u, 255u, 255u, 255u, 255u, 0u, 0u, 0u, 0u};
781        ITextureResource::SubresourceData subData = {(void*)texData, 8, 0};
782
783        auto texView = createTexView(device, size, gfx::Format::R8G8B8A8_TYPELESS, &subData);
784        setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat4");
785        compareComputeResult(
786            device,
787            floatResults,
788            Slang::makeArray<float>(
789                0.0f,
790                0.0f,
791                0.0f,
792                1.0f,
793                0.498039216f,
794                0.498039216f,
795                0.498039216f,
796                1.0f,
797                1.0f,
798                1.0f,
799                1.0f,
800                1.0f,
801                0.0f,
802                0.0f,
803                0.0f,
804                0.0f));
805
806        texView = createTexView(device, size, gfx::Format::R8G8B8A8_UNORM, &subData);
807        setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat4");
808        compareComputeResult(
809            device,
810            floatResults,
811            Slang::makeArray<float>(
812                0.0f,
813                0.0f,
814                0.0f,
815                1.0f,
816                0.498039216f,
817                0.498039216f,
818                0.498039216f,
819                1.0f,
820                1.0f,
821                1.0f,
822                1.0f,
823                1.0f,
824                0.0f,
825                0.0f,
826                0.0f,
827                0.0f));
828
829        texView = createTexView(device, size, gfx::Format::R8G8B8A8_UNORM_SRGB, &subData);
830        setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat4");
831        compareComputeResult(
832            device,
833            floatResults,
834            Slang::makeArray<float>(
835                0.0f,
836                0.0f,
837                0.0f,
838                1.0f,
839                0.211914062f,
840                0.211914062f,
841                0.211914062f,
842                1.0f,
843                1.0f,
844                1.0f,
845                1.0f,
846                1.0f,
847                0.0f,
848                0.0f,
849                0.0f,
850                0.0f));
851    }
852
853    // Ignore this test on swiftshader. Swiftshader produces different results than expected.
854    if (!Slang::String(device->getDeviceInfo().adapterName).toLower().contains("swiftshader"))
855    {
856        uint8_t texData[] = {255u, 0u, 0u, 255u, 255u, 255u, 127u, 127u};
857        ITextureResource::SubresourceData subData = {(void*)texData, 4, 0};
858
859        auto texView = createTexView(device, size, gfx::Format::R8G8_TYPELESS, &subData);
860        setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat2");
861        compareComputeResult(
862            device,
863            floatResults,
864            Slang::makeArray<
865                float>(1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.498039216f, 0.498039216f));
866
867        texView = createTexView(device, size, gfx::Format::R8G8_UNORM, &subData);
868        setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat2");
869        compareComputeResult(
870            device,
871            floatResults,
872            Slang::makeArray<
873                float>(1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.498039216f, 0.498039216f));
874    }
875
876    // Ignore this test on swiftshader. Swiftshader produces different results than expected.
877    if (!Slang::String(device->getDeviceInfo().adapterName).toLower().contains("swiftshader"))
878    {
879        uint8_t texData[] = {255u, 0u, 127u, 63u};
880        ITextureResource::SubresourceData subData = {(void*)texData, 2, 0};
881
882        auto texView = createTexView(device, size, gfx::Format::R8_TYPELESS, &subData);
883        setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat");
884        compareComputeResult(
885            device,
886            floatResults,
887            Slang::makeArray<float>(1.0f, 0.0f, 0.498039216f, 0.247058824f));
888
889        texView = createTexView(device, size, gfx::Format::R8_UNORM, &subData);
890        setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat");
891        compareComputeResult(
892            device,
893            floatResults,
894            Slang::makeArray<float>(1.0f, 0.0f, 0.498039216f, 0.247058824f));
895    }
896
897    // Ignore this test on swiftshader. Swiftshader produces different results than expected.
898    if (!Slang::String(device->getDeviceInfo().adapterName).toLower().contains("swiftshader"))
899    {
900        uint8_t texData[] =
901            {0u, 0u, 0u, 255u, 127u, 127u, 127u, 255u, 255u, 255u, 255u, 255u, 0u, 0u, 0u, 0u};
902        ITextureResource::SubresourceData subData = {(void*)texData, 8, 0};
903
904        auto texView = createTexView(device, size, gfx::Format::B8G8R8A8_TYPELESS, &subData);
905        setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat4");
906        compareComputeResult(
907            device,
908            floatResults,
909            Slang::makeArray<float>(
910                0.0f,
911                0.0f,
912                0.0f,
913                1.0f,
914                0.498039216f,
915                0.498039216f,
916                0.498039216f,
917                1.0f,
918                1.0f,
919                1.0f,
920                1.0f,
921                1.0f,
922                0.0f,
923                0.0f,
924                0.0f,
925                0.0f));
926
927        texView = createTexView(device, size, gfx::Format::B8G8R8A8_UNORM, &subData);
928        setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat4");
929        compareComputeResult(
930            device,
931            floatResults,
932            Slang::makeArray<float>(
933                0.0f,
934                0.0f,
935                0.0f,
936                1.0f,
937                0.498039216f,
938                0.498039216f,
939                0.498039216f,
940                1.0f,
941                1.0f,
942                1.0f,
943                1.0f,
944                1.0f,
945                0.0f,
946                0.0f,
947                0.0f,
948                0.0f));
949
950        texView = createTexView(device, size, gfx::Format::B8G8R8A8_UNORM_SRGB, &subData);
951        setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat4");
952        compareComputeResult(
953            device,
954            floatResults,
955            Slang::makeArray<float>(
956                0.0f,
957                0.0f,
958                0.0f,
959                1.0f,
960                0.211914062f,
961                0.211914062f,
962                0.211914062f,
963                1.0f,
964                1.0f,
965                1.0f,
966                1.0f,
967                1.0f,
968                0.0f,
969                0.0f,
970                0.0f,
971                0.0f));
972    }
973
974    {
975        int16_t texData[] =
976            {32767, 0, 0, 32767, 0, 32767, 0, 32767, 0, 0, 32767, 32767, -32768, -32768, 0, 32767};
977        ITextureResource::SubresourceData subData = {(void*)texData, 16, 0};
978
979        auto texView = createTexView(device, size, gfx::Format::R16G16B16A16_SNORM, &subData);
980        setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat4");
981        compareComputeResult(
982            device,
983            floatResults,
984            Slang::makeArray<float>(
985                1.0f,
986                0.0f,
987                0.0f,
988                1.0f,
989                0.0f,
990                1.0f,
991                0.0f,
992                1.0f,
993                0.0f,
994                0.0f,
995                1.0f,
996                1.0f,
997                -1.0f,
998                -1.0f,
999                0.0f,
1000                1.0f));
1001    }
1002
1003    {
1004        int16_t texData[] = {32767, 0, 0, 32767, 32767, 32767, -32768, -32768};
1005        ITextureResource::SubresourceData subData = {(void*)texData, 8, 0};
1006
1007        auto texView = createTexView(device, size, gfx::Format::R16G16_SNORM, &subData);
1008        setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat2");
1009        compareComputeResult(
1010            device,
1011            floatResults,
1012            Slang::makeArray<float>(1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, -1.0f, -1.0f));
1013    }
1014
1015    {
1016        int16_t texData[] = {32767, 0, -32768, 0};
1017        ITextureResource::SubresourceData subData = {(void*)texData, 4, 0};
1018
1019        auto texView = createTexView(device, size, gfx::Format::R16_SNORM, &subData);
1020        setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat");
1021        compareComputeResult(
1022            device,
1023            floatResults,
1024            Slang::makeArray<float>(1.0f, 0.0f, -1.0f, 0.0f));
1025    }
1026
1027    {
1028        int8_t texData[] = {127, 0, 0, 127, 0, 127, 0, 127, 0, 0, 127, 127, -128, -128, 0, 127};
1029        ITextureResource::SubresourceData subData = {(void*)texData, 8, 0};
1030
1031        auto texView = createTexView(device, size, gfx::Format::R8G8B8A8_SNORM, &subData);
1032        setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat4");
1033        compareComputeResult(
1034            device,
1035            floatResults,
1036            Slang::makeArray<float>(
1037                1.0f,
1038                0.0f,
1039                0.0f,
1040                1.0f,
1041                0.0f,
1042                1.0f,
1043                0.0f,
1044                1.0f,
1045                0.0f,
1046                0.0f,
1047                1.0f,
1048                1.0f,
1049                -1.0f,
1050                -1.0f,
1051                0.0f,
1052                1.0f));
1053    }
1054
1055    {
1056        int8_t texData[] = {127, 0, 0, 127, 127, 127, -128, -128};
1057        ITextureResource::SubresourceData subData = {(void*)texData, 4, 0};
1058
1059        auto texView = createTexView(device, size, gfx::Format::R8G8_SNORM, &subData);
1060        setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat2");
1061        compareComputeResult(
1062            device,
1063            floatResults,
1064            Slang::makeArray<float>(1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, -1.0f, -1.0f));
1065    }
1066
1067    {
1068        int8_t texData[] = {127, 0, -128, 0};
1069        ITextureResource::SubresourceData subData = {(void*)texData, 2, 0};
1070
1071        auto texView = createTexView(device, size, gfx::Format::R8_SNORM, &subData);
1072        setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat");
1073        compareComputeResult(
1074            device,
1075            floatResults,
1076            Slang::makeArray<float>(1.0f, 0.0f, -1.0f, 0.0f));
1077    }
1078
1079    // Ignore this test on swiftshader. Swiftshader produces unsupported format warnings for this
1080    // test.
1081    if (!Slang::String(device->getDeviceInfo().adapterName).toLower().contains("swiftshader"))
1082    {
1083        uint8_t texData[] = {15u, 240u, 240u, 240u, 0u, 255u, 119u, 119u};
1084        ITextureResource::SubresourceData subData = {(void*)texData, 4, 0};
1085
1086        auto texView = createTexView(device, size, gfx::Format::B4G4R4A4_UNORM, &subData);
1087        setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat4");
1088        compareComputeResult(
1089            device,
1090            floatResults,
1091            Slang::makeArray<float>(
1092                0.0f,
1093                0.0f,
1094                1.0f,
1095                1.0f,
1096                0.0f,
1097                1.0f,
1098                0.0f,
1099                1.0f,
1100                1.0f,
1101                0.0f,
1102                0.0f,
1103                1.0f,
1104                0.466666669f,
1105                0.466666669f,
1106                0.466666669f,
1107                0.466666669f));
1108    }
1109
1110    // Ignore this test on swiftshader. Swiftshader produces different results than expected.
1111    if (!Slang::String(device->getDeviceInfo().adapterName).toLower().contains("swiftshader"))
1112    {
1113        uint16_t texData[] = {31u, 2016u, 63488u, 31727u};
1114        ITextureResource::SubresourceData subData = {(void*)texData, 4, 0};
1115
1116        auto texView = createTexView(device, size, gfx::Format::B5G6R5_UNORM, &subData);
1117        setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat3");
1118        compareComputeResult(
1119            device,
1120            floatResults,
1121            Slang::makeArray<float>(
1122                0.0f,
1123                0.0f,
1124                1.0f,
1125                0.0f,
1126                1.0f,
1127                0.0f,
1128                1.0f,
1129                0.0f,
1130                0.0f,
1131                0.482352942f,
1132                0.490196079f,
1133                0.482352942f));
1134
1135        texView = createTexView(device, size, gfx::Format::B5G5R5A1_UNORM, &subData);
1136        setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat4");
1137        compareComputeResult(
1138            device,
1139            floatResults,
1140            Slang::makeArray<float>(
1141                0.0f,
1142                0.0f,
1143                1.0f,
1144                0.0f,
1145                0.0313725509f,
1146                1.0f,
1147                0.0f,
1148                0.0f,
1149                0.968627453f,
1150                0.0f,
1151                0.0f,
1152                1.0f,
1153                0.968627453f,
1154                1.0f,
1155                0.482352942f,
1156                0.0f));
1157    }
1158
1159    {
1160        uint32_t texData[] = {2950951416u, 2013265920u, 3086219772u, 3087007228u};
1161        ITextureResource::SubresourceData subData = {(void*)texData, 8, 0};
1162
1163        auto texView = createTexView(device, size, gfx::Format::R9G9B9E5_SHAREDEXP, &subData);
1164        setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat3");
1165        compareComputeResult(
1166            device,
1167            floatResults,
1168            Slang::makeArray<float>(
1169                63.0f,
1170                63.0f,
1171                63.0f,
1172                0.0f,
1173                0.0f,
1174                0.0f,
1175                127.0f,
1176                127.0f,
1177                127.0f,
1178                127.0f,
1179                127.5f,
1180                127.75f));
1181    }
1182
1183    // Ignore this test on swiftshader. Swiftshader produces different results than expected.
1184    if (!Slang::String(device->getDeviceInfo().adapterName).toLower().contains("swiftshader"))
1185    {
1186        uint32_t texData[] = {4294967295u, 0u, 2683829759u, 1193046471u};
1187        ITextureResource::SubresourceData subData = {(void*)texData, 8, 0};
1188
1189        auto texView = createTexView(device, size, gfx::Format::R10G10B10A2_TYPELESS, &subData);
1190        setUpAndRunTest(device, texView, uintBufferView, "copyTexUint4");
1191        compareComputeResult(
1192            device,
1193            uintResults,
1194            Slang::makeArray<uint32_t>(
1195                1023u,
1196                1023u,
1197                1023u,
1198                3u,
1199                0u,
1200                0u,
1201                0u,
1202                0u,
1203                511u,
1204                511u,
1205                511u,
1206                2u,
1207                455u,
1208                796u,
1209                113u,
1210                1u));
1211
1212        texView = createTexView(device, size, gfx::Format::R10G10B10A2_UNORM, &subData);
1213        setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat4");
1214        compareComputeResult(
1215            device,
1216            floatResults,
1217            Slang::makeArray<float>(
1218                1.0f,
1219                1.0f,
1220                1.0f,
1221                1.0f,
1222                0.0f,
1223                0.0f,
1224                0.0f,
1225                0.0f,
1226                0.499511242f,
1227                0.499511242f,
1228                0.499511242f,
1229                0.666666687f,
1230                0.444770277f,
1231                0.778103590f,
1232                0.110459432f,
1233                0.333333343f));
1234
1235        texView = createTexView(device, size, gfx::Format::R10G10B10A2_UINT, &subData);
1236        setUpAndRunTest(device, texView, uintBufferView, "copyTexUint4");
1237        compareComputeResult(
1238            device,
1239            uintResults,
1240            Slang::makeArray<uint32_t>(
1241                1023u,
1242                1023u,
1243                1023u,
1244                3u,
1245                0u,
1246                0u,
1247                0u,
1248                0u,
1249                511u,
1250                511u,
1251                511u,
1252                2u,
1253                455u,
1254                796u,
1255                113u,
1256                1u));
1257    }
1258
1259    {
1260        uint32_t texData[] = {3085827519u, 0u, 2951478655u, 1880884096u};
1261        ITextureResource::SubresourceData subData = {(void*)texData, 8, 0};
1262
1263        auto texView = createTexView(device, size, gfx::Format::R11G11B10_FLOAT, &subData);
1264        setUpAndRunTest(device, texView, floatBufferView, "copyTexFloat3");
1265        compareComputeResult(
1266            device,
1267            floatResults,
1268            Slang::makeArray<float>(
1269                254.0f,
1270                254.0f,
1271                252.0f,
1272                0.0f,
1273                0.0f,
1274                0.0f,
1275                127.0f,
1276                127.0f,
1277                126.0f,
1278                0.5f,
1279                0.5f,
1280                0.5f));
1281    }
1282
1283    // These BC1 tests also check that mipmaps are working correctly for compressed formats.
1284    // Ignore this test on swiftshader. Swiftshader produces different results than expected.
1285    if (!Slang::String(device->getDeviceInfo().adapterName).toLower().contains("swiftshader"))
1286    {
1287        uint8_t texData[] = {16u, 0u, 0u,  0u, 0u,   0u,   0u,   0u,   16u, 0u, 0u,  0u, 0u, 0u,
1288                             0u,  0u, 16u, 0u, 0u,   0u,   0u,   0u,   0u,  0u, 16u, 0u, 0u, 0u,
1289                             0u,  0u, 0u,  0u, 255u, 255u, 255u, 255u, 0u,  0u, 0u,  0u};
1290        ITextureResource::SubresourceData subData[] = {
1291            ITextureResource::SubresourceData{(void*)texData, 16, 32},
1292            ITextureResource::SubresourceData{(void*)(texData + 32), 8, 0}};
1293        ITextureResource::Extents size = {};
1294        size.width = 8;
1295        size.height = 8;
1296        size.depth = 1;
1297
1298        auto texView = createTexView(device, size, gfx::Format::BC1_UNORM, subData, 2);
1299        setUpAndRunTest(device, texView, floatBufferView, "sampleMips", sampler);
1300        compareComputeResult(
1301            device,
1302            floatResults,
1303            Slang::makeArray<float>(0.0f, 0.0f, 0.517647088f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f));
1304
1305        texView = createTexView(device, size, gfx::Format::BC1_UNORM_SRGB, subData, 2);
1306        setUpAndRunTest(device, texView, floatBufferView, "sampleMips", sampler);
1307        compareComputeResult(
1308            device,
1309            floatResults,
1310            Slang::makeArray<float>(0.0f, 0.0f, 0.230468750f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f));
1311    }
1312
1313    // Ignore this test on swiftshader. Swiftshader produces different results than expected.
1314    if (!Slang::String(device->getDeviceInfo().adapterName).toLower().contains("swiftshader"))
1315    {
1316        uint8_t texData[] =
1317            {255u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, 16u, 0u, 0u, 0u, 0u, 0u, 0u, 0u};
1318        ITextureResource::SubresourceData subData = {(void*)texData, 16, 0};
1319
1320        auto texView = createTexView(device, bcSize, gfx::Format::BC2_UNORM, &subData);
1321        setUpAndRunTest(device, texView, floatBufferView, "sampleTex", sampler);
1322        compareComputeResult(
1323            device,
1324            floatResults,
1325            Slang::makeArray<float>(0.0f, 0.0f, 0.517647088f, 1.0f));
1326
1327        texView = createTexView(device, bcSize, gfx::Format::BC2_UNORM_SRGB, &subData);
1328        setUpAndRunTest(device, texView, floatBufferView, "sampleTex", sampler);
1329        compareComputeResult(
1330            device,
1331            floatResults,
1332            Slang::makeArray<float>(0.0f, 0.0f, 0.230468750f, 1.0f));
1333    }
1334
1335    // Ignore this test on swiftshader. Swiftshader produces different results than expected.
1336    if (!Slang::String(device->getDeviceInfo().adapterName).toLower().contains("swiftshader"))
1337    {
1338        uint8_t texData[] =
1339            {0u, 255u, 255u, 255u, 255u, 255u, 255u, 255u, 16u, 0u, 0u, 0u, 0u, 0u, 0u, 0u};
1340        ITextureResource::SubresourceData subData = {(void*)texData, 16, 0};
1341
1342        auto texView = createTexView(device, bcSize, gfx::Format::BC3_UNORM, &subData);
1343        setUpAndRunTest(device, texView, floatBufferView, "sampleTex", sampler);
1344        compareComputeResult(
1345            device,
1346            floatResults,
1347            Slang::makeArray<float>(0.0f, 0.0f, 0.517647088f, 1.0f));
1348
1349        texView = createTexView(device, bcSize, gfx::Format::BC3_UNORM_SRGB, &subData);
1350        setUpAndRunTest(device, texView, floatBufferView, "sampleTex", sampler);
1351        compareComputeResult(
1352            device,
1353            floatResults,
1354            Slang::makeArray<float>(0.0f, 0.0f, 0.230468750f, 1.0f));
1355    }
1356
1357    // Ignore this test on swiftshader. Swiftshader produces different results than expected.
1358    if (!Slang::String(device->getDeviceInfo().adapterName).toLower().contains("swiftshader"))
1359    {
1360        uint8_t texData[] = {127u, 0u, 0u, 0u, 0u, 0u, 0u, 0u};
1361        ITextureResource::SubresourceData subData = {(void*)texData, 8, 0};
1362
1363        auto texView = createTexView(device, bcSize, gfx::Format::BC4_UNORM, &subData);
1364        setUpAndRunTest(device, texView, floatBufferView, "sampleTex", sampler);
1365        compareComputeResult(
1366            device,
1367            floatResults,
1368            Slang::makeArray<float>(0.498039216f, 0.0f, 0.0f, 1.0f));
1369
1370        texView = createTexView(device, bcSize, gfx::Format::BC4_SNORM, &subData);
1371        setUpAndRunTest(device, texView, floatBufferView, "sampleTex", sampler);
1372        compareComputeResult(device, floatResults, Slang::makeArray<float>(1.0f, 0.0f, 0.0f, 1.0f));
1373    }
1374
1375    // Ignore this test on swiftshader. Swiftshader produces different results than expected.
1376    if (!Slang::String(device->getDeviceInfo().adapterName).toLower().contains("swiftshader"))
1377    {
1378        uint8_t texData[] = {127u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 127u, 0u, 0u, 0u, 0u, 0u, 0u, 0u};
1379        ITextureResource::SubresourceData subData = {(void*)texData, 16, 0};
1380
1381        auto texView = createTexView(device, bcSize, gfx::Format::BC5_UNORM, &subData);
1382        setUpAndRunTest(device, texView, floatBufferView, "sampleTex", sampler);
1383        compareComputeResult(
1384            device,
1385            floatResults,
1386            Slang::makeArray<float>(
1387                0.498039216f,
1388                0.498039216f,
1389                0.0f,
1390                1.0f,
1391                0.498039216f,
1392                0.498039216f,
1393                0.0f,
1394                1.0f));
1395
1396        texView = createTexView(device, bcSize, gfx::Format::BC5_SNORM, &subData);
1397        setUpAndRunTest(device, texView, floatBufferView, "sampleTex", sampler);
1398        compareComputeResult(
1399            device,
1400            floatResults,
1401            Slang::makeArray<float>(1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f));
1402    }
1403
1404    // BC6H_UF16 and BC6H_SF16 are tested separately due to requiring different texture data.
1405    // Ignore this test on swiftshader. Swiftshader produces different results than expected.
1406    if (!Slang::String(device->getDeviceInfo().adapterName).toLower().contains("swiftshader"))
1407    {
1408        uint8_t texData[] = {
1409            98u,
1410            238u,
1411            232u,
1412            77u,
1413            240u,
1414            66u,
1415            148u,
1416            31u,
1417            124u,
1418            95u,
1419            2u,
1420            224u,
1421            255u,
1422            107u,
1423            77u,
1424            250u};
1425        ITextureResource::SubresourceData subData = {(void*)texData, 16, 0};
1426
1427        auto texView = createTexView(device, bcSize, gfx::Format::BC6H_UF16, &subData);
1428        setUpAndRunTest(device, texView, floatBufferView, "sampleTex", sampler);
1429        compareComputeResult(
1430            device,
1431            floatResults,
1432            Slang::makeArray<float>(0.336669922f, 0.911132812f, 2.13867188f, 1.0f));
1433    }
1434
1435    // Ignore this test on swiftshader. Swiftshader produces different results than expected.
1436    if (!Slang::String(device->getDeviceInfo().adapterName).toLower().contains("swiftshader"))
1437    {
1438        uint8_t texData[] = {
1439            107u,
1440            238u,
1441            232u,
1442            77u,
1443            240u,
1444            71u,
1445            128u,
1446            127u,
1447            1u,
1448            0u,
1449            255u,
1450            255u,
1451            170u,
1452            218u,
1453            221u,
1454            254u};
1455        ITextureResource::SubresourceData subData = {(void*)texData, 16, 0};
1456
1457        auto texView = createTexView(device, bcSize, gfx::Format::BC6H_SF16, &subData);
1458        setUpAndRunTest(device, texView, floatBufferView, "sampleTex", sampler);
1459        compareComputeResult(
1460            device,
1461            floatResults,
1462            Slang::makeArray<float>(0.336914062f, 0.910644531f, 2.14062500f, 1.0f));
1463    }
1464
1465    // Ignore this test on swiftshader. Swiftshader produces different results than expected.
1466    if (!Slang::String(device->getDeviceInfo().adapterName).toLower().contains("swiftshader"))
1467    {
1468        uint8_t texData[] =
1469            {104u, 0u, 0u, 0u, 64u, 163u, 209u, 104u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u};
1470        ITextureResource::SubresourceData subData = {(void*)texData, 16, 0};
1471
1472        auto texView = createTexView(device, bcSize, gfx::Format::BC7_UNORM, &subData);
1473        setUpAndRunTest(device, texView, floatBufferView, "sampleTex", sampler);
1474        compareComputeResult(
1475            device,
1476            floatResults,
1477            Slang::makeArray<float>(0.0f, 0.101960786f, 0.0f, 1.0f));
1478
1479        texView = createTexView(device, bcSize, gfx::Format::BC7_UNORM_SRGB, &subData);
1480        setUpAndRunTest(device, texView, floatBufferView, "sampleTex", sampler);
1481        compareComputeResult(
1482            device,
1483            floatResults,
1484            Slang::makeArray<float>(0.0f, 0.0103149414f, 0.0f, 1.0f));
1485    }
1486}
1487
1488SLANG_UNIT_TEST(FormatTestsD3D11)
1489{
1490    runTestImpl(formatTestsImpl, unitTestContext, Slang::RenderApiFlag::D3D11);
1491}
1492
1493#if SLANG_WINDOWS_FAMILY
1494SLANG_UNIT_TEST(FormatTestsD3D12)
1495{
1496    runTestImpl(formatTestsImpl, unitTestContext, Slang::RenderApiFlag::D3D12);
1497}
1498#endif
1499
1500SLANG_UNIT_TEST(FormatTestsVulkan)
1501{
1502    runTestImpl(formatTestsImpl, unitTestContext, Slang::RenderApiFlag::Vulkan);
1503}
1504
1505} // namespace gfx_test
1506
1507#endif