Skip to content

Commit

Permalink
Add WebGPU support to slang-test
Browse files Browse the repository at this point in the history
This helps to address issue #5051.
  • Loading branch information
aleino-nv committed Oct 2, 2024
1 parent 30178d8 commit 46ff5d9
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/slang-gfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ enum class DeviceType
Metal,
CPU,
CUDA,
WebGPU,
CountOf,
};

Expand Down
6 changes: 6 additions & 0 deletions source/core/slang-render-api-util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace Slang {
{ RenderApiType::Metal, "mtl,metal", ""},
{ RenderApiType::CPU, "cpu", ""},
{ RenderApiType::CUDA, "cuda", "cuda,ptx"},
{ RenderApiType::WebGPU, "wgpu,webgpu", "wgsl"},
};

static int _calcAvailableApis()
Expand Down Expand Up @@ -265,6 +266,11 @@ static bool _canLoadSharedLibrary(const char* libName)
{
#if SLANG_WINDOWS_FAMILY
case RenderApiType::Vulkan: return _canLoadSharedLibrary("vulkan-1") || _canLoadSharedLibrary("vk_swiftshader");
case RenderApiType::WebGPU:
return
_canLoadSharedLibrary("webgpu_dawn") &&
_canLoadSharedLibrary("dxcompiler") &&
_canLoadSharedLibrary("dxil");
#elif SLANG_APPLE_FAMILY
case RenderApiType::Vulkan: return true;
case RenderApiType::Metal: return true;
Expand Down
2 changes: 2 additions & 0 deletions source/core/slang-render-api-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ enum class RenderApiType
Metal,
CPU,
CUDA,
WebGPU,
CountOf,
};

Expand All @@ -31,6 +32,7 @@ struct RenderApiFlag
Metal = 1 << int(RenderApiType::Metal),
CPU = 1 << int(RenderApiType::CPU),
CUDA = 1 << int(RenderApiType::CUDA),
WebGPU = 1 << int(RenderApiType::WebGPU),
AllOf = (1 << int(RenderApiType::CountOf)) - 1 ///< All bits set
};
};
Expand Down
1 change: 1 addition & 0 deletions tools/render-test/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ static rhi::DeviceType _toRenderType(Slang::RenderApiType apiType)
case RenderApiType::Metal: return rhi::DeviceType::Metal;
case RenderApiType::CPU: return rhi::DeviceType::CPU;
case RenderApiType::CUDA: return rhi::DeviceType::CUDA;
case RenderApiType::WebGPU: return rhi::DeviceType::WGPU;
default:
return rhi::DeviceType::Default;
}
Expand Down
6 changes: 6 additions & 0 deletions tools/render-test/render-test-main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1229,6 +1229,12 @@ static SlangResult _innerMain(Slang::StdWriters* stdWriters, SlangSession* sessi
input.profile = "";
nativeLanguage = SLANG_SOURCE_LANGUAGE_CUDA;
slangPassThrough = SLANG_PASS_THROUGH_NVRTC;
break;
case DeviceType::WGPU:
input.target = SLANG_WGSL;
input.profile = "";
nativeLanguage = SLANG_SOURCE_LANGUAGE_WGSL;
slangPassThrough = SLANG_PASS_THROUGH_NONE;
break;

default:
Expand Down
4 changes: 4 additions & 0 deletions tools/slang-test/slang-test-main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1122,6 +1122,10 @@ static SlangResult _extractRenderTestRequirements(const CommandLine& cmdLine, Te
nativeLanguage = SLANG_SOURCE_LANGUAGE_CUDA;
passThru = SLANG_PASS_THROUGH_NVRTC;
break;
case RenderApiType::WebGPU:
target = SLANG_WGSL;
SLANG_ASSERT(!usePassthru);
break;
}

SlangSourceLanguage sourceLanguage = nativeLanguage;
Expand Down

0 comments on commit 46ff5d9

Please sign in to comment.