Skip to content

Commit

Permalink
Release (#168)
Browse files Browse the repository at this point in the history
* fix: separate sampler and textures (#166)

* fix: separate sampler and textures correctly

* chore: commit changeset

* chore(release): bump version (#167)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Mar 14, 2024
1 parent ac91cbf commit 15bfcbb
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @antv/g-device-api

## 1.6.5

### Patch Changes

- d9b7078: Separate sampler and textures correctly.

## 1.6.4

### Patch Changes
Expand Down
70 changes: 70 additions & 0 deletions __tests__/unit/compiler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,4 +509,74 @@ vec3 u_blur_height_fixed;
};
`);
});

it('should separate sampler textures correctly.', () => {
const raw = `uniform sampler2D u_Texture;
in vec2 v_TexCoord;
out vec4 outputColor;
vec4 FXAA(PD_SAMPLER_2D(t_Texture), in vec2 t_PixelCenter, in vec2 t_InvResolution) {
float lumaNW = MonochromeNTSC(texture(PU_SAMPLER_2D(t_Texture), t_PixelTopLeft.xy) .rgb);
return rgbOutput;
}
void main() {
outputColor = FXAA(PP_SAMPLER_2D(u_Texture), v_TexCoord.xy, u_InvResolution.xy);
}`;
const glsl100 = preprocessShader_GLSL(WebGL1VendorInfo, 'frag', raw);
expect(glsl100).toEqual(`#extension GL_OES_standard_derivatives : enable
precision mediump float;
uniform sampler2D u_Texture; // BINDING=0
varying vec2 v_TexCoord;
vec4 outputColor;
vec4 FXAA(sampler2D P_t_Texture, in vec2 t_PixelCenter, in vec2 t_InvResolution) {
float lumaNW = MonochromeNTSC(texture2D(P_t_Texture, t_PixelTopLeft.xy) .rgb);
return rgbOutput;
}
void main() {
outputColor = FXAA(u_Texture, v_TexCoord.xy, u_InvResolution.xy);
gl_FragColor = vec4(outputColor);
}`);

const glsl300 = preprocessShader_GLSL(WebGL2VendorInfo, 'frag', raw);
expect(glsl300).toEqual(`#version 300
precision mediump float;
uniform sampler2D u_Texture; // BINDING=0
in vec2 v_TexCoord;
out vec4 outputColor;
vec4 FXAA(sampler2D P_t_Texture, in vec2 t_PixelCenter, in vec2 t_InvResolution) {
float lumaNW = MonochromeNTSC(texture(P_t_Texture, t_PixelTopLeft.xy) .rgb);
return rgbOutput;
}
void main() {
outputColor = FXAA(u_Texture, v_TexCoord.xy, u_InvResolution.xy);
}`);

const glsl440 = preprocessShader_GLSL(WebGPUVendorInfo, 'frag', raw);
expect(glsl440).toEqual(`#version 440
precision mediump float;
#define VIEWPORT_ORIGIN_TL 1
#define CLIPSPACE_NEAR_ZERO 1
#define gl_VertexID gl_VertexIndex
#define gl_InstanceID gl_InstanceIndex
layout(set = 1, binding = 0) uniform texture2D T_u_Texture;
layout(set = 1, binding = 1) uniform sampler S_u_Texture;
layout(location = 0) in vec2 v_TexCoord;
out vec4 outputColor;
vec4 FXAA(texture2D T_P_t_Texture, sampler S_P_t_Texture, in vec2 t_PixelCenter, in vec2 t_InvResolution) {
float lumaNW = MonochromeNTSC(texture(sampler2D(T_P_t_Texture, S_P_t_Texture), t_PixelTopLeft.xy) .rgb);
return rgbOutput;
}
void main() {
outputColor = FXAA(T_u_Texture, S_u_Texture, v_TexCoord.xy, u_InvResolution.xy);
}`);
});
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-device-api",
"version": "1.6.4",
"version": "1.6.5",
"description": "A Device API references WebGPU implementations",
"keywords": [
"antv",
Expand Down
48 changes: 48 additions & 0 deletions src/shader/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,41 @@ layout(set = ${set}, binding = ${
);
}

rest = rest.replace(
/\bPU_SAMPLER_(\w+)\((.*?)\)/g,
(substr, combinedSamplerType, samplerName) => {
return `SAMPLER_${combinedSamplerType}(P_${samplerName})`;
},
);

rest = rest.replace(
/\bPF_SAMPLER_(\w+)\((.*?)\)/g,
(substr, combinedSamplerType, samplerName) => {
return `PP_SAMPLER_${combinedSamplerType}(P_${samplerName})`;
},
);

rest = rest.replace(/\bPU_TEXTURE\((.*?)\)/g, (substr, samplerName) => {
return `TEXTURE(P_${samplerName})`;
});

if (vendorInfo.separateSamplerTextures) {
rest = rest.replace(
/\bPD_SAMPLER_(\w+)\((.*?)\)/g,
(substr, combinedSamplerType, samplerName) => {
const [textureType, samplerType] =
getSeparateSamplerTypes(combinedSamplerType);
return `texture${textureType} T_P_${samplerName}, sampler${samplerType} S_P_${samplerName}`;
},
);

rest = rest.replace(
/\bPP_SAMPLER_(\w+)\((.*?)\)/g,
(substr, combinedSamplerType, samplerName) => {
return `T_${samplerName}, S_${samplerName}`;
},
);

rest = rest.replace(
/\bSAMPLER_(\w+)\((.*?)\)/g,
(substr, combinedSamplerType, samplerName) => {
Expand All @@ -279,6 +313,20 @@ layout(set = ${set}, binding = ${
});
} else {
const samplerNames: [string, string][] = [];
rest = rest.replace(
/\bPD_SAMPLER_(\w+)\((.*?)\)/g,
(substr, combinedSamplerType, samplerName) => {
return `sampler${combinedSamplerType} P_${samplerName}`;
},
);

rest = rest.replace(
/\bPP_SAMPLER_(\w+)\((.*?)\)/g,
(substr, combinedSamplerType, samplerName) => {
return samplerName;
},
);

rest = rest.replace(
/\bSAMPLER_(\w+)\((.*?)\)/g,
(substr, combinedSamplerType, samplerName) => {
Expand Down

0 comments on commit 15bfcbb

Please sign in to comment.