From d7af6e6a2476b05e5aeec416f7139c88afc3d2c9 Mon Sep 17 00:00:00 2001 From: chyyran Date: Sun, 29 Sep 2024 00:30:39 -0400 Subject: [PATCH 1/7] rt(d3d12): use InterfaceRef for D3D12InputImage to avoid refcount for input image --- .../src/runtime/d3d12/filter_chain.rs | 19 ++---- librashader-cli/src/render/d3d12/mod.rs | 18 +++--- librashader-runtime-d3d12/src/framebuffer.rs | 2 +- librashader-runtime-d3d12/src/luts.rs | 2 +- librashader-runtime-d3d12/src/texture.rs | 62 ++++++------------- .../tests/hello_triangle/mod.rs | 2 +- 6 files changed, 35 insertions(+), 70 deletions(-) diff --git a/librashader-capi/src/runtime/d3d12/filter_chain.rs b/librashader-capi/src/runtime/d3d12/filter_chain.rs index 80ab7c8f..e3b33893 100644 --- a/librashader-capi/src/runtime/d3d12/filter_chain.rs +++ b/librashader-capi/src/runtime/d3d12/filter_chain.rs @@ -8,6 +8,7 @@ use std::ffi::CStr; use std::mem::{ManuallyDrop, MaybeUninit}; use std::ptr::NonNull; use std::slice; +use windows::core::Interface; use windows::Win32::Graphics::Direct3D12::{ ID3D12Device, ID3D12GraphicsCommandList, ID3D12Resource, D3D12_CPU_DESCRIPTOR_HANDLE, }; @@ -93,19 +94,6 @@ config_struct! { } } -impl TryFrom for D3D12InputImage { - type Error = LibrashaderError; - - fn try_from(value: libra_source_image_d3d12_t) -> Result { - let resource = value.resource.clone(); - - Ok(D3D12InputImage { - resource: ManuallyDrop::into_inner(resource), - descriptor: value.descriptor, - }) - } -} - extern_fn! { /// Create the filter chain given the shader preset. /// @@ -295,7 +283,10 @@ extern_fn! { } }; - let image = image.try_into()?; + let image = D3D12InputImage { + resource: image.resource.to_ref(), + descriptor: image.descriptor, + }; unsafe { chain.frame(&command_list, image, &viewport, frame_count, options.as_ref())?; } diff --git a/librashader-cli/src/render/d3d12/mod.rs b/librashader-cli/src/render/d3d12/mod.rs index cc151b81..b905cdc4 100644 --- a/librashader-cli/src/render/d3d12/mod.rs +++ b/librashader-cli/src/render/d3d12/mod.rs @@ -45,7 +45,7 @@ pub struct Direct3D12 { _cpu_heap: D3D12DescriptorHeap, rtv_heap: D3D12DescriptorHeap, - texture: D3D12InputImage, + texture: ID3D12Resource, _heap_slot: D3D12DescriptorHeapSlot, command_pool: ID3D12CommandAllocator, queue: ID3D12CommandQueue, @@ -154,7 +154,10 @@ impl RenderTest for Direct3D12 { for frame in 0..=frame_count { filter_chain.frame( &cmd, - self.texture.clone(), + D3D12InputImage { + resource: self.texture.to_ref(), + descriptor: *self._heap_slot.as_ref(), + }, &viewport, frame, options.as_ref(), @@ -249,7 +252,7 @@ impl Direct3D12 { path: &Path, ) -> anyhow::Result<( Image, - D3D12InputImage, + ID3D12Resource, D3D12DescriptorHeapSlot, )> { // 1 time queue infrastructure for lut uploads @@ -392,14 +395,7 @@ impl Direct3D12 { CloseHandle(fence_event)?; } - Ok(( - image, - D3D12InputImage { - resource, - descriptor: descriptor.as_ref().clone(), - }, - descriptor, - )) + Ok((image, resource, descriptor)) } } diff --git a/librashader-runtime-d3d12/src/framebuffer.rs b/librashader-runtime-d3d12/src/framebuffer.rs index 26e0a333..f2fe9053 100644 --- a/librashader-runtime-d3d12/src/framebuffer.rs +++ b/librashader-runtime-d3d12/src/framebuffer.rs @@ -295,7 +295,7 @@ impl OwnedImage { ); } - Ok(InputTexture::new::( + Ok(InputTexture::new( &self.resource, descriptor, self.size, diff --git a/librashader-runtime-d3d12/src/luts.rs b/librashader-runtime-d3d12/src/luts.rs index fdcfdc8d..4b24d6e0 100644 --- a/librashader-runtime-d3d12/src/luts.rs +++ b/librashader-runtime-d3d12/src/luts.rs @@ -201,7 +201,7 @@ impl LutTexture { D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE, ); - let view = InputTexture::new::( + let view = InputTexture::new( &resource, descriptor, source.size, diff --git a/librashader-runtime-d3d12/src/texture.rs b/librashader-runtime-d3d12/src/texture.rs index 5b38e30f..610556e3 100644 --- a/librashader-runtime-d3d12/src/texture.rs +++ b/librashader-runtime-d3d12/src/texture.rs @@ -1,15 +1,16 @@ use crate::descriptor_heap::{CpuStagingHeap, RenderTargetHeap}; -use crate::resource::ResourceHandleStrategy; -use d3d12_descriptor_heap::D3D12DescriptorHeapSlot; +use crate::resource::{OutlivesFrame, ResourceHandleStrategy}; +use d3d12_descriptor_heap::{D3D12DescriptorHeap, D3D12DescriptorHeapSlot}; use librashader_common::{FilterMode, GetSize, Size, WrapMode}; use std::mem::ManuallyDrop; +use windows::core::InterfaceRef; use windows::Win32::Graphics::Direct3D12::{ID3D12Resource, D3D12_CPU_DESCRIPTOR_HANDLE}; use windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT; /// An image for use as shader resource view. #[derive(Clone)] -pub struct D3D12InputImage { - pub resource: ID3D12Resource, +pub struct D3D12InputImage<'a> { + pub resource: InterfaceRef<'a, ID3D12Resource>, pub descriptor: D3D12_CPU_DESCRIPTOR_HANDLE, } @@ -95,12 +96,13 @@ pub struct InputTexture { pub(crate) format: DXGI_FORMAT, pub(crate) wrap_mode: WrapMode, pub(crate) filter: FilterMode, - drop_flag: bool, } impl InputTexture { - pub fn new, T>( - resource: &T, + // Create a new input texture, with runtime lifetime tracking. + // The source owned framebuffer must outlive this input. + pub fn new( + resource: &ManuallyDrop, handle: D3D12DescriptorHeapSlot, size: Size, format: DXGI_FORMAT, @@ -114,13 +116,12 @@ impl InputTexture { // as valid for the lifetime of handle. // Also, resource is non-null by construction. // Option and have the same layout. - resource: unsafe { std::mem::transmute(S::obtain(resource)) }, + resource: unsafe { std::mem::transmute(OutlivesFrame::obtain(resource)) }, descriptor: srv, size, format, wrap_mode, filter, - drop_flag: S::NEEDS_CLEANUP, } } @@ -132,42 +133,27 @@ impl InputTexture { ) -> InputTexture { let desc = unsafe { image.resource.GetDesc() }; InputTexture { - resource: ManuallyDrop::new(image.resource.clone()), + resource: unsafe { std::mem::transmute(image.resource) }, descriptor: InputDescriptor::Raw(image.descriptor), size: Size::new(desc.Width as u32, desc.Height), format: desc.Format, wrap_mode, filter, - drop_flag: true, } } } impl Clone for InputTexture { fn clone(&self) -> Self { - // ensure lifetime for raw resources or if there is a drop flag - if self.descriptor.is_raw() || self.drop_flag { - InputTexture { - resource: ManuallyDrop::clone(&self.resource), - descriptor: self.descriptor.clone(), - size: self.size, - format: self.format, - wrap_mode: self.wrap_mode, - filter: self.filter, - drop_flag: true, - } - } else { - // SAFETY: the parent doesn't have drop flag, so that means - // we don't need to handle drop. - InputTexture { - resource: unsafe { std::mem::transmute_copy(&self.resource) }, - descriptor: self.descriptor.clone(), - size: self.size, - format: self.format, - wrap_mode: self.wrap_mode, - filter: self.filter, - drop_flag: false, - } + // SAFETY: the parent doesn't have drop flag, so that means + // we don't need to handle drop. + InputTexture { + resource: unsafe { std::mem::transmute_copy(&self.resource) }, + descriptor: self.descriptor.clone(), + size: self.size, + format: self.format, + wrap_mode: self.wrap_mode, + filter: self.filter, } } } @@ -185,11 +171,3 @@ impl GetSize for D3D12OutputView { Ok(self.size) } } - -impl Drop for InputTexture { - fn drop(&mut self) { - if self.drop_flag { - unsafe { ManuallyDrop::drop(&mut self.resource) } - } - } -} diff --git a/librashader-runtime-d3d12/tests/hello_triangle/mod.rs b/librashader-runtime-d3d12/tests/hello_triangle/mod.rs index 354fdfa6..fa983804 100644 --- a/librashader-runtime-d3d12/tests/hello_triangle/mod.rs +++ b/librashader-runtime-d3d12/tests/hello_triangle/mod.rs @@ -620,7 +620,7 @@ pub mod d3d12_hello_triangle { .frame( command_list, D3D12InputImage { - resource: ID3D12Resource::clone(&*resources.framebuffer), + resource: resources.framebuffer.to_ref(), descriptor: framebuffer, }, &Viewport { From a2cf752a38d5210216a10f510eb7e956376a093b Mon Sep 17 00:00:00 2001 From: chyyran Date: Sun, 29 Sep 2024 01:31:21 -0400 Subject: [PATCH 2/7] rt(d3d12): allow creating output view from a resource ref --- librashader-runtime-d3d12/src/error.rs | 3 + librashader-runtime-d3d12/src/filter_chain.rs | 2 +- librashader-runtime-d3d12/src/framebuffer.rs | 33 ++--------- librashader-runtime-d3d12/src/texture.rs | 58 ++++++++++++++++++- 4 files changed, 65 insertions(+), 31 deletions(-) diff --git a/librashader-runtime-d3d12/src/error.rs b/librashader-runtime-d3d12/src/error.rs index 7139d071..29fb5568 100644 --- a/librashader-runtime-d3d12/src/error.rs +++ b/librashader-runtime-d3d12/src/error.rs @@ -3,6 +3,7 @@ use d3d12_descriptor_heap::D3D12DescriptorHeapError; use thiserror::Error; +use windows::Win32::Graphics::Direct3D12::D3D12_RESOURCE_DIMENSION; /// Cumulative error type for Direct3D12 filter chains. #[derive(Error, Debug)] @@ -26,6 +27,8 @@ pub enum FilterChainError { HeapError(#[from] D3D12DescriptorHeapError), #[error("allocation error")] AllocationError(#[from] gpu_allocator::AllocationError), + #[error("invalid resource dimension {0:?}")] + InvalidDimensionError(D3D12_RESOURCE_DIMENSION), #[error("unreachable")] Infallible(#[from] std::convert::Infallible), } diff --git a/librashader-runtime-d3d12/src/filter_chain.rs b/librashader-runtime-d3d12/src/filter_chain.rs index 60c7705b..91d19d13 100644 --- a/librashader-runtime-d3d12/src/filter_chain.rs +++ b/librashader-runtime-d3d12/src/filter_chain.rs @@ -68,7 +68,7 @@ pub struct FilterChainD3D12 { pub(crate) feedback_framebuffers: Box<[OwnedImage]>, pub(crate) history_framebuffers: VecDeque, staging_heap: D3D12DescriptorHeap, - rtv_heap: D3D12DescriptorHeap, + pub(crate) rtv_heap: D3D12DescriptorHeap, work_heap: ID3D12DescriptorHeap, sampler_heap: ID3D12DescriptorHeap, diff --git a/librashader-runtime-d3d12/src/framebuffer.rs b/librashader-runtime-d3d12/src/framebuffer.rs index f2fe9053..70fc50fb 100644 --- a/librashader-runtime-d3d12/src/framebuffer.rs +++ b/librashader-runtime-d3d12/src/framebuffer.rs @@ -16,20 +16,20 @@ use librashader_runtime::scaling::{MipmapSize, ScaleFramebuffer, ViewportSize}; use parking_lot::Mutex; use std::mem::ManuallyDrop; use std::sync::Arc; +use windows::core::Interface; use windows::Win32::Graphics::Direct3D12::{ ID3D12Device, ID3D12GraphicsCommandList, ID3D12Resource, D3D12_BOX, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING, D3D12_FEATURE_DATA_FORMAT_SUPPORT, D3D12_FORMAT_SUPPORT1_MIP, D3D12_FORMAT_SUPPORT1_RENDER_TARGET, D3D12_FORMAT_SUPPORT1_SHADER_SAMPLE, D3D12_FORMAT_SUPPORT1_TEXTURE2D, D3D12_FORMAT_SUPPORT2_UAV_TYPED_LOAD, D3D12_FORMAT_SUPPORT2_UAV_TYPED_STORE, - D3D12_RENDER_TARGET_VIEW_DESC, 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_RESOURCE_STATE_RENDER_TARGET, 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_SRV_DIMENSION_TEXTURE2D, 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_FORMAT, DXGI_SAMPLE_DESC}; @@ -309,32 +309,7 @@ impl OwnedImage { &self, heap: &mut D3D12DescriptorHeap, ) -> error::Result { - let descriptor = heap.allocate_descriptor()?; - - unsafe { - let rtv_desc = D3D12_RENDER_TARGET_VIEW_DESC { - Format: self.format.into(), - ViewDimension: D3D12_RTV_DIMENSION_TEXTURE2D, - Anonymous: D3D12_RENDER_TARGET_VIEW_DESC_0 { - Texture2D: D3D12_TEX2D_RTV { - MipSlice: 0, - ..Default::default() - }, - }, - }; - - self.device.CreateRenderTargetView( - self.handle.resource(), - Some(&rtv_desc), - *descriptor.as_ref(), - ); - } - - Ok(D3D12OutputView::new( - descriptor, - self.size, - self.format.into(), - )) + D3D12OutputView::new_from_resource_internal(self.resource.to_ref(), &self.device, heap) } pub fn scale( diff --git a/librashader-runtime-d3d12/src/texture.rs b/librashader-runtime-d3d12/src/texture.rs index 610556e3..6f429865 100644 --- a/librashader-runtime-d3d12/src/texture.rs +++ b/librashader-runtime-d3d12/src/texture.rs @@ -1,12 +1,22 @@ use crate::descriptor_heap::{CpuStagingHeap, RenderTargetHeap}; +use crate::{error, FilterChainD3D12}; use crate::resource::{OutlivesFrame, ResourceHandleStrategy}; use d3d12_descriptor_heap::{D3D12DescriptorHeap, D3D12DescriptorHeapSlot}; use librashader_common::{FilterMode, GetSize, Size, WrapMode}; use std::mem::ManuallyDrop; +use std::ops::Deref; use windows::core::InterfaceRef; -use windows::Win32::Graphics::Direct3D12::{ID3D12Resource, D3D12_CPU_DESCRIPTOR_HANDLE}; +use windows::Win32::Graphics::Direct3D12::{ + ID3D12Device, ID3D12Resource, D3D12_CPU_DESCRIPTOR_HANDLE, D3D12_RENDER_TARGET_VIEW_DESC, + D3D12_RENDER_TARGET_VIEW_DESC_0, D3D12_RESOURCE_DIMENSION_TEXTURE2D, + D3D12_RTV_DIMENSION_TEXTURE2D, D3D12_TEX2D_RTV, +}; use windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT; +/// A **non-owning** reference to a ID3D12Resource. +/// This does not `AddRef` or `Release` the underlying interface. +pub type D3D12ResourceRef<'a> = InterfaceRef<'a, ID3D12Resource>; + /// An image for use as shader resource view. #[derive(Clone)] pub struct D3D12InputImage<'a> { @@ -87,6 +97,52 @@ impl D3D12OutputView { format, } } + + /// Create a new output view from a resource ref, linked to the chain. + /// + /// The output view will be automatically disposed on drop. + pub fn new_from_resource( + image: D3D12ResourceRef, + chain: &mut FilterChainD3D12 + ) -> error::Result { + Self::new_from_resource_internal(image, &chain.common.d3d12, &mut chain.rtv_heap) + } + + /// Create a new output view from a resource ref + pub(crate) fn new_from_resource_internal( + image: D3D12ResourceRef, + device: &ID3D12Device, + heap: &mut D3D12DescriptorHeap, + ) -> error::Result { + let desc = unsafe { image.GetDesc() }; + if desc.Dimension != D3D12_RESOURCE_DIMENSION_TEXTURE2D { + return Err(crate::error::FilterChainError::InvalidDimensionError( + desc.Dimension, + )); + } + + let slot = heap.allocate_descriptor()?; + unsafe { + let rtv_desc = D3D12_RENDER_TARGET_VIEW_DESC { + Format: desc.Format, + ViewDimension: D3D12_RTV_DIMENSION_TEXTURE2D, + Anonymous: D3D12_RENDER_TARGET_VIEW_DESC_0 { + Texture2D: D3D12_TEX2D_RTV { + MipSlice: 0, + ..Default::default() + }, + }, + }; + + device.CreateRenderTargetView(image.deref(), Some(&rtv_desc), *slot.as_ref()); + } + + Ok(Self::new( + slot, + Size::new(desc.Width as u32, desc.Height), + desc.Format, + )) + } } pub struct InputTexture { From e416be6c027607aa1394c101ac8598e10512daea Mon Sep 17 00:00:00 2001 From: chyyran Date: Sun, 29 Sep 2024 01:41:02 -0400 Subject: [PATCH 3/7] rt(d3d12): allow creating input view without a CPU handle --- .../src/runtime/d3d12/filter_chain.rs | 2 +- librashader-cli/src/render/d3d12/mod.rs | 2 +- librashader-runtime-d3d12/src/filter_chain.rs | 4 +- librashader-runtime-d3d12/src/texture.rs | 60 ++++++++++++++----- .../tests/hello_triangle/mod.rs | 2 +- 5 files changed, 49 insertions(+), 21 deletions(-) diff --git a/librashader-capi/src/runtime/d3d12/filter_chain.rs b/librashader-capi/src/runtime/d3d12/filter_chain.rs index e3b33893..adc08896 100644 --- a/librashader-capi/src/runtime/d3d12/filter_chain.rs +++ b/librashader-capi/src/runtime/d3d12/filter_chain.rs @@ -285,7 +285,7 @@ extern_fn! { let image = D3D12InputImage { resource: image.resource.to_ref(), - descriptor: image.descriptor, + descriptor: Some(image.descriptor), }; unsafe { chain.frame(&command_list, image, &viewport, frame_count, options.as_ref())?; diff --git a/librashader-cli/src/render/d3d12/mod.rs b/librashader-cli/src/render/d3d12/mod.rs index b905cdc4..15712a57 100644 --- a/librashader-cli/src/render/d3d12/mod.rs +++ b/librashader-cli/src/render/d3d12/mod.rs @@ -156,7 +156,7 @@ impl RenderTest for Direct3D12 { &cmd, D3D12InputImage { resource: self.texture.to_ref(), - descriptor: *self._heap_slot.as_ref(), + descriptor: None, }, &viewport, frame, diff --git a/librashader-runtime-d3d12/src/filter_chain.rs b/librashader-runtime-d3d12/src/filter_chain.rs index 91d19d13..d39ce1ba 100644 --- a/librashader-runtime-d3d12/src/filter_chain.rs +++ b/librashader-runtime-d3d12/src/filter_chain.rs @@ -336,7 +336,7 @@ impl FilterChainD3D12 { let rtv_heap = unsafe { D3D12DescriptorHeap::new( device, - (MAX_BINDINGS_COUNT as usize) * shader_count + (1 + MAX_BINDINGS_COUNT as usize) * shader_count + MIPMAP_RESERVED_WORKHEAP_DESCRIPTORS + lut_count, ) @@ -735,7 +735,7 @@ impl FilterChainD3D12 { Some(fbo.create_shader_resource_view(&mut self.staging_heap, filter, wrap_mode)?); } - let original = unsafe { InputTexture::new_from_raw(input, filter, wrap_mode) }; + let original = unsafe { InputTexture::new_from_raw(input, filter, wrap_mode, &self.common.d3d12, &mut self.staging_heap)? }; let mut source = original.clone(); // swap output and feedback **before** recording command buffers diff --git a/librashader-runtime-d3d12/src/texture.rs b/librashader-runtime-d3d12/src/texture.rs index 6f429865..1813151f 100644 --- a/librashader-runtime-d3d12/src/texture.rs +++ b/librashader-runtime-d3d12/src/texture.rs @@ -6,12 +6,9 @@ use librashader_common::{FilterMode, GetSize, Size, WrapMode}; use std::mem::ManuallyDrop; use std::ops::Deref; use windows::core::InterfaceRef; -use windows::Win32::Graphics::Direct3D12::{ - ID3D12Device, ID3D12Resource, D3D12_CPU_DESCRIPTOR_HANDLE, D3D12_RENDER_TARGET_VIEW_DESC, - D3D12_RENDER_TARGET_VIEW_DESC_0, D3D12_RESOURCE_DIMENSION_TEXTURE2D, - D3D12_RTV_DIMENSION_TEXTURE2D, D3D12_TEX2D_RTV, -}; +use windows::Win32::Graphics::Direct3D12::{ID3D12Device, ID3D12Resource, D3D12_CPU_DESCRIPTOR_HANDLE, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING, D3D12_RENDER_TARGET_VIEW_DESC, D3D12_RENDER_TARGET_VIEW_DESC_0, D3D12_RESOURCE_DIMENSION_TEXTURE2D, 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}; use windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT; +use crate::error::FilterChainError; /// A **non-owning** reference to a ID3D12Resource. /// This does not `AddRef` or `Release` the underlying interface. @@ -21,7 +18,16 @@ pub type D3D12ResourceRef<'a> = InterfaceRef<'a, ID3D12Resource>; #[derive(Clone)] pub struct D3D12InputImage<'a> { pub resource: InterfaceRef<'a, ID3D12Resource>, - pub descriptor: D3D12_CPU_DESCRIPTOR_HANDLE, + pub descriptor: Option, +} + +impl<'a> From> for D3D12InputImage<'a> { + fn from(value: InterfaceRef<'a, ID3D12Resource>) -> Self { + Self { + resource: value, + descriptor: None + } + } } #[derive(Clone)] @@ -30,12 +36,6 @@ pub(crate) enum InputDescriptor { Raw(D3D12_CPU_DESCRIPTOR_HANDLE), } -impl InputDescriptor { - fn is_raw(&self) -> bool { - matches!(self, InputDescriptor::Raw(_)) - } -} - #[derive(Clone)] pub(crate) enum OutputDescriptor { Owned(D3D12DescriptorHeapSlot), @@ -186,17 +186,45 @@ impl InputTexture { image: D3D12InputImage, filter: FilterMode, wrap_mode: WrapMode, - ) -> InputTexture { + device: &ID3D12Device, + heap: &mut D3D12DescriptorHeap, + ) -> error::Result { let desc = unsafe { image.resource.GetDesc() }; - InputTexture { + if desc.Dimension != D3D12_RESOURCE_DIMENSION_TEXTURE2D { + return Err(FilterChainError::InvalidDimensionError(desc.Dimension)); + } + + let descriptor = image.descriptor.map_or_else(|| { + let slot = heap.allocate_descriptor()?; + unsafe { + let srv_desc = D3D12_SHADER_RESOURCE_VIEW_DESC { + Format: desc.Format, + ViewDimension: D3D12_SRV_DIMENSION_TEXTURE2D, + Shader4ComponentMapping: D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING, + Anonymous: D3D12_SHADER_RESOURCE_VIEW_DESC_0 { + Texture2D: D3D12_TEX2D_SRV { + MipLevels: desc.MipLevels as u32, + ..Default::default() + }, + }, + }; + device.CreateShaderResourceView(image.resource.deref(), Some(&srv_desc), *slot.as_ref()); + } + + Ok::<_, FilterChainError>(InputDescriptor::Owned(slot)) + }, |raw| Ok(InputDescriptor::Raw(raw)))?; + + Ok(InputTexture { resource: unsafe { std::mem::transmute(image.resource) }, - descriptor: InputDescriptor::Raw(image.descriptor), + descriptor, size: Size::new(desc.Width as u32, desc.Height), format: desc.Format, wrap_mode, filter, - } + }) } + + } impl Clone for InputTexture { diff --git a/librashader-runtime-d3d12/tests/hello_triangle/mod.rs b/librashader-runtime-d3d12/tests/hello_triangle/mod.rs index fa983804..5d9fe564 100644 --- a/librashader-runtime-d3d12/tests/hello_triangle/mod.rs +++ b/librashader-runtime-d3d12/tests/hello_triangle/mod.rs @@ -621,7 +621,7 @@ pub mod d3d12_hello_triangle { command_list, D3D12InputImage { resource: resources.framebuffer.to_ref(), - descriptor: framebuffer, + descriptor: Some(framebuffer), }, &Viewport { x: 0.0, From f4a8b50ec466a7a2a756d81f8088f54d9c29f45e Mon Sep 17 00:00:00 2001 From: chyyran Date: Sun, 29 Sep 2024 01:51:05 -0400 Subject: [PATCH 4/7] capi(d3d12): change the layout so that descriptor is first in libra_source_image_d3d12_t --- librashader-capi/src/runtime/d3d12/filter_chain.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/librashader-capi/src/runtime/d3d12/filter_chain.rs b/librashader-capi/src/runtime/d3d12/filter_chain.rs index adc08896..01251f4b 100644 --- a/librashader-capi/src/runtime/d3d12/filter_chain.rs +++ b/librashader-capi/src/runtime/d3d12/filter_chain.rs @@ -23,10 +23,10 @@ use librashader::runtime::{FilterChainParameters, Size, Viewport}; /// Direct3D 12 parameters for the source image. #[repr(C)] pub struct libra_source_image_d3d12_t { - /// The resource containing the image. - pub resource: ManuallyDrop, /// A CPU descriptor handle to a shader resource view of the image. pub descriptor: D3D12_CPU_DESCRIPTOR_HANDLE, + /// The resource containing the image. + pub resource: ManuallyDrop, } /// Direct3D 12 parameters for the output image. From 435a57c29e814133adb75464998ce3a9e0f78e13 Mon Sep 17 00:00:00 2001 From: chyyran Date: Mon, 30 Sep 2024 01:42:16 -0400 Subject: [PATCH 5/7] rt(d3d12): allow construction of D3D12InputImage without a descriptor handle --- .../src/runtime/d3d12/filter_chain.rs | 4 +- librashader-cli/src/render/d3d12/mod.rs | 5 +- librashader-runtime-d3d12/src/filter_chain.rs | 19 +++- librashader-runtime-d3d12/src/framebuffer.rs | 14 +-- librashader-runtime-d3d12/src/luts.rs | 2 +- librashader-runtime-d3d12/src/texture.rs | 86 ++++++++++++------- 6 files changed, 85 insertions(+), 45 deletions(-) diff --git a/librashader-capi/src/runtime/d3d12/filter_chain.rs b/librashader-capi/src/runtime/d3d12/filter_chain.rs index 01251f4b..525f929e 100644 --- a/librashader-capi/src/runtime/d3d12/filter_chain.rs +++ b/librashader-capi/src/runtime/d3d12/filter_chain.rs @@ -283,9 +283,9 @@ extern_fn! { } }; - let image = D3D12InputImage { + let image = D3D12InputImage::External { resource: image.resource.to_ref(), - descriptor: Some(image.descriptor), + descriptor: image.descriptor, }; unsafe { chain.frame(&command_list, image, &viewport, frame_count, options.as_ref())?; diff --git a/librashader-cli/src/render/d3d12/mod.rs b/librashader-cli/src/render/d3d12/mod.rs index 15712a57..bf6f8c1e 100644 --- a/librashader-cli/src/render/d3d12/mod.rs +++ b/librashader-cli/src/render/d3d12/mod.rs @@ -154,10 +154,7 @@ impl RenderTest for Direct3D12 { for frame in 0..=frame_count { filter_chain.frame( &cmd, - D3D12InputImage { - resource: self.texture.to_ref(), - descriptor: None, - }, + D3D12InputImage::Managed(self.texture.to_ref()), &viewport, frame, options.as_ref(), diff --git a/librashader-runtime-d3d12/src/filter_chain.rs b/librashader-runtime-d3d12/src/filter_chain.rs index d39ce1ba..8aea2fae 100644 --- a/librashader-runtime-d3d12/src/filter_chain.rs +++ b/librashader-runtime-d3d12/src/filter_chain.rs @@ -67,7 +67,7 @@ pub struct FilterChainD3D12 { pub(crate) output_framebuffers: Box<[OwnedImage]>, pub(crate) feedback_framebuffers: Box<[OwnedImage]>, pub(crate) history_framebuffers: VecDeque, - staging_heap: D3D12DescriptorHeap, + pub(crate) staging_heap: D3D12DescriptorHeap, pub(crate) rtv_heap: D3D12DescriptorHeap, work_heap: ID3D12DescriptorHeap, @@ -735,7 +735,22 @@ impl FilterChainD3D12 { Some(fbo.create_shader_resource_view(&mut self.staging_heap, filter, wrap_mode)?); } - let original = unsafe { InputTexture::new_from_raw(input, filter, wrap_mode, &self.common.d3d12, &mut self.staging_heap)? }; + let original = unsafe { + match input { + D3D12InputImage::Managed(input) => InputTexture::new_from_resource( + input, + filter, + wrap_mode, + &self.common.d3d12, + &mut self.staging_heap, + )?, + D3D12InputImage::External { + resource, + descriptor, + } => InputTexture::new_from_raw(resource, descriptor, filter, wrap_mode), + } + }; + let mut source = original.clone(); // swap output and feedback **before** recording command buffers diff --git a/librashader-runtime-d3d12/src/framebuffer.rs b/librashader-runtime-d3d12/src/framebuffer.rs index 70fc50fb..110fc31c 100644 --- a/librashader-runtime-d3d12/src/framebuffer.rs +++ b/librashader-runtime-d3d12/src/framebuffer.rs @@ -27,10 +27,10 @@ use windows::Win32::Graphics::Direct3D12::{ 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_SHADER_RESOURCE_VIEW_DESC, D3D12_SHADER_RESOURCE_VIEW_DESC_0, - D3D12_SRV_DIMENSION_TEXTURE2D, D3D12_TEX2D_SRV, D3D12_TEXTURE_COPY_LOCATION, - D3D12_TEXTURE_COPY_LOCATION_0, D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX, + D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_SHADER_RESOURCE_VIEW_DESC, + D3D12_SHADER_RESOURCE_VIEW_DESC_0, D3D12_SRV_DIMENSION_TEXTURE2D, 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_FORMAT, DXGI_SAMPLE_DESC}; @@ -295,7 +295,7 @@ impl OwnedImage { ); } - Ok(InputTexture::new( + Ok(InputTexture::new_owned( &self.resource, descriptor, self.size, @@ -309,7 +309,9 @@ impl OwnedImage { &self, heap: &mut D3D12DescriptorHeap, ) -> error::Result { - D3D12OutputView::new_from_resource_internal(self.resource.to_ref(), &self.device, heap) + unsafe { + D3D12OutputView::new_from_resource_internal(self.resource.to_ref(), &self.device, heap) + } } pub fn scale( diff --git a/librashader-runtime-d3d12/src/luts.rs b/librashader-runtime-d3d12/src/luts.rs index 4b24d6e0..8e743300 100644 --- a/librashader-runtime-d3d12/src/luts.rs +++ b/librashader-runtime-d3d12/src/luts.rs @@ -201,7 +201,7 @@ impl LutTexture { D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE, ); - let view = InputTexture::new( + let view = InputTexture::new_owned( &resource, descriptor, source.size, diff --git a/librashader-runtime-d3d12/src/texture.rs b/librashader-runtime-d3d12/src/texture.rs index 1813151f..c766b1ca 100644 --- a/librashader-runtime-d3d12/src/texture.rs +++ b/librashader-runtime-d3d12/src/texture.rs @@ -1,14 +1,21 @@ use crate::descriptor_heap::{CpuStagingHeap, RenderTargetHeap}; -use crate::{error, FilterChainD3D12}; +use crate::error::FilterChainError; use crate::resource::{OutlivesFrame, ResourceHandleStrategy}; +use crate::{error, FilterChainD3D12}; use d3d12_descriptor_heap::{D3D12DescriptorHeap, D3D12DescriptorHeapSlot}; use librashader_common::{FilterMode, GetSize, Size, WrapMode}; use std::mem::ManuallyDrop; use std::ops::Deref; use windows::core::InterfaceRef; -use windows::Win32::Graphics::Direct3D12::{ID3D12Device, ID3D12Resource, D3D12_CPU_DESCRIPTOR_HANDLE, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING, D3D12_RENDER_TARGET_VIEW_DESC, D3D12_RENDER_TARGET_VIEW_DESC_0, D3D12_RESOURCE_DIMENSION_TEXTURE2D, 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}; +use windows::Win32::Graphics::Direct3D12::{ + ID3D12Device, ID3D12Resource, D3D12_CPU_DESCRIPTOR_HANDLE, + D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING, D3D12_RENDER_TARGET_VIEW_DESC, + D3D12_RENDER_TARGET_VIEW_DESC_0, D3D12_RESOURCE_DIMENSION_TEXTURE2D, + 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, +}; use windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT; -use crate::error::FilterChainError; /// A **non-owning** reference to a ID3D12Resource. /// This does not `AddRef` or `Release` the underlying interface. @@ -16,18 +23,16 @@ pub type D3D12ResourceRef<'a> = InterfaceRef<'a, ID3D12Resource>; /// An image for use as shader resource view. #[derive(Clone)] -pub struct D3D12InputImage<'a> { - pub resource: InterfaceRef<'a, ID3D12Resource>, - pub descriptor: Option, -} - -impl<'a> From> for D3D12InputImage<'a> { - fn from(value: InterfaceRef<'a, ID3D12Resource>) -> Self { - Self { - resource: value, - descriptor: None - } - } +pub enum D3D12InputImage<'a> { + /// The filter chain manages the CPU descriptor to the shader resource view. + Managed(InterfaceRef<'a, ID3D12Resource>), + /// The CPU descriptor to the shader resource view is managed externally. + External { + /// The ID3D12Resource that holds the image data. + resource: InterfaceRef<'a, ID3D12Resource>, + /// The CPU descriptor to the shader resource view. + descriptor: D3D12_CPU_DESCRIPTOR_HANDLE, + }, } #[derive(Clone)] @@ -85,6 +90,9 @@ impl D3D12OutputView { } // unsafe since the lifetime of the handle has to survive + /// Create a new D3D12OutputView from a CPU descriptor handle of a render target view. + /// + /// SAFETY: the handle must be valid until the command list is submitted. pub unsafe fn new_from_raw( handle: D3D12_CPU_DESCRIPTOR_HANDLE, size: Size, @@ -101,15 +109,17 @@ impl D3D12OutputView { /// Create a new output view from a resource ref, linked to the chain. /// /// The output view will be automatically disposed on drop. - pub fn new_from_resource( + /// + /// SAFETY: the image must be valid until the command list is submitted. + pub unsafe fn new_from_resource( image: D3D12ResourceRef, - chain: &mut FilterChainD3D12 + chain: &mut FilterChainD3D12, ) -> error::Result { - Self::new_from_resource_internal(image, &chain.common.d3d12, &mut chain.rtv_heap) + unsafe { Self::new_from_resource_internal(image, &chain.common.d3d12, &mut chain.rtv_heap) } } /// Create a new output view from a resource ref - pub(crate) fn new_from_resource_internal( + pub(crate) unsafe fn new_from_resource_internal( image: D3D12ResourceRef, device: &ID3D12Device, heap: &mut D3D12DescriptorHeap, @@ -145,7 +155,7 @@ impl D3D12OutputView { } } -pub struct InputTexture { +pub(crate) struct InputTexture { pub(crate) resource: ManuallyDrop, pub(crate) descriptor: InputDescriptor, pub(crate) size: Size, @@ -157,7 +167,7 @@ pub struct InputTexture { impl InputTexture { // Create a new input texture, with runtime lifetime tracking. // The source owned framebuffer must outlive this input. - pub fn new( + pub fn new_owned( resource: &ManuallyDrop, handle: D3D12DescriptorHeapSlot, size: Size, @@ -168,7 +178,7 @@ impl InputTexture { let srv = InputDescriptor::Owned(handle); InputTexture { // SAFETY: `new` is only used for owned textures. We know this because - // we also hold `handle`, so the texture is at least + // we also hold `handle`, so the texture must be valid for at least // as valid for the lifetime of handle. // Also, resource is non-null by construction. // Option and have the same layout. @@ -182,19 +192,19 @@ impl InputTexture { } // unsafe since the lifetime of the handle has to survive - pub unsafe fn new_from_raw( - image: D3D12InputImage, + pub unsafe fn new_from_resource<'a>( + image: InterfaceRef<'a, ID3D12Resource>, filter: FilterMode, wrap_mode: WrapMode, device: &ID3D12Device, heap: &mut D3D12DescriptorHeap, ) -> error::Result { - let desc = unsafe { image.resource.GetDesc() }; + let desc = unsafe { image.GetDesc() }; if desc.Dimension != D3D12_RESOURCE_DIMENSION_TEXTURE2D { return Err(FilterChainError::InvalidDimensionError(desc.Dimension)); } - let descriptor = image.descriptor.map_or_else(|| { + let descriptor = { let slot = heap.allocate_descriptor()?; unsafe { let srv_desc = D3D12_SHADER_RESOURCE_VIEW_DESC { @@ -208,14 +218,14 @@ impl InputTexture { }, }, }; - device.CreateShaderResourceView(image.resource.deref(), Some(&srv_desc), *slot.as_ref()); + device.CreateShaderResourceView(image.deref(), Some(&srv_desc), *slot.as_ref()); } Ok::<_, FilterChainError>(InputDescriptor::Owned(slot)) - }, |raw| Ok(InputDescriptor::Raw(raw)))?; + }?; Ok(InputTexture { - resource: unsafe { std::mem::transmute(image.resource) }, + resource: unsafe { std::mem::transmute(image) }, descriptor, size: Size::new(desc.Width as u32, desc.Height), format: desc.Format, @@ -224,7 +234,23 @@ impl InputTexture { }) } - + // unsafe since the lifetime of the handle has to survive + pub unsafe fn new_from_raw( + image: InterfaceRef, + descriptor: D3D12_CPU_DESCRIPTOR_HANDLE, + filter: FilterMode, + wrap_mode: WrapMode, + ) -> InputTexture { + let desc = unsafe { image.GetDesc() }; + InputTexture { + resource: unsafe { std::mem::transmute(image) }, + descriptor: InputDescriptor::Raw(descriptor), + size: Size::new(desc.Width as u32, desc.Height), + format: desc.Format, + wrap_mode, + filter, + } + } } impl Clone for InputTexture { From 978c5ce47feaf0b49d9eb5791e27d0142cdd285a Mon Sep 17 00:00:00 2001 From: chyyran Date: Mon, 30 Sep 2024 02:27:16 -0400 Subject: [PATCH 6/7] capi(d3d12): allow d3d12 to optionally use a resource handle with chain-managed descriptors --- MIGRATION-ABI2.md | 8 ++ include/librashader.h | 75 +++++++++++- include/librashader_ld.h | 2 +- .../src/runtime/d3d12/filter_chain.rs | 111 +++++++++++++++--- librashader-cli/src/render/d3d12/mod.rs | 14 +-- librashader-runtime-d3d12/src/texture.rs | 36 +++--- 6 files changed, 198 insertions(+), 48 deletions(-) diff --git a/MIGRATION-ABI2.md b/MIGRATION-ABI2.md index c2559778..437abbc4 100644 --- a/MIGRATION-ABI2.md +++ b/MIGRATION-ABI2.md @@ -66,9 +66,17 @@ The following changes are applicable if `LIBRA_RUNTIME_D3D11` is defined. ## `LIBRA_RUNTIME_D3D12` changes The following changes are applicable if `LIBRA_RUNTIME_D3D12` is defined. +* The lifetime of resources will not be extended past the call to the `libra_d3d12_filter_chain_frame` function. In other words, the refcount for any resources passed into the function + will no longer be changed, and it is explicitly the responsibility of the caller to ensure any resources remain alive until the `ID3D12GraphicsCommandList` provided is submitted. * The fields `format`, `width`, and `height` have been removed from `libra_source_image_d3d12_t`. * The fields `width` and `height` have been added to `libra_output_image_d3d12_t`. * You should now pass what was previously `.width` and `.height` of `libra_viewport_t` to these new fields in `libra_output_image_d3d12_t`. +* The `image` parameter of `libra_d3d12_filter_chain_frame` has changed from `libra_source_image_d3d12_t` to `libra_image_d3d12_t`. + * To maintain the previous behaviour, `.image_type` of the `libra_image_d3d12_t` should be set to `IMAGE_TYPE_SOURCE_IMAGE`, and `.handle.source` should be the `libra_source_image_d3d12_t`struct. +* The `out` parameter of `libra_d3d12_filter_chain_frame` has changed from `libra_output_image_d3d11_t` to `libra_image_d3d12_t`. + * To maintain the previous behaviour, `.image_type` of the `libra_image_d3d12_t` should be set to `IMAGE_TYPE_OUTPUT_IMAGE`, and `.handle.output` should be the `libra_output_image_d3d12_t`struct. +* Any `libra_image_d3d12_t` can now optionally pass only the `ID3D12Resource *` for the texture by setting `.image_type` to `IMAGE_TYPE_RESOURCE` and setting `.handle.resource` to the resource pointer. + * If using `IMAGE_TYPE_RESOURCE`, shader resource view and render target view descriptors for the input and output images will be internally allocated by the filter chain. This may result in marginally worse performance. * In `libra_d3d12_filter_chain_frame`, the position of the `viewport` parameter has moved to after the `out` parameter, and its type has changed from `libra_viewport_t` to `libra_viewport_t *`, which is allowed to be `NULL`. See [`libra_viewport_t` changes](#libra_viewport_t-changes) for more details. * The `chain` parameter of `libra_d3d12_filter_chain_get_param` has been made `const`. diff --git a/include/librashader.h b/include/librashader.h index 9bfcc5d5..6107306a 100644 --- a/include/librashader.h +++ b/include/librashader.h @@ -51,19 +51,45 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #endif +#if (defined(_WIN32) && defined(LIBRA_RUNTIME_D3D12)) +/// The type of image passed to the image. +typedef enum LIBRA_D3D12_IMAGE_TYPE { +#if (defined(_WIN32) && defined(LIBRA_RUNTIME_D3D12)) + /// The image handle is a pointer to a `ID3D12Resource`. + LIBRA_D3D12_IMAGE_TYPE_IMAGE_TYPE_RESOURCE = 0, +#endif +#if (defined(_WIN32) && defined(LIBRA_RUNTIME_D3D12)) + /// The image handle is a `libra_source_image_d3d12_t` + LIBRA_D3D12_IMAGE_TYPE_IMAGE_TYPE_SOURCE_IMAGE = 1, +#endif +#if (defined(_WIN32) && defined(LIBRA_RUNTIME_D3D12)) + /// The image handle is a `libra_output_image_d3d12_t` + LIBRA_D3D12_IMAGE_TYPE_IMAGE_TYPE_OUTPUT_IMAGE = 2, +#endif +} LIBRA_D3D12_IMAGE_TYPE; +#endif + /// Error codes for librashader error types. enum LIBRA_ERRNO #ifdef __cplusplus : int32_t #endif // __cplusplus { + /// Error code for an unknown error. LIBRA_ERRNO_UNKNOWN_ERROR = 0, + /// Error code for an invalid parameter. LIBRA_ERRNO_INVALID_PARAMETER = 1, + /// Error code for an invalid (non-UTF8) string. LIBRA_ERRNO_INVALID_STRING = 2, + /// Error code for a preset parser error. LIBRA_ERRNO_PRESET_ERROR = 3, + /// Error code for a preprocessor error. LIBRA_ERRNO_PREPROCESS_ERROR = 4, + /// Error code for a shader parameter error. LIBRA_ERRNO_SHADER_PARAMETER_ERROR = 5, + /// Error code for a reflection error. LIBRA_ERRNO_REFLECT_ERROR = 6, + /// Error code for a runtime error. LIBRA_ERRNO_RUNTIME_ERROR = 7, }; #ifndef __cplusplus @@ -76,23 +102,32 @@ enum LIBRA_PRESET_CTX_ORIENTATION : uint32_t #endif // __cplusplus { + /// Context parameter for vertical orientation. LIBRA_PRESET_CTX_ORIENTATION_VERTICAL = 0, + /// Context parameter for horizontal orientation. LIBRA_PRESET_CTX_ORIENTATION_HORIZONTAL, }; #ifndef __cplusplus typedef uint32_t LIBRA_PRESET_CTX_ORIENTATION; #endif // __cplusplus +/// An enum representing graphics runtimes (video drivers) for use in preset contexts. enum LIBRA_PRESET_CTX_RUNTIME #ifdef __cplusplus : uint32_t #endif // __cplusplus { + /// No runtime. LIBRA_PRESET_CTX_RUNTIME_NONE = 0, + /// OpenGL 3.3+ LIBRA_PRESET_CTX_RUNTIME_GL_CORE, + /// Vulkan LIBRA_PRESET_CTX_RUNTIME_VULKAN, + /// Direct3D 11 LIBRA_PRESET_CTX_RUNTIME_D3D11, + /// Direct3D 12 LIBRA_PRESET_CTX_RUNTIME_D3D12, + /// Metal LIBRA_PRESET_CTX_RUNTIME_METAL, }; #ifndef __cplusplus @@ -418,10 +453,10 @@ typedef struct _filter_chain_d3d12 *libra_d3d12_filter_chain_t; #if (defined(_WIN32) && defined(LIBRA_RUNTIME_D3D12)) /// Direct3D 12 parameters for the source image. typedef struct libra_source_image_d3d12_t { - /// The resource containing the image. - ID3D12Resource * resource; /// A CPU descriptor handle to a shader resource view of the image. D3D12_CPU_DESCRIPTOR_HANDLE descriptor; + /// The resource containing the image. + ID3D12Resource * resource; } libra_source_image_d3d12_t; #endif @@ -439,6 +474,31 @@ typedef struct libra_output_image_d3d12_t { } libra_output_image_d3d12_t; #endif +#if (defined(_WIN32) && defined(LIBRA_RUNTIME_D3D12)) +/// A handle to a Direct3D 12 image. +/// +/// This must be either a pointer to a `ID3D12Resource`, +/// or a valid source or output image type. +typedef union libra_image_d3d12_handle_t { + /// A pointer to an `ID3D12Resource`, with descriptors managed by the filter chain. + ID3D12Resource * resource; + /// A source image with externally managed descriptors. + struct libra_source_image_d3d12_t source; + /// An output image with externally managed descriptors. + struct libra_output_image_d3d12_t output; +} libra_image_d3d12_handle_t; +#endif + +#if (defined(_WIN32) && defined(LIBRA_RUNTIME_D3D12)) +/// Tagged union for a Direct3D 12 image +typedef struct libra_image_d3d12_t { + /// The type of the image. + enum LIBRA_D3D12_IMAGE_TYPE image_type; + /// The handle to the image. + union libra_image_d3d12_handle_t image; +} libra_image_d3d12_t; +#endif + #if (defined(_WIN32) && defined(LIBRA_RUNTIME_D3D12)) /// Options for each Direct3D 12 shader frame. typedef struct frame_d3d12_opt_t { @@ -469,6 +529,7 @@ typedef struct filter_chain_mtl_opt_t { #endif #if (defined(__APPLE__) && defined(LIBRA_RUNTIME_METAL) && defined(__OBJC__)) +/// A handle to a Vulkan filter chain. typedef struct _filter_chain_mtl *libra_mtl_filter_chain_t; #endif @@ -491,6 +552,7 @@ typedef struct frame_mtl_opt_t { } frame_mtl_opt_t; #endif +/// ABI version type alias. typedef size_t LIBRASHADER_ABI_VERSION; /// Function pointer definition for libra_abi_version @@ -887,8 +949,8 @@ typedef libra_error_t (*PFN_libra_d3d12_filter_chain_create_deferred)(libra_shad typedef libra_error_t (*PFN_libra_d3d12_filter_chain_frame)(libra_d3d12_filter_chain_t *chain, ID3D12GraphicsCommandList * command_list, size_t frame_count, - struct libra_source_image_d3d12_t image, - struct libra_output_image_d3d12_t out, + struct libra_image_d3d12_t image, + struct libra_image_d3d12_t out, const struct libra_viewport_t *viewport, const float *mvp, const struct frame_d3d12_opt_t *options); @@ -1761,8 +1823,8 @@ libra_error_t libra_d3d12_filter_chain_create_deferred(libra_shader_preset_t *pr libra_error_t libra_d3d12_filter_chain_frame(libra_d3d12_filter_chain_t *chain, ID3D12GraphicsCommandList * command_list, size_t frame_count, - struct libra_source_image_d3d12_t image, - struct libra_output_image_d3d12_t out, + struct libra_image_d3d12_t image, + struct libra_image_d3d12_t out, const struct libra_viewport_t *viewport, const float *mvp, const struct frame_d3d12_opt_t *options); @@ -2025,6 +2087,7 @@ libra_error_t libra_preset_ctx_set_param(libra_preset_ctx_t *context, /// - GLCore /// - Direct3D11 /// - Direct3D12 +/// - Metal /// /// This will also set the appropriate video driver extensions. /// diff --git a/include/librashader_ld.h b/include/librashader_ld.h index a55bf198..de37c40e 100644 --- a/include/librashader_ld.h +++ b/include/librashader_ld.h @@ -358,7 +358,7 @@ libra_error_t __librashader__noop_d3d12_filter_chain_create_deferred( libra_error_t __librashader__noop_d3d12_filter_chain_frame( libra_d3d12_filter_chain_t *chain, ID3D12GraphicsCommandList *command_list, - size_t frame_count, struct libra_source_image_d3d12_t image, struct libra_output_image_d3d12_t out, + size_t frame_count, struct libra_image_d3d12_t image, struct libra_image_d3d12_t out, const struct libra_viewport_t *viewport, const float *mvp, const struct frame_d3d12_opt_t *opt) { return NULL; diff --git a/librashader-capi/src/runtime/d3d12/filter_chain.rs b/librashader-capi/src/runtime/d3d12/filter_chain.rs index 525f929e..c5ea0ab6 100644 --- a/librashader-capi/src/runtime/d3d12/filter_chain.rs +++ b/librashader-capi/src/runtime/d3d12/filter_chain.rs @@ -8,7 +8,6 @@ use std::ffi::CStr; use std::mem::{ManuallyDrop, MaybeUninit}; use std::ptr::NonNull; use std::slice; -use windows::core::Interface; use windows::Win32::Graphics::Direct3D12::{ ID3D12Device, ID3D12GraphicsCommandList, ID3D12Resource, D3D12_CPU_DESCRIPTOR_HANDLE, }; @@ -20,6 +19,40 @@ use librashader::runtime::d3d12::{ }; use librashader::runtime::{FilterChainParameters, Size, Viewport}; +/// Tagged union for a Direct3D 12 image +#[repr(C)] +pub struct libra_image_d3d12_t { + /// The type of the image. + pub image_type: LIBRA_D3D12_IMAGE_TYPE, + /// The handle to the image. + pub handle: libra_image_d3d12_handle_t, +} + +/// A handle to a Direct3D 12 image. +/// +/// This must be either a pointer to a `ID3D12Resource`, +/// or a valid source or output image type. +#[repr(C)] +pub union libra_image_d3d12_handle_t { + /// A pointer to an `ID3D12Resource`, with descriptors managed by the filter chain. + pub resource: ManuallyDrop, + /// A source image with externally managed descriptors. + pub source: ManuallyDrop, + /// An output image with externally managed descriptors. + pub output: ManuallyDrop, +} + +/// The type of image passed to the image. +#[repr(C)] +pub enum LIBRA_D3D12_IMAGE_TYPE { + /// The image handle is a pointer to a `ID3D12Resource`. + IMAGE_TYPE_RESOURCE = 0, + /// The image handle is a `libra_source_image_d3d12_t` + IMAGE_TYPE_SOURCE_IMAGE = 1, + /// The image handle is a `libra_output_image_d3d12_t` + IMAGE_TYPE_OUTPUT_IMAGE = 2, +} + /// Direct3D 12 parameters for the source image. #[repr(C)] pub struct libra_source_image_d3d12_t { @@ -200,18 +233,26 @@ extern_fn! { /// remain in `D3D12_RESOURCE_STATE_RENDER_TARGET` after all shader passes. The caller must transition /// the output image to the final resource state. /// + /// The refcount of any COM pointers passed into this frame will not be changed. It is the responsibility + /// of the caller to ensure any resources remain alive until the `ID3D12GraphicsCommandList` provided is + /// submitted. + /// /// ## Parameters /// /// - `chain` is a handle to the filter chain. /// - `command_list` is a `ID3D12GraphicsCommandList` to record draw commands to. /// The provided command list must be open and associated with the `ID3D12Device` this filter chain was created with. /// - `frame_count` is the number of frames passed to the shader - /// - `image` is a `libra_source_image_d3d12_t`, containing a `ID3D12Resource` pointer and CPU descriptor - /// to an image that will serve as the source image for the frame. The input image must be in the - /// `D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE` resource state or equivalent barrier layout. - /// - `out` is a `libra_output_image_d3d12_t`, containing a CPU descriptor handle, format, and size information - /// for the render target of the frame. The output image must be in + /// - `image` is a `libra_image_d3d12_t` with `image_type` set to `IMAGE_TYPE_SOURCE_IMAGE` or `IMAGE_TYPE_RESOURCE`, + /// with `image_handle` either a `ID3D12Resource*` or an `libra_source_image_d3d12_t` containing a CPU descriptor to a shader resource view, + /// and the image resource the view is of, which will serve as the source image for the frame. + /// The input image resource must be in the `D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE` resource state + /// or equivalent barrier layout. The image resource must have dimension `D3D12_RESOURCE_DIMENSION_TEXTURE2D`. + /// - `out` is a `libra_image_d3d12_t`, with `image_type` set to `IMAGE_TYPE_OUTPUT_IMAGE` or `IMAGE_TYPE_RESOURCE`, + /// with `image_handle` being either a `ID3D12Resource*` or an `libra_output_image_d3d12_t`, containing a CPU descriptor handle, + /// format, and size information for the render target of the frame. The output image must be in /// `D3D12_RESOURCE_STATE_RENDER_TARGET` resource state or equivalent barrier layout. + /// The image resource must have dimension `D3D12_RESOURCE_DIMENSION_TEXTURE2D`. /// /// - `viewport` is a pointer to a `libra_viewport_t` that specifies the area onto which scissor and viewport /// will be applied to the render target. It may be null, in which case a default viewport spanning the @@ -228,18 +269,23 @@ extern_fn! { /// values for the model view projection matrix. /// - `opt` may be null, or if it is not null, must be an aligned pointer to a valid `frame_d3d12_opt_t` /// struct. - /// - `out` must be a descriptor handle to a render target view. - /// - `image.resource` must not be null. + /// - Any resource pointers contained within a `libra_image_d3d12_t` must be non-null. + /// - The `handle` field of any `libra_image_d3d12_t` must be valid for it's `image_type`. + /// - If `image_type` is `IMAGE_TYPE_RESOURCE`, then `handle` must be `ID3D12Resource *`. + /// - If `image_type` is `IMAGE_TYPE_SOURCE`, then `handle` must be `libra_source_image_d3d12_t`. + /// - If `image_type` is `IMAGE_TYPE_OUTPUT`, then `handle` must be `libra_output_image_d3d12_t`. /// - `command_list` must be a non-null pointer to a `ID3D12GraphicsCommandList` that is open, /// and must be associated with the `ID3D12Device` this filter chain was created with. + /// - All resource pointers contained within a `libra_image_d3d12_t` must remain valid until the `ID3D12GraphicsCommandList *` + /// provided is submitted after the call to this function. /// - You must ensure that only one thread has access to `chain` before you call this function. Only one /// thread at a time may call this function. nopanic fn libra_d3d12_filter_chain_frame( chain: *mut libra_d3d12_filter_chain_t, command_list: ManuallyDrop, frame_count: usize, - image: libra_source_image_d3d12_t, - out: libra_output_image_d3d12_t, + image: libra_image_d3d12_t, + out: libra_image_d3d12_t, viewport: *const libra_viewport_t, mvp: *const f32, options: *const MaybeUninit @@ -261,10 +307,26 @@ extern_fn! { let options = options.map(FromUninit::from_uninit); let output = unsafe { - D3D12OutputView::new_from_raw( - out.descriptor, - Size::new(out.width, out.height), - out.format) + match out.image_type { + LIBRA_D3D12_IMAGE_TYPE::IMAGE_TYPE_RESOURCE => { + let out = out.handle.resource; + D3D12OutputView::new_from_resource( + out, + chain, + )? + } + LIBRA_D3D12_IMAGE_TYPE::IMAGE_TYPE_OUTPUT_IMAGE => { + let out = out.handle.output; + D3D12OutputView::new_from_raw( + out.descriptor, + Size::new(out.width, out.height), + out.format, + ) + } + LIBRA_D3D12_IMAGE_TYPE::IMAGE_TYPE_SOURCE_IMAGE => { + return Err(LibrashaderError::InvalidParameter("out")) + } + } }; let viewport = if viewport.is_null() { @@ -283,10 +345,25 @@ extern_fn! { } }; - let image = D3D12InputImage::External { - resource: image.resource.to_ref(), - descriptor: image.descriptor, + let image = unsafe { + match image.image_type { + LIBRA_D3D12_IMAGE_TYPE::IMAGE_TYPE_RESOURCE => { + let image = image.handle.resource; + D3D12InputImage::Managed(image) + } + LIBRA_D3D12_IMAGE_TYPE::IMAGE_TYPE_SOURCE_IMAGE => { + let image = ManuallyDrop::into_inner(image.handle.source); + D3D12InputImage::External { + resource: image.resource, + descriptor: image.descriptor, + } + } + LIBRA_D3D12_IMAGE_TYPE::IMAGE_TYPE_OUTPUT_IMAGE => { + return Err(LibrashaderError::InvalidParameter("image")) + } + } }; + unsafe { chain.frame(&command_list, image, &viewport, frame_count, options.as_ref())?; } diff --git a/librashader-cli/src/render/d3d12/mod.rs b/librashader-cli/src/render/d3d12/mod.rs index bf6f8c1e..04c9b35a 100644 --- a/librashader-cli/src/render/d3d12/mod.rs +++ b/librashader-cli/src/render/d3d12/mod.rs @@ -7,9 +7,7 @@ use anyhow::anyhow; use d3d12_descriptor_heap::{D3D12DescriptorHeap, D3D12DescriptorHeapSlot}; use image::RgbaImage; use librashader::presets::ShaderPreset; -use librashader::runtime::d3d12::{ - D3D12InputImage, D3D12OutputView, FilterChain, FilterChainOptions, FrameOptions, -}; +use librashader::runtime::d3d12::{D3D12OutputView, FilterChain, FilterChainOptions, FrameOptions}; use librashader::runtime::Viewport; use librashader::runtime::{FilterChainParameters, RuntimeParameters}; use librashader_runtime::image::{Image, PixelFormat, UVDirection, BGRA8}; @@ -151,14 +149,10 @@ impl RenderTest for Direct3D12 { current_subframe: options.current_subframe, }); + let image = self.texture.to_ref(); + for frame in 0..=frame_count { - filter_chain.frame( - &cmd, - D3D12InputImage::Managed(self.texture.to_ref()), - &viewport, - frame, - options.as_ref(), - )?; + filter_chain.frame(&cmd, image.into(), &viewport, frame, options.as_ref())?; } cmd.Close()?; diff --git a/librashader-runtime-d3d12/src/texture.rs b/librashader-runtime-d3d12/src/texture.rs index c766b1ca..748508c0 100644 --- a/librashader-runtime-d3d12/src/texture.rs +++ b/librashader-runtime-d3d12/src/texture.rs @@ -17,24 +17,26 @@ use windows::Win32::Graphics::Direct3D12::{ }; use windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT; -/// A **non-owning** reference to a ID3D12Resource. -/// This does not `AddRef` or `Release` the underlying interface. -pub type D3D12ResourceRef<'a> = InterfaceRef<'a, ID3D12Resource>; - /// An image for use as shader resource view. #[derive(Clone)] -pub enum D3D12InputImage<'a> { +pub enum D3D12InputImage { /// The filter chain manages the CPU descriptor to the shader resource view. - Managed(InterfaceRef<'a, ID3D12Resource>), + Managed(ManuallyDrop), /// The CPU descriptor to the shader resource view is managed externally. External { /// The ID3D12Resource that holds the image data. - resource: InterfaceRef<'a, ID3D12Resource>, + resource: ManuallyDrop, /// The CPU descriptor to the shader resource view. descriptor: D3D12_CPU_DESCRIPTOR_HANDLE, }, } +impl<'a> From> for D3D12InputImage { + fn from(value: InterfaceRef<'a, ID3D12Resource>) -> Self { + Self::Managed(unsafe { std::mem::transmute(value) }) + } +} + #[derive(Clone)] pub(crate) enum InputDescriptor { Owned(D3D12DescriptorHeapSlot), @@ -112,15 +114,21 @@ impl D3D12OutputView { /// /// SAFETY: the image must be valid until the command list is submitted. pub unsafe fn new_from_resource( - image: D3D12ResourceRef, + image: ManuallyDrop, chain: &mut FilterChainD3D12, ) -> error::Result { - unsafe { Self::new_from_resource_internal(image, &chain.common.d3d12, &mut chain.rtv_heap) } + unsafe { + Self::new_from_resource_internal( + std::mem::transmute(image), + &chain.common.d3d12, + &mut chain.rtv_heap, + ) + } } /// Create a new output view from a resource ref pub(crate) unsafe fn new_from_resource_internal( - image: D3D12ResourceRef, + image: InterfaceRef, device: &ID3D12Device, heap: &mut D3D12DescriptorHeap, ) -> error::Result { @@ -192,8 +200,8 @@ impl InputTexture { } // unsafe since the lifetime of the handle has to survive - pub unsafe fn new_from_resource<'a>( - image: InterfaceRef<'a, ID3D12Resource>, + pub unsafe fn new_from_resource( + image: ManuallyDrop, filter: FilterMode, wrap_mode: WrapMode, device: &ID3D12Device, @@ -225,7 +233,7 @@ impl InputTexture { }?; Ok(InputTexture { - resource: unsafe { std::mem::transmute(image) }, + resource: image, descriptor, size: Size::new(desc.Width as u32, desc.Height), format: desc.Format, @@ -236,7 +244,7 @@ impl InputTexture { // unsafe since the lifetime of the handle has to survive pub unsafe fn new_from_raw( - image: InterfaceRef, + image: ManuallyDrop, descriptor: D3D12_CPU_DESCRIPTOR_HANDLE, filter: FilterMode, wrap_mode: WrapMode, From c019276e9ba9d8fd3eafb805ae3f7b5f3acda726 Mon Sep 17 00:00:00 2001 From: chyyran Date: Mon, 30 Sep 2024 02:34:41 -0400 Subject: [PATCH 7/7] doc(d3d12,vk): clear up language for barriers also remove useless `libra_PFN_vkGetInstanceProcAddr` --- Cargo.lock | 55 +++++++++++-------- include/librashader.h | 4 +- .../src/runtime/d3d12/filter_chain.rs | 2 +- .../src/runtime/vk/filter_chain.rs | 10 ++-- 4 files changed, 39 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fcf76009..1c4a942d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -474,9 +474,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.1.22" +version = "1.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9540e661f81799159abee814118cc139a2004b3a3aa3ea37724a1b66530b90e0" +checksum = "3bbb537bb4a30b90362caddba8f360c0a56bc13d3a5570028e7197204cb54a17" dependencies = [ "jobserver", "libc", @@ -1145,9 +1145,9 @@ dependencies = [ [[package]] name = "glslang" -version = "0.5.2" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68ea691c064fdb88b4a329c240f76ed9ff21a9bde51f534e35106f97e95c7188" +checksum = "6e058f69c0b36dc2ce7e5243f440d186ae65ab7aa9e76cd4c5b953ea4b43286d" dependencies = [ "bitflags 2.6.0", "glslang-sys", @@ -1158,9 +1158,9 @@ dependencies = [ [[package]] name = "glslang-sys" -version = "0.5.2+fa9c3de" +version = "0.6.1+46ef757" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca4ade0a93e3a8597c8fd1e1df6a22c847803819401b39835fffb96a5b5ee06f" +checksum = "ad4a20351d34b8185981fe9e00c2934f061b59f54705dc497e7ae9cbecec0a07" dependencies = [ "cc", "glob", @@ -2275,9 +2275,12 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.19.0" +version = "1.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +checksum = "82881c4be219ab5faaf2ad5e5e5ecdff8c66bd7402ca3160975c93b24961afd1" +dependencies = [ + "portable-atomic", +] [[package]] name = "orbclient" @@ -2334,7 +2337,7 @@ checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" dependencies = [ "cfg-if", "libc", - "redox_syscall 0.5.6", + "redox_syscall 0.5.7", "smallvec", "windows-targets 0.52.6", ] @@ -2483,6 +2486,12 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "22686f4785f02a4fcc856d3b3bb19bf6c8160d103f7a99cc258bddd0251dc7f2" +[[package]] +name = "portable-atomic" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc9c68a3f6da06753e9335d63e27f6b9754dd1920d941135b7ea8224f141adb2" + [[package]] name = "pp-rs" version = "0.2.1" @@ -2655,9 +2664,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.5.6" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "355ae415ccd3a04315d3f8246e86d67689ea74d88d915576e1589a351062a13b" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" dependencies = [ "bitflags 2.6.0", ] @@ -2675,9 +2684,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.10.6" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" +checksum = "38200e5ee88914975b69f657f0801b6f6dccafd44fd9326302a4aaeecfacb1d8" dependencies = [ "aho-corasick", "memchr", @@ -2687,9 +2696,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.7" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" +checksum = "368758f23274712b504848e9d5a6f010445cc8b87a7cdb4d7cbee666c1288da3" dependencies = [ "aho-corasick", "memchr", @@ -2698,9 +2707,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] name = "renderdoc-sys" @@ -2974,9 +2983,9 @@ dependencies = [ [[package]] name = "spirv-cross2" -version = "0.4.4" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c5d14dec73c90ee9b2bbe23ca7e0964bd12033fccf362c67eb31f8fdb24b647" +checksum = "414b3818c6cc873baead8240dd4690052223c5bc982cb4093047a0b8fc839c45" dependencies = [ "bitflags 2.6.0", "bytemuck", @@ -3108,9 +3117,9 @@ checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" [[package]] name = "tempfile" -version = "3.12.0" +version = "3.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "f0f2c9fc62d0beef6951ccffd757e241266a2c833136efbe35af6cd2567dca5b" dependencies = [ "cfg-if", "fastrand", @@ -3267,9 +3276,9 @@ checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" [[package]] name = "ucd-trie" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9" +checksum = "2896d95c02a80c6d6a5d6e953d479f5ddf2dfdb6a244441010e373ac0fb88971" [[package]] name = "unicode-ident" diff --git a/include/librashader.h b/include/librashader.h index 6107306a..207f224b 100644 --- a/include/librashader.h +++ b/include/librashader.h @@ -1386,7 +1386,7 @@ libra_error_t libra_vk_filter_chain_create_deferred(libra_shader_preset_t *prese /// Records rendering commands for a frame with the given parameters for the given filter chain /// to the input command buffer. /// -/// librashader **will not** create a pipeline barrier for the final pass. The output image must be +/// A pipeline barrier **will not** be created for the final pass. The output image must be /// in `VK_COLOR_ATTACHMENT_OPTIMAL`, and will remain so after all shader passes. The caller must transition /// the output image to the final layout. /// @@ -1782,7 +1782,7 @@ libra_error_t libra_d3d12_filter_chain_create_deferred(libra_shader_preset_t *pr /// Records rendering commands for a frame with the given parameters for the given filter chain /// to the input command list. /// -/// librashader **will not** create a resource barrier for the final pass. The output image will +/// A resource barrier **will not** be created for the final pass. The output image will /// remain in `D3D12_RESOURCE_STATE_RENDER_TARGET` after all shader passes. The caller must transition /// the output image to the final resource state. /// diff --git a/librashader-capi/src/runtime/d3d12/filter_chain.rs b/librashader-capi/src/runtime/d3d12/filter_chain.rs index c5ea0ab6..5ca7d3f7 100644 --- a/librashader-capi/src/runtime/d3d12/filter_chain.rs +++ b/librashader-capi/src/runtime/d3d12/filter_chain.rs @@ -229,7 +229,7 @@ extern_fn! { /// Records rendering commands for a frame with the given parameters for the given filter chain /// to the input command list. /// - /// librashader **will not** create a resource barrier for the final pass. The output image will + /// A resource barrier **will not** be created for the final pass. The output image will /// remain in `D3D12_RESOURCE_STATE_RENDER_TARGET` after all shader passes. The caller must transition /// the output image to the final resource state. /// diff --git a/librashader-capi/src/runtime/vk/filter_chain.rs b/librashader-capi/src/runtime/vk/filter_chain.rs index f809fb0a..55705f0f 100644 --- a/librashader-capi/src/runtime/vk/filter_chain.rs +++ b/librashader-capi/src/runtime/vk/filter_chain.rs @@ -7,7 +7,7 @@ use librashader::runtime::vk::{ FilterChain, FilterChainOptions, FrameOptions, VulkanImage, VulkanInstance, }; use std::ffi::CStr; -use std::ffi::{c_char, c_void}; +use std::ffi::c_char; use std::mem::MaybeUninit; use std::ptr::NonNull; use std::slice; @@ -18,11 +18,9 @@ use librashader::runtime::{Size, Viewport}; use crate::LIBRASHADER_API_VERSION; use ash::vk; use ash::vk::Handle; -pub use ash::vk::PFN_vkGetInstanceProcAddr; -/// A Vulkan instance function loader that the Vulkan filter chain needs to be initialized with. -pub type libra_PFN_vkGetInstanceProcAddr = - unsafe extern "system" fn(instance: *mut c_void, p_name: *const c_char); +/// A Vulkan instance function loader that the Vulkan filter chain needs to be initialized with. +pub use ash::vk::PFN_vkGetInstanceProcAddr; /// Vulkan parameters for an image. #[repr(C)] @@ -237,7 +235,7 @@ extern_fn! { /// Records rendering commands for a frame with the given parameters for the given filter chain /// to the input command buffer. /// - /// librashader **will not** create a pipeline barrier for the final pass. The output image must be + /// A pipeline barrier **will not** be created for the final pass. The output image must be /// in `VK_COLOR_ATTACHMENT_OPTIMAL`, and will remain so after all shader passes. The caller must transition /// the output image to the final layout. ///