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
66use os:: { App , Window } ;
77use 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+
1521fn 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