Skip to content

Commit f8f9b10

Browse files
committed
[mtl] Set rasterization flag based on vertex shader requirements
1 parent e7b3ede commit f8f9b10

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

src/backend/metal/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ block = "0.1"
3131
cocoa = "0.18"
3232
core-graphics = "0.17"
3333
smallvec = "0.6"
34-
spirv_cross = "0.10"
34+
spirv_cross = "0.11.1"
3535
parking_lot = "0.6.3"
3636
storage-map = "0.1.2"

src/backend/metal/src/device.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,10 @@ impl Device {
652652
}
653653

654654
pub fn create_shader_library_from_source<S>(
655-
&self, source: S, version: LanguageVersion,
655+
&self,
656+
source: S,
657+
version: LanguageVersion,
658+
rasterization_enabled: bool,
656659
) -> Result<n::ShaderModule, ShaderError> where S: AsRef<str> {
657660
let options = metal::CompileOptions::new();
658661
let msl_version = match version {
@@ -673,6 +676,7 @@ impl Device {
673676
.map(|library| n::ShaderModule::Compiled(n::ModuleInfo {
674677
library,
675678
entry_point_map: n::EntryPointMap::default(),
679+
rasterization_enabled,
676680
}))
677681
.map_err(|e| ShaderError::CompilationFailed(e.into()))
678682
}
@@ -737,6 +741,9 @@ impl Device {
737741
});
738742
}
739743

744+
let rasterization_enabled = ast.is_rasterization_enabled()
745+
.map_err(|_| ShaderError::CompilationFailed("Unknown compile error".into()))?;
746+
740747
// done
741748
debug!("SPIRV-Cross generated shader:\n{}", shader_code);
742749

@@ -751,6 +758,7 @@ impl Device {
751758
Ok(n::ModuleInfo {
752759
library,
753760
entry_point_map,
761+
rasterization_enabled,
754762
})
755763
}
756764

@@ -760,7 +768,7 @@ impl Device {
760768
layout: &n::PipelineLayout,
761769
primitive_class: MTLPrimitiveTopologyClass,
762770
pipeline_cache: Option<&n::PipelineCache>,
763-
) -> Result<(metal::Library, metal::Function, metal::MTLSize), pso::CreationError> {
771+
) -> Result<(metal::Library, metal::Function, metal::MTLSize, bool), pso::CreationError> {
764772
let device = &self.shared.device;
765773
let msl_version = self.private_caps.msl_version;
766774
let module_map;
@@ -812,7 +820,7 @@ impl Device {
812820
pso::CreationError::Other
813821
})?;
814822

815-
Ok((lib, mtl_function, wg_size))
823+
Ok((lib, mtl_function, wg_size, info.rasterization_enabled))
816824
}
817825

818826
fn describe_argument(
@@ -1209,7 +1217,7 @@ impl hal::Device<Backend> for Device {
12091217
pipeline.set_input_primitive_topology(primitive_class);
12101218

12111219
// Vertex shader
1212-
let (vs_lib, vs_function, _) = self.load_shader(
1220+
let (vs_lib, vs_function, _, enable_rasterization) = self.load_shader(
12131221
&pipeline_desc.shaders.vertex,
12141222
pipeline_layout,
12151223
primitive_class,
@@ -1221,7 +1229,7 @@ impl hal::Device<Backend> for Device {
12211229
let fs_function;
12221230
let fs_lib = match pipeline_desc.shaders.fragment {
12231231
Some(ref ep) => {
1224-
let (lib, fun, _) = self.load_shader(ep, pipeline_layout, primitive_class, cache)?;
1232+
let (lib, fun, _, _) = self.load_shader(ep, pipeline_layout, primitive_class, cache)?;
12251233
fs_function = fun;
12261234
pipeline.set_fragment_function(Some(&fs_function));
12271235
Some(lib)
@@ -1247,6 +1255,8 @@ impl hal::Device<Backend> for Device {
12471255
return Err(pso::CreationError::Shader(ShaderError::UnsupportedStage(pso::Stage::Geometry)));
12481256
}
12491257

1258+
pipeline.set_rasterization_enabled(enable_rasterization);
1259+
12501260
// Assign target formats
12511261
let blend_targets = pipeline_desc.blender.targets
12521262
.iter()
@@ -1428,7 +1438,7 @@ impl hal::Device<Backend> for Device {
14281438
debug!("create_compute_pipeline {:?}", pipeline_desc);
14291439
let pipeline = metal::ComputePipelineDescriptor::new();
14301440

1431-
let (cs_lib, cs_function, work_group_size) = self.load_shader(
1441+
let (cs_lib, cs_function, work_group_size, _) = self.load_shader(
14321442
&pipeline_desc.shader,
14331443
&pipeline_desc.layout,
14341444
MTLPrimitiveTopologyClass::Unspecified,

src/backend/metal/src/native.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ impl PipelineLayout {
210210
pub struct ModuleInfo {
211211
pub library: metal::Library,
212212
pub entry_point_map: EntryPointMap,
213+
pub rasterization_enabled: bool,
213214
}
214215

215216
pub struct PipelineCache {

0 commit comments

Comments
 (0)