Skip to content

Commit

Permalink
Fix for textureGather (#3918)
Browse files Browse the repository at this point in the history
textureGather needs to not choose centers of texels because
depending on the backend it could choose the texels to the
left or right (up or down) from the texture coordinate.

There was code to do this but it needed to know it was being
used for textureGather.
  • Loading branch information
greggman authored Aug 26, 2024
1 parent fd4023c commit 08ed9c3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ Parameters:

const calls: TextureCall<vec2>[] = generateTextureBuiltinInputs2D(50, {
method: samplePoints,
textureBuiltin: 'textureGather',
sampler,
descriptor,
offset,
Expand Down Expand Up @@ -304,6 +305,7 @@ Parameters:

const calls: TextureCall<vec2>[] = generateTextureBuiltinInputs2D(50, {
method: samplePoints,
textureBuiltin: 'textureGather',
sampler,
descriptor,
arrayIndex: { num: texture.depthOrArrayLayers, type: A },
Expand Down Expand Up @@ -486,6 +488,7 @@ Parameters:

const calls: TextureCall<vec2>[] = generateTextureBuiltinInputs2D(50, {
method: samplePoints,
textureBuiltin: 'textureGather',
sampler,
descriptor,
offset,
Expand Down Expand Up @@ -654,6 +657,7 @@ Parameters:

const calls: TextureCall<vec2>[] = generateTextureBuiltinInputs2D(50, {
method: samplePoints,
textureBuiltin: 'textureGather',
sampler,
descriptor,
arrayIndex: { num: texture.depthOrArrayLayers, type: A },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ Parameters:

const calls: TextureCall<vec2>[] = generateTextureBuiltinInputs2D(50, {
method: samplePoints,
textureBuiltin: 'textureGatherCompare',
sampler,
descriptor,
arrayIndex: { num: texture.depthOrArrayLayers, type: A },
Expand Down Expand Up @@ -284,6 +285,7 @@ Parameters:

const calls: TextureCall<vec2>[] = generateTextureBuiltinInputs2D(50, {
method: samplePoints,
textureBuiltin: 'textureGatherCompare',
sampler,
descriptor,
offset,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ export interface TextureCall<T extends Dimensionality> extends TextureCallArgs<T
}

const isBuiltinComparison = (builtin: TextureBuiltin) => builtin === 'textureGatherCompare';
const isBuiltinGather = (builtin: TextureBuiltin) =>
const isBuiltinGather = (builtin: TextureBuiltin | undefined) =>
builtin === 'textureGather' || builtin === 'textureGatherCompare';

const s_u32 = new Uint32Array(1);
Expand Down Expand Up @@ -2515,8 +2515,8 @@ function generateTextureBuiltinInputsImpl<T extends Dimensionality>(
// MacOS, M1 Mac: 256
const kSubdivisionsPerTexel = 4;
const avoidEdgeCase =
!args.sampler || args.sampler.minFilter === 'nearest' || isBuiltinGather(args.textureBuiltin!);
const edgeRemainder = args.textureBuiltin === 'textureGather' ? kSubdivisionsPerTexel / 2 : 0;
!args.sampler || args.sampler.minFilter === 'nearest' || isBuiltinGather(args.textureBuiltin);
const edgeRemainder = isBuiltinGather(args.textureBuiltin) ? kSubdivisionsPerTexel / 2 : 0;
const numComponents = isDepthOrStencilTextureFormat(descriptor.format) ? 1 : 4;
return coords.map((c, i) => {
const mipLevel = args.mipLevel
Expand Down Expand Up @@ -2948,8 +2948,8 @@ export function generateSamplePointsCube(
//
const kSubdivisionsPerTexel = 4;
const avoidEdgeCase =
!args.sampler || args.sampler.minFilter === 'nearest' || isBuiltinGather(args.textureBuiltin!);
const edgeRemainder = isBuiltinGather(args.textureBuiltin!) ? kSubdivisionsPerTexel / 2 : 0;
!args.sampler || args.sampler.minFilter === 'nearest' || isBuiltinGather(args.textureBuiltin);
const edgeRemainder = isBuiltinGather(args.textureBuiltin) ? kSubdivisionsPerTexel / 2 : 0;

return coords.map((c, i) => {
const mipLevel = args.mipLevel
Expand Down

0 comments on commit 08ed9c3

Please sign in to comment.