diff --git a/librashader-runtime-d3d12/src/framebuffer.rs b/librashader-runtime-d3d12/src/framebuffer.rs index 3941871..071e0ce 100644 --- a/librashader-runtime-d3d12/src/framebuffer.rs +++ b/librashader-runtime-d3d12/src/framebuffer.rs @@ -15,14 +15,14 @@ use windows::Win32::Graphics::Direct3D12::{ D3D12_FORMAT_SUPPORT1_RENDER_TARGET, D3D12_FORMAT_SUPPORT1_SHADER_SAMPLE, D3D12_FORMAT_SUPPORT1_TEXTURE2D, D3D12_HEAP_FLAG_NONE, D3D12_HEAP_PROPERTIES, D3D12_HEAP_TYPE_DEFAULT, D3D12_MEMORY_POOL_UNKNOWN, D3D12_RENDER_TARGET_VIEW_DESC, - D3D12_RENDER_TARGET_VIEW_DESC_0, D3D12_RESOURCE_DESC, D3D12_RESOURCE_DIMENSION_TEXTURE2D, - D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET, D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS, - D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_COPY_SOURCE, - D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE, D3D12_RESOURCE_STATE_RENDER_TARGET, - D3D12_RTV_DIMENSION_TEXTURE2D, D3D12_SHADER_RESOURCE_VIEW_DESC, - D3D12_SHADER_RESOURCE_VIEW_DESC_0, D3D12_SRV_DIMENSION_TEXTURE2D, D3D12_TEX2D_RTV, - D3D12_TEX2D_SRV, D3D12_TEXTURE_COPY_LOCATION, D3D12_TEXTURE_COPY_LOCATION_0, - D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX, + D3D12_RENDER_TARGET_VIEW_DESC_0, D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES, D3D12_RESOURCE_DESC, + D3D12_RESOURCE_DIMENSION_TEXTURE2D, D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET, + D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_DEST, + D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE, + D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RTV_DIMENSION_TEXTURE2D, + D3D12_SHADER_RESOURCE_VIEW_DESC, D3D12_SHADER_RESOURCE_VIEW_DESC_0, + D3D12_SRV_DIMENSION_TEXTURE2D, D3D12_TEX2D_RTV, D3D12_TEX2D_SRV, D3D12_TEXTURE_COPY_LOCATION, + D3D12_TEXTURE_COPY_LOCATION_0, D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX, }; use windows::Win32::Graphics::Dxgi::Common::DXGI_SAMPLE_DESC; @@ -116,19 +116,23 @@ impl OwnedImage { cmd: &ID3D12GraphicsCommandList, input: &InputTexture, ) -> error::Result<()> { - util::d3d12_resource_transition( - cmd, - &input.resource, - D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE, - D3D12_RESOURCE_STATE_COPY_SOURCE, - ); + let barriers = [ + util::d3d12_get_resource_transition_subresource( + &input.resource, + D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE, + D3D12_RESOURCE_STATE_COPY_SOURCE, + D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES, + ), + util::d3d12_get_resource_transition_subresource( + &self.handle, + D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE, + D3D12_RESOURCE_STATE_COPY_DEST, + D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES, + ), + ]; + + cmd.ResourceBarrier(&barriers); - util::d3d12_resource_transition( - cmd, - &self.handle, - D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE, - D3D12_RESOURCE_STATE_COPY_DEST, - ); unsafe { cmd.CopyTextureRegion( &D3D12_TEXTURE_COPY_LOCATION { @@ -159,18 +163,21 @@ impl OwnedImage { ); } - util::d3d12_resource_transition( - cmd, - &input.resource, - D3D12_RESOURCE_STATE_COPY_SOURCE, - D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE, - ); - util::d3d12_resource_transition( - cmd, - &self.handle, - D3D12_RESOURCE_STATE_COPY_DEST, - D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE, - ); + let barriers = [ + util::d3d12_get_resource_transition_subresource( + &input.resource, + D3D12_RESOURCE_STATE_COPY_SOURCE, + D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE, + D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES, + ), + util::d3d12_get_resource_transition_subresource( + &self.handle, + D3D12_RESOURCE_STATE_COPY_DEST, + D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE, + D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES, + ), + ]; + cmd.ResourceBarrier(&barriers); Ok(()) } diff --git a/librashader-runtime-d3d12/src/lib.rs b/librashader-runtime-d3d12/src/lib.rs index aead3fd..ffc2bcc 100644 --- a/librashader-runtime-d3d12/src/lib.rs +++ b/librashader-runtime-d3d12/src/lib.rs @@ -1,5 +1,4 @@ #![cfg(target_os = "windows")] - #![feature(const_trait_impl)] #![feature(let_chains)] #![feature(type_alias_impl_trait)] @@ -34,8 +33,8 @@ mod tests { fn triangle_d3d12() { let sample = hello_triangle::d3d12_hello_triangle::Sample::new( // "../test/slang-shaders/crt/crt-lottes.slangp", - // "../test/slang-shaders/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV.slangp", - "../test/slang-shaders/crt/crt-royale.slangp", + "../test/slang-shaders/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV.slangp", + // "../test/slang-shaders/crt/crt-royale.slangp", // "../test/slang-shaders/vhs/VHSPro.slangp", &SampleCommandLine { use_warp_device: false, diff --git a/librashader-runtime-d3d12/src/texture.rs b/librashader-runtime-d3d12/src/texture.rs index 733a36b..3f15bf4 100644 --- a/librashader-runtime-d3d12/src/texture.rs +++ b/librashader-runtime-d3d12/src/texture.rs @@ -42,7 +42,6 @@ impl AsRef for OutputDescriptor { } } - /// An image view for use as a render target. /// /// Can be created from a CPU descriptor handle, and a size. diff --git a/librashader-runtime-d3d12/src/util.rs b/librashader-runtime-d3d12/src/util.rs index eab4077..28ae96a 100644 --- a/librashader-runtime-d3d12/src/util.rs +++ b/librashader-runtime-d3d12/src/util.rs @@ -226,15 +226,13 @@ pub fn d3d12_resource_transition( ); } -#[inline(always)] -pub fn d3d12_resource_transition_subresource( - cmd: &ID3D12GraphicsCommandList, +pub fn d3d12_get_resource_transition_subresource( resource: &ID3D12Resource, before: D3D12_RESOURCE_STATES, after: D3D12_RESOURCE_STATES, subresource: u32, -) { - let barrier = [D3D12_RESOURCE_BARRIER { +) -> D3D12_RESOURCE_BARRIER { + let barrier = D3D12_RESOURCE_BARRIER { Type: D3D12_RESOURCE_BARRIER_TYPE_TRANSITION, Flags: D3D12_RESOURCE_BARRIER_FLAG_NONE, Anonymous: D3D12_RESOURCE_BARRIER_0 { @@ -245,8 +243,25 @@ pub fn d3d12_resource_transition_subresource( StateAfter: after, }), }, - }]; + }; + barrier +} + +#[inline(always)] +pub fn d3d12_resource_transition_subresource( + cmd: &ID3D12GraphicsCommandList, + resource: &ID3D12Resource, + before: D3D12_RESOURCE_STATES, + after: D3D12_RESOURCE_STATES, + subresource: u32, +) { + let barrier = [d3d12_get_resource_transition_subresource( + resource, + before, + after, + subresource, + )]; unsafe { cmd.ResourceBarrier(&barrier) } }