Skip to content

Commit e43cd2d

Browse files
polymonsterGBDixonAlex
authored andcommitted
- improve bindless and bindful samples, make cmdbuf methods mutable and include null graphics api in compilation
2 parents 9572773 + 4396853 commit e43cd2d

44 files changed

Lines changed: 2774 additions & 398 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.vscode/launch.json

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"version": "0.2.0",
66
"configurations": [
77
{
8-
"name": "client (Debug)",
8+
"name": "client (Win32|Debug)",
99
"type": "cppvsdbg",
1010
"request": "launch",
1111
"program": "${workspaceFolder}/target/debug/client.exe",
@@ -17,7 +17,7 @@
1717
"preLaunchTask": "pmbuild-debug"
1818
},
1919
{
20-
"name": "client (Release)",
20+
"name": "client (Win32|Release)",
2121
"type": "cppvsdbg",
2222
"request": "launch",
2323
"program": "${workspaceFolder}/target/release/client.exe",
@@ -29,7 +29,31 @@
2929
"preLaunchTask": "pmbuild-release"
3030
},
3131
{
32-
"name": "triangle (Debug)",
32+
"name": "window (Win32|Debug)",
33+
"type": "cppvsdbg",
34+
"request": "launch",
35+
"program": "${workspaceFolder}/target/debug/examples/window.exe",
36+
"args": [],
37+
"stopAtEntry": false,
38+
"cwd": "${fileDirname}",
39+
"environment": [],
40+
"console": "externalTerminal",
41+
"preLaunchTask": "examples"
42+
},
43+
{
44+
"name": "swap_chain (Win32|Debug)",
45+
"type": "cppvsdbg",
46+
"request": "launch",
47+
"program": "${workspaceFolder}/target/debug/examples/swap_chain.exe",
48+
"args": [],
49+
"stopAtEntry": false,
50+
"cwd": "${fileDirname}",
51+
"environment": [],
52+
"console": "externalTerminal",
53+
"preLaunchTask": "examples"
54+
},
55+
{
56+
"name": "triangle (Win32|Debug)",
3357
"type": "cppvsdbg",
3458
"request": "launch",
3559
"program": "${workspaceFolder}/target/debug/examples/triangle.exe",
@@ -41,7 +65,7 @@
4165
"preLaunchTask": "examples"
4266
},
4367
{
44-
"name": "bindless (Debug)",
68+
"name": "bindless (Win32|Debug)",
4569
"type": "cppvsdbg",
4670
"request": "launch",
4771
"program": "${workspaceFolder}/target/debug/examples/bindless.exe",
@@ -53,7 +77,7 @@
5377
"preLaunchTask": "examples"
5478
},
5579
{
56-
"name": "bindful (Debug)",
80+
"name": "bindful (Win32|Debug)",
5781
"type": "cppvsdbg",
5882
"request": "launch",
5983
"program": "${workspaceFolder}/target/debug/examples/bindful.exe",
@@ -65,7 +89,7 @@
6589
"preLaunchTask": "examples"
6690
},
6791
{
68-
"name": "imgui_demo (Debug)",
92+
"name": "imgui_demo (Win32|Debug)",
6993
"type": "cppvsdbg",
7094
"request": "launch",
7195
"program": "${workspaceFolder}/target/debug/examples/imgui_demo.exe",
@@ -77,7 +101,7 @@
77101
"preLaunchTask": "examples"
78102
},
79103
{
80-
"name": "play_video (Debug)",
104+
"name": "play_video (Win32|Debug)",
81105
"type": "cppvsdbg",
82106
"request": "launch",
83107
"program": "${workspaceFolder}/target/debug/examples/play_video.exe",
@@ -89,7 +113,7 @@
89113
"preLaunchTask": "examples"
90114
},
91115
{
92-
"name": "resource_tests (Debug)",
116+
"name": "resource_tests (Win32|Debug)",
93117
"type": "cppvsdbg",
94118
"request": "launch",
95119
"program": "${workspaceFolder}/target/debug/examples/resource_tests.exe",
@@ -101,7 +125,7 @@
101125
"preLaunchTask": "examples"
102126
},
103127
{
104-
"name": "raytraced_triangle (Debug)",
128+
"name": "raytraced_triangle (Win32|Debug)",
105129
"type": "cppvsdbg",
106130
"request": "launch",
107131
"program": "${workspaceFolder}/target/debug/examples/raytraced_triangle.exe",
@@ -113,7 +137,7 @@
113137
"preLaunchTask": "examples"
114138
},
115139
{
116-
"name": "tests (Debug)",
140+
"name": "tests (Win32|Debug)",
117141
"type": "cppvsdbg",
118142
"request": "launch",
119143
"program": "${workspaceFolder}/target/debug/deps/tests-9d060b7b8785eb4b.exe",

config.jsn

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@
7575
["${src_data_dir}/fonts", "${data_dir}/fonts"]
7676

7777
// default imgui layouts form the client.. todo. move to target
78-
["plugins/imgui.ini", "target/debug/imgui.ini"]
78+
["plugins/imgui.ini", "target/release/imgui.ini"]
79+
["plugins/imgui.ini", "target/release/deps/imgui.ini"]
80+
7981
["plugins/imgui.ini", "target/debug/imgui.ini"]
8082
["plugins/imgui.ini", "target/debug/deps/imgui.ini"]
8183

@@ -113,20 +115,24 @@
113115
pmfx: {
114116
args: [
115117
"-shader_platform hlsl"
116-
"-shader_version 6_3"
118+
"-shader_version 6_5"
119+
117120
"-i ${src_shader_dir}/"
118121
"-o ${data_dir}/shaders"
119122
"-t ${temp_dir}/shaders"
120123
"-num_threads 1"
121124
"-args"
122125
"-Zpr"
126+
"-Zi"
127+
"-Qembed_debug"
128+
"-Od"
123129
]
124130
}
125131
pmfx_dev: {
126132
explicit: true
127133
args: [
128134
"-shader_platform hlsl"
129-
"-shader_version 6_3"
135+
"-shader_version 6_5"
130136
"-i ${src_shader_dir}/"
131137
"-o ${data_dir}/shaders"
132138
"-t ${temp_dir}/shaders"

examples/bindful/main.rs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// currently windows only because here we need a concrete gfx and os implementation
22
#![cfg(target_os = "windows")]
33

4-
use hotline_rs::{*, prelude::{Pipeline, Texture}};
4+
use hotline_rs::{*, prelude::*};
55

66
use os::{App, Window};
77
use gfx::{CmdBuf, Device, SwapChain, RenderPass};
@@ -12,6 +12,12 @@ struct Vertex {
1212
color: [f32; 4],
1313
}
1414

15+
#[repr(C)]
16+
struct LetterboxPushConstants {
17+
x: f32,
18+
y: f32
19+
}
20+
1521
fn main() -> Result<(), hotline_rs::Error> {
1622
// app
1723
let mut app = os_platform::App::create(os::AppInfo {
@@ -38,8 +44,8 @@ fn main() -> Result<(), hotline_rs::Error> {
3844
rect: os::Rect {
3945
x: 100,
4046
y: 100,
41-
width: 1024,
42-
height: 1024,
47+
width: 1280,
48+
height: 720,
4349
},
4450
style: os::WindowStyleFlags::NONE,
4551
parent_handle: None,
@@ -152,7 +158,6 @@ fn main() -> Result<(), hotline_rs::Error> {
152158

153159
cmdbuffer.set_heap(pso_pmfx, dev.get_shader_heap());
154160

155-
// set bindings
156161
let srv0 = textures[0].get_srv_index().unwrap();
157162
let srv1 = textures[1].get_srv_index().unwrap();
158163
let srv2 = textures[2].get_srv_index().unwrap();
@@ -177,6 +182,23 @@ fn main() -> Result<(), hotline_rs::Error> {
177182
if let Some(t3) = pso_pmfx.get_pipeline_slot(3, 0, gfx::DescriptorType::ShaderResource) {
178183
cmdbuffer.set_binding(pso_pmfx, dev.get_shader_heap(), t3.index, srv3);
179184
}
185+
186+
// lookup push constants for letterboxing the quad
187+
if let Some(c0) = pso_pmfx.get_pipeline_slot(0, 0, gfx::DescriptorType::PushConstants) {
188+
let pc = if vp_rect.width >= vp_rect.height {
189+
LetterboxPushConstants {
190+
x: vp_rect.height as f32 / vp_rect.width as f32,
191+
y: 1.0
192+
}
193+
}
194+
else {
195+
LetterboxPushConstants {
196+
x: 1.0,
197+
y: vp_rect.width as f32 / vp_rect.height as f32
198+
}
199+
};
200+
cmdbuffer.push_render_constants(c0.index, 2, 0, gfx::as_u8_slice(&pc));
201+
}
180202

181203
cmdbuffer.set_index_buffer(&index_buffer);
182204
cmdbuffer.set_vertex_buffer(&vertex_buffer, 0);
@@ -196,7 +218,7 @@ fn main() -> Result<(), hotline_rs::Error> {
196218

197219
dev.execute(&cmdbuffer);
198220

199-
swap_chain.swap(&dev);
221+
swap_chain.swap(&mut dev);
200222
ci = (ci + 1) % 4;
201223
}
202224

examples/bindless/main.rs

Lines changed: 43 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// currently windows only because here we need a concrete gfx and os implementation
22
#![cfg(target_os = "windows")]
33

4-
use hotline_rs::*;
4+
use hotline_rs::{*, prelude::*};
55

66
use os::{App, Window};
77
use gfx::{CmdBuf, Device, SwapChain, RenderPass};
@@ -12,6 +12,12 @@ struct Vertex {
1212
color: [f32; 4],
1313
}
1414

15+
#[repr(C)]
16+
struct LetterboxPushConstants {
17+
x: f32,
18+
y: f32
19+
}
20+
1521
fn main() -> Result<(), hotline_rs::Error> {
1622
// app
1723
let mut app = os_platform::App::create(os::AppInfo {
@@ -38,8 +44,8 @@ fn main() -> Result<(), hotline_rs::Error> {
3844
rect: os::Rect {
3945
x: 100,
4046
y: 100,
41-
width: 1024,
42-
height: 1024,
47+
width: 1280,
48+
height: 720,
4349
},
4450
style: os::WindowStyleFlags::NONE,
4551
parent_handle: None,
@@ -55,10 +61,10 @@ fn main() -> Result<(), hotline_rs::Error> {
5561
a: 1.00,
5662
}),
5763
};
58-
let mut swap_chain = dev.create_swap_chain::<os_platform::App>(&swap_chain_info, &win)?;
64+
let mut swap_chain = dev.create_swap_chain::<os_platform::App>(&swap_chain_info, &win)?; // 2
5965

6066
// cmd buffer
61-
let mut cmdbuffer = dev.create_cmd_buf(2);
67+
let mut cmdbuffer = dev.create_cmd_buf(2); // 2
6268

6369
// vertex buffer
6470
let vertices = [
@@ -128,26 +134,13 @@ fn main() -> Result<(), hotline_rs::Error> {
128134
textures.push(tex);
129135
}
130136

131-
// push constants
132-
let constants: [f32; 4] = [1.0, 1.0, 0.0, 1.0];
133-
134-
// constant buffer
135-
let mut cbuffer: [f32; 64] = [0.0; 64];
136-
cbuffer[0] = 1.0;
137-
cbuffer[1] = 0.0;
138-
cbuffer[2] = 1.0;
139-
cbuffer[3] = 1.0;
140-
141-
let info = gfx::BufferInfo {
142-
usage: gfx::BufferUsage::CONSTANT_BUFFER,
143-
cpu_access: gfx::CpuAccessFlags::NONE,
144-
format: gfx::Format::Unknown,
145-
stride: cbuffer.len() * 4,
146-
num_elements: 1,
147-
initial_state: gfx::ResourceState::VertexConstantBuffer
148-
};
149-
150-
let _constant_buffer = dev.create_buffer(&info, data![gfx::as_u8_slice(&cbuffer)]);
137+
// srv indices are used to index into descriptor arrays
138+
let srv_indices = [
139+
textures[0].get_srv_index().unwrap() as u32,
140+
textures[1].get_srv_index().unwrap() as u32,
141+
textures[2].get_srv_index().unwrap() as u32,
142+
textures[3].get_srv_index().unwrap() as u32,
143+
];
151144

152145
// render target
153146
let rt_info = gfx::TextureInfo {
@@ -164,21 +157,6 @@ fn main() -> Result<(), hotline_rs::Error> {
164157
};
165158
let render_target = dev.create_texture(&rt_info, data![]).unwrap();
166159

167-
// depth stencil target
168-
let ds_info = gfx::TextureInfo {
169-
format: gfx::Format::D24nS8u,
170-
tex_type: gfx::TextureType::Texture2D,
171-
width: 512,
172-
height: 512,
173-
depth: 1,
174-
array_layers: 1,
175-
mip_levels: 1,
176-
samples: 1,
177-
usage: gfx::TextureUsage::DEPTH_STENCIL,
178-
initial_state: gfx::ResourceState::DepthStencil,
179-
};
180-
let depth_stencil = dev.create_texture::<u8>(&ds_info, None).unwrap();
181-
182160
// pass for render target with depth stencil
183161
let render_target_pass = dev
184162
.create_render_pass(&gfx::RenderPassInfo {
@@ -189,7 +167,7 @@ fn main() -> Result<(), hotline_rs::Error> {
189167
b: 1.0,
190168
a: 1.0,
191169
}),
192-
depth_stencil: Some(&depth_stencil),
170+
depth_stencil: None, //Some(&depth_stencil),
193171
ds_clear: Some(gfx::ClearDepthStencil {
194172
depth: Some(1.0),
195173
stencil: None,
@@ -224,7 +202,7 @@ fn main() -> Result<(), hotline_rs::Error> {
224202

225203
// compute pass
226204
cmdbuffer.set_marker(0xff00ffff, "Frame Start");
227-
205+
228206
cmdbuffer.begin_event(0xff0000ff, "Compute Pass");
229207
cmdbuffer.set_compute_pipeline(pso_compute);
230208
cmdbuffer.set_heap(pso_compute, dev.get_shader_heap());
@@ -288,7 +266,27 @@ fn main() -> Result<(), hotline_rs::Error> {
288266
cmdbuffer.set_index_buffer(&index_buffer);
289267
cmdbuffer.set_vertex_buffer(&vertex_buffer, 0);
290268

291-
cmdbuffer.push_render_constants(0, 4, 0, constants.as_slice());
269+
// lookup push constants for letterboxing the quad and push the data
270+
if let Some(c0) = pso_pmfx.get_pipeline_slot(0, 0, gfx::DescriptorType::PushConstants) {
271+
let pc = if vp_rect.width >= vp_rect.height {
272+
LetterboxPushConstants {
273+
x: vp_rect.height as f32 / vp_rect.width as f32,
274+
y: 1.0
275+
}
276+
}
277+
else {
278+
LetterboxPushConstants {
279+
x: 1.0,
280+
y: vp_rect.width as f32 / vp_rect.height as f32
281+
}
282+
};
283+
cmdbuffer.push_render_constants(c0.index, 2, 0, gfx::as_u8_slice(&pc));
284+
}
285+
286+
// lookup push srv indices and push the data
287+
if let Some(c1) = pso_pmfx.get_pipeline_slot(1, 0, gfx::DescriptorType::PushConstants) {
288+
cmdbuffer.push_render_constants(c1.index, 4, 0, gfx::as_u8_slice(&srv_indices));
289+
}
292290

293291
cmdbuffer.draw_indexed_instanced(6, 1, 0, 0, 0);
294292

@@ -306,7 +304,7 @@ fn main() -> Result<(), hotline_rs::Error> {
306304

307305
dev.execute(&cmdbuffer);
308306

309-
swap_chain.swap(&dev);
307+
swap_chain.swap(&mut dev);
310308
ci = (ci + 1) % 4;
311309
}
312310

@@ -317,4 +315,4 @@ fn main() -> Result<(), hotline_rs::Error> {
317315
dev.cleanup_dropped_resources(&swap_chain);
318316

319317
Ok(())
320-
}
318+
}

0 commit comments

Comments
 (0)