[D3D12] Refactor root signature creation
This commit is contained in:
parent
110d4724f9
commit
ff014d47d4
|
@ -21,6 +21,7 @@
|
|||
#include "xenia/gpu/d3d12/d3d12_graphics_system.h"
|
||||
#include "xenia/gpu/d3d12/d3d12_shader.h"
|
||||
#include "xenia/gpu/xenos.h"
|
||||
#include "xenia/ui/d3d12/d3d12_util.h"
|
||||
|
||||
// Disabled because the current positions look worse than sampling at centers.
|
||||
DEFINE_bool(d3d12_programmable_sample_positions, false,
|
||||
|
@ -278,41 +279,16 @@ ID3D12RootSignature* D3D12CommandProcessor::GetRootSignature(
|
|||
++desc.NumParameters;
|
||||
}
|
||||
|
||||
ID3DBlob* blob;
|
||||
ID3DBlob* error_blob = nullptr;
|
||||
if (FAILED(D3D12SerializeRootSignature(&desc, D3D_ROOT_SIGNATURE_VERSION_1,
|
||||
&blob, &error_blob))) {
|
||||
XELOGE(
|
||||
"Failed to serialize a root signature with %u pixel textures, %u "
|
||||
"pixel samplers, %u vertex textures and %u vertex samplers",
|
||||
pixel_texture_count, pixel_sampler_count, vertex_texture_count,
|
||||
vertex_sampler_count);
|
||||
if (error_blob != nullptr) {
|
||||
XELOGE("%s",
|
||||
reinterpret_cast<const char*>(error_blob->GetBufferPointer()));
|
||||
error_blob->Release();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
if (error_blob != nullptr) {
|
||||
error_blob->Release();
|
||||
}
|
||||
|
||||
auto device = GetD3D12Context()->GetD3D12Provider()->GetDevice();
|
||||
ID3D12RootSignature* root_signature;
|
||||
if (FAILED(device->CreateRootSignature(0, blob->GetBufferPointer(),
|
||||
blob->GetBufferSize(),
|
||||
IID_PPV_ARGS(&root_signature)))) {
|
||||
ID3D12RootSignature* root_signature = ui::d3d12::util::CreateRootSignature(
|
||||
GetD3D12Context()->GetD3D12Provider()->GetDevice(), desc);
|
||||
if (root_signature == nullptr) {
|
||||
XELOGE(
|
||||
"Failed to create a root signature with %u pixel textures, %u pixel "
|
||||
"samplers, %u vertex textures and %u vertex samplers",
|
||||
pixel_texture_count, pixel_sampler_count, vertex_texture_count,
|
||||
vertex_sampler_count);
|
||||
blob->Release();
|
||||
return nullptr;
|
||||
}
|
||||
blob->Release();
|
||||
|
||||
root_signatures_.insert({index, root_signature});
|
||||
return root_signature;
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
#include "xenia/base/logging.h"
|
||||
#include "xenia/gpu/d3d12/d3d12_command_processor.h"
|
||||
#include "xenia/ui/d3d12/d3d12_provider.h"
|
||||
#include "xenia/ui/d3d12/d3d12_util.h"
|
||||
#include "xenia/xbox.h"
|
||||
|
||||
namespace xe {
|
||||
|
@ -78,31 +78,12 @@ X_STATUS D3D12GraphicsSystem::Setup(cpu::Processor* processor,
|
|||
stretch_root_desc.pStaticSamplers = &stretch_sampler_desc;
|
||||
stretch_root_desc.Flags =
|
||||
D3D12_ROOT_SIGNATURE_FLAG_DENY_VERTEX_SHADER_ROOT_ACCESS;
|
||||
ID3DBlob* stretch_root_blob;
|
||||
ID3DBlob* stretch_root_error_blob = nullptr;
|
||||
if (FAILED(D3D12SerializeRootSignature(
|
||||
&stretch_root_desc, D3D_ROOT_SIGNATURE_VERSION_1, &stretch_root_blob,
|
||||
&stretch_root_error_blob))) {
|
||||
XELOGE("Failed to serialize the front buffer stretch root signature");
|
||||
if (stretch_root_error_blob != nullptr) {
|
||||
XELOGE("%s", reinterpret_cast<const char*>(
|
||||
stretch_root_error_blob->GetBufferPointer()));
|
||||
stretch_root_error_blob->Release();
|
||||
}
|
||||
return X_STATUS_UNSUCCESSFUL;
|
||||
}
|
||||
if (stretch_root_error_blob != nullptr) {
|
||||
stretch_root_error_blob->Release();
|
||||
}
|
||||
if (FAILED(device->CreateRootSignature(
|
||||
0, stretch_root_blob->GetBufferPointer(),
|
||||
stretch_root_blob->GetBufferSize(),
|
||||
IID_PPV_ARGS(&stretch_root_signature_)))) {
|
||||
stretch_root_signature_ =
|
||||
ui::d3d12::util::CreateRootSignature(device, stretch_root_desc);
|
||||
if (stretch_root_signature_ == nullptr) {
|
||||
XELOGE("Failed to create the front buffer stretch root signature");
|
||||
stretch_root_blob->Release();
|
||||
return X_STATUS_UNSUCCESSFUL;
|
||||
}
|
||||
stretch_root_blob->Release();
|
||||
|
||||
// Create the stretch pipeline.
|
||||
D3D12_GRAPHICS_PIPELINE_STATE_DESC stretch_pipeline_desc = {};
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "xenia/gpu/d3d12/d3d12_command_processor.h"
|
||||
#include "xenia/gpu/texture_info.h"
|
||||
#include "xenia/gpu/texture_util.h"
|
||||
#include "xenia/ui/d3d12/d3d12_util.h"
|
||||
|
||||
namespace xe {
|
||||
namespace gpu {
|
||||
|
@ -136,64 +137,24 @@ bool RenderTargetCache::Initialize() {
|
|||
load_store_root_desc.NumStaticSamplers = 0;
|
||||
load_store_root_desc.pStaticSamplers = nullptr;
|
||||
load_store_root_desc.Flags = D3D12_ROOT_SIGNATURE_FLAG_NONE;
|
||||
ID3DBlob* load_store_root_blob;
|
||||
ID3DBlob* load_store_root_error_blob = nullptr;
|
||||
if (FAILED(D3D12SerializeRootSignature(
|
||||
&load_store_root_desc, D3D_ROOT_SIGNATURE_VERSION_1,
|
||||
&load_store_root_blob, &load_store_root_error_blob))) {
|
||||
XELOGE("Failed to serialize the EDRAM buffer load/store root signature");
|
||||
if (load_store_root_error_blob != nullptr) {
|
||||
XELOGE("%s", reinterpret_cast<const char*>(
|
||||
load_store_root_error_blob->GetBufferPointer()));
|
||||
load_store_root_error_blob->Release();
|
||||
}
|
||||
Shutdown();
|
||||
return false;
|
||||
}
|
||||
if (load_store_root_error_blob != nullptr) {
|
||||
load_store_root_error_blob->Release();
|
||||
load_store_root_error_blob = nullptr;
|
||||
}
|
||||
if (FAILED(device->CreateRootSignature(
|
||||
0, load_store_root_blob->GetBufferPointer(),
|
||||
load_store_root_blob->GetBufferSize(),
|
||||
IID_PPV_ARGS(&edram_load_store_root_signature_)))) {
|
||||
XELOGE("Failed to create the EDRAM buffer load/store root signature");
|
||||
load_store_root_blob->Release();
|
||||
Shutdown();
|
||||
return false;
|
||||
}
|
||||
load_store_root_blob->Release();
|
||||
|
||||
edram_load_store_root_signature_ =
|
||||
ui::d3d12::util::CreateRootSignature(device, load_store_root_desc);
|
||||
if (edram_load_store_root_signature_ == nullptr) {
|
||||
XELOGE("Failed to create the EDRAM load/store root signature");
|
||||
Shutdown();
|
||||
return false;
|
||||
}
|
||||
// Create the clear root signature (the same, but with the UAV only).
|
||||
load_store_root_parameters[1].DescriptorTable.NumDescriptorRanges = 1;
|
||||
++load_store_root_parameters[1].DescriptorTable.pDescriptorRanges;
|
||||
if (FAILED(D3D12SerializeRootSignature(
|
||||
&load_store_root_desc, D3D_ROOT_SIGNATURE_VERSION_1,
|
||||
&load_store_root_blob, &load_store_root_error_blob))) {
|
||||
XELOGE("Failed to serialize the EDRAM buffer clear root signature");
|
||||
if (load_store_root_error_blob != nullptr) {
|
||||
XELOGE("%s", reinterpret_cast<const char*>(
|
||||
load_store_root_error_blob->GetBufferPointer()));
|
||||
load_store_root_error_blob->Release();
|
||||
}
|
||||
Shutdown();
|
||||
return false;
|
||||
}
|
||||
if (load_store_root_error_blob != nullptr) {
|
||||
load_store_root_error_blob->Release();
|
||||
load_store_root_error_blob = nullptr;
|
||||
}
|
||||
if (FAILED(device->CreateRootSignature(
|
||||
0, load_store_root_blob->GetBufferPointer(),
|
||||
load_store_root_blob->GetBufferSize(),
|
||||
IID_PPV_ARGS(&edram_clear_root_signature_)))) {
|
||||
edram_clear_root_signature_ =
|
||||
ui::d3d12::util::CreateRootSignature(device, load_store_root_desc);
|
||||
if (edram_clear_root_signature_ == nullptr) {
|
||||
XELOGE("Failed to create the EDRAM buffer clear root signature");
|
||||
load_store_root_blob->Release();
|
||||
Shutdown();
|
||||
return false;
|
||||
}
|
||||
load_store_root_blob->Release();
|
||||
|
||||
// Create the load/store pipelines.
|
||||
D3D12_COMPUTE_PIPELINE_STATE_DESC pipeline_desc;
|
||||
|
@ -304,33 +265,13 @@ bool RenderTargetCache::Initialize() {
|
|||
resolve_root_desc.pStaticSamplers = &resolve_sampler_desc;
|
||||
resolve_root_desc.Flags =
|
||||
D3D12_ROOT_SIGNATURE_FLAG_DENY_VERTEX_SHADER_ROOT_ACCESS;
|
||||
ID3DBlob* resolve_root_blob;
|
||||
ID3DBlob* resolve_root_error_blob = nullptr;
|
||||
if (FAILED(D3D12SerializeRootSignature(
|
||||
&resolve_root_desc, D3D_ROOT_SIGNATURE_VERSION_1, &resolve_root_blob,
|
||||
&resolve_root_error_blob))) {
|
||||
XELOGE("Failed to serialize the converting resolve root signature");
|
||||
if (resolve_root_error_blob != nullptr) {
|
||||
XELOGE("%s", reinterpret_cast<const char*>(
|
||||
resolve_root_error_blob->GetBufferPointer()));
|
||||
resolve_root_error_blob->Release();
|
||||
}
|
||||
Shutdown();
|
||||
return false;
|
||||
}
|
||||
if (resolve_root_error_blob != nullptr) {
|
||||
resolve_root_error_blob->Release();
|
||||
}
|
||||
if (FAILED(device->CreateRootSignature(
|
||||
0, resolve_root_blob->GetBufferPointer(),
|
||||
resolve_root_blob->GetBufferSize(),
|
||||
IID_PPV_ARGS(&resolve_root_signature_)))) {
|
||||
resolve_root_signature_ =
|
||||
ui::d3d12::util::CreateRootSignature(device, resolve_root_desc);
|
||||
if (resolve_root_signature_ == nullptr) {
|
||||
XELOGE("Failed to create the converting resolve root signature");
|
||||
resolve_root_blob->Release();
|
||||
Shutdown();
|
||||
return false;
|
||||
}
|
||||
resolve_root_blob->Release();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "xenia/gpu/d3d12/d3d12_command_processor.h"
|
||||
#include "xenia/gpu/texture_info.h"
|
||||
#include "xenia/gpu/texture_util.h"
|
||||
#include "xenia/ui/d3d12/d3d12_util.h"
|
||||
|
||||
namespace xe {
|
||||
namespace gpu {
|
||||
|
@ -230,34 +231,13 @@ bool TextureCache::Initialize() {
|
|||
root_signature_desc.NumStaticSamplers = 0;
|
||||
root_signature_desc.pStaticSamplers = nullptr;
|
||||
root_signature_desc.Flags = D3D12_ROOT_SIGNATURE_FLAG_NONE;
|
||||
ID3DBlob* root_signature_blob;
|
||||
ID3DBlob* root_signature_error_blob = nullptr;
|
||||
if (FAILED(D3D12SerializeRootSignature(
|
||||
&root_signature_desc, D3D_ROOT_SIGNATURE_VERSION_1,
|
||||
&root_signature_blob, &root_signature_error_blob))) {
|
||||
XELOGE("Failed to serialize the texture loading root signature");
|
||||
if (root_signature_error_blob != nullptr) {
|
||||
XELOGE("%s", reinterpret_cast<const char*>(
|
||||
root_signature_error_blob->GetBufferPointer()));
|
||||
root_signature_error_blob->Release();
|
||||
}
|
||||
Shutdown();
|
||||
return false;
|
||||
}
|
||||
if (root_signature_error_blob != nullptr) {
|
||||
root_signature_error_blob->Release();
|
||||
root_signature_error_blob = nullptr;
|
||||
}
|
||||
if (FAILED(device->CreateRootSignature(
|
||||
0, root_signature_blob->GetBufferPointer(),
|
||||
root_signature_blob->GetBufferSize(),
|
||||
IID_PPV_ARGS(&load_root_signature_)))) {
|
||||
load_root_signature_ =
|
||||
ui::d3d12::util::CreateRootSignature(device, root_signature_desc);
|
||||
if (load_root_signature_ == nullptr) {
|
||||
XELOGE("Failed to create the texture loading root signature");
|
||||
root_signature_blob->Release();
|
||||
Shutdown();
|
||||
return false;
|
||||
}
|
||||
root_signature_blob->Release();
|
||||
// Create the tiling root signature (almost the same, but with root constants
|
||||
// in parameter 0).
|
||||
root_parameters[0].ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS;
|
||||
|
@ -265,32 +245,13 @@ bool TextureCache::Initialize() {
|
|||
root_parameters[0].Constants.RegisterSpace = 0;
|
||||
root_parameters[0].Constants.Num32BitValues =
|
||||
sizeof(TileConstants) / sizeof(uint32_t);
|
||||
if (FAILED(D3D12SerializeRootSignature(
|
||||
&root_signature_desc, D3D_ROOT_SIGNATURE_VERSION_1,
|
||||
&root_signature_blob, &root_signature_error_blob))) {
|
||||
XELOGE("Failed to serialize the texture tiling root signature");
|
||||
if (root_signature_error_blob != nullptr) {
|
||||
XELOGE("%s", reinterpret_cast<const char*>(
|
||||
root_signature_error_blob->GetBufferPointer()));
|
||||
root_signature_error_blob->Release();
|
||||
}
|
||||
Shutdown();
|
||||
return false;
|
||||
}
|
||||
if (root_signature_error_blob != nullptr) {
|
||||
root_signature_error_blob->Release();
|
||||
root_signature_error_blob = nullptr;
|
||||
}
|
||||
if (FAILED(device->CreateRootSignature(
|
||||
0, root_signature_blob->GetBufferPointer(),
|
||||
root_signature_blob->GetBufferSize(),
|
||||
IID_PPV_ARGS(&tile_root_signature_)))) {
|
||||
tile_root_signature_ =
|
||||
ui::d3d12::util::CreateRootSignature(device, root_signature_desc);
|
||||
if (tile_root_signature_ == nullptr) {
|
||||
XELOGE("Failed to create the texture tiling root signature");
|
||||
root_signature_blob->Release();
|
||||
Shutdown();
|
||||
return false;
|
||||
}
|
||||
root_signature_blob->Release();
|
||||
|
||||
// Create the loading and tiling pipelines.
|
||||
D3D12_COMPUTE_PIPELINE_STATE_DESC pipeline_desc;
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "xenia/base/assert.h"
|
||||
#include "xenia/base/logging.h"
|
||||
#include "xenia/base/math.h"
|
||||
#include "xenia/ui/d3d12/d3d12_util.h"
|
||||
|
||||
namespace xe {
|
||||
namespace ui {
|
||||
|
@ -172,33 +173,13 @@ bool D3D12ImmediateDrawer::Initialize() {
|
|||
root_signature_desc.pStaticSamplers = nullptr;
|
||||
root_signature_desc.Flags =
|
||||
D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT;
|
||||
ID3DBlob* root_signature_blob;
|
||||
ID3DBlob* root_signature_error_blob = nullptr;
|
||||
if (FAILED(D3D12SerializeRootSignature(
|
||||
&root_signature_desc, D3D_ROOT_SIGNATURE_VERSION_1,
|
||||
&root_signature_blob, &root_signature_error_blob))) {
|
||||
XELOGE("Failed to serialize immediate drawer root signature");
|
||||
if (root_signature_error_blob != nullptr) {
|
||||
XELOGE("%s", reinterpret_cast<const char*>(
|
||||
root_signature_error_blob->GetBufferPointer()));
|
||||
root_signature_error_blob->Release();
|
||||
}
|
||||
root_signature_ =
|
||||
ui::d3d12::util::CreateRootSignature(device, root_signature_desc);
|
||||
if (root_signature_ == nullptr) {
|
||||
XELOGE("Failed to create the immediate drawer root signature");
|
||||
Shutdown();
|
||||
return false;
|
||||
}
|
||||
if (root_signature_error_blob != nullptr) {
|
||||
root_signature_error_blob->Release();
|
||||
}
|
||||
if (FAILED(device->CreateRootSignature(
|
||||
0, root_signature_blob->GetBufferPointer(),
|
||||
root_signature_blob->GetBufferSize(),
|
||||
IID_PPV_ARGS(&root_signature_)))) {
|
||||
XELOGE("Failed to create immediate drawer root signature");
|
||||
root_signature_blob->Release();
|
||||
Shutdown();
|
||||
return false;
|
||||
}
|
||||
root_signature_blob->Release();
|
||||
|
||||
// Create the pipelines.
|
||||
D3D12_GRAPHICS_PIPELINE_STATE_DESC pipeline_desc = {};
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
/**
|
||||
******************************************************************************
|
||||
* Xenia : Xbox 360 Emulator Research Project *
|
||||
******************************************************************************
|
||||
* Copyright 2018 Ben Vanik. All rights reserved. *
|
||||
* Released under the BSD license - see LICENSE in the root for more details. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#include "xenia/ui/d3d12/d3d12_util.h"
|
||||
|
||||
#include "xenia/base/logging.h"
|
||||
|
||||
namespace xe {
|
||||
namespace ui {
|
||||
namespace d3d12 {
|
||||
namespace util {
|
||||
|
||||
ID3D12RootSignature* CreateRootSignature(
|
||||
ID3D12Device* device, const D3D12_ROOT_SIGNATURE_DESC& desc) {
|
||||
ID3DBlob* blob;
|
||||
ID3DBlob* error_blob = nullptr;
|
||||
if (FAILED(D3D12SerializeRootSignature(&desc, D3D_ROOT_SIGNATURE_VERSION_1,
|
||||
&blob, &error_blob))) {
|
||||
XELOGE("Failed to serialize a root signature");
|
||||
if (error_blob != nullptr) {
|
||||
XELOGE("%s",
|
||||
reinterpret_cast<const char*>(error_blob->GetBufferPointer()));
|
||||
error_blob->Release();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
if (error_blob != nullptr) {
|
||||
error_blob->Release();
|
||||
}
|
||||
ID3D12RootSignature* root_signature = nullptr;
|
||||
device->CreateRootSignature(0, blob->GetBufferPointer(),
|
||||
blob->GetBufferSize(),
|
||||
IID_PPV_ARGS(&root_signature));
|
||||
blob->Release();
|
||||
return root_signature;
|
||||
}
|
||||
|
||||
} // namespace util
|
||||
} // namespace d3d12
|
||||
} // namespace ui
|
||||
} // namespace xe
|
|
@ -0,0 +1,37 @@
|
|||
/**
|
||||
******************************************************************************
|
||||
* Xenia : Xbox 360 Emulator Research Project *
|
||||
******************************************************************************
|
||||
* Copyright 2018 Ben Vanik. All rights reserved. *
|
||||
* Released under the BSD license - see LICENSE in the root for more details. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef XENIA_UI_D3D12_D3D12_UTIL_H_
|
||||
#define XENIA_UI_D3D12_D3D12_UTIL_H_
|
||||
|
||||
#include "xenia/ui/d3d12/d3d12_provider.h"
|
||||
|
||||
namespace xe {
|
||||
namespace ui {
|
||||
namespace d3d12 {
|
||||
namespace util {
|
||||
|
||||
inline bool ReleaseAndNull(IUnknown*& object) {
|
||||
if (object != nullptr) {
|
||||
object->Release();
|
||||
object = nullptr;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
ID3D12RootSignature* CreateRootSignature(ID3D12Device* device,
|
||||
const D3D12_ROOT_SIGNATURE_DESC& desc);
|
||||
|
||||
} // namespace util
|
||||
} // namespace d3d12
|
||||
} // namespace ui
|
||||
} // namespace xe
|
||||
|
||||
#endif // XENIA_UI_D3D12_D3D12_UTIL_H_
|
Loading…
Reference in New Issue