d3d12: build mipmapper shader
This commit is contained in:
parent
d7da5c175f
commit
48e5a8a149
|
@ -18,6 +18,7 @@ use windows::Win32::Graphics::Direct3D12::{
|
||||||
};
|
};
|
||||||
use windows::Win32::System::Threading::{CreateEventA, WaitForSingleObject};
|
use windows::Win32::System::Threading::{CreateEventA, WaitForSingleObject};
|
||||||
use windows::Win32::System::WindowsProgramming::INFINITE;
|
use windows::Win32::System::WindowsProgramming::INFINITE;
|
||||||
|
use crate::mipmap::D3D12MipmapGen;
|
||||||
|
|
||||||
pub struct FilterChainD3D12 {
|
pub struct FilterChainD3D12 {
|
||||||
pub(crate) common: FilterCommon,
|
pub(crate) common: FilterCommon,
|
||||||
|
@ -39,6 +40,7 @@ pub(crate) struct FilterCommon {
|
||||||
// pub disable_mipmaps: bool,
|
// pub disable_mipmaps: bool,
|
||||||
lut_heap: D3D12DescriptorHeap<LutTextureHeap>,
|
lut_heap: D3D12DescriptorHeap<LutTextureHeap>,
|
||||||
luts: FxHashMap<usize, LutTexture>,
|
luts: FxHashMap<usize, LutTexture>,
|
||||||
|
mipmap_gen: D3D12MipmapGen,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FilterChainD3D12 {
|
impl FilterChainD3D12 {
|
||||||
|
@ -124,8 +126,9 @@ impl FilterChainD3D12 {
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let samplers = SamplerSet::new(device)?;
|
let samplers = SamplerSet::new(device)?;
|
||||||
let mut lut_heap = D3D12DescriptorHeap::new(device, preset.textures.len())?;
|
let mipmap_gen = D3D12MipmapGen::new(device)?;
|
||||||
|
|
||||||
|
let mut lut_heap = D3D12DescriptorHeap::new(device, preset.textures.len())?;
|
||||||
let luts = FilterChainD3D12::load_luts(device, &mut lut_heap, &preset.textures)?;
|
let luts = FilterChainD3D12::load_luts(device, &mut lut_heap, &preset.textures)?;
|
||||||
|
|
||||||
Ok(FilterChainD3D12 {
|
Ok(FilterChainD3D12 {
|
||||||
|
@ -134,6 +137,7 @@ impl FilterChainD3D12 {
|
||||||
samplers,
|
samplers,
|
||||||
lut_heap,
|
lut_heap,
|
||||||
luts,
|
luts,
|
||||||
|
mipmap_gen,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -279,17 +279,19 @@ pub mod d3d12_hello_triangle {
|
||||||
fn new(filter: impl AsRef<Path>, command_line: &SampleCommandLine) -> Result<Self> {
|
fn new(filter: impl AsRef<Path>, command_line: &SampleCommandLine) -> Result<Self> {
|
||||||
let (dxgi_factory, device) = create_device(command_line)?;
|
let (dxgi_factory, device) = create_device(command_line)?;
|
||||||
//
|
//
|
||||||
let queue = device.cast::<ID3D12InfoQueue1>()?;
|
if let Ok(queue) = device.cast::<ID3D12InfoQueue1>() {
|
||||||
unsafe {
|
unsafe {
|
||||||
queue
|
queue
|
||||||
.RegisterMessageCallback(
|
.RegisterMessageCallback(
|
||||||
Some(debug_log),
|
Some(debug_log),
|
||||||
D3D12_MESSAGE_CALLBACK_FLAG_NONE,
|
D3D12_MESSAGE_CALLBACK_FLAG_NONE,
|
||||||
std::ptr::null_mut(),
|
std::ptr::null_mut(),
|
||||||
&mut 0,
|
&mut 0,
|
||||||
)
|
)
|
||||||
.expect("could not register message callback");
|
.expect("could not register message callback");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let filter = FilterChainD3D12::load_from_path(&device, filter, None).unwrap();
|
let filter = FilterChainD3D12::load_from_path(&device, filter, None).unwrap();
|
||||||
|
|
||||||
Ok(Sample {
|
Ok(Sample {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use windows::Win32::Graphics::Direct3D12::{D3D12_CPU_DESCRIPTOR_HANDLE, D3D12_GPU_DESCRIPTOR_HANDLE, ID3D12Device, ID3D12PipelineState, ID3D12RootSignature};
|
use windows::Win32::Graphics::Direct3D12::{D3D12_COMPUTE_PIPELINE_STATE_DESC, D3D12_CPU_DESCRIPTOR_HANDLE, D3D12_DESCRIPTOR_RANGE, D3D12_DESCRIPTOR_RANGE_TYPE_SRV, D3D12_DESCRIPTOR_RANGE_TYPE_UAV, D3D12_FILTER_MIN_MAG_LINEAR_MIP_POINT, D3D12_GPU_DESCRIPTOR_HANDLE, D3D12_ROOT_CONSTANTS, D3D12_ROOT_DESCRIPTOR_TABLE, D3D12_ROOT_PARAMETER, D3D12_ROOT_PARAMETER_0, D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS, D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE, D3D12_ROOT_SIGNATURE_DESC, D3D12_ROOT_SIGNATURE_FLAG_DENY_DOMAIN_SHADER_ROOT_ACCESS, D3D12_ROOT_SIGNATURE_FLAG_DENY_GEOMETRY_SHADER_ROOT_ACCESS, D3D12_ROOT_SIGNATURE_FLAG_DENY_HULL_SHADER_ROOT_ACCESS, D3D12_ROOT_SIGNATURE_FLAG_DENY_PIXEL_SHADER_ROOT_ACCESS, D3D12_ROOT_SIGNATURE_FLAG_DENY_VERTEX_SHADER_ROOT_ACCESS, D3D12_SHADER_BYTECODE, D3D12_SHADER_VISIBILITY_ALL, D3D12_STATIC_SAMPLER_DESC, D3D12_TEXTURE_ADDRESS_MODE_CLAMP, ID3D12Device, ID3D12PipelineState, ID3D12RootSignature};
|
||||||
use librashader_common::Size;
|
use librashader_common::Size;
|
||||||
use crate::error;
|
use crate::error;
|
||||||
|
use crate::util::d3d_compile_shader;
|
||||||
|
|
||||||
static GENERATE_MIPS_SRC: &[u8] = b"
|
static GENERATE_MIPS_SRC: &[u8] = b"
|
||||||
// Copyright (c) Microsoft Corporation.
|
// Copyright (c) Microsoft Corporation.
|
||||||
|
@ -54,7 +55,31 @@ pub struct D3D12MipmapGen {
|
||||||
|
|
||||||
impl D3D12MipmapGen {
|
impl D3D12MipmapGen {
|
||||||
pub fn new(device: &ID3D12Device) -> error::Result<D3D12MipmapGen> {
|
pub fn new(device: &ID3D12Device) -> error::Result<D3D12MipmapGen> {
|
||||||
todo!()
|
unsafe {
|
||||||
|
let blob = d3d_compile_shader(GENERATE_MIPS_SRC, b"main\0", b"cs_5_1\0")?;
|
||||||
|
let blob = std::slice::from_raw_parts(blob.GetBufferPointer().cast(), blob.GetBufferSize());
|
||||||
|
let root_signature: ID3D12RootSignature = device.CreateRootSignature(0, blob)?;
|
||||||
|
|
||||||
|
let desc = D3D12_COMPUTE_PIPELINE_STATE_DESC {
|
||||||
|
pRootSignature: windows::core::ManuallyDrop::new(&root_signature),
|
||||||
|
CS: D3D12_SHADER_BYTECODE {
|
||||||
|
pShaderBytecode: blob.as_ptr().cast(),
|
||||||
|
BytecodeLength: blob.len()
|
||||||
|
},
|
||||||
|
NodeMask: 0,
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
let pipeline = device.CreateComputePipelineState(&desc)?;
|
||||||
|
|
||||||
|
Ok(D3D12MipmapGen {
|
||||||
|
device: device.clone(),
|
||||||
|
root_signature,
|
||||||
|
pipeline,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn generate_mipmaps(miplevels: u16,
|
pub fn generate_mipmaps(miplevels: u16,
|
||||||
|
|
|
@ -2,9 +2,7 @@ use std::mem::ManuallyDrop;
|
||||||
use std::u64;
|
use std::u64;
|
||||||
use crate::error;
|
use crate::error;
|
||||||
use windows::core::PCSTR;
|
use windows::core::PCSTR;
|
||||||
use windows::Win32::Graphics::Direct3D::Fxc::{
|
use windows::Win32::Graphics::Direct3D::Fxc::{D3DCompile, D3DCOMPILE_DEBUG, D3DCOMPILE_OPTIMIZATION_LEVEL3, D3DCOMPILE_SKIP_OPTIMIZATION};
|
||||||
D3DCompile, D3DCOMPILE_DEBUG, D3DCOMPILE_SKIP_OPTIMIZATION,
|
|
||||||
};
|
|
||||||
use windows::Win32::Graphics::Direct3D::ID3DBlob;
|
use windows::Win32::Graphics::Direct3D::ID3DBlob;
|
||||||
use windows::Win32::Graphics::Direct3D12::{ID3D12Device, D3D12_FEATURE_DATA_FORMAT_SUPPORT, D3D12_FEATURE_FORMAT_SUPPORT, ID3D12CommandList, ID3D12GraphicsCommandList, ID3D12Resource, D3D12_RESOURCE_DESC, D3D12_RESOURCE_BARRIER, D3D12_RESOURCE_BARRIER_TYPE_TRANSITION, D3D12_RESOURCE_BARRIER_FLAG_NONE, D3D12_RESOURCE_DESC1, D3D12_RESOURCE_BARRIER_0, D3D12_RESOURCE_TRANSITION_BARRIER, D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES, D3D12_RESOURCE_STATES, D3D12_PLACED_SUBRESOURCE_FOOTPRINT, D3D12_MEMCPY_DEST, D3D12_SUBRESOURCE_DATA, D3D12_RESOURCE_DIMENSION_BUFFER, D3D12_TEXTURE_COPY_LOCATION, D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX, D3D12_TEXTURE_COPY_LOCATION_0, D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT};
|
use windows::Win32::Graphics::Direct3D12::{ID3D12Device, D3D12_FEATURE_DATA_FORMAT_SUPPORT, D3D12_FEATURE_FORMAT_SUPPORT, ID3D12CommandList, ID3D12GraphicsCommandList, ID3D12Resource, D3D12_RESOURCE_DESC, D3D12_RESOURCE_BARRIER, D3D12_RESOURCE_BARRIER_TYPE_TRANSITION, D3D12_RESOURCE_BARRIER_FLAG_NONE, D3D12_RESOURCE_DESC1, D3D12_RESOURCE_BARRIER_0, D3D12_RESOURCE_TRANSITION_BARRIER, D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES, D3D12_RESOURCE_STATES, D3D12_PLACED_SUBRESOURCE_FOOTPRINT, D3D12_MEMCPY_DEST, D3D12_SUBRESOURCE_DATA, D3D12_RESOURCE_DIMENSION_BUFFER, D3D12_TEXTURE_COPY_LOCATION, D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX, D3D12_TEXTURE_COPY_LOCATION_0, D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT};
|
||||||
use windows::Win32::Graphics::Dxgi::Common::*;
|
use windows::Win32::Graphics::Dxgi::Common::*;
|
||||||
|
@ -131,7 +129,7 @@ pub fn d3d_compile_shader(source: &[u8], entry: &[u8], version: &[u8]) -> error:
|
||||||
if cfg!(feature = "debug-shader") {
|
if cfg!(feature = "debug-shader") {
|
||||||
D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION
|
D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION
|
||||||
} else {
|
} else {
|
||||||
0
|
D3DCOMPILE_OPTIMIZATION_LEVEL3
|
||||||
},
|
},
|
||||||
0,
|
0,
|
||||||
&mut blob,
|
&mut blob,
|
||||||
|
|
Loading…
Reference in a new issue