mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
hlsl-out: implement constant buffer support
This commit is contained in:
committed by
Dzmitry Malyshau
parent
16206f2eb2
commit
39eaa57a77
@@ -344,7 +344,7 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
crate::StorageClass::Function => unreachable!("Function storage class"),
|
||||
crate::StorageClass::Private => ("static ", ""),
|
||||
crate::StorageClass::WorkGroup => ("groupshared ", ""),
|
||||
crate::StorageClass::Uniform => ("", "b"),
|
||||
crate::StorageClass::Uniform => ("cbuffer", "b"),
|
||||
crate::StorageClass::Storage | crate::StorageClass::Handle => {
|
||||
if let TypeInner::Sampler { .. } = *inner {
|
||||
("", "s")
|
||||
@@ -358,12 +358,13 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
};
|
||||
|
||||
write!(self.out, "{}", storage)?;
|
||||
self.write_type(module, global.ty)?;
|
||||
write!(
|
||||
self.out,
|
||||
" {}",
|
||||
&self.names[&NameKey::GlobalVariable(handle)]
|
||||
)?;
|
||||
// constant buffer declarations are expected to be inlined, e.g.
|
||||
// cbuffer foo: register(b0) { field1: type1; };
|
||||
if global.class != crate::StorageClass::Uniform {
|
||||
self.write_type(module, global.ty)?;
|
||||
}
|
||||
let name = &self.names[&NameKey::GlobalVariable(handle)];
|
||||
write!(self.out, " {}", name)?;
|
||||
if let TypeInner::Array { size, .. } = module.types[global.ty].inner {
|
||||
self.write_array_size(module, size)?;
|
||||
}
|
||||
@@ -375,14 +376,22 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
if self.options.shader_model > super::ShaderModel::V5_0 {
|
||||
write!(self.out, ", space{}", bt.space)?;
|
||||
}
|
||||
writeln!(self.out, ");")?;
|
||||
} else {
|
||||
write!(self.out, ")")?;
|
||||
} else if global.class == crate::StorageClass::Private {
|
||||
write!(self.out, " = ")?;
|
||||
if let Some(init) = global.init {
|
||||
self.write_constant(module, init)?;
|
||||
} else {
|
||||
self.write_default_init(module, global.ty)?;
|
||||
}
|
||||
}
|
||||
|
||||
if global.class == crate::StorageClass::Uniform {
|
||||
write!(self.out, " {{ ")?;
|
||||
self.write_type(module, global.ty)?;
|
||||
let name = &self.names[&NameKey::GlobalVariable(handle)];
|
||||
writeln!(self.out, " {}; }}", name)?;
|
||||
} else {
|
||||
writeln!(self.out, ";")?;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
static const bool Foo = true;
|
||||
|
||||
groupshared float wg[10] = (float[10])0;
|
||||
groupshared float wg[10];
|
||||
|
||||
[numthreads(1, 1, 1)]
|
||||
void main()
|
||||
|
||||
@@ -16,7 +16,7 @@ struct Lights {
|
||||
Light data[1];
|
||||
};
|
||||
|
||||
Globals u_globals : register(b0);
|
||||
cbuffer u_globals : register(b0) { Globals u_globals; }
|
||||
Lights s_lights : register(t1);
|
||||
Texture2DArray t_shadow : register(t2);
|
||||
SamplerComparisonState sampler_shadow : register(s3);
|
||||
|
||||
@@ -8,7 +8,7 @@ struct Data {
|
||||
float4x4 view;
|
||||
};
|
||||
|
||||
Data r_data : register(b0, space0);
|
||||
cbuffer r_data : register(b0, space0) { Data r_data; }
|
||||
TextureCube<float4> r_texture : register(t0, space0);
|
||||
SamplerState r_sampler : register(s0, space1);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user