Skip to content
This repository has been archived by the owner on Jan 29, 2025. It is now read-only.

[msl-out] Add and fix min version checks #2486

Merged
merged 8 commits into from
Oct 17, 2023
48 changes: 37 additions & 11 deletions src/back/msl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,22 @@ pub enum Error {
UnsupportedBuiltIn(crate::BuiltIn),
#[error("capability {0:?} is not supported")]
CapabilityNotSupported(crate::valid::Capabilities),
#[error("address space {0:?} is not supported for target MSL version")]
UnsupportedAddressSpace(crate::AddressSpace),
#[error("attribute '{0}' is not supported for target MSL version")]
UnsupportedAttribute(String),
#[error("function '{0}' is not supported for target MSL version")]
UnsupportedFunction(String),
#[error("can not use writeable storage buffers in fragment stage prior to MSL 1.2")]
UnsupportedWriteableStorageBuffer,
#[error("can not use writeable storage textures in {0:?} stage prior to MSL 1.2")]
UnsupportedWriteableStorageTexture(crate::ShaderStage),
#[error("can not use read-write storage textures prior to MSL 1.2")]
UnsupportedRWStorageTexture,
#[error("array of '{0}' is not supported for target MSL version")]
UnsupportedArrayOf(String),
#[error("array of type '{0:?}' is not supported")]
UnsupportedArrayOfType(Handle<crate::Type>),
#[error("ray tracing is not supported prior to MSL 2.3")]
UnsupportedRayTracing,
}

