yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
43d0c2100
master
1#include "core/slang-basic.h" 2#include "gfx-test-util.h" 3#include "slang-rhi/shader-cursor.h" 4#include "unit-test/slang-unit-test.h" 5 6#include <slang-rhi.h> 7 8#if SLANG_WINDOWS_FAMILY 9#include <d3d12.h> 10#endif 11 12using namespace rhi ; 13 14namespace gfx_test 15{ 16void getTextureResourceHandleTestImpl (IDevice * device ,UnitTestContext * context ) 17{ 18TextureDesc desc = {}; 19desc .type = TextureType ::Texture2D ; 20desc .mipCount = 1 ; 21desc .size .width = 1 ; 22desc .size .height = 1 ; 23desc .size .depth = 1 ; 24desc .defaultState = ResourceState ::UnorderedAccess ; 25desc .format = Format ::RGBA16Float ; 26desc .usage = TextureUsage ::UnorderedAccess ; 27 28Slang ::ComPtr < ITexture > texture ; 29GFX_CHECK_CALL_ABORT (device -> createTexture (desc ,nullptr ,texture .writeRef ())); 30 31NativeHandle handle ; 32GFX_CHECK_CALL_ABORT (texture -> getNativeHandle (& handle )); 33if (device -> getInfo ().deviceType == rhi::DeviceType ::Vulkan ) 34 { 35SLANG_CHECK (handle .value != 0 ); 36 } 37 38#if SLANG_WINDOWS_FAMILY 39else 40 { 41auto d3d12Handle = (ID3D12Resource * )handle .value ; 42Slang ::ComPtr < IUnknown > testHandle1 ; 43GFX_CHECK_CALL_ABORT (d3d12Handle -> QueryInterface < IUnknown > (testHandle1 .writeRef ())); 44Slang ::ComPtr < ID3D12Resource > testHandle2 ; 45GFX_CHECK_CALL_ABORT (testHandle1 -> QueryInterface < ID3D12Resource > (testHandle2 .writeRef ())); 46SLANG_CHECK (d3d12Handle == testHandle2 .get ()); 47 } 48#endif 49} 50 51void getTextureResourceHandleTestAPI (UnitTestContext * context ,Slang ::RenderApiFlag ::Enum api ) 52{ 53if (context -> enableDebugLayers ) 54getRHI ()-> enableDebugLayers (); 55if ((api & context -> enabledApis )== 0 ) 56 { 57SLANG_IGNORE_TEST ; 58 } 59Slang ::ComPtr < IDevice > device ; 60DeviceDesc deviceDesc = {}; 61switch (api ) 62 { 63case Slang ::RenderApiFlag ::D3D11 : 64deviceDesc .deviceType = rhi::DeviceType ::D3D11 ; 65break ; 66case Slang ::RenderApiFlag ::D3D12 : 67deviceDesc .deviceType = rhi::DeviceType ::D3D12 ; 68break ; 69case Slang ::RenderApiFlag ::Vulkan : 70deviceDesc .deviceType = rhi::DeviceType ::Vulkan ; 71break ; 72default : 73SLANG_IGNORE_TEST ; 74 } 75deviceDesc .slang .slangGlobalSession = context -> slangGlobalSession ; 76const char * searchPaths []= {"" ,"../../tools/gfx-unit-test" ,"tools/gfx-unit-test" }; 77deviceDesc .slang .searchPathCount = (SlangInt )SLANG_COUNT_OF (searchPaths ); 78deviceDesc .slang .searchPaths = searchPaths ; 79auto createDeviceResult = getRHI ()-> createDevice (deviceDesc ,device .writeRef ()); 80if (SLANG_FAILED (createDeviceResult )) 81 { 82SLANG_IGNORE_TEST ; 83 } 84// Ignore this test on swiftshader. Swiftshader seems to have a bug that causes the test 85// to crash. 86if (Slang ::String (device -> getInfo ().adapterName ).toLower ().contains ("swiftshader" )) 87 { 88SLANG_IGNORE_TEST ; 89 } 90getTextureResourceHandleTestImpl (device ,context ); 91} 92 93SLANG_UNIT_TEST (getTextureResourceHandleD3D12 ) 94{ 95return getTextureResourceHandleTestAPI (unitTestContext ,Slang ::RenderApiFlag ::D3D12 ); 96} 97 98SLANG_UNIT_TEST (getTextureResourceHandleVulkan ) 99{ 100return getTextureResourceHandleTestAPI (unitTestContext ,Slang ::RenderApiFlag ::Vulkan ); 101} 102 103}// namespace gfx_test