Skip to content

Commit 2f1891c

Browse files
committed
Added CB, SRV, UAV, and samplers to PSO descriptor
1 parent ffc2390 commit 2f1891c

File tree

5 files changed

+56
-29
lines changed

5 files changed

+56
-29
lines changed

src/core/src/pso.rs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
//! will want to use the typed and safe `PipelineState`. See the `pso` module inside the `gfx`
1919
//! crate.
2020
21-
use {MAX_COLOR_TARGETS, MAX_VERTEX_ATTRIBUTES};
21+
use {MAX_COLOR_TARGETS, MAX_VERTEX_ATTRIBUTES, MAX_CONSTANT_BUFFERS,
22+
MAX_RESOURCE_VIEWS, MAX_UNORDERED_VIEWS, MAX_SAMPLERS};
2223
use {ConstantBufferSlot, ColorSlot, ResourceViewSlot,
2324
UnorderedViewSlot, SamplerSlot,
2425
Primitive, Resources};
@@ -137,7 +138,7 @@ pub struct Element<F> {
137138

138139
/// Vertex buffer descriptor
139140
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
140-
pub struct BufferDesc {
141+
pub struct VertexBufferDesc {
141142
/// Total container size, in bytes
142143
pub stride: ElemStride,
143144
/// Rate of the input for the given buffer
@@ -146,6 +147,14 @@ pub struct BufferDesc {
146147

147148
/// PSO vertex attribute descriptor
148149
pub type AttributeDesc = (BufferIndex, Element<format::Format>);
150+
/// PSO constant buffer descriptor
151+
pub type ConstantBufferDesc = Usage;
152+
/// PSO shader resource view descriptor
153+
pub type ResourceViewDesc = Usage;
154+
/// PSO unordered access view descriptor
155+
pub type UnorderedViewDesc = Usage;
156+
/// PSO sampler descriptor
157+
pub type SamplerDesc = Usage;
149158
/// PSO color target descriptor
150159
pub type ColorTargetDesc = (format::Format, ColorInfo);
151160
/// PSO depth-stencil target descriptor
@@ -162,9 +171,17 @@ pub struct Descriptor {
162171
/// Enable scissor test
163172
pub scissor: bool,
164173
/// Vertex buffers
165-
pub vertex_buffers: [Option<BufferDesc>; MAX_VERTEX_BUFFERS],
174+
pub vertex_buffers: [Option<VertexBufferDesc>; MAX_VERTEX_BUFFERS],
166175
/// Vertex attributes
167176
pub attributes: [Option<AttributeDesc>; MAX_VERTEX_ATTRIBUTES],
177+
/// Constant buffers
178+
pub constant_buffers: [Option<ConstantBufferDesc>; MAX_CONSTANT_BUFFERS],
179+
/// Shader resource views
180+
pub resource_views: [Option<ResourceViewDesc>; MAX_RESOURCE_VIEWS],
181+
/// Unordered access views
182+
pub unordered_views: [Option<UnorderedViewDesc>; MAX_UNORDERED_VIEWS],
183+
/// Samplers
184+
pub samplers: [Option<SamplerDesc>; MAX_SAMPLERS],
168185
/// Render target views (RTV)
169186
pub color_targets: [Option<ColorTargetDesc>; MAX_COLOR_TARGETS],
170187
/// Depth stencil view (DSV)
@@ -180,6 +197,10 @@ impl Descriptor {
180197
scissor: false,
181198
vertex_buffers: [None; MAX_VERTEX_BUFFERS],
182199
attributes: [None; MAX_VERTEX_ATTRIBUTES],
200+
constant_buffers: [None; MAX_CONSTANT_BUFFERS],
201+
resource_views: [None; MAX_RESOURCE_VIEWS],
202+
unordered_views: [None; MAX_UNORDERED_VIEWS],
203+
samplers: [None; MAX_SAMPLERS],
183204
color_targets: [None; MAX_COLOR_TARGETS],
184205
depth_stencil: None,
185206
}

src/render/src/macros/pso.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ macro_rules! gfx_pipeline_inner {
4343
// v#
4444
let mut _num_vb = 0;
4545
$(
46-
if let Some(vd) = meta.$field.link_vertex_buffer(_num_vb, &self.$field) {
46+
if let Some(d) = meta.$field.link_vertex_buffer(_num_vb, &self.$field) {
4747
assert!(meta.$field.is_active());
48-
desc.vertex_buffers[_num_vb as usize] = Some(vd);
48+
desc.vertex_buffers[_num_vb as usize] = Some(d);
4949
_num_vb += 1;
5050
}
5151
)*
@@ -69,8 +69,9 @@ macro_rules! gfx_pipeline_inner {
6969
for cb in &info.constant_buffers {
7070
$(
7171
match meta.$field.link_constant_buffer(cb, &self.$field) {
72-
Some(Ok(())) => {
72+
Some(Ok(d)) => {
7373
assert!(meta.$field.is_active());
74+
desc.constant_buffers[cb.slot as usize] = Some(d);
7475
continue;
7576
},
7677
Some(Err(_)) => return Err(
@@ -101,8 +102,9 @@ macro_rules! gfx_pipeline_inner {
101102
for srv in &info.textures {
102103
$(
103104
match meta.$field.link_resource_view(srv, &self.$field) {
104-
Some(Ok(())) => {
105+
Some(Ok(d)) => {
105106
assert!(meta.$field.is_active());
107+
desc.resource_views[srv.slot as usize] = Some(d);
106108
continue;
107109
},
108110
Some(Err(_)) => return Err(
@@ -117,8 +119,9 @@ macro_rules! gfx_pipeline_inner {
117119
for uav in &info.unordereds {
118120
$(
119121
match meta.$field.link_unordered_view(uav, &self.$field) {
120-
Some(Ok(())) => {
122+
Some(Ok(d)) => {
121123
assert!(meta.$field.is_active());
124+
desc.unordered_views[uav.slot as usize] = Some(d);
122125
continue;
123126
},
124127
Some(Err(_)) => return Err(
@@ -133,8 +136,9 @@ macro_rules! gfx_pipeline_inner {
133136
for sm in &info.samplers {
134137
$(
135138
match meta.$field.link_sampler(sm, &self.$field) {
136-
Some(()) => {
139+
Some(d) => {
137140
assert!(meta.$field.is_active());
141+
desc.samplers[sm.slot as usize] = Some(d);
138142
continue;
139143
},
140144
None => (),

src/render/src/pso/buffer.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ impl<'a,
7171
self.0.is_active()
7272
}
7373
fn link_vertex_buffer(&mut self, index: BufferIndex, _: &Self::Init)
74-
-> Option<pso::BufferDesc> {
74+
-> Option<pso::VertexBufferDesc> {
7575
use std::mem;
7676
(self.0).0 = Some(index);
7777
let rate = <I as Default>::default().as_ref().len();
78-
Some(pso::BufferDesc {
78+
Some(pso::VertexBufferDesc {
7979
stride: mem::size_of::<T>() as ElemStride,
8080
rate: rate as InstanceRate,
8181
})
@@ -116,9 +116,9 @@ impl<'a> DataLink<'a> for RawVertexBuffer {
116116
self.0.is_some()
117117
}
118118
fn link_vertex_buffer(&mut self, index: BufferIndex, init: &Self::Init)
119-
-> Option<pso::BufferDesc> {
119+
-> Option<pso::VertexBufferDesc> {
120120
self.0 = Some(index);
121-
Some(pso::BufferDesc {
121+
Some(pso::VertexBufferDesc {
122122
stride: init.1,
123123
rate: init.2,
124124
})
@@ -153,10 +153,10 @@ DataLink<'a> for ConstantBuffer<T> {
153153
self.0.is_some()
154154
}
155155
fn link_constant_buffer(&mut self, cb: &shade::ConstantBufferVar, init: &Self::Init) ->
156-
Option<Result<(), shade::ConstFormat>> {
156+
Option<Result<pso::ConstantBufferDesc, shade::ConstFormat>> {
157157
if &cb.name == *init {
158158
self.0 = Some((cb.usage, cb.slot));
159-
Some(Ok(()))
159+
Some(Ok(cb.usage))
160160
}else {
161161
None
162162
}

src/render/src/pso/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,13 @@ pub trait DataLink<'a>: Sized {
199199
fn is_active(&self) -> bool;
200200
/// Attempt to link with a vertex buffer containing multiple attributes.
201201
fn link_vertex_buffer(&mut self, _: d::pso::BufferIndex, _: &Self::Init) ->
202-
Option<d::pso::BufferDesc> { None }
202+
Option<d::pso::VertexBufferDesc> { None }
203203
/// Attempt to link with a vertex attribute.
204204
fn link_input(&mut self, _: &d::shade::AttributeVar, _: &Self::Init) ->
205205
Option<Result<d::pso::AttributeDesc, d::format::Format>> { None }
206206
/// Attempt to link with a constant buffer.
207207
fn link_constant_buffer(&mut self, _: &d::shade::ConstantBufferVar, _: &Self::Init) ->
208-
Option<Result<(), d::shade::ConstFormat>> { None }
208+
Option<Result<d::pso::ConstantBufferDesc, d::shade::ConstFormat>> { None }
209209
/// Attempt to link with a global constant.
210210
fn link_global_constant(&mut self, _: &d::shade::ConstVar, _: &Self::Init) ->
211211
Option<Result<(), d::shade::UniformValue>> { None }
@@ -217,12 +217,13 @@ pub trait DataLink<'a>: Sized {
217217
Option<d::pso::DepthStencilDesc> { None }
218218
/// Attempt to link with a shader resource (SRV).
219219
fn link_resource_view(&mut self, _: &d::shade::TextureVar, _: &Self::Init) ->
220-
Option<Result<(), d::format::Format>> { None }
220+
Option<Result<d::pso::ResourceViewDesc, d::format::Format>> { None }
221221
/// Attempt to link with an unordered access (UAV).
222222
fn link_unordered_view(&mut self, _: &d::shade::UnorderedVar, _: &Self::Init) ->
223-
Option<Result<(), d::format::Format>> { None }
223+
Option<Result<d::pso::UnorderedViewDesc, d::format::Format>> { None }
224224
/// Attempt to link with a sampler.
225-
fn link_sampler(&mut self, _: &d::shade::SamplerVar, _: &Self::Init) -> Option<()> { None }
225+
fn link_sampler(&mut self, _: &d::shade::SamplerVar, _: &Self::Init)
226+
-> Option<d::pso::SamplerDesc> { None }
226227
/// Attempt to enable scissor test.
227228
fn link_scissor(&mut self) -> bool { false }
228229
}

src/render/src/pso/resource.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl<'a, T> DataLink<'a> for ShaderResource<T> {
5858
self.0.is_active()
5959
}
6060
fn link_resource_view(&mut self, var: &shade::TextureVar, init: &Self::Init)
61-
-> Option<Result<(), Format>> {
61+
-> Option<Result<pso::ResourceViewDesc, Format>> {
6262
self.0.link_resource_view(var, init)
6363
}
6464
}
@@ -80,10 +80,10 @@ impl<'a> DataLink<'a> for RawShaderResource {
8080
self.0.is_some()
8181
}
8282
fn link_resource_view(&mut self, var: &shade::TextureVar, init: &Self::Init)
83-
-> Option<Result<(), Format>> {
83+
-> Option<Result<pso::ResourceViewDesc, Format>> {
8484
if *init == var.name {
8585
self.0 = Some((var.slot, var.usage));
86-
Some(Ok(())) //TODO: check format
86+
Some(Ok(var.usage)) //TODO: check format
8787
}else {
8888
None
8989
}
@@ -110,10 +110,10 @@ impl<'a, T> DataLink<'a> for UnorderedAccess<T> {
110110
self.0.is_some()
111111
}
112112
fn link_unordered_view(&mut self, var: &shade::UnorderedVar, init: &Self::Init)
113-
-> Option<Result<(), Format>> {
113+
-> Option<Result<pso::UnorderedViewDesc, Format>> {
114114
if *init == var.name {
115115
self.0 = Some((var.slot, var.usage));
116-
Some(Ok(())) //TODO: check format
116+
Some(Ok(var.usage)) //TODO: check format
117117
}else {
118118
None
119119
}
@@ -139,10 +139,11 @@ impl<'a> DataLink<'a> for Sampler {
139139
fn is_active(&self) -> bool {
140140
self.0.is_some()
141141
}
142-
fn link_sampler(&mut self, var: &shade::SamplerVar, init: &Self::Init) -> Option<()> {
142+
fn link_sampler(&mut self, var: &shade::SamplerVar, init: &Self::Init)
143+
-> Option<pso::SamplerDesc> {
143144
if *init == var.name {
144145
self.0 = Some((var.slot, var.usage));
145-
Some(())
146+
Some(var.usage)
146147
}else {
147148
None
148149
}
@@ -169,10 +170,10 @@ impl<'a, T> DataLink<'a> for TextureSampler<T> {
169170
self.0.is_active()
170171
}
171172
fn link_resource_view(&mut self, var: &shade::TextureVar, init: &Self::Init)
172-
-> Option<Result<(), Format>> {
173+
-> Option<Result<pso::ResourceViewDesc, Format>> {
173174
self.0.link_resource_view(var, init)
174175
}
175-
fn link_sampler(&mut self, var: &shade::SamplerVar, init: &Self::Init) -> Option<()> {
176+
fn link_sampler(&mut self, var: &shade::SamplerVar, init: &Self::Init) -> Option<pso::SamplerDesc> {
176177
self.1.link_sampler(var, init)
177178
}
178179
}

0 commit comments

Comments
 (0)