Skip to content

Commit

Permalink
chore(WebGPU): better render encoder checks
Browse files Browse the repository at this point in the history
Catch encore/pipeline attachment mismatches earlier
in the code to make them easier to debug.
  • Loading branch information
martinken committed May 24, 2021
1 parent 172ff83 commit 32434b8
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 15 deletions.
23 changes: 13 additions & 10 deletions Sources/Rendering/WebGPU/Pipeline/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ function vtkWebGPUPipeline(publicAPI, model) {

publicAPI.initialize = (device) => {
// start with the renderencoder settings
const pipelineDesc = model.renderEncoder.getPipelineSettings();
model.pipelineDescription = model.renderEncoder.getPipelineSettings();

pipelineDesc.primitive.topology = model.topology;
model.pipelineDescription.primitive.topology = model.topology;

pipelineDesc.vertex = model.vertexState;
model.pipelineDescription.vertex = model.vertexState;

// add in bind group layouts
const bindGroupLayouts = [];
Expand All @@ -25,22 +25,24 @@ function vtkWebGPUPipeline(publicAPI, model) {
model.pipelineLayout = device
.getHandle()
.createPipelineLayout({ bindGroupLayouts });
pipelineDesc.layout = model.pipelineLayout;
model.pipelineDescription.layout = model.pipelineLayout;

for (let i = 0; i < model.shaderDescriptions.length; i++) {
const sd = model.shaderDescriptions[i];
const sm = device.getShaderModule(sd);
if (sd.getType() === 'vertex') {
pipelineDesc.vertex.module = sm.getHandle();
pipelineDesc.vertex.entryPoint = 'main';
model.pipelineDescription.vertex.module = sm.getHandle();
model.pipelineDescription.vertex.entryPoint = 'main';
}
if (sd.getType() === 'fragment') {
pipelineDesc.fragment.module = sm.getHandle();
pipelineDesc.fragment.entryPoint = 'main';
model.pipelineDescription.fragment.module = sm.getHandle();
model.pipelineDescription.fragment.entryPoint = 'main';
}
}

model.handle = device.getHandle().createRenderPipeline(pipelineDesc);
model.handle = device
.getHandle()
.createRenderPipeline(model.pipelineDescription);
};

publicAPI.getShaderDescription = (stype) => {
Expand Down Expand Up @@ -87,6 +89,7 @@ const DEFAULT_VALUES = {
shaderDescriptions: null,
vertexState: null,
topology: null,
pipelineDescription: null,
};

// ----------------------------------------------------------------------------
Expand All @@ -99,7 +102,7 @@ export function extend(publicAPI, model, initialValues = {}) {
model.layouts = [];
model.shaderDescriptions = [];

macro.get(publicAPI, model, ['handle']);
macro.get(publicAPI, model, ['handle', 'pipelineDescription']);
macro.setGet(publicAPI, model, [
'device',
'renderEncoder',
Expand Down
38 changes: 33 additions & 5 deletions Sources/Rendering/WebGPU/RenderEncoder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,39 @@ function vtkWebGPURenderEncoder(publicAPI, model) {

publicAPI.setPipeline = (pl) => {
model.handle.setPipeline(pl.getHandle());
// todo check attachment state?
// console.log(
// `bound pipeline for ${model.pipelineHash} ${JSON.stringify(pl.get())}`
// );
// console.log(model.description);
const pd = pl.getPipelineDescription();

// check attachment state
if (model.colorTextureViews.length !== pd.fragment.targets.length) {
console.log(
`mismatched attachment counts on pipeline ${pd.fragment.targets.length} while encoder has ${model.colorTextureViews.length}`
);
console.trace();
} else {
for (let i = 0; i < model.colorTextureViews.length; i++) {
const fmt = model.colorTextureViews[i].getTexture().getFormat();
if (fmt !== pd.fragment.targets[i].format) {
console.log(
`mismatched attachments for attachment ${i} on pipeline ${pd.fragment.targets[i].format} while encoder has ${fmt}`
);
console.trace();
}
}
}

// check depth buffer
if (!model.depthTextureView !== !('depthStencil' in pd)) {
console.log('mismatched depth attachments');
console.trace();
} else if (model.depthTextureView) {
const dfmt = model.depthTextureView.getTexture().getFormat();
if (dfmt !== pd.depthStencil.format) {
console.log(
`mismatched depth attachments on pipeline ${pd.depthStencil.format} while encoder has ${dfmt}`
);
console.trace();
}
}
model.boundPipeline = pl;
};

Expand Down

0 comments on commit 32434b8

Please sign in to comment.