Skip to content

Commit

Permalink
Some more WebGPU fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
magcius committed Oct 31, 2024
1 parent db143d2 commit 68c24f7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/SuperMarioGalaxy/ImageEffect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ const bindingLayouts: GfxBindingLayoutDescriptor[] = [
class BloomPassBaseProgram extends DeviceProgram {
public static BindingsDefinition = `
uniform sampler2D u_Texture;
uniform sampler2D u_Texture2;
layout(std140) uniform ub_Params {
vec4 u_Misc[1];
Expand Down Expand Up @@ -387,6 +388,7 @@ const BloomSimplePSCommon = `
${ImageEffectShaderLib}
uniform sampler2D u_Texture;
uniform sampler2D u_Texture2;
in vec2 v_TexCoord;
layout(std140) uniform ub_Params {
Expand Down
12 changes: 12 additions & 0 deletions src/gfx/platform/GfxPlatformWebGPU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,18 @@ class GfxImplP_WebGPU implements GfxSwapChain, GfxDevice {
throw "whoops";
}

// Workaround for https://github.com/gfx-rs/naga/issues/1355
for (const depthTextureName of ['u_TextureFramebufferDepth']) {
if (!code.includes(depthTextureName)) continue;
code = code.replace(`var T_${depthTextureName}: texture_2d<f32>;`, `var T_${depthTextureName}: texture_depth_2d;`);
code = code.replace(new RegExp(`textureSample\\\(T_${depthTextureName}(.*)\\\);$`, 'gm'), (sub, cap) => {
return `vec4<f32>(textureSample(T_${depthTextureName}${cap}), 0.0, 0.0, 0.0);`
});
code = code.replace(new RegExp(`textureLoad\\\(T_${depthTextureName}(.*)\\\);$`, 'gm'), (sub, cap) => {
return `vec4<f32>(textureLoad(T_${depthTextureName}${cap}), 0.0, 0.0, 0.0);`
});
}

const shaderModule = this.device.createShaderModule({ code });
const stage = { module: shaderModule, entryPoint: 'main' };
if (IS_DEVELOPMENT) {
Expand Down

0 comments on commit 68c24f7

Please sign in to comment.