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 getQueueHandleTestImpl (IDevice * device ,UnitTestContext * context ) 17{ 18ComPtr < ICommandQueue > queue ; 19GFX_CHECK_CALL_ABORT (device -> getQueue (QueueType ::Graphics ,queue .writeRef ())); 20NativeHandle handle ; 21GFX_CHECK_CALL_ABORT (queue -> getNativeHandle (& handle )); 22if (device -> getInfo ().deviceType == rhi::DeviceType ::Vulkan ) 23 { 24SLANG_CHECK (handle .value != 0 ); 25 } 26#if SLANG_WINDOWS_FAMILY 27else 28 { 29auto d3d12Queue = (ID3D12CommandQueue * )handle .value ; 30Slang ::ComPtr < IUnknown > testHandle1 ; 31GFX_CHECK_CALL_ABORT (d3d12Queue -> QueryInterface < IUnknown > (testHandle1 .writeRef ())); 32Slang ::ComPtr < ID3D12CommandQueue > testHandle2 ; 33GFX_CHECK_CALL_ABORT ( 34testHandle1 -> QueryInterface < ID3D12CommandQueue > (testHandle2 .writeRef ())); 35SLANG_CHECK (d3d12Queue == testHandle2 .get ()); 36 } 37#endif 38} 39 40void getQueueHandleTestAPI (UnitTestContext * context ,Slang ::RenderApiFlag ::Enum api ) 41{ 42if (context -> enableDebugLayers ) 43getRHI ()-> enableDebugLayers (); 44if ((api & context -> enabledApis )== 0 ) 45 { 46SLANG_IGNORE_TEST ; 47 } 48Slang ::ComPtr < IDevice > device ; 49DeviceDesc deviceDesc = {}; 50switch (api ) 51 { 52case Slang ::RenderApiFlag ::D3D11 : 53deviceDesc .deviceType = rhi::DeviceType ::D3D11 ; 54break ; 55case Slang ::RenderApiFlag ::D3D12 : 56deviceDesc .deviceType = rhi::DeviceType ::D3D12 ; 57break ; 58case Slang ::RenderApiFlag ::Vulkan : 59deviceDesc .deviceType = rhi::DeviceType ::Vulkan ; 60break ; 61default : 62SLANG_IGNORE_TEST ; 63 } 64deviceDesc .slang .slangGlobalSession = context -> slangGlobalSession ; 65const char * searchPaths []= {"" ,"../../tools/gfx-unit-test" ,"tools/gfx-unit-test" }; 66deviceDesc .slang .searchPathCount = (SlangInt )SLANG_COUNT_OF (searchPaths ); 67deviceDesc .slang .searchPaths = searchPaths ; 68auto createDeviceResult = getRHI ()-> createDevice (deviceDesc ,device .writeRef ()); 69if (SLANG_FAILED (createDeviceResult )) 70 { 71SLANG_IGNORE_TEST ; 72 } 73// Ignore this test on swiftshader. Swiftshader seems to have a bug that causes the test 74// to crash. 75if (Slang ::String (device -> getInfo ().adapterName ).toLower ().contains ("swiftshader" )) 76 { 77SLANG_IGNORE_TEST ; 78 } 79getQueueHandleTestImpl (device ,context ); 80} 81 82SLANG_UNIT_TEST (getCmdQueueHandleD3D12 ) 83{ 84return getQueueHandleTestAPI (unitTestContext ,Slang ::RenderApiFlag ::D3D12 ); 85} 86 87SLANG_UNIT_TEST (getCmdQueueHandleVulkan ) 88{ 89return getQueueHandleTestAPI (unitTestContext ,Slang ::RenderApiFlag ::Vulkan ); 90} 91 92}// namespace gfx_test