[D3D12] Output gamma ramp

This commit is contained in:
Triang3l
2018-10-03 14:36:17 +03:00
parent c624bf8c49
commit b77ffe3df6
17 changed files with 483 additions and 51 deletions

View File

@@ -20,6 +20,7 @@ namespace d3d12 {
// Generated with `xb buildhlsl`.
#include "xenia/gpu/d3d12/shaders/dxbc/fullscreen_vs.h"
#include "xenia/gpu/d3d12/shaders/dxbc/stretch_gamma_ps.h"
#include "xenia/gpu/d3d12/shaders/dxbc/stretch_ps.h"
D3D12GraphicsSystem::D3D12GraphicsSystem() {}
@@ -43,20 +44,23 @@ X_STATUS D3D12GraphicsSystem::Setup(cpu::Processor* processor,
target_window->context());
}
// Create the stretch pipeline root signature.
D3D12_ROOT_PARAMETER stretch_root_parameter;
stretch_root_parameter.ParameterType =
// Create the stretch pipeline root signature, with 1 parameter (source
// texture) for raw stretch and 3 parameters (source texture, gamma ramp LUT,
// inverse of the size of the gamma ramp LUT) for gamma-correcting stretch.
// Raw.
D3D12_ROOT_PARAMETER stretch_root_parameters[3];
stretch_root_parameters[0].ParameterType =
D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE;
stretch_root_parameter.DescriptorTable.NumDescriptorRanges = 1;
stretch_root_parameters[0].DescriptorTable.NumDescriptorRanges = 1;
D3D12_DESCRIPTOR_RANGE stretch_root_texture_range;
stretch_root_texture_range.RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_SRV;
stretch_root_texture_range.NumDescriptors = 1;
stretch_root_texture_range.BaseShaderRegister = 0;
stretch_root_texture_range.RegisterSpace = 0;
stretch_root_texture_range.OffsetInDescriptorsFromTableStart = 0;
stretch_root_parameter.DescriptorTable.pDescriptorRanges =
stretch_root_parameters[0].DescriptorTable.pDescriptorRanges =
&stretch_root_texture_range;
stretch_root_parameter.ShaderVisibility = D3D12_SHADER_VISIBILITY_PIXEL;
stretch_root_parameters[0].ShaderVisibility = D3D12_SHADER_VISIBILITY_PIXEL;
D3D12_STATIC_SAMPLER_DESC stretch_sampler_desc;
stretch_sampler_desc.Filter = D3D12_FILTER_MIN_MAG_MIP_LINEAR;
stretch_sampler_desc.AddressU = D3D12_TEXTURE_ADDRESS_MODE_CLAMP;
@@ -73,7 +77,7 @@ X_STATUS D3D12GraphicsSystem::Setup(cpu::Processor* processor,
stretch_sampler_desc.ShaderVisibility = D3D12_SHADER_VISIBILITY_PIXEL;
D3D12_ROOT_SIGNATURE_DESC stretch_root_desc;
stretch_root_desc.NumParameters = 1;
stretch_root_desc.pParameters = &stretch_root_parameter;
stretch_root_desc.pParameters = stretch_root_parameters;
stretch_root_desc.NumStaticSamplers = 1;
stretch_root_desc.pStaticSamplers = &stretch_sampler_desc;
stretch_root_desc.Flags =
@@ -84,8 +88,39 @@ X_STATUS D3D12GraphicsSystem::Setup(cpu::Processor* processor,
XELOGE("Failed to create the front buffer stretch root signature");
return X_STATUS_UNSUCCESSFUL;
}
// Gamma.
stretch_root_parameters[1].ParameterType =
D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE;
stretch_root_parameters[1].DescriptorTable.NumDescriptorRanges = 1;
D3D12_DESCRIPTOR_RANGE stretch_root_gamma_ramp_range;
stretch_root_gamma_ramp_range.RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_SRV;
stretch_root_gamma_ramp_range.NumDescriptors = 1;
stretch_root_gamma_ramp_range.BaseShaderRegister = 1;
stretch_root_gamma_ramp_range.RegisterSpace = 0;
stretch_root_texture_range.OffsetInDescriptorsFromTableStart = 0;
stretch_root_parameters[1].DescriptorTable.pDescriptorRanges =
&stretch_root_gamma_ramp_range;
stretch_root_parameters[1].ShaderVisibility = D3D12_SHADER_VISIBILITY_PIXEL;
stretch_root_parameters[2].ParameterType =
D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS;
stretch_root_parameters[2].Constants.ShaderRegister = 0;
stretch_root_parameters[2].Constants.RegisterSpace = 0;
stretch_root_parameters[2].Constants.Num32BitValues = 1;
stretch_root_parameters[2].ShaderVisibility = D3D12_SHADER_VISIBILITY_PIXEL;
stretch_root_desc.NumParameters = 3;
stretch_root_desc.pParameters = stretch_root_parameters;
stretch_gamma_root_signature_ =
ui::d3d12::util::CreateRootSignature(device, stretch_root_desc);
if (stretch_gamma_root_signature_ == nullptr) {
XELOGE(
"Failed to create the gamma-correcting front buffer stretch root "
"signature");
stretch_root_signature_->Release();
stretch_root_signature_ = nullptr;
return X_STATUS_UNSUCCESSFUL;
}
// Create the stretch pipeline.
// Create the stretch pipelines.
D3D12_GRAPHICS_PIPELINE_STATE_DESC stretch_pipeline_desc = {};
stretch_pipeline_desc.pRootSignature = stretch_root_signature_;
stretch_pipeline_desc.VS.pShaderBytecode = fullscreen_vs;
@@ -107,6 +142,24 @@ X_STATUS D3D12GraphicsSystem::Setup(cpu::Processor* processor,
if (FAILED(device->CreateGraphicsPipelineState(
&stretch_pipeline_desc, IID_PPV_ARGS(&stretch_pipeline_)))) {
XELOGE("Failed to create the front buffer stretch pipeline state");
stretch_gamma_root_signature_->Release();
stretch_gamma_root_signature_ = nullptr;
stretch_root_signature_->Release();
stretch_root_signature_ = nullptr;
return X_STATUS_UNSUCCESSFUL;
}
stretch_pipeline_desc.pRootSignature = stretch_gamma_root_signature_;
stretch_pipeline_desc.PS.pShaderBytecode = stretch_gamma_ps;
stretch_pipeline_desc.PS.BytecodeLength = sizeof(stretch_gamma_ps);
if (FAILED(device->CreateGraphicsPipelineState(
&stretch_pipeline_desc, IID_PPV_ARGS(&stretch_gamma_pipeline_)))) {
XELOGE(
"Failed to create the gamma-correcting front buffer stretch "
"pipeline state");
stretch_pipeline_->Release();
stretch_pipeline_ = nullptr;
stretch_gamma_root_signature_->Release();
stretch_gamma_root_signature_ = nullptr;
stretch_root_signature_->Release();
stretch_root_signature_ = nullptr;
return X_STATUS_UNSUCCESSFUL;
@@ -116,7 +169,9 @@ X_STATUS D3D12GraphicsSystem::Setup(cpu::Processor* processor,
}
void D3D12GraphicsSystem::Shutdown() {
ui::d3d12::util::ReleaseAndNull(stretch_gamma_pipeline_);
ui::d3d12::util::ReleaseAndNull(stretch_pipeline_);
ui::d3d12::util::ReleaseAndNull(stretch_gamma_root_signature_);
ui::d3d12::util::ReleaseAndNull(stretch_root_signature_);
GraphicsSystem::Shutdown();
@@ -130,9 +185,17 @@ void D3D12GraphicsSystem::AwaitFrontBufferUnused() {
void D3D12GraphicsSystem::StretchTextureToFrontBuffer(
D3D12_GPU_DESCRIPTOR_HANDLE handle,
D3D12_GPU_DESCRIPTOR_HANDLE* gamma_ramp_handle, float gamma_ramp_inv_size,
ID3D12GraphicsCommandList* command_list) {
command_list->SetPipelineState(stretch_pipeline_);
command_list->SetGraphicsRootSignature(stretch_root_signature_);
if (gamma_ramp_handle != nullptr) {
command_list->SetPipelineState(stretch_gamma_pipeline_);
command_list->SetGraphicsRootSignature(stretch_gamma_root_signature_);
command_list->SetGraphicsRootDescriptorTable(1, *gamma_ramp_handle);
command_list->SetGraphicsRoot32BitConstants(2, 1, &gamma_ramp_inv_size, 0);
} else {
command_list->SetPipelineState(stretch_pipeline_);
command_list->SetGraphicsRootSignature(stretch_root_signature_);
}
command_list->SetGraphicsRootDescriptorTable(0, handle);
command_list->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
command_list->DrawInstanced(3, 1, 0, 0);
@@ -186,7 +249,8 @@ void D3D12GraphicsSystem::Swap(xe::ui::UIEvent* e) {
command_list->RSSetScissorRects(1, &scissor);
command_list->SetDescriptorHeaps(1, &swap_srv_heap);
StretchTextureToFrontBuffer(
swap_srv_heap->GetGPUDescriptorHandleForHeapStart(), command_list);
swap_srv_heap->GetGPUDescriptorHandleForHeapStart(), nullptr, 0.0f,
command_list);
}
} // namespace d3d12