diff --git a/src/back/hlsl/image.rs b/src/back/hlsl/image.rs index 85d5791da..67e940d2d 100644 --- a/src/back/hlsl/image.rs +++ b/src/back/hlsl/image.rs @@ -98,7 +98,7 @@ impl<'a, W: Write> super::Writer<'a, W> { &mut self, query: WrappedImageQuery, ) -> BackendResult { - let dim_str = super::writer::image_dimension_str(query.dim); + let dim_str = query.dim.to_hlsl_str(); let class_str = match query.class { crate::ImageClass::Sampled { multi: true, .. } => "MS", crate::ImageClass::Depth => "Depth", diff --git a/src/back/hlsl/mod.rs b/src/back/hlsl/mod.rs index f6ab3450d..e9f103036 100644 --- a/src/back/hlsl/mod.rs +++ b/src/back/hlsl/mod.rs @@ -57,6 +57,17 @@ impl crate::ShaderStage { } } +impl crate::ImageDimension { + fn to_hlsl_str(self) -> &'static str { + match self { + Self::D1 => "1D", + Self::D2 => "2D", + Self::D3 => "3D", + Self::Cube => "Cube", + } + } +} + #[derive(Clone, Debug, PartialEq, thiserror::Error)] #[cfg_attr(feature = "serialize", derive(serde::Serialize))] #[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] diff --git a/src/back/hlsl/writer.rs b/src/back/hlsl/writer.rs index 45d2ac7be..245fb78e7 100644 --- a/src/back/hlsl/writer.rs +++ b/src/back/hlsl/writer.rs @@ -343,7 +343,7 @@ impl<'a, W: Write> Writer<'a, W> { let (storage, register_ty) = match global.class { crate::StorageClass::Function => unreachable!("Function storage class"), crate::StorageClass::Private => ("static ", ""), - crate::StorageClass::WorkGroup => ("shared ", ""), + crate::StorageClass::WorkGroup => ("groupshared ", ""), crate::StorageClass::Uniform => ("", "b"), crate::StorageClass::Storage | crate::StorageClass::Handle => { if let TypeInner::Sampler { .. } = *inner { @@ -359,14 +359,14 @@ impl<'a, W: Write> Writer<'a, W> { write!(self.out, "{}", storage)?; self.write_type(module, global.ty)?; - if let TypeInner::Array { size, .. } = module.types[global.ty].inner { - self.write_array_size(module, size)?; - } write!( self.out, " {}", &self.names[&NameKey::GlobalVariable(handle)] )?; + if let TypeInner::Array { size, .. } = module.types[global.ty].inner { + self.write_array_size(module, size)?; + } if let Some(ref binding) = global.binding { // this was already resolved earlier when we started evaluating an entry point. @@ -604,7 +604,7 @@ impl<'a, W: Write> Writer<'a, W> { } => { use crate::ImageClass as Ic; - let dim_str = image_dimension_str(dim); + let dim_str = dim.to_hlsl_str(); let arrayed_str = if arrayed { "Array" } else { "" }; write!(self.out, "Texture{}{}", dim_str, arrayed_str)?; match class { @@ -1596,23 +1596,15 @@ impl<'a, W: Write> Writer<'a, W> { fn write_default_init(&mut self, module: &Module, ty: Handle) -> BackendResult { write!(self.out, "(")?; self.write_type(module, ty)?; + if let TypeInner::Array { size, .. } = module.types[ty].inner { + self.write_array_size(module, size)?; + } write!(self.out, ")0")?; Ok(()) } } -pub(super) fn image_dimension_str(dim: crate::ImageDimension) -> &'static str { - use crate::ImageDimension as IDim; - - match dim { - IDim::D1 => "1D", - IDim::D2 => "2D", - IDim::D3 => "3D", - IDim::Cube => "Cube", - } -} - fn builtin_str(built_in: crate::BuiltIn) -> &'static str { use crate::BuiltIn as Bi; diff --git a/tests/in/skybox.param.ron b/tests/in/skybox.param.ron index 03e56dde9..d21b3b852 100644 --- a/tests/in/skybox.param.ron +++ b/tests/in/skybox.param.ron @@ -45,4 +45,13 @@ }, ), hlsl_custom: true, + hlsl: ( + shader_model: V5_1, + binding_map: { + (group: 0, binding: 0): (space: 0, register: 0), + (group: 0, binding: 1): (space: 0, register: 0), + (group: 0, binding: 2): (space: 1, register: 0), + }, + fake_missing_bindings: false, + ), ) diff --git a/tests/out/hlsl/globals.hlsl b/tests/out/hlsl/globals.hlsl new file mode 100644 index 000000000..9ae432588 --- /dev/null +++ b/tests/out/hlsl/globals.hlsl @@ -0,0 +1,10 @@ +static const bool Foo = true; + +groupshared float wg[10] = (float[10])0; + +[numthreads(1, 1, 1)] +void main() +{ + wg[3] = 1.0; + return; +} diff --git a/tests/out/hlsl/globals.hlsl.config b/tests/out/hlsl/globals.hlsl.config new file mode 100644 index 000000000..71412ac2d --- /dev/null +++ b/tests/out/hlsl/globals.hlsl.config @@ -0,0 +1,2 @@ +compute=cs_5_0 +compute_name=main diff --git a/tests/out/hlsl/skybox.hlsl b/tests/out/hlsl/skybox.hlsl index 2d2220a09..283ab73b8 100644 --- a/tests/out/hlsl/skybox.hlsl +++ b/tests/out/hlsl/skybox.hlsl @@ -8,9 +8,9 @@ struct Data { float4x4 view; }; -Data r_data : register(b0); -TextureCube r_texture : register(t1); -SamplerState r_sampler : register(s2); +Data r_data : register(b0, space0); +TextureCube r_texture : register(t0, space0); +SamplerState r_sampler : register(s0, space1); struct VertexInput_vs_main { uint vertex_index1 : SV_VertexID; diff --git a/tests/out/hlsl/skybox.hlsl.config b/tests/out/hlsl/skybox.hlsl.config index 43702adbc..41df29cb7 100644 --- a/tests/out/hlsl/skybox.hlsl.config +++ b/tests/out/hlsl/skybox.hlsl.config @@ -1,4 +1,4 @@ -vertex=vs_5_0 +vertex=vs_5_1 vertex_name=vs_main -fragment=ps_5_0 +fragment=ps_5_1 fragment_name=fs_main diff --git a/tests/snapshots.rs b/tests/snapshots.rs index cd2d317fc..fb3369728 100644 --- a/tests/snapshots.rs +++ b/tests/snapshots.rs @@ -411,7 +411,7 @@ fn convert_wgsl() { ), ( "globals", - Targets::SPIRV | Targets::METAL | Targets::GLSL | Targets::WGSL, + Targets::SPIRV | Targets::METAL | Targets::GLSL | Targets::HLSL | Targets::WGSL, ), ("bounds-check-zero", Targets::SPIRV), (