The MSL backend emits a loop's `continuing` block at the top of the
`while` loop, above the body. Values the body computed and `continuing`
referenced were then either re-evaluated in place, reading whatever
state the body had left behind, or, for statement results such as call
results, hit an `unreachable!` panic.
Now, when a loop has a `continuing` block or `break_if`, the
temporaries it needs from the body are declared ahead of the loop, and
the body assigns to them instead of declaring them.
The WebGPU specification requires pipeline creation to validate
properties of shader stages, like workgroup sizes, that may depend on
the values of pipeline-overridable constants. Previously, wgpu-core
validated stages using an `Interface` built from the module before
overrides were applied, with results contrary to spec. Override
processing was then carried out by `wgpu_hal`, after all validation
had supposedly been taken care of.
This commit has `create_shader_module` save the validated Naga module
instead of creating a `wgpu_hal` shader module. At pipeline creation
time, `StageCompiler::compile` now applies the stage's override values
with `process_overrides`, validates the stage using an `Interface`
built from the result, and, if that validation succeeds, returns a
`CompiledStage` holding the `wgpu_hal` `ShaderModule` created from it.
Dropping the `CompiledStage` destroys that module once the pipeline
has been created.
Since the override values have already been applied, we pass
`wgpu_hal` empty sets of constants for these modules.
Since the `naga::back::pipeline_constants` module is now used by
`wgpu_core` rather than `wgpu_hal` backends, it can't be conditionally
available based on Naga's backend features. Include it
unconditionally.
This change removes `Interface::finalize_entry_point_name`, since we
no longer build an `Interface` at shader module creation. Instead, we
choose entry points from the `naga::Module` directly.
Add new tests: `tests/tests/wgpu-validation/api/overrides.rs`
Fixes#9774.
Introduce `StageCompiler`, in the new `wgpu_core::device::stage_compiler`
module, which performs the per-stage work that
`create_compute_pipeline_or_error_inner` and
`create_render_pipeline_or_error_inner` previously repeated for each
stage: checking the shader module's validity and device, choosing
the entry point, checking the stage against the module's interface,
and tracking which stages were validated.
`StageCompiler::compile` returns a `CompiledStage`, which borrows the
module the stage should use, and records the entry point name. From
this we can build a `hal::ProgrammableStage` to use when creating the
hal pipeline.
Have `StageCompiler::compile` reject a passthrough stage immediately
if the pipeline's layout is being derived. `ImplicitLayoutError::Passthrough`
now names only that stage, rather than every passthrough stage in the
pipeline.
Remove `ImplicitLayoutError::ReflectionError`, along with the check
that reported it. The condition it was concerned with, deriving a
layout from a stage we couldn't reflect, is already rejected as
`ImplicitLayoutError::Passthrough`. The only way left to reach it was
a bug: for mesh pipelines without a fragment stage, it expected the
last stage to be a vertex stage, and so rejected them incorrectly.
In this commit, `StageCompiler` only does validation, but by the end
of this pull request, it will be compiling shader modules. Having its
name overstate its role for one commit seems clearer than introducing
everything in one commit and renaming it in the next. The comments,
however, are accurate in each commit.
This commit also changes compute pipelines to report errors in the
same way as render pipelines: an invalid shader module is now reported
as a `CreatePipelineError::Stage` error, and the shader module is
checked after the pipeline layout, not before.
Gather the state that `Interface::check_stage` accumulates across all
of a pipeline's stages (the bind group layouts, minimum binding sizes,
and immediate data usage) into a new `PipelineResources` struct, which
`check_stage` takes by `&mut`.
Remove `immediates` from `StageIo`, so that `StageIo` holds only the
information one stage passes to the next.
Use `layout` to refer to the `BindingLayoutSource`, not `layouts`,
since that value describes a single pipeline layout. In the derived
case, it does hold an array of bind group layouts, but that is only
one variant; the value's name should make sense regardless which
variant is present.
In `wgpu_core/src/device/resource.rs`, in the function
`Device::create_render_pipeline_or_error_inner`, remove the leading
`_` from the following local variables' names, and simply leave them
uninitialized in their declaration:
- `_vertex_entry_point_name`
- `_task_entry_point_name`
- `_mesh_entry_point_name`
Rust is smart enough to see that these are always initialized before
they are used, and thus don't need to be initialized at their
declaration.
In `wgpu_core::pipeline`, delete `ShaderMetaData` and turn
`ShaderModuleState` into the equivalent enum, giving both the
`NagaModule` and `Passthrough` variants their own `raw` field.
Arrange for uses of `ShaderModuleState` to extract the raw `wgpu_hal`
module in the `match` expression that handles the two variants.
In isolation, this change looks like mere rearrangement, not a
cleanup, but hopefully either way it's easy to see that it has no
effect on behavior. Subsequent commits will remove `raw` from the
`NagaModule` variant; this refactor will allow that to affect only the
`NagaModule` `match` arms, leaving the passthrough code unaffected.
Move the definitions of `ShaderMetaData` and `PassthroughInterface`
from `wgpu_core::validation`, which does not use them, to
`wgpu_core::pipeline`, where they are used in `ShaderModuleState`, and
created.
Slightly reorder the sites that consume `ShaderMetaData` values, so
that the code for the `NagaModule` and `Passthrough` cases can be
gathered into `match` statements.
Rename the `ShaderMetaData::Interface` variant to `NagaModule`,
and make it a struct-like variant.
Delete `ShaderMetaData::interface`, and update its call sites to use a
`match` expression directly on the enum instead. This makes the use
sites clearer, by making it apparent which style of module we're
processing.
this is important as we need to return Abort error instead of Operation error which is raised on invalid buffer
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>