Skip to content

Commit b0bdc94

Browse files
committed
- refactor push_constants api
1 parent 534be40 commit b0bdc94

26 files changed

Lines changed: 155 additions & 202 deletions

examples/bindful/main.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -166,22 +166,20 @@ fn main() -> Result<(), hotline_rs::Error> {
166166
cmdbuffer.set_binding(pso_pmfx, 2, 0, gfx::DescriptorType::ShaderResource, dev.get_shader_heap(), srv2);
167167
cmdbuffer.set_binding(pso_pmfx, 3, 0, gfx::DescriptorType::ShaderResource, dev.get_shader_heap(), srv3);
168168

169-
// lookup push constants for letterboxing the quad
170-
if let Some(c0) = pso_pmfx.get_pipeline_slot(0, 0, gfx::DescriptorType::PushConstants) {
171-
let pc = if vp_rect.width >= vp_rect.height {
172-
LetterboxPushConstants {
173-
x: vp_rect.height as f32 / vp_rect.width as f32,
174-
y: 1.0
175-
}
169+
// push constants for letterboxing the quad
170+
let pc = if vp_rect.width >= vp_rect.height {
171+
LetterboxPushConstants {
172+
x: vp_rect.height as f32 / vp_rect.width as f32,
173+
y: 1.0
176174
}
177-
else {
178-
LetterboxPushConstants {
179-
x: 1.0,
180-
y: vp_rect.width as f32 / vp_rect.height as f32
181-
}
182-
};
183-
cmdbuffer.push_render_constants(c0.index, 2, 0, gfx::as_u8_slice(&pc));
184175
}
176+
else {
177+
LetterboxPushConstants {
178+
x: 1.0,
179+
y: vp_rect.width as f32 / vp_rect.height as f32
180+
}
181+
};
182+
cmdbuffer.push_render_constants(pso_pmfx, 0, 0, 2, 0, gfx::as_u8_slice(&pc));
185183

186184
cmdbuffer.set_index_buffer(&index_buffer);
187185
cmdbuffer.set_vertex_buffer(&vertex_buffer, 0);

examples/bindless/main.rs

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ fn main() -> Result<(), hotline_rs::Error> {
111111
let mut pmfx : pmfx::Pmfx<gfx_platform::Device> = pmfx::Pmfx::create(&mut dev, 0);
112112

113113
pmfx.load(&hotline_rs::get_data_path("shaders/bindless"))?;
114-
pmfx.create_compute_pipeline(&dev, "compute_rw")?;
115114
pmfx.create_render_pipeline(&dev, "bindless", swap_chain.get_backbuffer_pass())?;
116115

117116
let fmt = swap_chain.get_backbuffer_pass().get_format_hash();
@@ -171,27 +170,23 @@ fn main() -> Result<(), hotline_rs::Error> {
171170
cmdbuffer.set_index_buffer(&index_buffer);
172171
cmdbuffer.set_vertex_buffer(&vertex_buffer, 0);
173172

174-
// lookup push constants for letterboxing the quad and push the data
175-
if let Some(c0) = pso_pmfx.get_pipeline_slot(0, 0, gfx::DescriptorType::PushConstants) {
176-
let pc = if vp_rect.width >= vp_rect.height {
177-
LetterboxPushConstants {
178-
x: vp_rect.height as f32 / vp_rect.width as f32,
179-
y: 1.0
180-
}
173+
// push constants for letterboxing the quad
174+
let pc = if vp_rect.width >= vp_rect.height {
175+
LetterboxPushConstants {
176+
x: vp_rect.height as f32 / vp_rect.width as f32,
177+
y: 1.0
181178
}
182-
else {
183-
LetterboxPushConstants {
184-
x: 1.0,
185-
y: vp_rect.width as f32 / vp_rect.height as f32
186-
}
187-
};
188-
cmdbuffer.push_render_constants(c0.index, 2, 0, gfx::as_u8_slice(&pc));
189179
}
180+
else {
181+
LetterboxPushConstants {
182+
x: 1.0,
183+
y: vp_rect.width as f32 / vp_rect.height as f32
184+
}
185+
};
186+
cmdbuffer.push_render_constants(pso_pmfx, 0, 0, 2, 0, gfx::as_u8_slice(&pc));
190187

191-
// lookup push srv indices and push the data
192-
if let Some(c1) = pso_pmfx.get_pipeline_slot(1, 0, gfx::DescriptorType::PushConstants) {
193-
cmdbuffer.push_render_constants(c1.index, 4, 0, gfx::as_u8_slice(&srv_indices));
194-
}
188+
// push srv indices
189+
cmdbuffer.push_render_constants(pso_pmfx, 1, 0, 4, 0, gfx::as_u8_slice(&srv_indices));
195190

196191
cmdbuffer.draw_indexed_instanced(6, 1, 0, 0, 0);
197192

examples/raytraced_triangle/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ fn main() -> Result<(), hotline_rs::Error> {
166166
// set push constants on b0
167167
let border = 0.1;
168168
let aspect = window_rect.width as f32 / window_rect.height as f32;
169-
cmd.push_compute_constants(0, 8, 0, gfx::as_u8_slice(&[
169+
cmd.push_compute_constants(&raytracing_pipeline.pipeline, 0, 0, 8, 0, gfx::as_u8_slice(&[
170170
// viewport
171171
-1.0 + border,
172172
-1.0 + border * aspect,

plugins/ecs_examples/src/bindless_material_ibl.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -179,21 +179,15 @@ pub fn render_meshes_bindless_ibl(
179179
cmd_buf.set_render_pipeline(&pipeline);
180180

181181
// bind view push constants
182-
let slot = pipeline.get_pipeline_slot(0, 0, gfx::DescriptorType::PushConstants);
183-
if let Some(slot) = slot {
184-
cmd_buf.push_render_constants(slot.index, 16, 0, gfx::as_u8_slice(&camera.view_projection_matrix));
185-
cmd_buf.push_render_constants(slot.index, 4, 16, gfx::as_u8_slice(&camera.view_position));
186-
}
182+
cmd_buf.push_render_constants(pipeline, 0, 0, 16, 0, gfx::as_u8_slice(&camera.view_projection_matrix));
183+
cmd_buf.push_render_constants(pipeline, 0, 0, 4, 16, gfx::as_u8_slice(&camera.view_position));
187184

188185
// bind world buffer info with IBL indices in user_data
189186
let mut world_buffer_info = pmfx.get_world_buffer_info();
190187
world_buffer_info.user_data[0] = ibl_data.cubemap_srv;
191188
world_buffer_info.user_data[1] = ibl_data.lut_srv;
192-
let slot = pipeline.get_pipeline_slot(2, 0, gfx::DescriptorType::PushConstants);
193-
if let Some(slot) = slot {
194-
cmd_buf.push_render_constants(
195-
slot.index, gfx::num_32bit_constants(&world_buffer_info), 0, gfx::as_u8_slice(&world_buffer_info));
196-
}
189+
cmd_buf.push_render_constants(
190+
pipeline, 2, 0, gfx::num_32bit_constants(&world_buffer_info), 0, gfx::as_u8_slice(&world_buffer_info));
197191

198192
// bind the shader resource heap
199193
cmd_buf.set_heap(pipeline, &pmfx.shader_heap);
@@ -208,10 +202,7 @@ pub fn render_meshes_bindless_ibl(
208202

209203
// single draw calls
210204
for (mesh, world_matrix) in &single_draw_query {
211-
let slot = pipeline.get_pipeline_slot(1, 0, gfx::DescriptorType::PushConstants);
212-
if let Some(slot) = slot {
213-
cmd_buf.push_render_constants(slot.index, 12, 0, &world_matrix.0);
214-
}
205+
cmd_buf.push_render_constants(pipeline, 1, 0, 12, 0, &world_matrix.0);
215206
cmd_buf.set_index_buffer(&mesh.0.ib);
216207
cmd_buf.set_vertex_buffer(&mesh.0.vb, 0);
217208
cmd_buf.draw_indexed_instanced(mesh.0.num_indices, 1, 0, 0, 0);

plugins/ecs_examples/src/bindless_texture.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,13 @@ pub fn draw_meshes_bindless_texture(
156156
let camera = pmfx.get_camera_constants(&view.camera)?;
157157

158158
cmd_buf.set_render_pipeline(pipeline);
159-
cmd_buf.push_render_constants(0, 16, 0, gfx::as_u8_slice(&camera.view_projection_matrix));
159+
cmd_buf.push_render_constants(pipeline, 0, 0, 16, 0, gfx::as_u8_slice(&camera.view_projection_matrix));
160160

161161
cmd_buf.set_heap(pipeline, &pmfx.shader_heap);
162162

163163
for (world_matrix, mesh, texture) in &mesh_draw_query {
164-
cmd_buf.push_render_constants(1, 12, 0, &world_matrix.0);
165-
cmd_buf.push_render_constants(1, 1, 16, gfx::as_u8_slice(&texture.0));
164+
cmd_buf.push_render_constants(pipeline, 1, 0, 12, 0, &world_matrix.0);
165+
cmd_buf.push_render_constants(pipeline, 1, 0, 1, 16, gfx::as_u8_slice(&texture.0));
166166

167167
cmd_buf.set_index_buffer(&mesh.0.ib);
168168
cmd_buf.set_vertex_buffer(&mesh.0.vb, 0);

plugins/ecs_examples/src/blend_states.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ pub fn render_meshes_pipeline_coloured(
113113
// set pipeline per mesh
114114
let pipeline = pmfx.get_render_pipeline_for_format(&pipeline.0, fmt)?;
115115
cmd_buf.set_render_pipeline(pipeline);
116-
cmd_buf.push_render_constants(0, 16, 0, gfx::as_u8_slice(&camera.view_projection_matrix));
117-
cmd_buf.push_render_constants(1, 12, 0, &world_matrix.0);
118-
cmd_buf.push_render_constants(1, 4, 12, &colour.0);
116+
cmd_buf.push_render_constants(pipeline, 0, 0, 16, 0, gfx::as_u8_slice(&camera.view_projection_matrix));
117+
cmd_buf.push_render_constants(pipeline, 1, 0, 12, 0, &world_matrix.0);
118+
cmd_buf.push_render_constants(pipeline, 1, 0, 4, 12, &colour.0);
119119

120120
cmd_buf.set_index_buffer(&mesh.0.ib);
121121
cmd_buf.set_vertex_buffer(&mesh.0.vb, 0);

plugins/ecs_examples/src/cubemap.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@ pub fn render_meshes_cubemap(
7373
let camera = pmfx.get_camera_constants(&view.camera)?;
7474

7575
cmd_buf.set_render_pipeline(pipeline);
76-
cmd_buf.push_render_constants(0, 16, 0, gfx::as_u8_slice(&camera.view_projection_matrix));
76+
cmd_buf.push_render_constants(pipeline, 0, 0, 16, 0, gfx::as_u8_slice(&camera.view_projection_matrix));
7777

7878
cmd_buf.set_heap(pipeline, &pmfx.shader_heap);
7979

8080
let mut mip = 0;
8181
for (world_matrix, mesh, cubemap) in &mesh_draw_query {
82-
cmd_buf.push_render_constants(1, 12, 0, &world_matrix.0);
83-
cmd_buf.push_render_constants(1, 2, 16, gfx::as_u8_slice(&[cubemap.0, mip, 0, 0]));
82+
cmd_buf.push_render_constants(pipeline, 1, 0, 12, 0, &world_matrix.0);
83+
cmd_buf.push_render_constants(pipeline, 1, 0, 2, 16, gfx::as_u8_slice(&[cubemap.0, mip, 0, 0]));
8484

8585
cmd_buf.set_index_buffer(&mesh.0.ib);
8686
cmd_buf.set_vertex_buffer(&mesh.0.vb, 0);

plugins/ecs_examples/src/draw.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ pub fn draw_meshes(
8080
let camera = pmfx.get_camera_constants(&view.camera)?;
8181

8282
cmd_buf.set_render_pipeline(pipeline);
83-
cmd_buf.push_render_constants(0, 16, 0, gfx::as_u8_slice(&camera.view_projection_matrix));
83+
cmd_buf.push_render_constants(pipeline, 0, 0, 16, 0, gfx::as_u8_slice(&camera.view_projection_matrix));
8484

8585
for (_, mesh) in &mesh_draw_query {
8686
cmd_buf.set_vertex_buffer(&mesh.0.vb, 0);

plugins/ecs_examples/src/draw_cbuffer_instanced.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ pub fn draw_meshes_cbuffer_instanced(
104104
// set pipeline per batch
105105
let pipeline = pmfx.get_render_pipeline_for_format(&pipeline.0, fmt)?;
106106
cmd_buf.set_render_pipeline(pipeline);
107-
cmd_buf.push_render_constants(0, 16, 0, gfx::as_u8_slice(&camera.view_projection_matrix));
107+
cmd_buf.push_render_constants(pipeline, 0, 0, 16, 0, gfx::as_u8_slice(&camera.view_projection_matrix));
108108

109109
// bind the constant buffer (cbv) on the slot for b1, space0 specified in the shader
110110
cmd_buf.set_binding(

plugins/ecs_examples/src/draw_indexed.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub fn draw_meshes_indexed(
5050
let camera = pmfx.get_camera_constants(&view.camera)?;
5151

5252
cmd_buf.set_render_pipeline(pipeline);
53-
cmd_buf.push_render_constants(0, 16, 0, gfx::as_u8_slice(&camera.view_projection_matrix));
53+
cmd_buf.push_render_constants(pipeline, 0, 0, 16, 0, gfx::as_u8_slice(&camera.view_projection_matrix));
5454

5555
for (_, mesh) in &mesh_draw_query {
5656
cmd_buf.set_vertex_buffer(&mesh.0.vb, 0);

0 commit comments

Comments
 (0)