Skip to content

Commit af2a9ee

Browse files
committed
Add specialization constants via #[spirv(spec_constant(id = 123))] x: u32 entry-point inputs.
1 parent 55edc4e commit af2a9ee

File tree

8 files changed

+333
-67
lines changed

8 files changed

+333
-67
lines changed

CHANGELOG.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3030
## [Unreleased]
3131

3232
### Added ⭐
33+
- [PR#1081](https://github.com/EmbarkStudios/rust-gpu/pull/1081) added the ability
34+
to access SPIR-V specialization constants (`OpSpecConstant`) via entry-point
35+
inputs declared as `#[spirv(spec_constant(id = ..., default = ...))] x: u32`
36+
(see also [the `#[spirv(spec_constant)]` attribute documentation](docs/src/attributes.md#specialization-constants))
3337
- [PR#1036](https://github.com/EmbarkStudios/rust-gpu/pull/1036) added a `--force-spirv-passthru` flag to `example-runner-wgpu`, to bypass Naga (`wgpu`'s shader translator),
3438
used it to test `debugPrintf` for `wgpu`, and updated `ShaderPanicStrategy::DebugPrintfThenExit` docs to reflect what "enabling `debugPrintf`" looks like for `wgpu`
3539
<sub><sup>(e.g. `VK_LOADER_LAYERS_ENABLE=VK_LAYER_KHRONOS_validation VK_LAYER_ENABLES=VK_VALIDATION_FEATURE_ENABLE_DEBUG_PRINTF_EXT DEBUG_PRINTF_TO_STDOUT=1`)</sup></sub>
3640
- [PR#1080](https://github.com/EmbarkStudios/rust-gpu/pull/1080) added `debugPrintf`-based
37-
panic reporting, with the desired behavior selected via `spirv_builder::ShaderPanicStrategy`
41+
panic reporting, with the desired behavior selected via `spirv_builder::ShaderPanicStrategy`
3842
(see its documentation for more details about each available panic handling strategy)
3943

4044
### Changed 🛠

crates/rustc_codegen_spirv/src/attr.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ pub enum IntrinsicType {
6868
Matrix,
6969
}
7070

71+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
72+
pub struct SpecConstant {
73+
pub id: u32,
74+
pub default: Option<u32>,
75+
}
76+
7177
// NOTE(eddyb) when adding new `#[spirv(...)]` attributes, the tests found inside
7278
// `tests/ui/spirv-attr` should be updated (and new ones added if necessary).
7379
#[derive(Debug, Clone)]
@@ -87,6 +93,7 @@ pub enum SpirvAttribute {
8793
Flat,
8894
Invariant,
8995
InputAttachmentIndex(u32),
96+
SpecConstant(SpecConstant),
9097

9198
// `fn`/closure attributes:
9299
BufferLoadIntrinsic,
@@ -121,6 +128,7 @@ pub struct AggregatedSpirvAttributes {
121128
pub flat: Option<Spanned<()>>,
122129
pub invariant: Option<Spanned<()>>,
123130
pub input_attachment_index: Option<Spanned<u32>>,
131+
pub spec_constant: Option<Spanned<SpecConstant>>,
124132

125133
// `fn`/closure attributes:
126134
pub buffer_load_intrinsic: Option<Spanned<()>>,
@@ -211,6 +219,12 @@ impl AggregatedSpirvAttributes {
211219
span,
212220
"#[spirv(attachment_index)]",
213221
),
222+
SpecConstant(value) => try_insert(
223+
&mut self.spec_constant,
224+
value,
225+
span,
226+
"#[spirv(spec_constant)]",
227+
),
214228
BufferLoadIntrinsic => try_insert(
215229
&mut self.buffer_load_intrinsic,
216230
(),
@@ -300,7 +314,8 @@ impl CheckSpirvAttrVisitor<'_> {
300314
| SpirvAttribute::Binding(_)
301315
| SpirvAttribute::Flat
302316
| SpirvAttribute::Invariant
303-
| SpirvAttribute::InputAttachmentIndex(_) => match target {
317+
| SpirvAttribute::InputAttachmentIndex(_)
318+
| SpirvAttribute::SpecConstant(_) => match target {
304319
Target::Param => {
305320
let parent_hir_id = self.tcx.hir().parent_id(hir_id);
306321
let parent_is_entry_point =

0 commit comments

Comments
 (0)