"before all" hook for "setPipeline" ‣
TypeError: Cannot read properties of undefined (reading 'createShaderModule')
at Context.<anonymous> (https://greggman.github.io/webgpu-avoid-redundant-state-setting/test/tests/webgpu-avoid-redundant-state-setting-tests.js:222:37)
at callFn (https://greggman.github.io/webgpu-avoid-redundant-state-setting/test/mocha.js:13124:23)
at Runnable$3.run (https://greggman.github.io/webgpu-avoid-redundant-state-setting/test/mocha.js:13112:7)
at next (https://greggman.github.io/webgpu-avoid-redundant-state-setting/test/mocha.js:14489:12)
at https://greggman.github.io/webgpu-avoid-redundant-state-setting/test/mocha.js:14550:7
at timeslice (https://greggman.github.io/webgpu-avoid-redundant-state-setting/test/mocha.js:20501:29)
const shaderSrc = `
struct VSUniforms0 {
worldViewProjection: mat4x4<f32>,
};
struct VSUniforms1 {
worldInverseTranspose: mat4x4<f32>,
};
@group(0) @binding(0) var<uniform> vsUniforms0: VSUniforms0;
@group(0) @binding(2) var<uniform> vsUniforms1: VSUniforms1;
struct MyVSInput {
@location(0) position: vec4<f32>,
@location(1) normal: vec3<f32>,
@location(2) texcoord: vec2<f32>,
};
struct MyVSOutput {
@builtin(position) position: vec4<f32>,
@location(0) normal: vec3<f32>,
@location(1) texcoord: vec2<f32>,
};
@vertex
fn myVSMain(v: MyVSInput) -> MyVSOutput {
var vsOut: MyVSOutput;
vsOut.position = vsUniforms0.worldViewProjection * v.position;
vsOut.normal = (vsUniforms1.worldInverseTranspose * vec4<f32>(v.normal, 0.0)).xyz;
vsOut.texcoord = v.texcoord;
return vsOut;
}
@fragment
fn myFSMain(v: MyVSOutput) -> @location(0) vec4<f32> {
return vec4f(0);
}
`;
const shaderModule = device.createShaderModule({code: shaderSrc});
const pipelineDesc = {
layout: 'auto',
vertex: {
module: shaderModule,
entryPoint: 'myVSMain',
buffers: [
{ arrayStride: 3 * 4, attributes: [ {shaderLocation: 0, offset: 0, format: 'float32x3'}, ], },
{ arrayStride: 3 * 4, attributes: [ {shaderLocation: 1, offset: 0, format: 'float32x3'}, ], },
{ arrayStride: 2 * 4, attributes: [ {shaderLocation: 2, offset: 0, format: 'float32x2',}, ], },
],
},
fragment: {
module: shaderModule,
entryPoint: 'myFSMain',
targets: [ {format: 'rgba8unorm'}, ],
},
};
pipeline0 = device.createRenderPipeline(pipelineDesc);
pipeline1 = device.createRenderPipeline(pipelineDesc);
const vsUniformBuffer0 = device.createBuffer({
size: 1024,
usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST,
});
const vsUniformBuffer1 = device.createBuffer({
size: 1024,
usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST,
});
bindGroup0 = device.createBindGroup({
label: 'group0',
layout: pipeline0.getBindGroupLayout(0),
entries: [
{ binding: 0, resource: { buffer: vsUniformBuffer0 } },
{ binding: 2, resource: { buffer: vsUniformBuffer1 } },
],
});
bindGroup1 = device.createBindGroup({
label: 'group1',
layout: pipeline0.getBindGroupLayout(0),
entries: [
{ binding: 0, resource: { buffer: vsUniformBuffer0 } },
{ binding: 2, resource: { buffer: vsUniformBuffer1 } },
],
});
const bindGroupLayout = device.createBindGroupLayout({
entries: [
{ binding: 0, visibility: GPUShaderStage.VERTEX, buffer: { type: "uniform", hasDynamicOffset: true } },
{ binding: 2, visibility: GPUShaderStage.VERTEX, buffer: { type: "uniform", hasDynamicOffset: true } },
],
});
dynamicBindGroup0 = device.createBindGroup({
label: 'dynamicGroup0',
layout: bindGroupLayout,
entries: [
{ binding: 0, resource: { buffer: vsUniformBuffer0, size: 512 } },
{ binding: 2, resource: { buffer: vsUniformBuffer1, size: 512 } },
],
});
dynamicBindGroup0 = device.createBindGroup({
label: 'dynamicGroup1',
layout: bindGroupLayout,
entries: [
{ binding: 0, resource: { buffer: vsUniformBuffer0, size: 512 } },
{ binding: 2, resource: { buffer: vsUniformBuffer1, size: 512 } },
],
});
vertexBuffer0 = device.createBuffer({ size: 128, usage: GPUBufferUsage.VERTEX });
vertexBuffer1 = device.createBuffer({ size: 128, usage: GPUBufferUsage.VERTEX });
indexBuffer0 = device.createBuffer({ size: 128, usage: GPUBufferUsage.INDEX });
indexBuffer1 = device.createBuffer({ size: 128, usage: GPUBufferUsage.INDEX });
const tex = device.createTexture({
size: [2, 2, 1],
format: 'rgba8unorm',
usage: GPUTextureUsage.RENDER_ATTACHMENT
});
renderPassDescriptor = {
colorAttachments: [
{
view: tex.createView(),
clearValue: [0, 0, 0, 0],
loadOp: 'clear',
storeOp: 'store',
},
],
};
pass = encoder.beginRenderPass(renderPassDescriptor);