diff --git a/spirv_cross/build.rs b/spirv_cross/build.rs index 5583de12..d78e5477 100644 --- a/spirv_cross/build.rs +++ b/spirv_cross/build.rs @@ -20,6 +20,8 @@ fn main() { .file("src/wrapper.cpp") .file("src/vendor/SPIRV-Cross/spirv_cfg.cpp") .file("src/vendor/SPIRV-Cross/spirv_cross.cpp") + .file("src/vendor/SPIRV-Cross/spirv_cross_parsed_ir.cpp") + .file("src/vendor/SPIRV-Cross/spirv_parser.cpp") .file("src/vendor/SPIRV-Cross/spirv_cross_util.cpp") .file("src/vendor/SPIRV-Cross/spirv_glsl.cpp") .file("src/vendor/SPIRV-Cross/spirv_hlsl.cpp") diff --git a/spirv_cross/src/bindings.rs b/spirv_cross/src/bindings.rs index bb6f6d4d..b69a49fc 100644 --- a/spirv_cross/src/bindings.rs +++ b/spirv_cross/src/bindings.rs @@ -1481,18 +1481,22 @@ pub mod root { Void = 1, Boolean = 2, Char = 3, - Int = 4, - UInt = 5, - Int64 = 6, - UInt64 = 7, - AtomicCounter = 8, - Half = 9, - Float = 10, - Double = 11, - Struct = 12, - Image = 13, - SampledImage = 14, - Sampler = 15, + SByte = 4, + UByte = 5, + Short = 6, + UShort = 7, + Int = 8, + UInt = 9, + Int64 = 10, + UInt64 = 11, + AtomicCounter = 12, + Half = 13, + Float = 14, + Double = 15, + Struct = 16, + Image = 17, + SampledImage = 18, + Sampler = 19, } #[repr(C)] #[derive(Debug, Copy)] @@ -1505,6 +1509,13 @@ pub mod root { impl Clone for Resource { fn clone(&self) -> Self { *self } } + #[repr(u32)] + #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] + pub enum MSLVertexFormat { + MSL_VERTEX_FORMAT_OTHER = 0, + MSL_VERTEX_FORMAT_UINT8 = 1, + MSL_VERTEX_FORMAT_UINT16 = 2, + } #[repr(C)] #[derive(Debug, Copy)] pub struct MSLVertexAttr { @@ -1513,6 +1524,7 @@ pub mod root { pub msl_offset: u32, pub msl_stride: u32, pub per_instance: bool, + pub format: root::spirv_cross::MSLVertexFormat, pub used_by_shader: bool, } impl Clone for MSLVertexAttr { @@ -1597,7 +1609,6 @@ pub mod root { pub platform: u8, pub version: u32, pub enable_point_size_builtin: bool, - pub resolve_specialized_array_lengths: bool, pub disable_rasterization: bool, } impl Clone for ScMslCompilerOptions { diff --git a/spirv_cross/src/compiler.rs b/spirv_cross/src/compiler.rs index 5215a355..de8d3c1f 100644 --- a/spirv_cross/src/compiler.rs +++ b/spirv_cross/src/compiler.rs @@ -121,6 +121,10 @@ impl spirv::Type { b::Image => Image { array }, b::SampledImage => SampledImage { array }, b::Sampler => Sampler { array }, + b::SByte => SByte { array }, + b::UByte => UByte { array }, + b::Short => Short { array }, + b::UShort => UShort { array }, } } } diff --git a/spirv_cross/src/msl.rs b/spirv_cross/src/msl.rs index 34e81627..9bb6fd28 100644 --- a/spirv_cross/src/msl.rs +++ b/spirv_cross/src/msl.rs @@ -22,6 +22,26 @@ impl spirv::Target for Target { #[derive(Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)] pub struct VertexAttributeLocation(pub u32); +/// Format of the vertex attribute +#[derive(Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)] +pub enum Format { + Other, + Uint8, + Uint16, +} + +impl Format { + fn as_raw(&self) -> spirv_cross::MSLVertexFormat { + use self::Format::*; + use self::spirv_cross::MSLVertexFormat as R; + match self { + Other => R::MSL_VERTEX_FORMAT_OTHER, + Uint8 => R::MSL_VERTEX_FORMAT_UINT8, + Uint16 => R::MSL_VERTEX_FORMAT_UINT16, + } + } +} + /// Vertex attribute description for overriding #[derive(Debug, Clone, Hash, Eq, PartialEq)] pub struct VertexAttribute { @@ -30,6 +50,7 @@ pub struct VertexAttribute { pub stride: u32, pub step: spirv::VertexAttributeStep, pub force_used: bool, + pub format: Format, } /// Location of a resource binding to override @@ -107,8 +128,6 @@ pub struct CompilerOptions { pub vertex: CompilerVertexOptions, /// Whether the built-in point size should be enabled. pub enable_point_size_builtin: bool, - /// Whether array lengths should be resolved instead of specialized. - pub resolve_specialized_array_lengths: bool, /// Whether rasterization should be enabled. pub enable_rasterization: bool, /// MSL resource bindings overrides. @@ -125,7 +144,6 @@ impl CompilerOptions { platform: self.platform as _, version: self.version.as_raw(), enable_point_size_builtin: self.enable_point_size_builtin, - resolve_specialized_array_lengths: self.resolve_specialized_array_lengths, disable_rasterization: !self.enable_rasterization, } } @@ -138,7 +156,6 @@ impl Default for CompilerOptions { version: Version::V1_2, vertex: CompilerVertexOptions::default(), enable_point_size_builtin: true, - resolve_specialized_array_lengths: true, enable_rasterization: true, resource_binding_overrides: Default::default(), vertex_attribute_overrides: Default::default(), @@ -213,6 +230,7 @@ impl spirv::Compile for spirv::Ast { spirv::VertexAttributeStep::Instance => true, }, used_by_shader: vat.force_used, + format: vat.format.as_raw(), }) ); diff --git a/spirv_cross/src/spirv.rs b/spirv_cross/src/spirv.rs index f528b44d..dd3b6f03 100644 --- a/spirv_cross/src/spirv.rs +++ b/spirv_cross/src/spirv.rs @@ -184,6 +184,18 @@ pub enum Type { Sampler { array: Vec, }, + SByte { + array: Vec, + }, + UByte { + array: Vec, + }, + Short { + array: Vec, + }, + UShort { + array: Vec, + }, } /// A SPIR-V shader module. diff --git a/spirv_cross/src/vendor/SPIRV-Cross b/spirv_cross/src/vendor/SPIRV-Cross index bfbe36f6..52f26ee7 160000 --- a/spirv_cross/src/vendor/SPIRV-Cross +++ b/spirv_cross/src/vendor/SPIRV-Cross @@ -1 +1 @@ -Subproject commit bfbe36f6362fa277aa0f966e35927c9aedd60d01 +Subproject commit 52f26ee73648a25e9465035a55b276898f453830 diff --git a/spirv_cross/src/wrapper.cpp b/spirv_cross/src/wrapper.cpp index b6b23dd3..6f8c97a5 100644 --- a/spirv_cross/src/wrapper.cpp +++ b/spirv_cross/src/wrapper.cpp @@ -127,7 +127,6 @@ extern "C" msl_options.platform = static_cast(options->platform); msl_options.msl_version = options->version; msl_options.enable_point_size_builtin = options->enable_point_size_builtin; - msl_options.resolve_specialized_array_lengths = options->resolve_specialized_array_lengths; msl_options.disable_rasterization = options->disable_rasterization; compiler_msl->set_msl_options(msl_options); } while (0);) diff --git a/spirv_cross/src/wrapper.hpp b/spirv_cross/src/wrapper.hpp index 65211c86..9e8ab20d 100644 --- a/spirv_cross/src/wrapper.hpp +++ b/spirv_cross/src/wrapper.hpp @@ -59,7 +59,6 @@ extern "C" uint8_t platform; uint32_t version; bool enable_point_size_builtin; - bool resolve_specialized_array_lengths; bool disable_rasterization; } ScMslCompilerOptions; diff --git a/spirv_cross/tests/hlsl_tests.rs b/spirv_cross/tests/hlsl_tests.rs index 06b070e8..af0776c9 100644 --- a/spirv_cross/tests/hlsl_tests.rs +++ b/spirv_cross/tests/hlsl_tests.rs @@ -29,12 +29,13 @@ fn ast_compiles_to_hlsl() { assert_eq!( ast.compile().unwrap(), "\ -cbuffer _22 +cbuffer uniform_buffer_object { row_major float4x4 _22_u_model_view_projection : packoffset(c0); float _22_u_scale : packoffset(c4); }; + static float4 gl_Position; static float3 v_normal; static float3 a_normal;