yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
43d0c2100
master
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{ 16switch (format ) 17 { 18case gfx::Format ::R32G32B32A32_TYPELESS : 19return gfx::Format ::R32G32B32A32_FLOAT ; 20case gfx::Format ::R32G32B32_TYPELESS : 21return gfx::Format ::R32G32B32_FLOAT ; 22case gfx::Format ::R32G32_TYPELESS : 23return gfx::Format ::R32G32_FLOAT ; 24case gfx::Format ::R32_TYPELESS : 25return gfx::Format ::R32_FLOAT ; 26case gfx::Format ::R16G16B16A16_TYPELESS : 27return gfx::Format ::R16G16B16A16_FLOAT ; 28case gfx::Format ::R16G16_TYPELESS : 29return gfx::Format ::R16G16_FLOAT ; 30case gfx::Format ::R16_TYPELESS : 31return gfx::Format ::R16_FLOAT ; 32case gfx::Format ::R8G8B8A8_TYPELESS : 33return gfx::Format ::R8G8B8A8_UNORM ; 34case gfx::Format ::R8G8_TYPELESS : 35return gfx::Format ::R8G8_UNORM ; 36case gfx::Format ::R8_TYPELESS : 37return gfx::Format ::R8_UNORM ; 38case gfx::Format ::B8G8R8A8_TYPELESS : 39return gfx::Format ::B8G8R8A8_UNORM ; 40case gfx::Format ::R10G10B10A2_TYPELESS : 41return gfx::Format ::R10G10B10A2_UINT ; 42default : 43return gfx::Format ::Unknown ; 44 } 45} 46 47void setUpAndRunTest ( 48IDevice * device , 49ComPtr < IResourceView > texView , 50ComPtr < IResourceView > bufferView , 51const char * entryPoint , 52ComPtr < ISamplerState > sampler = nullptr ) 53{ 54Slang ::ComPtr < ITransientResourceHeap > transientHeap ; 55ITransientResourceHeap ::Desc transientHeapDesc = {}; 56transientHeapDesc .constantBufferSize = 4096 ; 57GFX_CHECK_CALL_ABORT ( 58device -> createTransientResourceHeap (transientHeapDesc ,transientHeap .writeRef ())); 59 60ComPtr < IShaderProgram > shaderProgram ; 61 slang::ProgramLayout * slangReflection ; 62GFX_CHECK_CALL_ABORT (loadComputeProgram ( 63device , 64shaderProgram , 65"format-test-shaders" , 66entryPoint , 67slangReflection )); 68 69ComputePipelineStateDesc pipelineDesc = {}; 70pipelineDesc .program = shaderProgram .get (); 71ComPtr < gfx::IPipelineState > pipelineState ; 72GFX_CHECK_CALL_ABORT ( 73device -> 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 { 78ICommandQueue ::Desc queueDesc = {ICommandQueue ::QueueType ::Graphics }; 79auto queue = device -> createCommandQueue (queueDesc ); 80 81auto commandBuffer = transientHeap -> createCommandBuffer (); 82auto encoder = commandBuffer -> encodeComputeCommands (); 83 84auto rootObject = encoder -> bindPipeline (pipelineState ); 85 86ShaderCursor entryPointCursor ( 87rootObject -> getEntryPoint (0 ));// get a cursor the the first entry-point. 88 89// Bind texture view to the entry point 90entryPointCursor .getPath ("tex" ).setResource (texView ); 91 92if (sampler ) 93entryPointCursor .getPath ("sampler" ).setSampler (sampler ); 94 95// Bind buffer view to the entry point. 96entryPointCursor .getPath ("buffer" ).setResource (bufferView ); 97 98encoder -> dispatchCompute (1 ,1 ,1 ); 99encoder -> endEncoding (); 100commandBuffer -> close (); 101queue -> executeCommandBuffer (commandBuffer ); 102queue -> waitOnHost (); 103 } 104} 105 106ComPtr < IResourceView > createTexView ( 107IDevice * device , 108ITextureResource ::Extents size , 109 gfx::Format format , 110ITextureResource ::SubresourceData * data , 111int mips = 1 ) 112{ 113ITextureResource ::Desc texDesc = {}; 114texDesc .type = IResource ::Type ::Texture2D ; 115texDesc .numMipLevels = mips ; 116texDesc .arraySize = 1 ; 117texDesc .size = size ; 118texDesc .defaultState = ResourceState ::ShaderResource ; 119texDesc .format = format ; 120 121ComPtr < ITextureResource > inTex ; 122GFX_CHECK_CALL_ABORT (device -> createTextureResource (texDesc ,data ,inTex .writeRef ())); 123 124ComPtr < IResourceView > texView ; 125IResourceView ::Desc texViewDesc = {}; 126texViewDesc .type = IResourceView ::Type ::ShaderResource ; 127texViewDesc .format = gfxIsTypelessFormat (format ) ?convertTypelessFormat (format ) :format ; 128GFX_CHECK_CALL_ABORT (device -> createTextureView (inTex ,texViewDesc ,texView .writeRef ())); 129return texView ; 130} 131 132template < typename T > 133ComPtr < IBufferResource > createBuffer (IDevice * device ,int size ,void * initialData ) 134{ 135IBufferResource ::Desc bufferDesc = {}; 136bufferDesc .sizeInBytes = size * sizeof (T ); 137bufferDesc .format = gfx::Format ::Unknown ; 138bufferDesc .elementSize = sizeof (T ); 139bufferDesc .allowedStates = ResourceStateSet ( 140ResourceState ::ShaderResource , 141ResourceState ::UnorderedAccess , 142ResourceState ::CopyDestination , 143ResourceState ::CopySource ); 144bufferDesc .defaultState = ResourceState ::UnorderedAccess ; 145bufferDesc .memoryType = MemoryType ::DeviceLocal ; 146 147ComPtr < IBufferResource > outBuffer ; 148GFX_CHECK_CALL_ABORT ( 149device -> createBufferResource (bufferDesc ,initialData ,outBuffer .writeRef ())); 150return outBuffer ; 151} 152 153ComPtr < IResourceView > createBufferView (IDevice * device ,ComPtr < IBufferResource > outBuffer ) 154{ 155ComPtr < IResourceView > bufferView ; 156IResourceView ::Desc viewDesc = {}; 157viewDesc .type = IResourceView ::Type ::UnorderedAccess ; 158viewDesc .format = Format ::Unknown ; 159GFX_CHECK_CALL_ABORT ( 160device -> createBufferView (outBuffer ,nullptr ,viewDesc ,bufferView .writeRef ())); 161return bufferView ; 162} 163 164void formatTestsImpl (IDevice * device ,UnitTestContext * context ) 165{ 166ISamplerState ::Desc samplerDesc ; 167auto sampler = device -> createSamplerState (samplerDesc ); 168 169float initFloatData [16 ]= {0.0f }; 170auto floatResults = createBuffer < float > (device ,16 ,initFloatData ); 171auto floatBufferView = createBufferView (device ,floatResults ); 172 173uint32_t initUintData [16 ]= {0u }; 174auto uintResults = createBuffer < uint32_t > (device ,16 ,initUintData ); 175auto uintBufferView = createBufferView (device ,uintResults ); 176 177int32_t initIntData [16 ]= {0 }; 178auto intResults = createBuffer < uint32_t > (device ,16 ,initIntData ); 179auto intBufferView = createBufferView (device ,intResults ); 180 181ITextureResource ::Extents size = {}; 182size .width = 2 ; 183size .height = 2 ; 184size .depth = 1 ; 185 186ITextureResource ::Extents bcSize = {}; 187bcSize .width = 4 ; 188bcSize .height = 4 ; 189bcSize .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 { 194float texData []= { 1951.0f , 1960.0f , 1970.0f , 1981.0f , 1990.0f , 2001.0f , 2010.0f , 2021.0f , 2030.0f , 2040.0f , 2051.0f , 2061.0f , 2070.5f , 2080.5f , 2090.5f , 2101.0f }; 211ITextureResource ::SubresourceData subData = {(void * )texData ,32 ,0 }; 212 213auto texView = createTexView (device ,size , gfx::Format ::R32G32B32A32_FLOAT ,& subData ); 214setUpAndRunTest (device ,texView ,floatBufferView ,"copyTexFloat4" ); 215compareComputeResult ( 216device , 217floatResults , 218Slang ::makeArray < float > ( 2191.0f , 2200.0f , 2210.0f , 2221.0f , 2230.0f , 2241.0f , 2250.0f , 2261.0f , 2270.0f , 2280.0f , 2291.0f , 2301.0f , 2310.5f , 2320.5f , 2330.5f , 2341.0f )); 235 236texView = createTexView (device ,size , gfx::Format ::R32G32B32A32_TYPELESS ,& subData ); 237setUpAndRunTest (device ,texView ,floatBufferView ,"copyTexFloat4" ); 238compareComputeResult ( 239device , 240floatResults , 241Slang ::makeArray < float > ( 2421.0f , 2430.0f , 2440.0f , 2451.0f , 2460.0f , 2471.0f , 2480.0f , 2491.0f , 2500.0f , 2510.0f , 2521.0f , 2531.0f , 2540.5f , 2550.5f , 2560.5f , 2571.0f )); 258 } 259 260// Ignore this test since it is not supported by swiftshader and nvidia's driver. 261if (false) 262 { 263float 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 }; 264ITextureResource ::SubresourceData subData = {(void * )texData ,24 ,0 }; 265 266auto texView = createTexView (device ,size , gfx::Format ::R32G32B32_FLOAT ,& subData ); 267setUpAndRunTest (device ,texView ,floatBufferView ,"copyTexFloat3" ); 268compareComputeResult ( 269device , 270floatResults , 271Slang ::makeArray < 272float > (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 274texView = createTexView (device ,size , gfx::Format ::R32G32B32_TYPELESS ,& subData ); 275setUpAndRunTest (device ,texView ,floatBufferView ,"copyTexFloat3" ); 276compareComputeResult ( 277device , 278floatResults , 279Slang ::makeArray < 280float > (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 { 284float texData []= {1.0f ,0.0f ,0.0f ,1.0f ,1.0f ,1.0f ,0.5f ,0.5f }; 285ITextureResource ::SubresourceData subData = {(void * )texData ,16 ,0 }; 286 287auto texView = createTexView (device ,size , gfx::Format ::R32G32_FLOAT ,& subData ); 288setUpAndRunTest (device ,texView ,floatBufferView ,"copyTexFloat2" ); 289compareComputeResult ( 290device , 291floatResults , 292Slang ::makeArray < float > (1.0f ,0.0f ,0.0f ,1.0f ,1.0f ,1.0f ,0.5f ,0.5f )); 293 294texView = createTexView (device ,size , gfx::Format ::R32G32_TYPELESS ,& subData ); 295setUpAndRunTest (device ,texView ,floatBufferView ,"copyTexFloat2" ); 296compareComputeResult ( 297device , 298floatResults , 299Slang ::makeArray < float > (1.0f ,0.0f ,0.0f ,1.0f ,1.0f ,1.0f ,0.5f ,0.5f )); 300 } 301 302 { 303float texData []= {1.0f ,0.0f ,0.5f ,0.25f }; 304ITextureResource ::SubresourceData subData = {(void * )texData ,8 ,0 }; 305 306auto texView = createTexView (device ,size , gfx::Format ::R32_FLOAT ,& subData ); 307setUpAndRunTest (device ,texView ,floatBufferView ,"copyTexFloat" ); 308compareComputeResult ( 309device , 310floatResults , 311Slang ::makeArray < float > (1.0f ,0.0f ,0.5f ,0.25f )); 312 313texView = createTexView (device ,size , gfx::Format ::R32_TYPELESS ,& subData ); 314setUpAndRunTest (device ,texView ,floatBufferView ,"copyTexFloat" ); 315compareComputeResult ( 316device , 317floatResults , 318Slang ::makeArray < float > (1.0f ,0.0f ,0.5f ,0.25f )); 319 } 320 321 { 322uint16_t texData []= { 32315360u , 3240u , 3250u , 32615360u , 3270u , 32815360u , 3290u , 33015360u , 3310u , 3320u , 33315360u , 33415360u , 33514336u , 33614336u , 33714336u , 33815360u }; 339ITextureResource ::SubresourceData subData = {(void * )texData ,16 ,0 }; 340 341auto texView = createTexView (device ,size , gfx::Format ::R16G16B16A16_FLOAT ,& subData ); 342setUpAndRunTest (device ,texView ,floatBufferView ,"copyTexFloat4" ); 343compareComputeResult ( 344device , 345floatResults , 346Slang ::makeArray < float > ( 3471.0f , 3480.0f , 3490.0f , 3501.0f , 3510.0f , 3521.0f , 3530.0f , 3541.0f , 3550.0f , 3560.0f , 3571.0f , 3581.0f , 3590.5f , 3600.5f , 3610.5f , 3621.0f )); 363 364texView = createTexView (device ,size , gfx::Format ::R16G16B16A16_TYPELESS ,& subData ); 365setUpAndRunTest (device ,texView ,floatBufferView ,"copyTexFloat4" ); 366compareComputeResult ( 367device , 368floatResults , 369Slang ::makeArray < float > ( 3701.0f , 3710.0f , 3720.0f , 3731.0f , 3740.0f , 3751.0f , 3760.0f , 3771.0f , 3780.0f , 3790.0f , 3801.0f , 3811.0f , 3820.5f , 3830.5f , 3840.5f , 3851.0f )); 386 } 387 388 { 389uint16_t texData []= {15360u ,0u ,0u ,15360u ,15360u ,15360u ,14336u ,14336u }; 390ITextureResource ::SubresourceData subData = {(void * )texData ,8 ,0 }; 391 392auto texView = createTexView (device ,size , gfx::Format ::R16G16_FLOAT ,& subData ); 393setUpAndRunTest (device ,texView ,floatBufferView ,"copyTexFloat2" ); 394compareComputeResult ( 395device , 396floatResults , 397Slang ::makeArray < float > (1.0f ,0.0f ,0.0f ,1.0f ,1.0f ,1.0f ,0.5f ,0.5f )); 398 399texView = createTexView (device ,size , gfx::Format ::R16G16_TYPELESS ,& subData ); 400setUpAndRunTest (device ,texView ,floatBufferView ,"copyTexFloat2" ); 401compareComputeResult ( 402device , 403floatResults , 404Slang ::makeArray < float > (1.0f ,0.0f ,0.0f ,1.0f ,1.0f ,1.0f ,0.5f ,0.5f )); 405 } 406 407 { 408uint16_t texData []= {15360u ,0u ,14336u ,13312u }; 409ITextureResource ::SubresourceData subData = {(void * )texData ,4 ,0 }; 410 411auto texView = createTexView (device ,size , gfx::Format ::R16_FLOAT ,& subData ); 412setUpAndRunTest (device ,texView ,floatBufferView ,"copyTexFloat" ); 413compareComputeResult ( 414device , 415floatResults , 416Slang ::makeArray < float > (1.0f ,0.0f ,0.5f ,0.25f )); 417 418texView = createTexView (device ,size , gfx::Format ::R16_TYPELESS ,& subData ); 419setUpAndRunTest (device ,texView ,floatBufferView ,"copyTexFloat" ); 420compareComputeResult ( 421device , 422floatResults , 423Slang ::makeArray < float > (1.0f ,0.0f ,0.5f ,0.25f )); 424 } 425 426 { 427uint32_t texData []= 428 {255u ,0u ,0u ,255u ,0u ,255u ,0u ,255u ,0u ,0u ,255u ,255u ,127u ,127u ,127u ,255u }; 429ITextureResource ::SubresourceData subData = {(void * )texData ,32 ,0 }; 430 431auto texView = createTexView (device ,size , gfx::Format ::R32G32B32A32_UINT ,& subData ); 432setUpAndRunTest (device ,texView ,uintBufferView ,"copyTexUint4" ); 433compareComputeResult ( 434device , 435uintResults , 436Slang ::makeArray < uint32_t > ( 437255u , 4380u , 4390u , 440255u , 4410u , 442255u , 4430u , 444255u , 4450u , 4460u , 447255u , 448255u , 449127u , 450127u , 451127u , 452255u )); 453 } 454 455// Ignore this test since validation layer reports that it is unsupported. 456if (false) 457 { 458uint32_t texData []= {255u ,0u ,0u ,0u ,255u ,0u ,0u ,0u ,255u ,127u ,127u ,127u }; 459ITextureResource ::SubresourceData subData = {(void * )texData ,24 ,0 }; 460 461auto texView = createTexView (device ,size , gfx::Format ::R32G32B32_UINT ,& subData ); 462setUpAndRunTest (device ,texView ,uintBufferView ,"copyTexUint3" ); 463compareComputeResult ( 464device , 465uintResults , 466Slang ::makeArray < uint32_t > (255u ,0u ,0u ,0u ,255u ,0u ,0u ,0u ,255u ,127u ,127u ,127u )); 467 } 468 469 { 470uint32_t texData []= {255u ,0u ,0u ,255u ,255u ,255u ,127u ,127u }; 471ITextureResource ::SubresourceData subData = {(void * )texData ,16 ,0 }; 472 473auto texView = createTexView (device ,size , gfx::Format ::R32G32_UINT ,& subData ); 474setUpAndRunTest (device ,texView ,uintBufferView ,"copyTexUint2" ); 475compareComputeResult ( 476device , 477uintResults , 478Slang ::makeArray < uint32_t > (255u ,0u ,0u ,255u ,255u ,255u ,127u ,127u )); 479 } 480 481 { 482uint32_t texData []= {255u ,0u ,127u ,73u }; 483ITextureResource ::SubresourceData subData = {(void * )texData ,8 ,0 }; 484 485auto texView = createTexView (device ,size , gfx::Format ::R32_UINT ,& subData ); 486setUpAndRunTest (device ,texView ,uintBufferView ,"copyTexUint" ); 487compareComputeResult (device ,uintResults ,Slang ::makeArray < uint32_t > (255u ,0u ,127u ,73u )); 488 } 489 490 { 491uint16_t texData []= 492 {255u ,0u ,0u ,255u ,0u ,255u ,0u ,255u ,0u ,0u ,255u ,255u ,127u ,127u ,127u ,255u }; 493ITextureResource ::SubresourceData subData = {(void * )texData ,16 ,0 }; 494 495auto texView = createTexView (device ,size , gfx::Format ::R16G16B16A16_UINT ,& subData ); 496setUpAndRunTest (device ,texView ,uintBufferView ,"copyTexUint4" ); 497compareComputeResult ( 498device , 499uintResults , 500Slang ::makeArray < uint32_t > ( 501255u , 5020u , 5030u , 504255u , 5050u , 506255u , 5070u , 508255u , 5090u , 5100u , 511255u , 512255u , 513127u , 514127u , 515127u , 516255u )); 517 } 518 519 { 520uint16_t texData []= {255u ,0u ,0u ,255u ,255u ,255u ,127u ,127u }; 521ITextureResource ::SubresourceData subData = {(void * )texData ,8 ,0 }; 522 523auto texView = createTexView (device ,size , gfx::Format ::R16G16_UINT ,& subData ); 524setUpAndRunTest (device ,texView ,uintBufferView ,"copyTexUint2" ); 525compareComputeResult ( 526device , 527uintResults , 528Slang ::makeArray < uint32_t > (255u ,0u ,0u ,255u ,255u ,255u ,127u ,127u )); 529 } 530 531 { 532uint16_t texData []= {255u ,0u ,127u ,73u }; 533ITextureResource ::SubresourceData subData = {(void * )texData ,4 ,0 }; 534 535auto texView = createTexView (device ,size , gfx::Format ::R16_UINT ,& subData ); 536setUpAndRunTest (device ,texView ,uintBufferView ,"copyTexUint" ); 537compareComputeResult (device ,uintResults ,Slang ::makeArray < uint32_t > (255u ,0u ,127u ,73u )); 538 } 539 540 { 541uint8_t texData []= 542 {255u ,0u ,0u ,255u ,0u ,255u ,0u ,255u ,0u ,0u ,255u ,255u ,127u ,127u ,127u ,255u }; 543ITextureResource ::SubresourceData subData = {(void * )texData ,8 ,0 }; 544 545auto texView = createTexView (device ,size , gfx::Format ::R8G8B8A8_UINT ,& subData ); 546setUpAndRunTest (device ,texView ,uintBufferView ,"copyTexUint4" ); 547compareComputeResult ( 548device , 549uintResults , 550Slang ::makeArray < uint32_t > ( 551255u , 5520u , 5530u , 554255u , 5550u , 556255u , 5570u , 558255u , 5590u , 5600u , 561255u , 562255u , 563127u , 564127u , 565127u , 566255u )); 567 } 568 569 { 570uint8_t texData []= {255u ,0u ,0u ,255u ,255u ,255u ,127u ,127u }; 571ITextureResource ::SubresourceData subData = {(void * )texData ,4 ,0 }; 572 573auto texView = createTexView (device ,size , gfx::Format ::R8G8_UINT ,& subData ); 574setUpAndRunTest (device ,texView ,uintBufferView ,"copyTexUint2" ); 575compareComputeResult ( 576device , 577uintResults , 578Slang ::makeArray < uint32_t > (255u ,0u ,0u ,255u ,255u ,255u ,127u ,127u )); 579 } 580 581 { 582uint8_t texData []= {255u ,0u ,127u ,73u }; 583ITextureResource ::SubresourceData subData = {(void * )texData ,2 ,0 }; 584 585auto texView = createTexView (device ,size , gfx::Format ::R8_UINT ,& subData ); 586setUpAndRunTest (device ,texView ,uintBufferView ,"copyTexUint" ); 587compareComputeResult (device ,uintResults ,Slang ::makeArray < uint32_t > (255u ,0u ,127u ,73u )); 588 } 589 590 { 591int32_t texData []= {255 ,0 ,0 ,255 ,0 ,255 ,0 ,255 ,0 ,0 ,255 ,255 ,127 ,127 ,127 ,255 }; 592ITextureResource ::SubresourceData subData = {(void * )texData ,32 ,0 }; 593 594auto texView = createTexView (device ,size , gfx::Format ::R32G32B32A32_SINT ,& subData ); 595setUpAndRunTest (device ,texView ,intBufferView ,"copyTexInt4" ); 596compareComputeResult ( 597device , 598intResults , 599Slang ::makeArray < 600int32_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. 605if (false) 606 { 607int32_t texData []= {255 ,0 ,0 ,0 ,255 ,0 ,0 ,0 ,255 ,127 ,127 ,127 }; 608ITextureResource ::SubresourceData subData = {(void * )texData ,24 ,0 }; 609 610auto texView = createTexView (device ,size , gfx::Format ::R32G32B32_SINT ,& subData ); 611setUpAndRunTest (device ,texView ,intBufferView ,"copyTexInt3" ); 612compareComputeResult ( 613device , 614intResults , 615Slang ::makeArray < int32_t > (255 ,0 ,0 ,0 ,255 ,0 ,0 ,0 ,255 ,127 ,127 ,127 )); 616 } 617 618 { 619int32_t texData []= {255 ,0 ,0 ,255 ,255 ,255 ,127 ,127 }; 620ITextureResource ::SubresourceData subData = {(void * )texData ,16 ,0 }; 621 622auto texView = createTexView (device ,size , gfx::Format ::R32G32_SINT ,& subData ); 623setUpAndRunTest (device ,texView ,intBufferView ,"copyTexInt2" ); 624compareComputeResult ( 625device , 626intResults , 627Slang ::makeArray < int32_t > (255 ,0 ,0 ,255 ,255 ,255 ,127 ,127 )); 628 } 629 630 { 631int32_t texData []= {255 ,0 ,127 ,73 }; 632ITextureResource ::SubresourceData subData = {(void * )texData ,8 ,0 }; 633 634auto texView = createTexView (device ,size , gfx::Format ::R32_SINT ,& subData ); 635setUpAndRunTest (device ,texView ,intBufferView ,"copyTexInt" ); 636compareComputeResult (device ,intResults ,Slang ::makeArray < int32_t > (255 ,0 ,127 ,73 )); 637 } 638 639 { 640int16_t texData []= {255 ,0 ,0 ,255 ,0 ,255 ,0 ,255 ,0 ,0 ,255 ,255 ,127 ,127 ,127 ,255 }; 641ITextureResource ::SubresourceData subData = {(void * )texData ,16 ,0 }; 642 643auto texView = createTexView (device ,size , gfx::Format ::R16G16B16A16_SINT ,& subData ); 644setUpAndRunTest (device ,texView ,intBufferView ,"copyTexInt4" ); 645compareComputeResult ( 646device , 647intResults , 648Slang ::makeArray < 649int32_t > (255 ,0 ,0 ,255 ,0 ,255 ,0 ,255 ,0 ,0 ,255 ,255 ,127 ,127 ,127 ,255 )); 650 } 651 652 { 653int16_t texData []= {255 ,0 ,0 ,255 ,255 ,255 ,127 ,127 }; 654ITextureResource ::SubresourceData subData = {(void * )texData ,8 ,0 }; 655 656auto texView = createTexView (device ,size , gfx::Format ::R16G16_SINT ,& subData ); 657setUpAndRunTest (device ,texView ,intBufferView ,"copyTexInt2" ); 658compareComputeResult ( 659device , 660intResults , 661Slang ::makeArray < int32_t > (255 ,0 ,0 ,255 ,255 ,255 ,127 ,127 )); 662 } 663 664 { 665int16_t texData []= {255 ,0 ,127 ,73 }; 666ITextureResource ::SubresourceData subData = {(void * )texData ,4 ,0 }; 667 668auto texView = createTexView (device ,size , gfx::Format ::R16_SINT ,& subData ); 669setUpAndRunTest (device ,texView ,intBufferView ,"copyTexInt" ); 670compareComputeResult (device ,intResults ,Slang ::makeArray < int32_t > (255 ,0 ,127 ,73 )); 671 } 672 673 { 674int8_t texData []= {127 ,0 ,0 ,127 ,0 ,127 ,0 ,127 ,0 ,0 ,127 ,127 ,0 ,0 ,0 ,127 }; 675ITextureResource ::SubresourceData subData = {(void * )texData ,8 ,0 }; 676 677auto texView = createTexView (device ,size , gfx::Format ::R8G8B8A8_SINT ,& subData ); 678setUpAndRunTest (device ,texView ,intBufferView ,"copyTexInt4" ); 679compareComputeResult ( 680device , 681intResults , 682Slang ::makeArray < 683int32_t > (127 ,0 ,0 ,127 ,0 ,127 ,0 ,127 ,0 ,0 ,127 ,127 ,0 ,0 ,0 ,127 )); 684 } 685 686 { 687int8_t texData []= {127 ,0 ,0 ,127 ,127 ,127 ,73 ,73 }; 688ITextureResource ::SubresourceData subData = {(void * )texData ,4 ,0 }; 689 690auto texView = createTexView (device ,size , gfx::Format ::R8G8_SINT ,& subData ); 691setUpAndRunTest (device ,texView ,intBufferView ,"copyTexInt2" ); 692compareComputeResult ( 693device , 694intResults , 695Slang ::makeArray < int32_t > (127 ,0 ,0 ,127 ,127 ,127 ,73 ,73 )); 696 } 697 698 { 699int8_t texData []= {127 ,0 ,73 ,25 }; 700ITextureResource ::SubresourceData subData = {(void * )texData ,2 ,0 }; 701 702auto texView = createTexView (device ,size , gfx::Format ::R8_SINT ,& subData ); 703setUpAndRunTest (device ,texView ,intBufferView ,"copyTexInt" ); 704compareComputeResult (device ,intResults ,Slang ::makeArray < int32_t > (127 ,0 ,73 ,25 )); 705 } 706 707 { 708uint16_t texData []= { 70965535u , 7100u , 7110u , 71265535u , 7130u , 71465535u , 7150u , 71665535u , 7170u , 7180u , 71965535u , 72065535u , 72132767u , 72232767u , 72332767u , 72432767u }; 725ITextureResource ::SubresourceData subData = {(void * )texData ,16 ,0 }; 726 727auto texView = createTexView (device ,size , gfx::Format ::R16G16B16A16_UNORM ,& subData ); 728setUpAndRunTest (device ,texView ,floatBufferView ,"copyTexFloat4" ); 729compareComputeResult ( 730device , 731floatResults , 732Slang ::makeArray < float > ( 7331.0f , 7340.0f , 7350.0f , 7361.0f , 7370.0f , 7381.0f , 7390.0f , 7401.0f , 7410.0f , 7420.0f , 7431.0f , 7441.0f , 7450.499992371f , 7460.499992371f , 7470.499992371f , 7480.499992371f )); 749 } 750 751 { 752uint16_t texData []= {65535u ,0u ,0u ,65535u ,65535u ,65535u ,32767u ,32767u }; 753ITextureResource ::SubresourceData subData = {(void * )texData ,8 ,0 }; 754 755auto texView = createTexView (device ,size , gfx::Format ::R16G16_UNORM ,& subData ); 756setUpAndRunTest (device ,texView ,floatBufferView ,"copyTexFloat2" ); 757compareComputeResult ( 758device , 759floatResults , 760Slang ::makeArray < 761float > (1.0f ,0.0f ,0.0f ,1.0f ,1.0f ,1.0f ,0.499992371f ,0.499992371f )); 762 } 763 764 { 765uint16_t texData []= {65535u ,0u ,32767u ,16383u }; 766ITextureResource ::SubresourceData subData = {(void * )texData ,4 ,0 }; 767 768auto texView = createTexView (device ,size , gfx::Format ::R16_UNORM ,& subData ); 769setUpAndRunTest (device ,texView ,floatBufferView ,"copyTexFloat" ); 770compareComputeResult ( 771device , 772floatResults , 773Slang ::makeArray < float > (1.0f ,0.0f ,0.499992371f ,0.249988556f )); 774 } 775 776// Ignore this test on swiftshader. Swiftshader produces different results than expected. 777if (!Slang ::String (device -> getDeviceInfo ().adapterName ).toLower ().contains ("swiftshader" )) 778 { 779uint8_t texData []= 780 {0u ,0u ,0u ,255u ,127u ,127u ,127u ,255u ,255u ,255u ,255u ,255u ,0u ,0u ,0u ,0u }; 781ITextureResource ::SubresourceData subData = {(void * )texData ,8 ,0 }; 782 783auto texView = createTexView (device ,size , gfx::Format ::R8G8B8A8_TYPELESS ,& subData ); 784setUpAndRunTest (device ,texView ,floatBufferView ,"copyTexFloat4" ); 785compareComputeResult ( 786device , 787floatResults , 788Slang ::makeArray < float > ( 7890.0f , 7900.0f , 7910.0f , 7921.0f , 7930.498039216f , 7940.498039216f , 7950.498039216f , 7961.0f , 7971.0f , 7981.0f , 7991.0f , 8001.0f , 8010.0f , 8020.0f , 8030.0f , 8040.0f )); 805 806texView = createTexView (device ,size , gfx::Format ::R8G8B8A8_UNORM ,& subData ); 807setUpAndRunTest (device ,texView ,floatBufferView ,"copyTexFloat4" ); 808compareComputeResult ( 809device , 810floatResults , 811Slang ::makeArray < float > ( 8120.0f , 8130.0f , 8140.0f , 8151.0f , 8160.498039216f , 8170.498039216f , 8180.498039216f , 8191.0f , 8201.0f , 8211.0f , 8221.0f , 8231.0f , 8240.0f , 8250.0f , 8260.0f , 8270.0f )); 828 829texView = createTexView (device ,size , gfx::Format ::R8G8B8A8_UNORM_SRGB ,& subData ); 830setUpAndRunTest (device ,texView ,floatBufferView ,"copyTexFloat4" ); 831compareComputeResult ( 832device , 833floatResults , 834Slang ::makeArray < float > ( 8350.0f , 8360.0f , 8370.0f , 8381.0f , 8390.211914062f , 8400.211914062f , 8410.211914062f , 8421.0f , 8431.0f , 8441.0f , 8451.0f , 8461.0f , 8470.0f , 8480.0f , 8490.0f , 8500.0f )); 851 } 852 853// Ignore this test on swiftshader. Swiftshader produces different results than expected. 854if (!Slang ::String (device -> getDeviceInfo ().adapterName ).toLower ().contains ("swiftshader" )) 855 { 856uint8_t texData []= {255u ,0u ,0u ,255u ,255u ,255u ,127u ,127u }; 857ITextureResource ::SubresourceData subData = {(void * )texData ,4 ,0 }; 858 859auto texView = createTexView (device ,size , gfx::Format ::R8G8_TYPELESS ,& subData ); 860setUpAndRunTest (device ,texView ,floatBufferView ,"copyTexFloat2" ); 861compareComputeResult ( 862device , 863floatResults , 864Slang ::makeArray < 865float > (1.0f ,0.0f ,0.0f ,1.0f ,1.0f ,1.0f ,0.498039216f ,0.498039216f )); 866 867texView = createTexView (device ,size , gfx::Format ::R8G8_UNORM ,& subData ); 868setUpAndRunTest (device ,texView ,floatBufferView ,"copyTexFloat2" ); 869compareComputeResult ( 870device , 871floatResults , 872Slang ::makeArray < 873float > (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. 877if (!Slang ::String (device -> getDeviceInfo ().adapterName ).toLower ().contains ("swiftshader" )) 878 { 879uint8_t texData []= {255u ,0u ,127u ,63u }; 880ITextureResource ::SubresourceData subData = {(void * )texData ,2 ,0 }; 881 882auto texView = createTexView (device ,size , gfx::Format ::R8_TYPELESS ,& subData ); 883setUpAndRunTest (device ,texView ,floatBufferView ,"copyTexFloat" ); 884compareComputeResult ( 885device , 886floatResults , 887Slang ::makeArray < float > (1.0f ,0.0f ,0.498039216f ,0.247058824f )); 888 889texView = createTexView (device ,size , gfx::Format ::R8_UNORM ,& subData ); 890setUpAndRunTest (device ,texView ,floatBufferView ,"copyTexFloat" ); 891compareComputeResult ( 892device , 893floatResults , 894Slang ::makeArray < float > (1.0f ,0.0f ,0.498039216f ,0.247058824f )); 895 } 896 897// Ignore this test on swiftshader. Swiftshader produces different results than expected. 898if (!Slang ::String (device -> getDeviceInfo ().adapterName ).toLower ().contains ("swiftshader" )) 899 { 900uint8_t texData []= 901 {0u ,0u ,0u ,255u ,127u ,127u ,127u ,255u ,255u ,255u ,255u ,255u ,0u ,0u ,0u ,0u }; 902ITextureResource ::SubresourceData subData = {(void * )texData ,8 ,0 }; 903 904auto texView = createTexView (device ,size , gfx::Format ::B8G8R8A8_TYPELESS ,& subData ); 905setUpAndRunTest (device ,texView ,floatBufferView ,"copyTexFloat4" ); 906compareComputeResult ( 907device , 908floatResults , 909Slang ::makeArray < float > ( 9100.0f , 9110.0f , 9120.0f , 9131.0f , 9140.498039216f , 9150.498039216f , 9160.498039216f , 9171.0f , 9181.0f , 9191.0f , 9201.0f , 9211.0f , 9220.0f , 9230.0f , 9240.0f , 9250.0f )); 926 927texView = createTexView (device ,size , gfx::Format ::B8G8R8A8_UNORM ,& subData ); 928setUpAndRunTest (device ,texView ,floatBufferView ,"copyTexFloat4" ); 929compareComputeResult ( 930device , 931floatResults , 932Slang ::makeArray < float > ( 9330.0f , 9340.0f , 9350.0f , 9361.0f , 9370.498039216f , 9380.498039216f , 9390.498039216f , 9401.0f , 9411.0f , 9421.0f , 9431.0f , 9441.0f , 9450.0f , 9460.0f , 9470.0f , 9480.0f )); 949 950texView = createTexView (device ,size , gfx::Format ::B8G8R8A8_UNORM_SRGB ,& subData ); 951setUpAndRunTest (device ,texView ,floatBufferView ,"copyTexFloat4" ); 952compareComputeResult ( 953device , 954floatResults , 955Slang ::makeArray < float > ( 9560.0f , 9570.0f , 9580.0f , 9591.0f , 9600.211914062f , 9610.211914062f , 9620.211914062f , 9631.0f , 9641.0f , 9651.0f , 9661.0f , 9671.0f , 9680.0f , 9690.0f , 9700.0f , 9710.0f )); 972 } 973 974 { 975int16_t texData []= 976 {32767 ,0 ,0 ,32767 ,0 ,32767 ,0 ,32767 ,0 ,0 ,32767 ,32767 ,-32768 ,-32768 ,0 ,32767 }; 977ITextureResource ::SubresourceData subData = {(void * )texData ,16 ,0 }; 978 979auto texView = createTexView (device ,size , gfx::Format ::R16G16B16A16_SNORM ,& subData ); 980setUpAndRunTest (device ,texView ,floatBufferView ,"copyTexFloat4" ); 981compareComputeResult ( 982device , 983floatResults , 984Slang ::makeArray < float > ( 9851.0f , 9860.0f , 9870.0f , 9881.0f , 9890.0f , 9901.0f , 9910.0f , 9921.0f , 9930.0f , 9940.0f , 9951.0f , 9961.0f , 997-1.0f , 998-1.0f , 9990.0f , 10001.0f )); 1001 } 1002 1003 { 1004int16_t texData []= {32767 ,0 ,0 ,32767 ,32767 ,32767 ,-32768 ,-32768 }; 1005ITextureResource ::SubresourceData subData = {(void * )texData ,8 ,0 }; 1006 1007auto texView = createTexView (device ,size , gfx::Format ::R16G16_SNORM ,& subData ); 1008setUpAndRunTest (device ,texView ,floatBufferView ,"copyTexFloat2" ); 1009compareComputeResult ( 1010device , 1011floatResults , 1012Slang ::makeArray < float > (1.0f ,0.0f ,0.0f ,1.0f ,1.0f ,1.0f ,-1.0f ,-1.0f )); 1013 } 1014 1015 { 1016int16_t texData []= {32767 ,0 ,-32768 ,0 }; 1017ITextureResource ::SubresourceData subData = {(void * )texData ,4 ,0 }; 1018 1019auto texView = createTexView (device ,size , gfx::Format ::R16_SNORM ,& subData ); 1020setUpAndRunTest (device ,texView ,floatBufferView ,"copyTexFloat" ); 1021compareComputeResult ( 1022device , 1023floatResults , 1024Slang ::makeArray < float > (1.0f ,0.0f ,-1.0f ,0.0f )); 1025 } 1026 1027 { 1028int8_t texData []= {127 ,0 ,0 ,127 ,0 ,127 ,0 ,127 ,0 ,0 ,127 ,127 ,-128 ,-128 ,0 ,127 }; 1029ITextureResource ::SubresourceData subData = {(void * )texData ,8 ,0 }; 1030 1031auto texView = createTexView (device ,size , gfx::Format ::R8G8B8A8_SNORM ,& subData ); 1032setUpAndRunTest (device ,texView ,floatBufferView ,"copyTexFloat4" ); 1033compareComputeResult ( 1034device , 1035floatResults , 1036Slang ::makeArray < float > ( 10371.0f , 10380.0f , 10390.0f , 10401.0f , 10410.0f , 10421.0f , 10430.0f , 10441.0f , 10450.0f , 10460.0f , 10471.0f , 10481.0f , 1049-1.0f , 1050-1.0f , 10510.0f , 10521.0f )); 1053 } 1054 1055 { 1056int8_t texData []= {127 ,0 ,0 ,127 ,127 ,127 ,-128 ,-128 }; 1057ITextureResource ::SubresourceData subData = {(void * )texData ,4 ,0 }; 1058 1059auto texView = createTexView (device ,size , gfx::Format ::R8G8_SNORM ,& subData ); 1060setUpAndRunTest (device ,texView ,floatBufferView ,"copyTexFloat2" ); 1061compareComputeResult ( 1062device , 1063floatResults , 1064Slang ::makeArray < float > (1.0f ,0.0f ,0.0f ,1.0f ,1.0f ,1.0f ,-1.0f ,-1.0f )); 1065 } 1066 1067 { 1068int8_t texData []= {127 ,0 ,-128 ,0 }; 1069ITextureResource ::SubresourceData subData = {(void * )texData ,2 ,0 }; 1070 1071auto texView = createTexView (device ,size , gfx::Format ::R8_SNORM ,& subData ); 1072setUpAndRunTest (device ,texView ,floatBufferView ,"copyTexFloat" ); 1073compareComputeResult ( 1074device , 1075floatResults , 1076Slang ::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. 1081if (!Slang ::String (device -> getDeviceInfo ().adapterName ).toLower ().contains ("swiftshader" )) 1082 { 1083uint8_t texData []= {15u ,240u ,240u ,240u ,0u ,255u ,119u ,119u }; 1084ITextureResource ::SubresourceData subData = {(void * )texData ,4 ,0 }; 1085 1086auto texView = createTexView (device ,size , gfx::Format ::B4G4R4A4_UNORM ,& subData ); 1087setUpAndRunTest (device ,texView ,floatBufferView ,"copyTexFloat4" ); 1088compareComputeResult ( 1089device , 1090floatResults , 1091Slang ::makeArray < float > ( 10920.0f , 10930.0f , 10941.0f , 10951.0f , 10960.0f , 10971.0f , 10980.0f , 10991.0f , 11001.0f , 11010.0f , 11020.0f , 11031.0f , 11040.466666669f , 11050.466666669f , 11060.466666669f , 11070.466666669f )); 1108 } 1109 1110// Ignore this test on swiftshader. Swiftshader produces different results than expected. 1111if (!Slang ::String (device -> getDeviceInfo ().adapterName ).toLower ().contains ("swiftshader" )) 1112 { 1113uint16_t texData []= {31u ,2016u ,63488u ,31727u }; 1114ITextureResource ::SubresourceData subData = {(void * )texData ,4 ,0 }; 1115 1116auto texView = createTexView (device ,size , gfx::Format ::B5G6R5_UNORM ,& subData ); 1117setUpAndRunTest (device ,texView ,floatBufferView ,"copyTexFloat3" ); 1118compareComputeResult ( 1119device , 1120floatResults , 1121Slang ::makeArray < float > ( 11220.0f , 11230.0f , 11241.0f , 11250.0f , 11261.0f , 11270.0f , 11281.0f , 11290.0f , 11300.0f , 11310.482352942f , 11320.490196079f , 11330.482352942f )); 1134 1135texView = createTexView (device ,size , gfx::Format ::B5G5R5A1_UNORM ,& subData ); 1136setUpAndRunTest (device ,texView ,floatBufferView ,"copyTexFloat4" ); 1137compareComputeResult ( 1138device , 1139floatResults , 1140Slang ::makeArray < float > ( 11410.0f , 11420.0f , 11431.0f , 11440.0f , 11450.0313725509f , 11461.0f , 11470.0f , 11480.0f , 11490.968627453f , 11500.0f , 11510.0f , 11521.0f , 11530.968627453f , 11541.0f , 11550.482352942f , 11560.0f )); 1157 } 1158 1159 { 1160uint32_t texData []= {2950951416u ,2013265920u ,3086219772u ,3087007228u }; 1161ITextureResource ::SubresourceData subData = {(void * )texData ,8 ,0 }; 1162 1163auto texView = createTexView (device ,size , gfx::Format ::R9G9B9E5_SHAREDEXP ,& subData ); 1164setUpAndRunTest (device ,texView ,floatBufferView ,"copyTexFloat3" ); 1165compareComputeResult ( 1166device , 1167floatResults , 1168Slang ::makeArray < float > ( 116963.0f , 117063.0f , 117163.0f , 11720.0f , 11730.0f , 11740.0f , 1175127.0f , 1176127.0f , 1177127.0f , 1178127.0f , 1179127.5f , 1180127.75f )); 1181 } 1182 1183// Ignore this test on swiftshader. Swiftshader produces different results than expected. 1184if (!Slang ::String (device -> getDeviceInfo ().adapterName ).toLower ().contains ("swiftshader" )) 1185 { 1186uint32_t texData []= {4294967295u ,0u ,2683829759u ,1193046471u }; 1187ITextureResource ::SubresourceData subData = {(void * )texData ,8 ,0 }; 1188 1189auto texView = createTexView (device ,size , gfx::Format ::R10G10B10A2_TYPELESS ,& subData ); 1190setUpAndRunTest (device ,texView ,uintBufferView ,"copyTexUint4" ); 1191compareComputeResult ( 1192device , 1193uintResults , 1194Slang ::makeArray < uint32_t > ( 11951023u , 11961023u , 11971023u , 11983u , 11990u , 12000u , 12010u , 12020u , 1203511u , 1204511u , 1205511u , 12062u , 1207455u , 1208796u , 1209113u , 12101u )); 1211 1212texView = createTexView (device ,size , gfx::Format ::R10G10B10A2_UNORM ,& subData ); 1213setUpAndRunTest (device ,texView ,floatBufferView ,"copyTexFloat4" ); 1214compareComputeResult ( 1215device , 1216floatResults , 1217Slang ::makeArray < float > ( 12181.0f , 12191.0f , 12201.0f , 12211.0f , 12220.0f , 12230.0f , 12240.0f , 12250.0f , 12260.499511242f , 12270.499511242f , 12280.499511242f , 12290.666666687f , 12300.444770277f , 12310.778103590f , 12320.110459432f , 12330.333333343f )); 1234 1235texView = createTexView (device ,size , gfx::Format ::R10G10B10A2_UINT ,& subData ); 1236setUpAndRunTest (device ,texView ,uintBufferView ,"copyTexUint4" ); 1237compareComputeResult ( 1238device , 1239uintResults , 1240Slang ::makeArray < uint32_t > ( 12411023u , 12421023u , 12431023u , 12443u , 12450u , 12460u , 12470u , 12480u , 1249511u , 1250511u , 1251511u , 12522u , 1253455u , 1254796u , 1255113u , 12561u )); 1257 } 1258 1259 { 1260uint32_t texData []= {3085827519u ,0u ,2951478655u ,1880884096u }; 1261ITextureResource ::SubresourceData subData = {(void * )texData ,8 ,0 }; 1262 1263auto texView = createTexView (device ,size , gfx::Format ::R11G11B10_FLOAT ,& subData ); 1264setUpAndRunTest (device ,texView ,floatBufferView ,"copyTexFloat3" ); 1265compareComputeResult ( 1266device , 1267floatResults , 1268Slang ::makeArray < float > ( 1269254.0f , 1270254.0f , 1271252.0f , 12720.0f , 12730.0f , 12740.0f , 1275127.0f , 1276127.0f , 1277126.0f , 12780.5f , 12790.5f , 12800.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. 1285if (!Slang ::String (device -> getDeviceInfo ().adapterName ).toLower ().contains ("swiftshader" )) 1286 { 1287uint8_t texData []= {16u ,0u ,0u ,0u ,0u ,0u ,0u ,0u ,16u ,0u ,0u ,0u ,0u ,0u , 12880u ,0u ,16u ,0u ,0u ,0u ,0u ,0u ,0u ,0u ,16u ,0u ,0u ,0u , 12890u ,0u ,0u ,0u ,255u ,255u ,255u ,255u ,0u ,0u ,0u ,0u }; 1290ITextureResource ::SubresourceData subData []= { 1291ITextureResource ::SubresourceData {(void * )texData ,16 ,32 }, 1292ITextureResource ::SubresourceData {(void * )(texData + 32 ),8 ,0 }}; 1293ITextureResource ::Extents size = {}; 1294size .width = 8 ; 1295size .height = 8 ; 1296size .depth = 1 ; 1297 1298auto texView = createTexView (device ,size , gfx::Format ::BC1_UNORM ,subData ,2 ); 1299setUpAndRunTest (device ,texView ,floatBufferView ,"sampleMips" ,sampler ); 1300compareComputeResult ( 1301device , 1302floatResults , 1303Slang ::makeArray < float > (0.0f ,0.0f ,0.517647088f ,1.0f ,1.0f ,1.0f ,1.0f ,1.0f )); 1304 1305texView = createTexView (device ,size , gfx::Format ::BC1_UNORM_SRGB ,subData ,2 ); 1306setUpAndRunTest (device ,texView ,floatBufferView ,"sampleMips" ,sampler ); 1307compareComputeResult ( 1308device , 1309floatResults , 1310Slang ::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. 1314if (!Slang ::String (device -> getDeviceInfo ().adapterName ).toLower ().contains ("swiftshader" )) 1315 { 1316uint8_t texData []= 1317 {255u ,255u ,255u ,255u ,255u ,255u ,255u ,255u ,16u ,0u ,0u ,0u ,0u ,0u ,0u ,0u }; 1318ITextureResource ::SubresourceData subData = {(void * )texData ,16 ,0 }; 1319 1320auto texView = createTexView (device ,bcSize , gfx::Format ::BC2_UNORM ,& subData ); 1321setUpAndRunTest (device ,texView ,floatBufferView ,"sampleTex" ,sampler ); 1322compareComputeResult ( 1323device , 1324floatResults , 1325Slang ::makeArray < float > (0.0f ,0.0f ,0.517647088f ,1.0f )); 1326 1327texView = createTexView (device ,bcSize , gfx::Format ::BC2_UNORM_SRGB ,& subData ); 1328setUpAndRunTest (device ,texView ,floatBufferView ,"sampleTex" ,sampler ); 1329compareComputeResult ( 1330device , 1331floatResults , 1332Slang ::makeArray < float > (0.0f ,0.0f ,0.230468750f ,1.0f )); 1333 } 1334 1335// Ignore this test on swiftshader. Swiftshader produces different results than expected. 1336if (!Slang ::String (device -> getDeviceInfo ().adapterName ).toLower ().contains ("swiftshader" )) 1337 { 1338uint8_t texData []= 1339 {0u ,255u ,255u ,255u ,255u ,255u ,255u ,255u ,16u ,0u ,0u ,0u ,0u ,0u ,0u ,0u }; 1340ITextureResource ::SubresourceData subData = {(void * )texData ,16 ,0 }; 1341 1342auto texView = createTexView (device ,bcSize , gfx::Format ::BC3_UNORM ,& subData ); 1343setUpAndRunTest (device ,texView ,floatBufferView ,"sampleTex" ,sampler ); 1344compareComputeResult ( 1345device , 1346floatResults , 1347Slang ::makeArray < float > (0.0f ,0.0f ,0.517647088f ,1.0f )); 1348 1349texView = createTexView (device ,bcSize , gfx::Format ::BC3_UNORM_SRGB ,& subData ); 1350setUpAndRunTest (device ,texView ,floatBufferView ,"sampleTex" ,sampler ); 1351compareComputeResult ( 1352device , 1353floatResults , 1354Slang ::makeArray < float > (0.0f ,0.0f ,0.230468750f ,1.0f )); 1355 } 1356 1357// Ignore this test on swiftshader. Swiftshader produces different results than expected. 1358if (!Slang ::String (device -> getDeviceInfo ().adapterName ).toLower ().contains ("swiftshader" )) 1359 { 1360uint8_t texData []= {127u ,0u ,0u ,0u ,0u ,0u ,0u ,0u }; 1361ITextureResource ::SubresourceData subData = {(void * )texData ,8 ,0 }; 1362 1363auto texView = createTexView (device ,bcSize , gfx::Format ::BC4_UNORM ,& subData ); 1364setUpAndRunTest (device ,texView ,floatBufferView ,"sampleTex" ,sampler ); 1365compareComputeResult ( 1366device , 1367floatResults , 1368Slang ::makeArray < float > (0.498039216f ,0.0f ,0.0f ,1.0f )); 1369 1370texView = createTexView (device ,bcSize , gfx::Format ::BC4_SNORM ,& subData ); 1371setUpAndRunTest (device ,texView ,floatBufferView ,"sampleTex" ,sampler ); 1372compareComputeResult (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. 1376if (!Slang ::String (device -> getDeviceInfo ().adapterName ).toLower ().contains ("swiftshader" )) 1377 { 1378uint8_t texData []= {127u ,0u ,0u ,0u ,0u ,0u ,0u ,0u ,127u ,0u ,0u ,0u ,0u ,0u ,0u ,0u }; 1379ITextureResource ::SubresourceData subData = {(void * )texData ,16 ,0 }; 1380 1381auto texView = createTexView (device ,bcSize , gfx::Format ::BC5_UNORM ,& subData ); 1382setUpAndRunTest (device ,texView ,floatBufferView ,"sampleTex" ,sampler ); 1383compareComputeResult ( 1384device , 1385floatResults , 1386Slang ::makeArray < float > ( 13870.498039216f , 13880.498039216f , 13890.0f , 13901.0f , 13910.498039216f , 13920.498039216f , 13930.0f , 13941.0f )); 1395 1396texView = createTexView (device ,bcSize , gfx::Format ::BC5_SNORM ,& subData ); 1397setUpAndRunTest (device ,texView ,floatBufferView ,"sampleTex" ,sampler ); 1398compareComputeResult ( 1399device , 1400floatResults , 1401Slang ::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. 1406if (!Slang ::String (device -> getDeviceInfo ().adapterName ).toLower ().contains ("swiftshader" )) 1407 { 1408uint8_t texData []= { 140998u , 1410238u , 1411232u , 141277u , 1413240u , 141466u , 1415148u , 141631u , 1417124u , 141895u , 14192u , 1420224u , 1421255u , 1422107u , 142377u , 1424250u }; 1425ITextureResource ::SubresourceData subData = {(void * )texData ,16 ,0 }; 1426 1427auto texView = createTexView (device ,bcSize , gfx::Format ::BC6H_UF16 ,& subData ); 1428setUpAndRunTest (device ,texView ,floatBufferView ,"sampleTex" ,sampler ); 1429compareComputeResult ( 1430device , 1431floatResults , 1432Slang ::makeArray < float > (0.336669922f ,0.911132812f ,2.13867188f ,1.0f )); 1433 } 1434 1435// Ignore this test on swiftshader. Swiftshader produces different results than expected. 1436if (!Slang ::String (device -> getDeviceInfo ().adapterName ).toLower ().contains ("swiftshader" )) 1437 { 1438uint8_t texData []= { 1439107u , 1440238u , 1441232u , 144277u , 1443240u , 144471u , 1445128u , 1446127u , 14471u , 14480u , 1449255u , 1450255u , 1451170u , 1452218u , 1453221u , 1454254u }; 1455ITextureResource ::SubresourceData subData = {(void * )texData ,16 ,0 }; 1456 1457auto texView = createTexView (device ,bcSize , gfx::Format ::BC6H_SF16 ,& subData ); 1458setUpAndRunTest (device ,texView ,floatBufferView ,"sampleTex" ,sampler ); 1459compareComputeResult ( 1460device , 1461floatResults , 1462Slang ::makeArray < float > (0.336914062f ,0.910644531f ,2.14062500f ,1.0f )); 1463 } 1464 1465// Ignore this test on swiftshader. Swiftshader produces different results than expected. 1466if (!Slang ::String (device -> getDeviceInfo ().adapterName ).toLower ().contains ("swiftshader" )) 1467 { 1468uint8_t texData []= 1469 {104u ,0u ,0u ,0u ,64u ,163u ,209u ,104u ,0u ,0u ,0u ,0u ,0u ,0u ,0u ,0u }; 1470ITextureResource ::SubresourceData subData = {(void * )texData ,16 ,0 }; 1471 1472auto texView = createTexView (device ,bcSize , gfx::Format ::BC7_UNORM ,& subData ); 1473setUpAndRunTest (device ,texView ,floatBufferView ,"sampleTex" ,sampler ); 1474compareComputeResult ( 1475device , 1476floatResults , 1477Slang ::makeArray < float > (0.0f ,0.101960786f ,0.0f ,1.0f )); 1478 1479texView = createTexView (device ,bcSize , gfx::Format ::BC7_UNORM_SRGB ,& subData ); 1480setUpAndRunTest (device ,texView ,floatBufferView ,"sampleTex" ,sampler ); 1481compareComputeResult ( 1482device , 1483floatResults , 1484Slang ::makeArray < float > (0.0f ,0.0103149414f ,0.0f ,1.0f )); 1485 } 1486} 1487 1488SLANG_UNIT_TEST (FormatTestsD3D11 ) 1489{ 1490runTestImpl (formatTestsImpl ,unitTestContext ,Slang ::RenderApiFlag ::D3D11 ); 1491} 1492 1493#if SLANG_WINDOWS_FAMILY 1494SLANG_UNIT_TEST (FormatTestsD3D12 ) 1495{ 1496runTestImpl (formatTestsImpl ,unitTestContext ,Slang ::RenderApiFlag ::D3D12 ); 1497} 1498#endif 1499 1500SLANG_UNIT_TEST (FormatTestsVulkan ) 1501{ 1502runTestImpl (formatTestsImpl ,unitTestContext ,Slang ::RenderApiFlag ::Vulkan ); 1503} 1504 1505}// namespace gfx_test 1506 1507#endif