|
| 1 | +export const description = `Test override execution`; |
| 2 | + |
| 3 | +import { makeTestGroup } from '../../../common/framework/test_group.js'; |
| 4 | +import { keysOf } from '../../../common/util/data_tables.js'; |
| 5 | +import { AllFeaturesMaxLimitsGPUTest } from '../../gpu_test.js'; |
| 6 | +import { checkElementsEqual } from '../../util/check_contents.js'; |
| 7 | + |
| 8 | +export const g = makeTestGroup(AllFeaturesMaxLimitsGPUTest); |
| 9 | + |
| 10 | +const kOverrideCases = { |
| 11 | + logical_lhs_override: { |
| 12 | + code: `x == 2 && 1 < 2`, |
| 13 | + }, |
| 14 | + logical_rhs_override: { |
| 15 | + code: `1 > 2 || x == 2`, |
| 16 | + }, |
| 17 | + logical_both_override: { |
| 18 | + code: `x > 2 || x == 2`, |
| 19 | + }, |
| 20 | +}; |
| 21 | + |
| 22 | +g.test('logical') |
| 23 | + .desc(`Test replacing an override in the LHS of a logical statement`) |
| 24 | + .params(u => u.combine('case', keysOf(kOverrideCases))) |
| 25 | + .fn(async t => { |
| 26 | + const expr = kOverrideCases[t.params.case].code; |
| 27 | + const code = ` |
| 28 | +override x: u32 = 2; |
| 29 | +override y: bool = ${expr}; |
| 30 | +
|
| 31 | +@group(0) @binding(0) var<storage, read_write> v : vec4u; |
| 32 | +
|
| 33 | +@compute @workgroup_size(1) |
| 34 | +fn main() { |
| 35 | + if (y) { |
| 36 | + v = vec4u(4, 4, 4, 4); |
| 37 | + } else { |
| 38 | + v = vec4u(1, 1, 1, 1); |
| 39 | + } |
| 40 | +}`; |
| 41 | + |
| 42 | + const pipeline = t.device.createComputePipeline({ |
| 43 | + layout: 'auto', |
| 44 | + compute: { |
| 45 | + module: t.device.createShaderModule({ |
| 46 | + code, |
| 47 | + }), |
| 48 | + entryPoint: 'main', |
| 49 | + }, |
| 50 | + }); |
| 51 | + |
| 52 | + const buffer = t.makeBufferWithContents( |
| 53 | + new Uint32Array([0, 0, 0, 0]), |
| 54 | + GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST |
| 55 | + ); |
| 56 | + |
| 57 | + const bg = t.device.createBindGroup({ |
| 58 | + layout: pipeline.getBindGroupLayout(0), |
| 59 | + entries: [ |
| 60 | + { |
| 61 | + binding: 0, |
| 62 | + resource: { |
| 63 | + buffer, |
| 64 | + }, |
| 65 | + }, |
| 66 | + ], |
| 67 | + }); |
| 68 | + |
| 69 | + const encoder = t.device.createCommandEncoder(); |
| 70 | + const pass = encoder.beginComputePass(); |
| 71 | + pass.setPipeline(pipeline); |
| 72 | + pass.setBindGroup(0, bg); |
| 73 | + pass.dispatchWorkgroups(1, 1, 1); |
| 74 | + pass.end(); |
| 75 | + t.queue.submit([encoder.finish()]); |
| 76 | + |
| 77 | + const bufferReadback = await t.readGPUBufferRangeTyped(buffer, { |
| 78 | + srcByteOffset: 0, |
| 79 | + type: Uint32Array, |
| 80 | + typedLength: 4, |
| 81 | + method: 'copy', |
| 82 | + }); |
| 83 | + const got: Uint32Array = bufferReadback.data; |
| 84 | + const expected = new Uint32Array([4, 4, 4, 4]); |
| 85 | + |
| 86 | + t.expectOK(checkElementsEqual(got, expected)); |
| 87 | + }); |
0 commit comments