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