Skip to content

Commit 9cd815f

Browse files
committed
Match entrypoints by both stage and name
1 parent 45a888d commit 9cd815f

File tree

11 files changed

+33
-29
lines changed

11 files changed

+33
-29
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Naga now infers the correct binding layout when a resource appears only in an as
6868
#### Naga
6969

7070
- Mark `readonly_and_readwrite_storage_textures` & `packed_4x8_integer_dot_product` language extensions as implemented. By @teoxoy in [#7543](https://github.com/gfx-rs/wgpu/pull/7543)
71-
- `naga::back::hlsl::Writer::new` has a new `pipeline_options` argument. `hlsl::PipelineOptions::default()` can be passed as a default. The `entry_point` member of `pipeline_options` can be used to write only a single entry point when using the HLSL and MSL backends (GLSL and SPIR-V already had this functionality). The Metal and DX12 HALs now write only a single entry point when loading shaders. By @andyleiserson in [#7626](https://github.com/gfx-rs/wgpu/pull/7626).
71+
- `naga::back::hlsl::Writer::new` has a new `pipeline_options` argument. `hlsl::PipelineOptions::default()` can be passed as a default. The `shader_stage` and `entry_point` members of `pipeline_options` can be used to write only a single entry point when using the HLSL and MSL backends (GLSL and SPIR-V already had this functionality). The Metal and DX12 HALs now write only a single entry point when loading shaders. By @andyleiserson in [#7626](https://github.com/gfx-rs/wgpu/pull/7626).
7272

7373
#### D3D12
7474

benches/benches/wgpu-benchmark/shader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ fn backends(c: &mut Criterion) {
349349
let options = naga::back::hlsl::Options::default();
350350
let mut string = String::new();
351351
for input in &inputs.inner {
352-
let pipeline_options = naga::back::hlsl::PipelineOptions { entry_point: None };
352+
let pipeline_options = Default::default();
353353
let mut writer =
354354
naga::back::hlsl::Writer::new(&mut string, &options, &pipeline_options);
355355
let _ = writer.write(

naga-cli/src/bin/naga.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ fn write_output(
824824
.unwrap_pretty();
825825

826826
let mut buffer = String::new();
827-
let pipeline_options = hlsl::PipelineOptions { entry_point: None };
827+
let pipeline_options = Default::default();
828828
let mut writer = hlsl::Writer::new(&mut buffer, &params.hlsl, &pipeline_options);
829829
writer.write(&module, &info, None).unwrap_pretty();
830830
fs::write(output_path, buffer)?;

naga/src/back/hlsl/mod.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ use core::fmt::Error as FmtError;
119119

120120
use thiserror::Error;
121121

122-
use crate::{back, proc};
122+
use crate::{back, ir, proc};
123123

124124
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
125125
#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
@@ -442,9 +442,12 @@ pub struct ReflectionInfo {
442442
pub struct PipelineOptions {
443443
/// The entry point to write.
444444
///
445+
/// Entry points are identified by a shader stage specification,
446+
/// and a name.
447+
///
445448
/// If `None`, all entry points will be written. If `Some` and the entry
446449
/// point is not found, an error will be thrown while writing.
447-
pub entry_point: Option<String>,
450+
pub entry_point: Option<(ir::ShaderStage, String)>,
448451
}
449452

450453
#[derive(Error, Debug)]
@@ -461,8 +464,8 @@ pub enum Error {
461464
Override,
462465
#[error(transparent)]
463466
ResolveArraySizeError(#[from] proc::ResolveArraySizeError),
464-
#[error("entry point with name '{0}' not found")]
465-
EntryPointNotFound(String),
467+
#[error("entry point with stage {0:?} and name '{1}' not found")]
468+
EntryPointNotFound(ir::ShaderStage, String),
466469
}
467470

468471
#[derive(PartialEq, Eq, Hash)]

naga/src/back/hlsl/writer.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use alloc::{
2-
borrow::ToOwned,
32
format,
43
string::{String, ToString},
54
vec::Vec,
@@ -389,8 +388,8 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
389388
writeln!(self.out)?;
390389
}
391390

392-
let ep_range = get_entry_points(module, self.pipeline_options.entry_point.as_deref())
393-
.map_err(|name| Error::EntryPointNotFound(name.to_owned()))?;
391+
let ep_range = get_entry_points(module, self.pipeline_options.entry_point.as_ref())
392+
.map_err(|(stage, name)| Error::EntryPointNotFound(stage, name))?;
394393

395394
// Write all entry points wrapped structs
396395
for index in ep_range.clone() {

naga/src/back/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Backend functions that export shader [`Module`](super::Module)s into binary and
99
)
1010
)]
1111

12-
use alloc::string::String;
12+
use alloc::{borrow::ToOwned, string::String};
1313

1414
#[cfg(dot_out)]
1515
pub mod dot;
@@ -86,17 +86,17 @@ impl core::fmt::Display for Level {
8686
/// `entry_point` is given, returns the complete range of entry point indices.
8787
/// If `entry_point` is given but does not exist, returns an error.
8888
#[cfg(any(hlsl_out, msl_out))]
89-
fn get_entry_points<'a>(
89+
fn get_entry_points(
9090
module: &crate::ir::Module,
91-
entry_point: Option<&'a str>,
92-
) -> Result<core::ops::Range<usize>, &'a str> {
93-
if let Some(entry_point) = entry_point {
91+
entry_point: Option<&(crate::ir::ShaderStage, String)>,
92+
) -> Result<core::ops::Range<usize>, (crate::ir::ShaderStage, String)> {
93+
if let Some(&(stage, ref name)) = entry_point {
9494
let Some(ep_index) = module
9595
.entry_points
9696
.iter()
97-
.position(|ep| ep.name == *entry_point)
97+
.position(|ep| ep.stage == stage && ep.name == *name)
9898
else {
99-
return Err(entry_point);
99+
return Err((stage, name.to_owned()));
100100
};
101101
Ok(ep_index..ep_index + 1)
102102
} else {

naga/src/back/msl/mod.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ use alloc::{
5252
};
5353
use core::fmt::{Error as FmtError, Write};
5454

55-
use crate::{arena::Handle, proc::index, valid::ModuleInfo};
55+
use crate::{arena::Handle, ir, proc::index, valid::ModuleInfo};
5656

5757
mod keywords;
5858
pub mod sampler;
@@ -184,7 +184,7 @@ pub enum Error {
184184
#[error("can not use writeable storage buffers in fragment stage prior to MSL 1.2")]
185185
UnsupportedWriteableStorageBuffer,
186186
#[error("can not use writeable storage textures in {0:?} stage prior to MSL 1.2")]
187-
UnsupportedWriteableStorageTexture(crate::ShaderStage),
187+
UnsupportedWriteableStorageTexture(ir::ShaderStage),
188188
#[error("can not use read-write storage textures prior to MSL 1.2")]
189189
UnsupportedRWStorageTexture,
190190
#[error("array of '{0}' is not supported for target MSL version")]
@@ -199,8 +199,8 @@ pub enum Error {
199199
UnsupportedBitCast(crate::TypeInner),
200200
#[error(transparent)]
201201
ResolveArraySizeError(#[from] crate::proc::ResolveArraySizeError),
202-
#[error("entry point with name '{0}' not found")]
203-
EntryPointNotFound(String),
202+
#[error("entry point with stage {0:?} and name '{1}' not found")]
203+
EntryPointNotFound(ir::ShaderStage, String),
204204
}
205205

206206
#[derive(Clone, Debug, PartialEq, thiserror::Error)]
@@ -424,9 +424,12 @@ pub struct VertexBufferMapping {
424424
pub struct PipelineOptions {
425425
/// The entry point to write.
426426
///
427+
/// Entry points are identified by a shader stage specification,
428+
/// and a name.
429+
///
427430
/// If `None`, all entry points will be written. If `Some` and the entry
428431
/// point is not found, an error will be thrown while writing.
429-
pub entry_point: Option<String>,
432+
pub entry_point: Option<(ir::ShaderStage, String)>,
430433

431434
/// Allow `BuiltIn::PointSize` and inject it if doesn't exist.
432435
///
@@ -745,5 +748,5 @@ pub fn write_string(
745748

746749
#[test]
747750
fn test_error_size() {
748-
assert_eq!(size_of::<Error>(), 32);
751+
assert_eq!(size_of::<Error>(), 40);
749752
}

naga/src/back/msl/writer.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use alloc::{
2-
borrow::ToOwned,
32
format,
43
string::{String, ToString},
54
vec,
@@ -5873,8 +5872,8 @@ template <typename A>
58735872
self.named_expressions.clear();
58745873
}
58755874

5876-
let ep_range = get_entry_points(module, pipeline_options.entry_point.as_deref())
5877-
.map_err(|name| Error::EntryPointNotFound(name.to_owned()))?;
5875+
let ep_range = get_entry_points(module, pipeline_options.entry_point.as_ref())
5876+
.map_err(|(stage, name)| Error::EntryPointNotFound(stage, name))?;
58785877

58795878
let mut info = TranslationInfo {
58805879
entry_point_names: Vec::with_capacity(ep_range.len()),

naga/tests/naga/snapshots.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ fn write_output_hlsl(
741741
.expect("override evaluation failed");
742742

743743
let mut buffer = String::new();
744-
let pipeline_options = hlsl::PipelineOptions { entry_point: None };
744+
let pipeline_options = Default::default();
745745
let mut writer = hlsl::Writer::new(&mut buffer, options, &pipeline_options);
746746
let reflection_info = writer
747747
.write(&module, &info, frag_ep.as_ref())

wgpu-hal/src/dx12/device.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ impl super::Device {
300300
};
301301

302302
let pipeline_options = hlsl::PipelineOptions {
303-
entry_point: Some(stage.entry_point.to_string()),
303+
entry_point: Some((naga_stage, stage.entry_point.to_string())),
304304
};
305305

306306
//TODO: reuse the writer

0 commit comments

Comments
 (0)