Sitelet https://github.com/gpuweb/gpuweb/pull/1352
Skip to content

Refactor the GPURenderPipelineDescriptor according to aspects - #1352

Merged
kvark merged 4 commits into
gpuweb:mainfrom
kvark:pipeline-aspect
Jan 22, 2021
Merged

kvark merged 4 commits into
gpuweb:mainfrom
kvark:pipeline-aspect

Conversation

@kvark

@kvark kvark commented Jan 15, 2021 •

Copy link
Copy Markdown
Contributor

Groups the properties of a pipeline according to the aspects. Related things are kept together, even if they can affect multiple stages of a pipeline.

Closes #1307
Closes #936

I also want to re-order the sections of the pipeline, but this can be done as a follow-up in order to make this PR easier.


Preview | Diff

@kvark
kvark requested review from kainino0x and toji January 15, 2021 17:15
@github-actions

Copy link
Copy Markdown
Contributor

Previews, as seen at the time of posting this comment:
WebGPU | IDL
WGSL
9510cc1

@toji

toji commented Jan 15, 2021

Copy link
Copy Markdown
Member

On the last call you had an example that showed every possible descriptor property in one big struct. Could you link that again here or paste it into the comments? It's slightly tricky to get the complete picture from the various diffed chunks spread throughout the spec and it would serve as a useful reference for the intent.

@kvark

kvark commented Jan 15, 2021

Copy link
Copy Markdown
Contributor Author
device.createRenderPipeline({
    vertex: {
        inputs: [{
            arrayStride: 16,
            stepMode: "vertex",
            attributes: [{
                offset: 0,
                format: "float2",
            }],
        }],
        module: module,
        entryPoint: "vs_main",
    },
    primitive: {
        topology: "triangle-strip",
        stripIndexFormat: "uint16",
        frontFace: "ccw",
        cullMode: "back",
    },
    depthStencil: {
        format: "depth24plus",
        depthWriteEnabled: true,
        depthCompare: "less",
        depthBias: 2,
        depthBiasSlopeScale: 1.0,
        depthBiasClamp: 8.0,
        stencilReadMask: 0xF,
        stencilWriteMask: 0x1,
        stencilFront: {
            compare: "greater",
            failOp: "keep",
            depthFailOp: "invert",
            passOp: "zero",
        },
        stencilBack: {},
    },
    multisample: {
        count: 4,
        mask: 0xF,
        alphaToCoverage: true,
    },
    fragment: {
        outputs: [{
            format: 'rgba8unorm',
            writeMask: 0xF,
            blend: {
                color: {
                    srcFactor: "one",
                    dstFactor: "src-alpha",
                    operation: "add",
                },
                alpha: {},
            },
        }],
        module: module,
        entryPoint: "fs_main",
    },
});

@toji toji left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking really good! Thanks!

Comment thread spec/index.bs Outdated
Comment thread spec/index.bs
Comment thread spec/index.bs Outdated

