Skip to content

Commit 4c0a5b1

Browse files
worleydlchyyran
andauthored
rt(d3d12): viewport param scissor fix, clear color fix (#218)
* d3d12: viewport param scissor fix, clear color fix * d3d12: specify color for optimized clear * doc: clean up comments --------- Co-authored-by: Ronny Chan <ronny@ronnychan.ca>
1 parent bd2b878 commit 4c0a5b1

1 file changed

Lines changed: 21 additions & 12 deletions

File tree

librashader-runtime-d3d12/src/filter_pass.rs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ use windows::core::Interface;
2424
use windows::Win32::Foundation::RECT;
2525
use windows::Win32::Graphics::Direct3D12::{
2626
ID3D12GraphicsCommandList, ID3D12GraphicsCommandList4, D3D12_RENDER_PASS_BEGINNING_ACCESS,
27-
D3D12_RENDER_PASS_BEGINNING_ACCESS_TYPE_DISCARD, D3D12_RENDER_PASS_ENDING_ACCESS,
27+
D3D12_RENDER_PASS_BEGINNING_ACCESS_0, D3D12_RENDER_PASS_BEGINNING_ACCESS_CLEAR_PARAMETERS,
28+
D3D12_CLEAR_VALUE, D3D12_CLEAR_VALUE_0,
29+
D3D12_RENDER_PASS_BEGINNING_ACCESS_TYPE_CLEAR, D3D12_RENDER_PASS_ENDING_ACCESS,
2830
D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_PRESERVE, D3D12_RENDER_PASS_FLAG_NONE,
2931
D3D12_RENDER_PASS_RENDER_TARGET_DESC, D3D12_VIEWPORT,
3032
};
@@ -206,25 +208,32 @@ impl FilterPass {
206208
// todo: check for non-renderpass.
207209

208210
let cmd = cmd.cast::<ID3D12GraphicsCommandList4>()?;
211+
212+
// Define the clear color here instead of ClearRenderTargetView
213+
let clear_value = D3D12_CLEAR_VALUE {
214+
Format: output.output.format,
215+
Anonymous: D3D12_CLEAR_VALUE_0 {
216+
Color: [0.0, 0.0, 0.0, 1.0],
217+
},
218+
};
219+
209220
unsafe {
210221
let pass = [D3D12_RENDER_PASS_RENDER_TARGET_DESC {
211222
cpuDescriptor: *output.output.descriptor.as_ref(),
212223
BeginningAccess: D3D12_RENDER_PASS_BEGINNING_ACCESS {
213-
Type: D3D12_RENDER_PASS_BEGINNING_ACCESS_TYPE_DISCARD,
214-
..Default::default()
224+
Type: D3D12_RENDER_PASS_BEGINNING_ACCESS_TYPE_CLEAR,
225+
Anonymous: D3D12_RENDER_PASS_BEGINNING_ACCESS_0 {
226+
Clear: D3D12_RENDER_PASS_BEGINNING_ACCESS_CLEAR_PARAMETERS {
227+
ClearValue: clear_value,
228+
},
229+
},
215230
},
216231
EndingAccess: D3D12_RENDER_PASS_ENDING_ACCESS {
217232
Type: D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_PRESERVE,
218233
Anonymous: Default::default(),
219234
},
220235
}];
221-
222-
cmd.ClearRenderTargetView(
223-
*output.output.descriptor.as_ref(),
224-
&[0.0, 0.0, 0.0, 0.0],
225-
None,
226-
);
227-
236+
228237
cmd.BeginRenderPass(Some(&pass), None, D3D12_RENDER_PASS_FLAG_NONE)
229238
}
230239

@@ -241,8 +250,8 @@ impl FilterPass {
241250
cmd.RSSetScissorRects(&[RECT {
242251
left: output.x as i32,
243252
top: output.y as i32,
244-
right: output.size.width as i32,
245-
bottom: output.size.height as i32,
253+
right: output.size.width as i32 + output.x as i32,
254+
bottom: output.size.height as i32 + output.y as i32,
246255
}]);
247256

248257
parent.draw_quad.draw_quad(&cmd, vbo_type)

0 commit comments

Comments
 (0)