@@ -19,6 +19,23 @@ use os::Window;
19
19
use os:: win32 as os_platform;
20
20
use gfx:: d3d12 as gfx_platform;
21
21
22
+ /// Create an rw texture output for raytracing to write into
23
+ fn create_raytracing_output ( device : & mut gfx_platform:: Device , window_rect : & os:: Rect < i32 > ) -> gfx_platform:: Texture {
24
+ let rw_info = gfx:: TextureInfo {
25
+ format : gfx:: Format :: RGBA8n ,
26
+ tex_type : gfx:: TextureType :: Texture2D ,
27
+ width : window_rect. width as u64 ,
28
+ height : window_rect. height as u64 ,
29
+ depth : 1 ,
30
+ array_layers : 1 ,
31
+ mip_levels : 1 ,
32
+ samples : 1 ,
33
+ usage : gfx:: TextureUsage :: SHADER_RESOURCE | gfx:: TextureUsage :: UNORDERED_ACCESS ,
34
+ initial_state : gfx:: ResourceState :: UnorderedAccess ,
35
+ } ;
36
+ device. create_texture :: < u8 > ( & rw_info, None ) . unwrap ( )
37
+ }
38
+
22
39
fn main ( ) -> Result < ( ) , hotline_rs:: Error > {
23
40
// setup app
24
41
let mut app = os_platform:: App :: create ( os:: AppInfo {
@@ -32,7 +49,7 @@ fn main() -> Result<(), hotline_rs::Error> {
32
49
let num_buffers : u32 = 2 ;
33
50
let mut device = gfx_platform:: Device :: create ( & gfx:: DeviceInfo {
34
51
render_target_heap_size : num_buffers as usize ,
35
- shader_heap_size : 4 ,
52
+ shader_heap_size : 32 ,
36
53
..Default :: default ( )
37
54
} ) ;
38
55
println ! ( "{}" , device. get_adapter_info( ) ) ;
@@ -123,29 +140,23 @@ fn main() -> Result<(), hotline_rs::Error> {
123
140
} ) ?;
124
141
125
142
// unordered access rw texture
126
- let window_rect = window. get_viewport_rect ( ) ;
127
- let rw_info = gfx:: TextureInfo {
128
- format : gfx:: Format :: RGBA8n ,
129
- tex_type : gfx:: TextureType :: Texture2D ,
130
- width : window_rect. width as u64 ,
131
- height : window_rect. height as u64 ,
132
- depth : 1 ,
133
- array_layers : 1 ,
134
- mip_levels : 1 ,
135
- samples : 1 ,
136
- usage : gfx:: TextureUsage :: SHADER_RESOURCE | gfx:: TextureUsage :: UNORDERED_ACCESS ,
137
- initial_state : gfx:: ResourceState :: UnorderedAccess ,
138
- } ;
139
- let raytracing_output = device. create_texture :: < u8 > ( & rw_info, None ) . unwrap ( ) ;
143
+ let mut raytracing_output = create_raytracing_output ( & mut device, & window. get_viewport_rect ( ) ) ;
140
144
141
145
while app. run ( ) {
142
146
// update window and swap chain
143
147
window. update ( & mut app) ;
144
- swap_chain. update :: < os_platform:: App > ( & mut device, & window, & mut cmd) ;
145
148
146
149
// update viewport from window size
147
150
let window_rect = window. get_viewport_rect ( ) ;
148
151
152
+ // update and or resize swap chain
153
+ let reized = swap_chain. update :: < os_platform:: App > ( & mut device, & window, & mut cmd) ;
154
+
155
+ // resize the rw texture output
156
+ if reized {
157
+ raytracing_output = create_raytracing_output ( & mut device, & window. get_viewport_rect ( ) ) ;
158
+ }
159
+
149
160
// build command buffer and make draw calls
150
161
cmd. reset ( & swap_chain) ;
151
162
0 commit comments