Skip to content

Commit 15bfcbb

Browse files
Release (#168)
* 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>
1 parent ac91cbf commit 15bfcbb

File tree

4 files changed

+125
-1
lines changed

4 files changed

+125
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @antv/g-device-api
22

3+
## 1.6.5
4+
5+
### Patch Changes
6+
7+
- d9b7078: Separate sampler and textures correctly.
8+
39
## 1.6.4
410

511
### Patch Changes

__tests__/unit/compiler.spec.ts

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,4 +509,74 @@ vec3 u_blur_height_fixed;
509509
};
510510
`);
511511
});
512+
513+
it('should separate sampler textures correctly.', () => {
514+
const raw = `uniform sampler2D u_Texture;
515+
in vec2 v_TexCoord;
516+
517+
out vec4 outputColor;
518+
519+
vec4 FXAA(PD_SAMPLER_2D(t_Texture), in vec2 t_PixelCenter, in vec2 t_InvResolution) {
520+
float lumaNW = MonochromeNTSC(texture(PU_SAMPLER_2D(t_Texture), t_PixelTopLeft.xy) .rgb);
521+
return rgbOutput;
522+
}
523+
524+
void main() {
525+
outputColor = FXAA(PP_SAMPLER_2D(u_Texture), v_TexCoord.xy, u_InvResolution.xy);
526+
}`;
527+
const glsl100 = preprocessShader_GLSL(WebGL1VendorInfo, 'frag', raw);
528+
expect(glsl100).toEqual(`#extension GL_OES_standard_derivatives : enable
529+
precision mediump float;
530+
531+
uniform sampler2D u_Texture; // BINDING=0
532+
varying vec2 v_TexCoord;
533+
vec4 outputColor;
534+
535+
vec4 FXAA(sampler2D P_t_Texture, in vec2 t_PixelCenter, in vec2 t_InvResolution) {
536+
float lumaNW = MonochromeNTSC(texture2D(P_t_Texture, t_PixelTopLeft.xy) .rgb);
537+
return rgbOutput;
538+
}
539+
void main() {
540+
outputColor = FXAA(u_Texture, v_TexCoord.xy, u_InvResolution.xy);
541+
542+
gl_FragColor = vec4(outputColor);
543+
}`);
544+
545+
const glsl300 = preprocessShader_GLSL(WebGL2VendorInfo, 'frag', raw);
546+
expect(glsl300).toEqual(`#version 300
547+
548+
precision mediump float;
549+
550+
uniform sampler2D u_Texture; // BINDING=0
551+
in vec2 v_TexCoord;
552+
out vec4 outputColor;
553+
vec4 FXAA(sampler2D P_t_Texture, in vec2 t_PixelCenter, in vec2 t_InvResolution) {
554+
float lumaNW = MonochromeNTSC(texture(P_t_Texture, t_PixelTopLeft.xy) .rgb);
555+
return rgbOutput;
556+
}
557+
void main() {
558+
outputColor = FXAA(u_Texture, v_TexCoord.xy, u_InvResolution.xy);
559+
}`);
560+
561+
const glsl440 = preprocessShader_GLSL(WebGPUVendorInfo, 'frag', raw);
562+
expect(glsl440).toEqual(`#version 440
563+
564+
precision mediump float;
565+
#define VIEWPORT_ORIGIN_TL 1
566+
#define CLIPSPACE_NEAR_ZERO 1
567+
#define gl_VertexID gl_VertexIndex
568+
#define gl_InstanceID gl_InstanceIndex
569+
570+
layout(set = 1, binding = 0) uniform texture2D T_u_Texture;
571+
layout(set = 1, binding = 1) uniform sampler S_u_Texture;
572+
layout(location = 0) in vec2 v_TexCoord;
573+
out vec4 outputColor;
574+
vec4 FXAA(texture2D T_P_t_Texture, sampler S_P_t_Texture, in vec2 t_PixelCenter, in vec2 t_InvResolution) {
575+
float lumaNW = MonochromeNTSC(texture(sampler2D(T_P_t_Texture, S_P_t_Texture), t_PixelTopLeft.xy) .rgb);
576+
return rgbOutput;
577+
}
578+
void main() {
579+
outputColor = FXAA(T_u_Texture, S_u_Texture, v_TexCoord.xy, u_InvResolution.xy);
580+
}`);
581+
});
512582
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@antv/g-device-api",
3-
"version": "1.6.4",
3+
"version": "1.6.5",
44
"description": "A Device API references WebGPU implementations",
55
"keywords": [
66
"antv",

src/shader/compiler.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,41 @@ layout(set = ${set}, binding = ${
266266
);
267267
}
268268

269+
rest = rest.replace(
270+
/\bPU_SAMPLER_(\w+)\((.*?)\)/g,
271+
(substr, combinedSamplerType, samplerName) => {
272+
return `SAMPLER_${combinedSamplerType}(P_${samplerName})`;
273+
},
274+
);
275+
276+
rest = rest.replace(
277+
/\bPF_SAMPLER_(\w+)\((.*?)\)/g,
278+
(substr, combinedSamplerType, samplerName) => {
279+
return `PP_SAMPLER_${combinedSamplerType}(P_${samplerName})`;
280+
},
281+
);
282+
283+
rest = rest.replace(/\bPU_TEXTURE\((.*?)\)/g, (substr, samplerName) => {
284+
return `TEXTURE(P_${samplerName})`;
285+
});
286+
269287
if (vendorInfo.separateSamplerTextures) {
288+
rest = rest.replace(
289+
/\bPD_SAMPLER_(\w+)\((.*?)\)/g,
290+
(substr, combinedSamplerType, samplerName) => {
291+
const [textureType, samplerType] =
292+
getSeparateSamplerTypes(combinedSamplerType);
293+
return `texture${textureType} T_P_${samplerName}, sampler${samplerType} S_P_${samplerName}`;
294+
},
295+
);
296+
297+
rest = rest.replace(
298+
/\bPP_SAMPLER_(\w+)\((.*?)\)/g,
299+
(substr, combinedSamplerType, samplerName) => {
300+
return `T_${samplerName}, S_${samplerName}`;
301+
},
302+
);
303+
270304
rest = rest.replace(
271305
/\bSAMPLER_(\w+)\((.*?)\)/g,
272306
(substr, combinedSamplerType, samplerName) => {
@@ -279,6 +313,20 @@ layout(set = ${set}, binding = ${
279313
});
280314
} else {
281315
const samplerNames: [string, string][] = [];
316+
rest = rest.replace(
317+
/\bPD_SAMPLER_(\w+)\((.*?)\)/g,
318+
(substr, combinedSamplerType, samplerName) => {
319+
return `sampler${combinedSamplerType} P_${samplerName}`;
320+
},
321+
);
322+
323+
rest = rest.replace(
324+
/\bPP_SAMPLER_(\w+)\((.*?)\)/g,
325+
(substr, combinedSamplerType, samplerName) => {
326+
return samplerName;
327+
},
328+
);
329+
282330
rest = rest.replace(
283331
/\bSAMPLER_(\w+)\((.*?)\)/g,
284332
(substr, combinedSamplerType, samplerName) => {

0 commit comments

Comments
 (0)