Add shader compiler for WebGPU
Use existing Vulkan compiler to generate SPIR-V and convert it into WGSL with tint compiler https://github.com/google/dawn/releases/tag/v20260219.200501
This commit is contained in:
@@ -2,12 +2,12 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Engine/Graphics/Shaders/GPUShaderProgram.h"
|
||||
#include "Engine/Core/Types/DataContainer.h"
|
||||
#include "Engine/Core/Collections/Dictionary.h"
|
||||
|
||||
#if GRAPHICS_API_WEBGPU
|
||||
|
||||
#include "Engine/Graphics/Shaders/GPUShaderProgram.h"
|
||||
#include "Engine/GraphicsDevice/Vulkan/Types.h"
|
||||
#include <webgpu/webgpu.h>
|
||||
|
||||
/// <summary>
|
||||
/// Shaders base class for Web GPU backend.
|
||||
/// </summary>
|
||||
@@ -15,15 +15,22 @@ template<typename BaseType>
|
||||
class GPUShaderProgramWebGPU : public BaseType
|
||||
{
|
||||
public:
|
||||
GPUShaderProgramWebGPU(const GPUShaderProgramInitializer& initializer)
|
||||
GPUShaderProgramWebGPU(const GPUShaderProgramInitializer& initializer, const SpirvShaderDescriptorInfo& descriptorInfo, WGPUShaderModule shaderModule)
|
||||
: DescriptorInfo(descriptorInfo)
|
||||
, ShaderModule(shaderModule)
|
||||
{
|
||||
BaseType::Init(initializer);
|
||||
}
|
||||
|
||||
~GPUShaderProgramWebGPU()
|
||||
{
|
||||
wgpuShaderModuleRelease(ShaderModule);
|
||||
}
|
||||
|
||||
public:
|
||||
SpirvShaderDescriptorInfo DescriptorInfo;
|
||||
WGPUShaderModule ShaderModule;
|
||||
|
||||
public:
|
||||
// [BaseType]
|
||||
uint32 GetBufferSize() const override
|
||||
@@ -32,7 +39,7 @@ public:
|
||||
}
|
||||
void* GetBufferHandle() const override
|
||||
{
|
||||
return nullptr;
|
||||
return ShaderModule;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -42,8 +49,8 @@ public:
|
||||
class GPUShaderProgramVSWebGPU : public GPUShaderProgramWebGPU<GPUShaderProgramVS>
|
||||
{
|
||||
public:
|
||||
GPUShaderProgramVSWebGPU(const GPUShaderProgramInitializer& initializer, GPUVertexLayout* inputLayout, GPUVertexLayout* vertexLayout, Span<byte> bytecode)
|
||||
: GPUShaderProgramWebGPU(initializer)
|
||||
GPUShaderProgramVSWebGPU(const GPUShaderProgramInitializer& initializer, GPUVertexLayout* inputLayout, GPUVertexLayout* vertexLayout, const SpirvShaderDescriptorInfo& descriptorInfo, WGPUShaderModule shaderModule)
|
||||
: GPUShaderProgramWebGPU(initializer, descriptorInfo, shaderModule)
|
||||
{
|
||||
InputLayout = inputLayout;
|
||||
Layout = vertexLayout;
|
||||
@@ -56,8 +63,8 @@ public:
|
||||
class GPUShaderProgramPSWebGPU : public GPUShaderProgramWebGPU<GPUShaderProgramPS>
|
||||
{
|
||||
public:
|
||||
GPUShaderProgramPSWebGPU(const GPUShaderProgramInitializer& initializer)
|
||||
: GPUShaderProgramWebGPU(initializer)
|
||||
GPUShaderProgramPSWebGPU(const GPUShaderProgramInitializer& initializer, const SpirvShaderDescriptorInfo& descriptorInfo, WGPUShaderModule shaderModule)
|
||||
: GPUShaderProgramWebGPU(initializer, descriptorInfo, shaderModule)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user