<script type=idl>
dictionary GPUFragmentState: GPUProgrammableStage {
required sequence<GPUColorState> outputs;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RE: my suggestion about changing inputs on the vertex stage, maybe this could be colorOutputs to keep them more aligned?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! Let's come back to this once we figure out what needs to be done with inputs, if anything

Comment thread spec/index.bs
Comment thread spec/index.bs Outdated
Comment thread spec/index.bs

- [$validating GPUProgrammableStageDescriptor$]({{GPUShaderStage/VERTEX}},
|descriptor|.{{GPURenderPipelineDescriptor/vertexStage}},
- [$validating GPUProgrammableStage$]({{GPUShaderStage/VERTEX}},

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the vertexState is a programmable stage now should this step be moved into the validating GPUVertexState algorithm? Same for fragmentState below.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do it for sure! I think we can also consider this to be a follow-up.

Comment thread spec/index.bs Outdated
Comment thread spec/index.bs Outdated
Comment thread spec/index.bs Outdated

@kvark kvark left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much detailed review, thank you!

Comment thread spec/index.bs

- [$validating GPUProgrammableStageDescriptor$]({{GPUShaderStage/VERTEX}},
|descriptor|.{{GPURenderPipelineDescriptor/vertexStage}},
- [$validating GPUProgrammableStage$]({{GPUShaderStage/VERTEX}},

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do it for sure! I think we can also consider this to be a follow-up.

Comment thread spec/index.bs Outdated

<script type=idl>
dictionary GPUFragmentState: GPUProgrammableStage {
required sequence<GPUColorState> outputs;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! Let's come back to this once we figure out what needs to be done with inputs, if anything

Comment thread spec/index.bs Outdated
@github-actions

Copy link
Copy Markdown
Contributor

Previews, as seen at the time of posting this comment:
WebGPU | IDL
WGSL
a418892

@Kangz Kangz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is amazing! Hopefully we don't need to move stuff around the GPURenderPipelineDescriptor a second time >_>

Comment thread spec/index.bs Outdated
@github-actions

Copy link
Copy Markdown
Contributor

Previews, as seen at the time of posting this comment:
WebGPU | IDL
WGSL
4c911d9

@kainino0x

Copy link
Copy Markdown
Contributor

This change is amazing! Hopefully we don't need to move stuff around the GPURenderPipelineDescriptor a second time >_>

FYI I want to consider a change after this one to change alphaToCoverageEnabled: true to multisampleMode: "alpha-to-coverage" because sample-rate shading would rightly go in that slot if we had it.

@kainino0x kainino0x left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great!

Comment thread spec/index.bs Outdated
@kvark

kvark commented Jan 21, 2021

Copy link
Copy Markdown
Contributor Author

In the last commit the changes are the following:

  1. tried to clean up the distinction between "xxxState" and "xxxDescriptor". Settled on the latter being used only for the top-level structures. Therefore, VertexBufferLayoutDescriptor is renamed to just VertexBufferState, and same for VertexAttributeState.
  2. renamed GPUColorState to GPUColorTargetState, since it's not a state of a "color"
  3. inputs became inputBuffers and outputs became outputTargets.

@kvark

kvark commented Jan 21, 2021

Copy link
Copy Markdown
Contributor Author

Also, rebased and squashed. It's very easy to run into conflicts with this.

@kainino0x

Copy link
Copy Markdown
Contributor
  1. Therefore, VertexBufferLayoutDescriptor is renamed to just VertexBufferState, and same for VertexAttributeState.

I like the word Layout, and think State isn't really important, could they just be VertexBufferLayout and VertexAttribute?

Also, rebased and squashed. It's very easy to run into conflicts with this.

sg but a merge commit would have been easier for incremental review if possible.

@toji

toji commented Jan 21, 2021

Copy link
Copy Markdown
Member

inputs became inputBuffers and outputs became outputTargets

That's perfect! 😄 This change LGTM now.

FYI I want to consider a change after this one to change alphaToCoverageEnabled: true to multisampleMode: "alpha-to-coverage"

Nit on Kai's follow up request: That would actually be multisample.mode, right?

@kainino0x

Copy link
Copy Markdown
Contributor

Nit on Kai's follow up request: That would actually be multisample.mode, right?

Yeah, probably, unless we have a better name than mode.

@kvark

kvark commented Jan 21, 2021

Copy link
Copy Markdown
Contributor Author

Let's have the multisample discussion in a separate issue, perhaps? It sounds interesting, but I don't want it to drag this change.
@kainino0x your suggestion sounds appropriate, I've added the commit doing this.

As for the merge commit - there was a conflict already. I generally resolve conflicts by rebasing, but in this case it's much easier to resolve it on the whole thing than trying to resolve conflicts on each commit one by one. Just squashed to save time.

@Kangz

Kangz commented Jan 21, 2021

Copy link
Copy Markdown
Contributor
  1. inputs became inputBuffers and outputs became outputTargets.

I don't think the longer names were necessary, but unless more people feel the same I don't think my opinion should block this change.

@kainino0x kainino0x closed this Jan 21, 2021
@kainino0x kainino0x reopened this Jan 21, 2021

@kainino0x kainino0x left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM modulo that final bikeshedding (I don't prefer the new names over inputs/outputs but they're okay)

Let's have the multisample discussion in a separate issue, perhaps?

Yeah, was planning to open a PR after this lands.

@toji

toji commented Jan 21, 2021

Copy link
Copy Markdown
Member

My sole reason for advocating for a name like inputBuffers is that it helps developers (especially ones new to the API) reason about what it describes better and disambiguates it from other types of shader input, but I think that's worthwhile.

I don't think the longer names were necessary

We have some serious refactoring to do if "reduce the amount of typing required" is an API goal. 😉

Comment thread spec/index.bs Outdated
@kvark

kvark commented Jan 21, 2021

Copy link
Copy Markdown
Contributor Author

@kainino0x oh, wait, I misunderstood. I thought you wanted these longer names, based on #1352 (comment)
If neither you or @Kangz are happy with these names, we should reconsider. What names would you want?

@kainino0x

Copy link
Copy Markdown
Contributor

@kvark It's not that I have anything against slightly longer names, I just am not sure whether these are actually clearer - e.g. inputBuffers doesn't clarify that it doesn't include uniform buffers (though this probably doesn't matter that much). But if Brandon thinks so I think it's a good signal.

@kainino0x
kainino0x requested a review from toji January 21, 2021 23:50
@kvark
kvark merged commit 0e7b94e into gpuweb:main Jan 22, 2021
@kvark
kvark deleted the pipeline-aspect branch January 22, 2021 04:11
@kainino0x

Copy link
Copy Markdown
Contributor

FYI I want to consider a change after this one to change alphaToCoverageEnabled: true to multisampleMode: "alpha-to-coverage" because sample-rate shading would rightly go in that slot if we had it.

Now that this PR landed I started looking into this. I learned that in fact alpha-to-coverage and sample-rate-shading are not exclusive with one another, so this idea doesn't make sense.

Sample-rate-shading means shading more than once per pixel, but can be fewer than once per sample (interpolation may occur for other samples, I think). In Vulkan I think the final coverage mask is the AND of all three mask values (pipeline sample mask, shader output sample mask, and alpha-to-coverage sample mask*), then only the relevant bits of the final mask are used (those for the samples covered by the shader invocation).

* though there is no guarantee about the alpha-to-coverage mask produced. According to #267, D3D12 disables alpha-to-coverage if SV_Coverage is used. I think this is why in WebGPU we don't allow alpha-to-coverage with SV_Coverage (added in #724), though given the leniency of the alpha-to-coverage mask I think we could simply allow it and stay within spec.

Additionally I learned that alpha-to-one is a separate (and optional) feature which is not turned on by enabling alpha-to-coverage.

@kainino0x

Copy link
Copy Markdown
Contributor

though given the leniency of the alpha-to-coverage mask I think we could simply allow it and stay within spec.

I should say, I don't think this is necessary. Being strict here is probably best as it sets expectations that the two aren't likely to actually work together.

ben-clayton pushed a commit to ben-clayton/gpuweb that referenced this pull request Sep 6, 2022
This CL adds unimplemented stub tests for the `trunc` builtin.

Issues: gpuweb#1243
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Re-organize GPURenderPipelineDescriptor according to the structure of the GPU pipeline

4 participants