librashader/librashader-runtime-d3d12/src/texture.rs

113 lines
3.1 KiB
Rust
Raw Normal View History

2023-02-02 10:09:34 +11:00
use std::ops::Deref;
2023-02-01 09:50:47 +11:00
use windows::Win32::Graphics::Direct3D12::{D3D12_CPU_DESCRIPTOR_HANDLE};
2023-02-01 17:25:39 +11:00
use windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT;
2023-02-01 09:50:47 +11:00
use librashader_common::{FilterMode, ImageFormat, Size, WrapMode};
2023-02-02 10:09:34 +11:00
use crate::descriptor_heap::{CpuStagingHeap, D3D12DescriptorHeapSlot, RenderTargetHeap};
2023-02-01 09:50:47 +11:00
2023-02-02 10:09:34 +11:00
#[derive(Clone)]
2023-02-01 11:23:57 +11:00
pub(crate) enum InputDescriptor {
2023-02-01 09:50:47 +11:00
Owned(D3D12DescriptorHeapSlot<CpuStagingHeap>),
Raw(D3D12_CPU_DESCRIPTOR_HANDLE)
}
2023-02-02 10:09:34 +11:00
#[derive(Clone)]
2023-02-01 11:23:57 +11:00
pub(crate) enum OutputDescriptor {
2023-02-01 16:16:06 +11:00
Owned(D3D12DescriptorHeapSlot<RenderTargetHeap>),
2023-02-01 09:50:47 +11:00
Raw(D3D12_CPU_DESCRIPTOR_HANDLE)
}
impl AsRef<D3D12_CPU_DESCRIPTOR_HANDLE> for InputDescriptor {
fn as_ref(&self) -> &D3D12_CPU_DESCRIPTOR_HANDLE {
match self {
2023-02-02 10:09:34 +11:00
InputDescriptor::Owned(h) => h.deref().as_ref(),
2023-02-01 09:50:47 +11:00
InputDescriptor::Raw(h) => h
}
}
}
impl AsRef<D3D12_CPU_DESCRIPTOR_HANDLE> for OutputDescriptor {
fn as_ref(&self) -> &D3D12_CPU_DESCRIPTOR_HANDLE {
match self {
2023-02-02 10:09:34 +11:00
OutputDescriptor::Owned(h) => h.deref().as_ref(),
2023-02-01 09:50:47 +11:00
OutputDescriptor::Raw(h) => h
}
}
}
2023-02-02 10:09:34 +11:00
#[derive(Clone)]
2023-02-01 09:50:47 +11:00
pub struct OutputTexture {
2023-02-01 16:16:06 +11:00
pub(crate) descriptor: OutputDescriptor,
pub(crate) size: Size<u32>,
2023-02-01 09:50:47 +11:00
}
impl OutputTexture {
2023-02-01 16:16:06 +11:00
pub fn new(handle: D3D12DescriptorHeapSlot<RenderTargetHeap>,
2023-02-01 09:50:47 +11:00
size: Size<u32>,
) -> OutputTexture {
let descriptor = OutputDescriptor::Owned(handle);
OutputTexture {
descriptor,
size,
}
}
// unsafe since the lifetime of the handle has to survive
pub unsafe fn new_from_raw(handle: D3D12_CPU_DESCRIPTOR_HANDLE,
size: Size<u32>,
) -> OutputTexture {
let descriptor = OutputDescriptor::Raw(handle);
OutputTexture {
descriptor,
size,
}
}
}
2023-02-02 10:09:34 +11:00
#[derive(Clone)]
2023-02-01 09:50:47 +11:00
pub struct InputTexture {
2023-02-01 11:23:57 +11:00
pub(crate) descriptor: InputDescriptor,
pub(crate) size: Size<u32>,
2023-02-01 17:25:39 +11:00
format: DXGI_FORMAT,
2023-02-01 11:23:57 +11:00
pub(crate) wrap_mode: WrapMode,
pub(crate) filter: FilterMode
2023-02-01 09:50:47 +11:00
}
impl InputTexture {
pub fn new(handle: D3D12DescriptorHeapSlot<CpuStagingHeap>,
size: Size<u32>,
format: ImageFormat,
wrap_mode: WrapMode,
filter: FilterMode) -> InputTexture {
let srv = InputDescriptor::Owned(handle);
InputTexture {
descriptor: srv,
size,
2023-02-01 17:25:39 +11:00
format: format.into(),
2023-02-01 09:50:47 +11:00
wrap_mode,
filter
}
}
// unsafe since the lifetime of the handle has to survive
pub unsafe fn new_from_raw(handle: D3D12_CPU_DESCRIPTOR_HANDLE,
size: Size<u32>,
2023-02-01 17:25:39 +11:00
format: DXGI_FORMAT,
2023-02-01 09:50:47 +11:00
wrap_mode: WrapMode,
filter: FilterMode
) -> InputTexture {
let srv = InputDescriptor::Raw(handle);
InputTexture {
descriptor: srv,
size,
format,
wrap_mode,
filter
}
}
}
2023-02-01 11:23:57 +11:00
impl AsRef<InputTexture> for InputTexture {
fn as_ref(&self) -> &InputTexture {
self
}
}