Skip to content

Commit

Permalink
Compat: Refactor subgroup tests for 0 storage buffers in frag
Browse files Browse the repository at this point in the history
  • Loading branch information
greggman committed Jan 3, 2025
1 parent 58f9d5d commit 2ad9545
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ g.test('fragment,all_active')
enable subgroups;
@group(0) @binding(0)
var<storage, read_write> inputs : array<u32>; // unused
var<uniform> inputs : array<vec4u, 1>; // unused
@fragment
fn main(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ g.test('fragment,all_active')
enable subgroups;
@group(0) @binding(0)
var<storage, read_write> inputs : array<u32>; // unused
var<uniform> inputs : array<vec4u, 1>; // unused
@fragment
fn main(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ g.test('fragment')
enable subgroups;
@group(0) @binding(0)
var<storage> inputs : array<u32>;
var<uniform> inputs : array<vec4u, 1>;
@fragment
fn main(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ g.test('fragment,all_active')
enable subgroups;
@group(0) @binding(0)
var<storage, read_write> inputs : array<u32>;
var<uniform> inputs : array<vec4u, ${inputData.length}>;
@fragment
fn main(
Expand All @@ -357,7 +357,7 @@ fn main(
let x_in_range = u32(pos.x) < (${t.params.size[0]} - 1);
let y_in_range = u32(pos.y) < (${t.params.size[1]} - 1);
let in_range = x_in_range && y_in_range;
let input = select(1u, inputs[linear], in_range);
let input = select(1u, inputs[linear].x, in_range);
let res = select(0u, 1u, subgroupAll(bool(input)));
return vec2u(res, subgroup_id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ g.test('fragment,all_active')
enable subgroups;
@group(0) @binding(0)
var<storage, read_write> inputs : array<u32>;
var<uniform> inputs : array<vec4u, ${inputData.length}>;
@fragment
fn main(
Expand All @@ -357,7 +357,7 @@ fn main(
let x_in_range = u32(pos.x) < (${t.params.size[0]} - 1);
let y_in_range = u32(pos.y) < (${t.params.size[1]} - 1);
let in_range = x_in_range && y_in_range;
let input = select(0u, inputs[linear], in_range);
let input = select(0u, inputs[linear].x, in_range);
let res = select(0u, 1u, subgroupAny(bool(input)));
return vec2u(res, subgroup_id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ g.test('fragment,all_active')
enable subgroups;
@group(0) @binding(0)
var<storage, read_write> inputs : array<u32>;
var<uniform> inputs : array<vec4u, ${inputData.length}>;
@fragment
fn main(
Expand All @@ -575,7 +575,7 @@ fn main(
let x_in_range = u32(pos.x) < (${t.params.size[0]} - 1);
let y_in_range = u32(pos.y) < (${t.params.size[1]} - 1);
let in_range = x_in_range && y_in_range;
let input = select(${ident}, inputs[linear], in_range);
let input = select(${ident}, inputs[linear].x, in_range);
let res = ${t.params.op}(input);
return vec2u(res, subgroup_id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -676,14 +676,16 @@ g.test('fragment')

const broadcast =
t.params.id === 0
? `subgroupBroadcastFirst(input[linear])`
: `subgroupBroadcast(input[linear], ${t.params.id})`;
? `subgroupBroadcastFirst(input[linear].x)`
: `subgroupBroadcast(input[linear].x, ${t.params.id})`;
const texels = t.params.size[0] * t.params.size[1];
const inputData = new Uint32Array([...iterRange(texels, x => x)]);

const fsShader = `
enable subgroups;
@group(0) @binding(0)
var<storage> input : array<u32>;
var<uniform> input : array<vec4u, ${inputData.length}>;
@fragment
fn main(
Expand All @@ -696,8 +698,6 @@ fn main(
return vec4u(${broadcast}, id, size, linear);
}`;

const texels = t.params.size[0] * t.params.size[1];
const inputData = new Uint32Array([...iterRange(texels, x => x)]);
await runFragmentTest(
t,
t.params.format,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ g.test('fragment')
enable subgroups;
@group(0) @binding(0)
var<storage, read_write> inputs : array<u32>; // unused
var<uniform> inputs : array<vec4u, 1>; // unused
@fragment
fn main(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ g.test('fragment')
enable subgroups;
@group(0) @binding(0)
var<storage, read_write> inputs : array<u32>;
var<uniform> inputs : array<vec4u, ${inputData.length}>;
@fragment
fn main(
Expand All @@ -612,7 +612,7 @@ fn main(
let x_in_range = u32(pos.x) < (${t.params.size[0]} - 1);
let y_in_range = u32(pos.y) < (${t.params.size[1]} - 1);
let in_range = x_in_range && y_in_range;
let input = select(${identity}, inputs[linear], in_range);
let input = select(${identity}, inputs[linear].x, in_range);
let res = ${t.params.op}(input);
return vec2u(res, subgroup_id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,11 +528,29 @@ g.test('fragment')
t.skipIf(innerTexels < subgroupMinSize, 'Too few texels to be reliable');
t.skipIf(subgroupMaxSize === 4 && t.params.quadIndex !== 0, 'Duplicate test');

// Max possible subgroup size is 128 which is too large so we reduce the
// multiplication by a factor of 4. We populate one element of each quad with a
// non-identity value. subgroupMaxSize of 4 is a special case where all
// elements are populated.
const numInputs = t.params.size[0] * t.params.size[1];
const inputData = new Uint32Array([
...iterRange(numInputs, x => {
if (subgroupMaxSize === 4) {
return 2;
} else {
const row = Math.floor(x / t.params.size[0]);
const col = x % t.params.size[0];
const idx = (col % 2) + 2 * (row % 2);
return idx === t.params.quadIndex ? 2 : kIdentity;
}
}),
]);

const fsShader = `
enable subgroups;
@group(0) @binding(0)
var<storage> inputs : array<u32>;
var<uniform> inputs : array<vec4u, ${inputData.length}>;
@fragment
fn main(
Expand All @@ -547,28 +565,10 @@ fn main(
let y_in_range = u32(pos.y) < (${t.params.size[1]} - 1);
let in_range = x_in_range && y_in_range;
let value = select(${kIdentity}, inputs[linear], in_range);
let value = select(${kIdentity}, inputs[linear].x, in_range);
return vec4u(${t.params.op}(value), id, subgroup_id, 0);
};`;

// Max possible subgroup size is 128 which is too large so we reduce the
// multiplication by a factor of 4. We populate one element of each quad with a
// non-identity value. subgroupMaxSize of 4 is a special case where all
// elements are populated.
const numInputs = t.params.size[0] * t.params.size[1];
const inputData = new Uint32Array([
...iterRange(numInputs, x => {
if (subgroupMaxSize === 4) {
return 2;
} else {
const row = Math.floor(x / t.params.size[0]);
const col = x % t.params.size[0];
const idx = (col % 2) + 2 * (row % 2);
return idx === t.params.quadIndex ? 2 : kIdentity;
}
}),
]);

await runFragmentTest(
t,
t.params.format,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ g.test('fragment')
enable subgroups;
@group(0) @binding(0)
var<storage, read_write> inputs : array<u32>; // unused
var<uniform> inputs : array<vec4u, 1>; // unused
@fragment
fn main(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -521,9 +521,19 @@ fn vsMain(@builtin(vertex_index) index : u32) -> @builtin(position) vec4f {
const byteLength = bytesPerRow * blocksPerColumn;
const uintLength = byteLength / 4;

const expandedInputData = new (
inputData instanceof Uint32Array
? Uint32Array
: inputData instanceof Float32Array
? Float32Array
: Float16Array
)(inputData.length * 4);
for (let i = 0; i < inputData.length; ++i) {
expandedInputData[i * 4] = inputData[i];
}
const buffer = t.makeBufferWithContents(
inputData,
GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_DST
expandedInputData,
GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
);

const bg = t.device.createBindGroup({
Expand Down

0 comments on commit 2ad9545

Please sign in to comment.