#[derive(Clone, Debug, PartialEq, thiserror::Error)]
Expand Down Expand Up @@ -197,7 +209,7 @@ pub struct Options {
impl Default for Options {
fn default() -> Self {
Options {
lang_version: (2, 0),
lang_version: (1, 0),
per_entry_point_map: EntryPointResourceMap::default(),
inline_samplers: Vec::new(),
spirv_cross_compatibility: false,
Expand Down Expand Up @@ -230,16 +242,30 @@ impl Options {
) -> Result<ResolvedBinding, Error> {
match *binding {
crate::Binding::BuiltIn(mut built_in) => {
if let crate::BuiltIn::Position { ref mut invariant } = built_in {
if *invariant && self.lang_version < (2, 1) {
return Err(Error::UnsupportedAttribute("invariant".to_string()));
match built_in {
crate::BuiltIn::Position { ref mut invariant } => {
if *invariant && self.lang_version < (2, 1) {
return Err(Error::UnsupportedAttribute("invariant".to_string()));
}

// The 'invariant' attribute may only appear on vertex
// shader outputs, not fragment shader inputs.
if !matches!(mode, LocationMode::VertexOutput) {
*invariant = false;
}
}

// The 'invariant' attribute may only appear on vertex
// shader outputs, not fragment shader inputs.
if !matches!(mode, LocationMode::VertexOutput) {
*invariant = false;
crate::BuiltIn::BaseInstance if self.lang_version < (1, 2) => {
return Err(Error::UnsupportedAttribute("base_instance".to_string()));
}
crate::BuiltIn::InstanceIndex if self.lang_version < (1, 2) => {
return Err(Error::UnsupportedAttribute("instance_id".to_string()));
}
// macOS: Since Metal 2.2
// iOS: Since Metal 2.3 (check depends on https://github.com/gfx-rs/naga/issues/2164)
crate::BuiltIn::PrimitiveIndex if self.lang_version < (2, 2) => {
return Err(Error::UnsupportedAttribute("primitive_id".to_string()));
}
_ => {}
}

Ok(ResolvedBinding::BuiltIn(built_in))
Expand Down
234 changes: 201 additions & 33 deletions src/back/msl/writer.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/in/access.param.ron
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
adjust_coordinate_space: false,
),
msl: (
lang_version: (2, 0),
lang_version: (1, 2),
jimblandy marked this conversation as resolved.
Show resolved Hide resolved
per_entry_point_map: {
"foo_vert": (
resources: {
Expand Down
2 changes: 1 addition & 1 deletion tests/in/bitcast.params.ron
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(
msl: (
lang_version: (1, 2),
lang_version: (1, 0),
per_entry_point_map: {
"main": (
resources: {
Expand Down
2 changes: 1 addition & 1 deletion tests/in/boids.param.ron
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
adjust_coordinate_space: false,
),
msl: (
lang_version: (2, 0),
lang_version: (1, 0),
per_entry_point_map: {
"main": (
resources: {
Expand Down
8 changes: 8 additions & 0 deletions tests/in/bounds-check-image-restrict.param.ron
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,12 @@
binding_map: { },
zero_initialize_workgroup_memory: true,
),
msl: (
lang_version: (1, 2),
per_entry_point_map: {},
inline_samplers: [],
spirv_cross_compatibility: false,
fake_missing_bindings: true,
zero_initialize_workgroup_memory: true,
),
)
8 changes: 8 additions & 0 deletions tests/in/bounds-check-image-rzsw.param.ron
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,12 @@
binding_map: { },
zero_initialize_workgroup_memory: true,
),
msl: (
lang_version: (1, 2),
per_entry_point_map: {},
inline_samplers: [],
spirv_cross_compatibility: false,
fake_missing_bindings: true,
zero_initialize_workgroup_memory: true,
),
)
18 changes: 8 additions & 10 deletions tests/in/dualsource.param.ron
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
(
god_mode: true,
vertex:[
],
fragment:[
(
entry_point:"main",
target_profile:"ps_5_1",
),
],
compute:[
],
msl: (
lang_version: (1, 2),
per_entry_point_map: {},
inline_samplers: [],
spirv_cross_compatibility: false,
fake_missing_bindings: false,
zero_initialize_workgroup_memory: true,
),
)
2 changes: 1 addition & 1 deletion tests/in/padding.param.ron
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
adjust_coordinate_space: false,
),
msl: (
lang_version: (2, 0),
lang_version: (1, 0),
per_entry_point_map: {
"vertex": (
resources: {
Expand Down
2 changes: 1 addition & 1 deletion tests/in/resource-binding-map.param.ron
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(
god_mode: true,
msl: (
lang_version: (2, 0),
lang_version: (1, 0),
per_entry_point_map: {
"entry_point_one": (
resources: {
Expand Down
2 changes: 1 addition & 1 deletion tests/in/workgroup-var-init.param.ron
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
adjust_coordinate_space: false,
),
msl: (
lang_version: (2, 0),
lang_version: (1, 0),
per_entry_point_map: {
"main": (
resources: {
Expand Down
2 changes: 1 addition & 1 deletion tests/out/msl/access.msl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// language: metal2.0
// language: metal1.2
#include <metal_stdlib>
#include <simd/simd.h>

Expand Down
2 changes: 1 addition & 1 deletion tests/out/msl/array-in-ctor.msl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// language: metal2.0
// language: metal1.0
#include <metal_stdlib>
#include <simd/simd.h>

Expand Down
2 changes: 1 addition & 1 deletion tests/out/msl/array-in-function-return-type.msl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// language: metal2.0
// language: metal1.0
#include <metal_stdlib>
#include <simd/simd.h>

Expand Down
2 changes: 1 addition & 1 deletion tests/out/msl/atomicOps.msl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// language: metal2.0
// language: metal1.0
#include <metal_stdlib>
#include <simd/simd.h>

Expand Down
2 changes: 1 addition & 1 deletion tests/out/msl/bitcast.msl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// language: metal2.0
// language: metal1.0
#include <metal_stdlib>
#include <simd/simd.h>

Expand Down
2 changes: 1 addition & 1 deletion tests/out/msl/boids.msl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// language: metal2.0
// language: metal1.0
#include <metal_stdlib>
#include <simd/simd.h>

Expand Down
2 changes: 1 addition & 1 deletion tests/out/msl/bounds-check-image-restrict.msl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// language: metal2.0
// language: metal1.2
#include <metal_stdlib>
#include <simd/simd.h>

Expand Down
2 changes: 1 addition & 1 deletion tests/out/msl/bounds-check-image-rzsw.msl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// language: metal2.0
// language: metal1.2
#include <metal_stdlib>
#include <simd/simd.h>

Expand Down
2 changes: 1 addition & 1 deletion tests/out/msl/bounds-check-restrict.msl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// language: metal2.0
// language: metal1.0
#include <metal_stdlib>
#include <simd/simd.h>

Expand Down
2 changes: 1 addition & 1 deletion tests/out/msl/bounds-check-zero-atomic.msl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// language: metal2.0
// language: metal1.0
#include <metal_stdlib>
#include <simd/simd.h>

Expand Down
2 changes: 1 addition & 1 deletion tests/out/msl/bounds-check-zero.msl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// language: metal2.0
// language: metal1.0
#include <metal_stdlib>
#include <simd/simd.h>

Expand Down
2 changes: 1 addition & 1 deletion tests/out/msl/break-if.msl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// language: metal2.0
// language: metal1.0
#include <metal_stdlib>
#include <simd/simd.h>

Expand Down
2 changes: 1 addition & 1 deletion tests/out/msl/collatz.msl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// language: metal2.0
// language: metal1.0
#include <metal_stdlib>
#include <simd/simd.h>

Expand Down
2 changes: 1 addition & 1 deletion tests/out/msl/const-exprs.msl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// language: metal2.0
// language: metal1.0
#include <metal_stdlib>
#include <simd/simd.h>

Expand Down
2 changes: 1 addition & 1 deletion tests/out/msl/constructors.msl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// language: metal2.0
// language: metal1.0
#include <metal_stdlib>
#include <simd/simd.h>

Expand Down
2 changes: 1 addition & 1 deletion tests/out/msl/control-flow.msl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// language: metal2.0
// language: metal1.0
#include <metal_stdlib>
#include <simd/simd.h>

Expand Down
2 changes: 1 addition & 1 deletion tests/out/msl/do-while.msl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// language: metal2.0
// language: metal1.0
#include <metal_stdlib>
#include <simd/simd.h>

Expand Down
2 changes: 1 addition & 1 deletion tests/out/msl/dualsource.msl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// language: metal2.0
// language: metal1.2
#include <metal_stdlib>
#include <simd/simd.h>

Expand Down
2 changes: 1 addition & 1 deletion tests/out/msl/empty-global-name.msl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// language: metal2.0
// language: metal1.0
#include <metal_stdlib>
#include <simd/simd.h>

Expand Down
2 changes: 1 addition & 1 deletion tests/out/msl/empty.msl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// language: metal2.0
// language: metal1.0
#include <metal_stdlib>
#include <simd/simd.h>

Expand Down
2 changes: 1 addition & 1 deletion tests/out/msl/fragment-output.msl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// language: metal2.0
// language: metal1.0
#include <metal_stdlib>
#include <simd/simd.h>

Expand Down
2 changes: 1 addition & 1 deletion tests/out/msl/functions.msl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// language: metal2.0
// language: metal1.0
#include <metal_stdlib>
#include <simd/simd.h>

Expand Down
2 changes: 1 addition & 1 deletion tests/out/msl/globals.msl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// language: metal2.0
// language: metal1.0
#include <metal_stdlib>
#include <simd/simd.h>

Expand Down
2 changes: 1 addition & 1 deletion tests/out/msl/image.msl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// language: metal2.0
// language: metal1.0
#include <metal_stdlib>
#include <simd/simd.h>

Expand Down
2 changes: 1 addition & 1 deletion tests/out/msl/interpolate.msl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// language: metal2.0
// language: metal1.0
#include <metal_stdlib>
#include <simd/simd.h>

Expand Down
2 changes: 1 addition & 1 deletion tests/out/msl/math-functions.msl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// language: metal2.0
// language: metal1.0
#include <metal_stdlib>
#include <simd/simd.h>

Expand Down
2 changes: 1 addition & 1 deletion tests/out/msl/msl-varyings.msl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// language: metal2.0
// language: metal1.0
#include <metal_stdlib>
#include <simd/simd.h>

Expand Down
2 changes: 1 addition & 1 deletion tests/out/msl/operators.msl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// language: metal2.0
// language: metal1.0
#include <metal_stdlib>
#include <simd/simd.h>

Expand Down
2 changes: 1 addition & 1 deletion tests/out/msl/padding.msl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// language: metal2.0
// language: metal1.0
#include <metal_stdlib>
#include <simd/simd.h>

Expand Down
2 changes: 1 addition & 1 deletion tests/out/msl/policy-mix.msl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// language: metal2.0
// language: metal1.0
#include <metal_stdlib>
#include <simd/simd.h>

Expand Down
2 changes: 1 addition & 1 deletion tests/out/msl/quad-vert.msl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// language: metal2.0
// language: metal1.0
#include <metal_stdlib>
#include <simd/simd.h>

Expand Down
2 changes: 1 addition & 1 deletion tests/out/msl/quad.msl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// language: metal2.0
// language: metal1.0
#include <metal_stdlib>
#include <simd/simd.h>

Expand Down
2 changes: 1 addition & 1 deletion tests/out/msl/resource-binding-map.msl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// language: metal2.0
// language: metal1.0
#include <metal_stdlib>
#include <simd/simd.h>

Expand Down
2 changes: 1 addition & 1 deletion tests/out/msl/shadow.msl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// language: metal2.0
// language: metal1.0
#include <metal_stdlib>
#include <simd/simd.h>

Expand Down
2 changes: 1 addition & 1 deletion tests/out/msl/standard.msl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// language: metal2.0
// language: metal1.0
#include <metal_stdlib>
#include <simd/simd.h>

Expand Down
2 changes: 1 addition & 1 deletion tests/out/msl/texture-arg.msl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// language: metal2.0
// language: metal1.0
#include <metal_stdlib>
#include <simd/simd.h>

Expand Down
2 changes: 1 addition & 1 deletion tests/out/msl/workgroup-uniform-load.msl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// language: metal2.0
// language: metal1.0
#include <metal_stdlib>
#include <simd/simd.h>

Expand Down
Loading