mirror of
https://github.com/libretro/RetroArch
synced 2025-03-31 19:21:06 +00:00
(D3D12) refactor init_pipeline.
This commit is contained in:
parent
c1a936ea81
commit
6d90aae5d6
gfx
@ -369,75 +369,53 @@ bool d3d12_init_descriptors(d3d12_video_t* d3d12)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool d3d12_init_pipeline(d3d12_video_t* d3d12)
|
||||
D3D12_RENDER_TARGET_BLEND_DESC d3d12_blend_enable_desc =
|
||||
{
|
||||
D3DBlob vs_code;
|
||||
D3DBlob ps_code;
|
||||
|
||||
static const char stock[] =
|
||||
#include "../drivers/d3d_shaders/opaque_sm5.hlsl.h"
|
||||
;
|
||||
|
||||
static const D3D12_INPUT_ELEMENT_DESC inputElementDesc[] = {
|
||||
{ "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, offsetof(d3d12_vertex_t, position),
|
||||
D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 },
|
||||
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, offsetof(d3d12_vertex_t, texcoord),
|
||||
D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 },
|
||||
{ "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, offsetof(d3d12_vertex_t, color),
|
||||
D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 },
|
||||
};
|
||||
|
||||
if (!d3d_compile(stock, sizeof(stock), NULL, "VSMain", "vs_5_0", &vs_code))
|
||||
return false;
|
||||
|
||||
if (!d3d_compile(stock, sizeof(stock), NULL, "PSMain", "ps_5_0", &ps_code))
|
||||
return false;
|
||||
TRUE,
|
||||
FALSE,
|
||||
D3D12_BLEND_SRC_ALPHA,
|
||||
D3D12_BLEND_INV_SRC_ALPHA,
|
||||
D3D12_BLEND_OP_ADD,
|
||||
D3D12_BLEND_SRC_ALPHA,
|
||||
D3D12_BLEND_INV_SRC_ALPHA,
|
||||
D3D12_BLEND_OP_ADD,
|
||||
D3D12_LOGIC_OP_NOOP,
|
||||
D3D12_COLOR_WRITE_ENABLE_ALL,
|
||||
};
|
||||
|
||||
bool d3d12_init_pipeline(
|
||||
D3D12Device device,
|
||||
D3DBlob vs_code,
|
||||
D3DBlob ps_code,
|
||||
D3DBlob gs_code,
|
||||
D3D12_GRAPHICS_PIPELINE_STATE_DESC* desc,
|
||||
D3D12PipelineState* out)
|
||||
{
|
||||
if(vs_code)
|
||||
{
|
||||
D3D12_GRAPHICS_PIPELINE_STATE_DESC psodesc = { 0 };
|
||||
psodesc.pRootSignature = d3d12->pipe.rootSignature;
|
||||
psodesc.VS.pShaderBytecode = D3DGetBufferPointer(vs_code);
|
||||
psodesc.VS.BytecodeLength = D3DGetBufferSize(vs_code);
|
||||
psodesc.PS.pShaderBytecode = D3DGetBufferPointer(ps_code);
|
||||
psodesc.PS.BytecodeLength = D3DGetBufferSize(ps_code);
|
||||
psodesc.BlendState.AlphaToCoverageEnable = FALSE;
|
||||
psodesc.BlendState.IndependentBlendEnable = FALSE;
|
||||
psodesc.BlendState.RenderTarget[0].BlendEnable = TRUE;
|
||||
psodesc.BlendState.RenderTarget[0].LogicOpEnable = FALSE;
|
||||
psodesc.BlendState.RenderTarget[0].SrcBlend = D3D12_BLEND_SRC_ALPHA;
|
||||
psodesc.BlendState.RenderTarget[0].DestBlend = D3D12_BLEND_INV_SRC_ALPHA;
|
||||
psodesc.BlendState.RenderTarget[0].BlendOp = D3D12_BLEND_OP_ADD;
|
||||
psodesc.BlendState.RenderTarget[0].SrcBlendAlpha = D3D12_BLEND_SRC_ALPHA;
|
||||
psodesc.BlendState.RenderTarget[0].DestBlendAlpha = D3D12_BLEND_INV_SRC_ALPHA;
|
||||
psodesc.BlendState.RenderTarget[0].BlendOpAlpha = D3D12_BLEND_OP_ADD;
|
||||
psodesc.BlendState.RenderTarget[0].LogicOp = D3D12_LOGIC_OP_NOOP;
|
||||
psodesc.BlendState.RenderTarget[0].RenderTargetWriteMask = D3D12_COLOR_WRITE_ENABLE_ALL;
|
||||
psodesc.SampleMask = UINT_MAX;
|
||||
psodesc.RasterizerState.FillMode = D3D12_FILL_MODE_SOLID;
|
||||
psodesc.RasterizerState.CullMode = D3D12_CULL_MODE_BACK;
|
||||
psodesc.RasterizerState.FrontCounterClockwise = FALSE;
|
||||
psodesc.RasterizerState.DepthBias = D3D12_DEFAULT_DEPTH_BIAS;
|
||||
psodesc.RasterizerState.DepthBiasClamp = D3D12_DEFAULT_DEPTH_BIAS_CLAMP;
|
||||
psodesc.RasterizerState.SlopeScaledDepthBias = D3D12_DEFAULT_SLOPE_SCALED_DEPTH_BIAS;
|
||||
psodesc.RasterizerState.DepthClipEnable = TRUE;
|
||||
psodesc.RasterizerState.MultisampleEnable = FALSE;
|
||||
psodesc.RasterizerState.AntialiasedLineEnable = FALSE;
|
||||
psodesc.RasterizerState.ForcedSampleCount = 0;
|
||||
psodesc.RasterizerState.ConservativeRaster = D3D12_CONSERVATIVE_RASTERIZATION_MODE_OFF;
|
||||
psodesc.DepthStencilState.DepthEnable = FALSE;
|
||||
psodesc.DepthStencilState.StencilEnable = FALSE;
|
||||
psodesc.InputLayout.pInputElementDescs = inputElementDesc;
|
||||
psodesc.InputLayout.NumElements = countof(inputElementDesc);
|
||||
psodesc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
|
||||
psodesc.NumRenderTargets = 1;
|
||||
psodesc.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
psodesc.SampleDesc.Count = 1;
|
||||
|
||||
D3D12CreateGraphicsPipelineState(d3d12->device, &psodesc, &d3d12->pipe.handle);
|
||||
desc->VS.pShaderBytecode = D3DGetBufferPointer(vs_code);
|
||||
desc->VS.BytecodeLength = D3DGetBufferSize(vs_code);
|
||||
}
|
||||
|
||||
Release(vs_code);
|
||||
Release(ps_code);
|
||||
if(ps_code)
|
||||
{
|
||||
desc->PS.pShaderBytecode = D3DGetBufferPointer(ps_code);
|
||||
desc->PS.BytecodeLength = D3DGetBufferSize(ps_code);
|
||||
}
|
||||
|
||||
if(gs_code)
|
||||
{
|
||||
desc->GS.pShaderBytecode = D3DGetBufferPointer(gs_code);
|
||||
desc->GS.BytecodeLength = D3DGetBufferSize(gs_code);
|
||||
}
|
||||
|
||||
desc->SampleMask = UINT_MAX;
|
||||
desc->RasterizerState.FillMode = D3D12_FILL_MODE_SOLID;
|
||||
desc->RasterizerState.CullMode = D3D12_CULL_MODE_NONE;
|
||||
desc->NumRenderTargets = 1;
|
||||
desc->SampleDesc.Count = 1;
|
||||
|
||||
D3D12CreateGraphicsPipelineState(device, desc, out);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1250,8 +1250,10 @@ D3D12GetGPUDescriptorHandleForHeapStart(D3D12DescriptorHeap descriptor_heap)
|
||||
/* internal */
|
||||
|
||||
#include <retro_math.h>
|
||||
#include <retro_common_api.h>
|
||||
#include <gfx/math/matrix_4x4.h>
|
||||
|
||||
#include "../common/d3dcompiler_common.h"
|
||||
#include "../video_driver.h"
|
||||
|
||||
typedef struct d3d12_vertex_t
|
||||
@ -1382,10 +1384,24 @@ typedef enum {
|
||||
SRV_HEAP_SLOT_MAX = 16
|
||||
} descriptor_heap_slot_t;
|
||||
|
||||
RETRO_BEGIN_DECLS
|
||||
|
||||
extern D3D12_RENDER_TARGET_BLEND_DESC d3d12_blend_enable_desc;
|
||||
|
||||
bool d3d12_init_base(d3d12_video_t* d3d12);
|
||||
|
||||
bool d3d12_init_descriptors(d3d12_video_t* d3d12);
|
||||
bool d3d12_init_pipeline(d3d12_video_t* d3d12);
|
||||
|
||||
bool d3d12_init_pipeline(
|
||||
D3D12Device device,
|
||||
D3DBlob vs_code,
|
||||
D3DBlob ps_code,
|
||||
D3DBlob gs_code,
|
||||
D3D12_GRAPHICS_PIPELINE_STATE_DESC* desc,
|
||||
D3D12PipelineState* out);
|
||||
|
||||
bool d3d12_init_swapchain(d3d12_video_t* d3d12, int width, int height, HWND hwnd);
|
||||
|
||||
bool d3d12_init_queue(d3d12_video_t* d3d12);
|
||||
|
||||
D3D12_GPU_VIRTUAL_ADDRESS
|
||||
@ -1402,6 +1418,10 @@ void d3d12_upload_texture(D3D12GraphicsCommandList cmd, d3d12_texture_t* texture
|
||||
void d3d12_create_fullscreen_quad_vbo(
|
||||
D3D12Device device, D3D12_VERTEX_BUFFER_VIEW* view, D3D12Resource* vbo);
|
||||
|
||||
DXGI_FORMAT d3d12_get_closest_match(
|
||||
D3D12Device device, DXGI_FORMAT desired_format, D3D12_FORMAT_SUPPORT1 desired_format_support);
|
||||
|
||||
#if !defined(__cplusplus ) || defined(CINTERFACE)
|
||||
static INLINE void d3d12_resource_transition(
|
||||
D3D12GraphicsCommandList cmd,
|
||||
D3D12Resource resource,
|
||||
@ -1451,9 +1471,6 @@ static INLINE void d3d12_update_texture(
|
||||
texture->dirty = true;
|
||||
}
|
||||
|
||||
DXGI_FORMAT d3d12_get_closest_match(
|
||||
D3D12Device device, DXGI_FORMAT desired_format, D3D12_FORMAT_SUPPORT1 desired_format_support);
|
||||
|
||||
static INLINE DXGI_FORMAT
|
||||
d3d12_get_closest_match_texture2D(D3D12Device device, DXGI_FORMAT desired_format)
|
||||
{
|
||||
@ -1461,3 +1478,6 @@ d3d12_get_closest_match_texture2D(D3D12Device device, DXGI_FORMAT desired_format
|
||||
device, desired_format,
|
||||
D3D12_FORMAT_SUPPORT1_TEXTURE2D | D3D12_FORMAT_SUPPORT1_SHADER_SAMPLE);
|
||||
}
|
||||
#endif
|
||||
|
||||
RETRO_END_DECLS
|
||||
|
@ -109,8 +109,45 @@ d3d12_gfx_init(const video_info_t* video, const input_driver_t** input, void** i
|
||||
if (!d3d12_init_descriptors(d3d12))
|
||||
goto error;
|
||||
|
||||
if (!d3d12_init_pipeline(d3d12))
|
||||
goto error;
|
||||
{
|
||||
bool success = false;
|
||||
D3DBlob vs_code = NULL;
|
||||
D3DBlob ps_code = NULL;
|
||||
D3D12_GRAPHICS_PIPELINE_STATE_DESC desc = { 0 };
|
||||
|
||||
static const char shader[] =
|
||||
#include "../drivers/d3d_shaders/opaque_sm5.hlsl.h"
|
||||
;
|
||||
|
||||
static const D3D12_INPUT_ELEMENT_DESC inputElementDesc[] = {
|
||||
{ "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, offsetof(d3d12_vertex_t, position),
|
||||
D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 },
|
||||
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, offsetof(d3d12_vertex_t, texcoord),
|
||||
D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 },
|
||||
{ "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, offsetof(d3d12_vertex_t, color),
|
||||
D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 },
|
||||
};
|
||||
|
||||
desc.pRootSignature = d3d12->pipe.rootSignature;
|
||||
desc.BlendState.RenderTarget[0] = d3d12_blend_enable_desc;
|
||||
desc.InputLayout.pInputElementDescs = inputElementDesc;
|
||||
desc.InputLayout.NumElements = countof(inputElementDesc);
|
||||
desc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
|
||||
desc.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
|
||||
d3d_compile(shader, sizeof(shader), NULL, "VSMain", "vs_5_0", &vs_code);
|
||||
d3d_compile(shader, sizeof(shader), NULL, "PSMain", "ps_5_0", &ps_code);
|
||||
|
||||
if (vs_code && ps_code)
|
||||
success = d3d12_init_pipeline(
|
||||
d3d12->device, vs_code, ps_code, NULL, &desc, &d3d12->pipe.handle);
|
||||
|
||||
Release(vs_code);
|
||||
Release(ps_code);
|
||||
|
||||
if(!success)
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!d3d12_init_queue(d3d12))
|
||||
goto error;
|
||||
|
Loading…
x
Reference in New Issue
Block a user