mirror of
https://github.com/libretro/RetroArch
synced 2025-01-31 15:32:59 +00:00
Merge pull request #6153 from aliaspider/master
(D3D11/12) refactors/fixes. add blending and selectable samplers for d3d12.
This commit is contained in:
commit
99500b6f10
@ -113,7 +113,7 @@ D3D12SerializeVersionedRootSignature(const D3D12_VERSIONED_ROOT_SIGNATURE_DESC *
|
||||
|
||||
#include <wiiu/wiiu_dbg.h>
|
||||
|
||||
bool d3d12_init_context(d3d12_video_t *d3d12)
|
||||
bool d3d12_init_base(d3d12_video_t *d3d12)
|
||||
{
|
||||
|
||||
#ifdef DEBUG
|
||||
@ -144,7 +144,7 @@ bool d3d12_init_context(d3d12_video_t *d3d12)
|
||||
bool d3d12_init_queue(d3d12_video_t *d3d12)
|
||||
{
|
||||
{
|
||||
D3D12_COMMAND_QUEUE_DESC desc =
|
||||
static const D3D12_COMMAND_QUEUE_DESC desc =
|
||||
{
|
||||
.Type = D3D12_COMMAND_LIST_TYPE_DIRECT,
|
||||
.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE,
|
||||
@ -185,8 +185,9 @@ bool d3d12_init_swapchain(d3d12_video_t *d3d12, int width, int height, HWND hwnd
|
||||
.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT,
|
||||
.OutputWindow = hwnd,
|
||||
.Windowed = TRUE,
|
||||
#if 1
|
||||
.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL,
|
||||
#if 0
|
||||
#else
|
||||
.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD,
|
||||
#endif
|
||||
};
|
||||
@ -221,10 +222,30 @@ static void d3d12_init_descriptor_heap(D3D12Device device, d3d12_descriptor_heap
|
||||
out->stride = D3D12GetDescriptorHandleIncrementSize(device, out->desc.Type);
|
||||
}
|
||||
|
||||
static void d3d12_init_sampler(D3D12Device device, d3d12_descriptor_heap_t *heap, descriptor_heap_slot_t heap_index,
|
||||
D3D12_FILTER filter, D3D12_TEXTURE_ADDRESS_MODE address_mode, D3D12_GPU_DESCRIPTOR_HANDLE* dst)
|
||||
{
|
||||
D3D12_SAMPLER_DESC sampler_desc =
|
||||
{
|
||||
.Filter = filter,
|
||||
.AddressU = address_mode,
|
||||
.AddressV = address_mode,
|
||||
.AddressW = address_mode,
|
||||
.MipLODBias = 0,
|
||||
.MaxAnisotropy = 0,
|
||||
.ComparisonFunc = D3D12_COMPARISON_FUNC_NEVER,
|
||||
.BorderColor = {0.0f},
|
||||
.MinLOD = 0.0f,
|
||||
.MaxLOD = D3D12_FLOAT32_MAX,
|
||||
};
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE handle = {heap->cpu.ptr + heap_index * heap->stride};
|
||||
D3D12CreateSampler(device, &sampler_desc, handle);
|
||||
dst->ptr = heap->gpu.ptr + heap_index * heap->stride;
|
||||
}
|
||||
|
||||
bool d3d12_init_descriptors(d3d12_video_t *d3d12)
|
||||
{
|
||||
static const D3D12_DESCRIPTOR_RANGE desc_table[] =
|
||||
static const D3D12_DESCRIPTOR_RANGE srv_table[] =
|
||||
{
|
||||
{
|
||||
.RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_SRV,
|
||||
@ -237,40 +258,33 @@ bool d3d12_init_descriptors(d3d12_video_t *d3d12)
|
||||
.OffsetInDescriptorsFromTableStart = D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND,
|
||||
},
|
||||
};
|
||||
|
||||
static const D3D12_DESCRIPTOR_RANGE sampler_table[] =
|
||||
{
|
||||
{
|
||||
.RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER,
|
||||
.NumDescriptors = 1,
|
||||
.BaseShaderRegister = 0,
|
||||
.RegisterSpace = 0,
|
||||
.OffsetInDescriptorsFromTableStart = D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND,
|
||||
},
|
||||
};
|
||||
|
||||
static const D3D12_ROOT_PARAMETER rootParameters[] =
|
||||
{
|
||||
{
|
||||
.ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE,
|
||||
.DescriptorTable = {countof(desc_table), desc_table},
|
||||
.DescriptorTable = {countof(srv_table), srv_table},
|
||||
.ShaderVisibility = D3D12_SHADER_VISIBILITY_PIXEL,
|
||||
},
|
||||
};
|
||||
|
||||
static const D3D12_STATIC_SAMPLER_DESC samplers[] =
|
||||
{
|
||||
{
|
||||
.Filter = D3D12_FILTER_MIN_MAG_MIP_LINEAR,
|
||||
.AddressU = D3D12_TEXTURE_ADDRESS_MODE_BORDER,
|
||||
.AddressV = D3D12_TEXTURE_ADDRESS_MODE_BORDER,
|
||||
.AddressW = D3D12_TEXTURE_ADDRESS_MODE_BORDER,
|
||||
.MipLODBias = 0,
|
||||
.MaxAnisotropy = 0,
|
||||
.ComparisonFunc = D3D12_COMPARISON_FUNC_NEVER,
|
||||
.BorderColor = D3D12_STATIC_BORDER_COLOR_TRANSPARENT_BLACK,
|
||||
.MinLOD = 0.0f,
|
||||
.MaxLOD = D3D12_FLOAT32_MAX,
|
||||
.ShaderRegister = 0,
|
||||
.RegisterSpace = 0,
|
||||
.ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE,
|
||||
.DescriptorTable = {countof(sampler_table), sampler_table},
|
||||
.ShaderVisibility = D3D12_SHADER_VISIBILITY_PIXEL,
|
||||
},
|
||||
};
|
||||
|
||||
static const D3D12_ROOT_SIGNATURE_DESC desc =
|
||||
{
|
||||
.NumParameters = countof(rootParameters), rootParameters,
|
||||
.NumStaticSamplers = countof(samplers), samplers,
|
||||
.Flags = D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT,
|
||||
};
|
||||
|
||||
@ -297,10 +311,21 @@ bool d3d12_init_descriptors(d3d12_video_t *d3d12)
|
||||
d3d12_init_descriptor_heap(d3d12->device, &d3d12->pipe.rtv_heap);
|
||||
|
||||
d3d12->pipe.srv_heap.desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
|
||||
d3d12->pipe.srv_heap.desc.NumDescriptors = 16;
|
||||
d3d12->pipe.srv_heap.desc.NumDescriptors = SRV_HEAP_SLOT_MAX;
|
||||
d3d12->pipe.srv_heap.desc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
|
||||
d3d12_init_descriptor_heap(d3d12->device, &d3d12->pipe.srv_heap);
|
||||
|
||||
d3d12->pipe.sampler_heap.desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER;
|
||||
d3d12->pipe.sampler_heap.desc.NumDescriptors = SAMPLER_HEAP_SLOT_MAX;
|
||||
d3d12->pipe.sampler_heap.desc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
|
||||
d3d12_init_descriptor_heap(d3d12->device, &d3d12->pipe.sampler_heap);
|
||||
|
||||
d3d12_init_sampler(d3d12->device, &d3d12->pipe.sampler_heap,
|
||||
SAMPLER_HEAP_SLOT_LINEAR, D3D12_FILTER_MIN_MAG_MIP_LINEAR,
|
||||
D3D12_TEXTURE_ADDRESS_MODE_BORDER, &d3d12->sampler_linear);
|
||||
d3d12_init_sampler(d3d12->device, &d3d12->pipe.sampler_heap,
|
||||
SAMPLER_HEAP_SLOT_NEAREST, D3D12_FILTER_MIN_MAG_MIP_POINT,
|
||||
D3D12_TEXTURE_ADDRESS_MODE_BORDER, &d3d12->sampler_nearest);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -313,7 +338,7 @@ bool d3d12_init_pipeline(d3d12_video_t *d3d12)
|
||||
#include "gfx/drivers/d3d_shaders/opaque_sm5.hlsl.h"
|
||||
;
|
||||
|
||||
D3D12_INPUT_ELEMENT_DESC inputElementDesc[] =
|
||||
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},
|
||||
@ -321,7 +346,7 @@ bool d3d12_init_pipeline(d3d12_video_t *d3d12)
|
||||
};
|
||||
|
||||
|
||||
D3D12_RASTERIZER_DESC rasterizerDesc =
|
||||
static const D3D12_RASTERIZER_DESC rasterizerDesc =
|
||||
{
|
||||
.FillMode = D3D12_FILL_MODE_SOLID,
|
||||
.CullMode = D3D12_CULL_MODE_BACK,
|
||||
@ -336,20 +361,17 @@ bool d3d12_init_pipeline(d3d12_video_t *d3d12)
|
||||
.ConservativeRaster = D3D12_CONSERVATIVE_RASTERIZATION_MODE_OFF,
|
||||
};
|
||||
|
||||
const D3D12_RENDER_TARGET_BLEND_DESC defaultRenderTargetBlendDesc =
|
||||
{
|
||||
.BlendEnable = FALSE, .LogicOpEnable = FALSE,
|
||||
D3D12_BLEND_ONE, D3D12_BLEND_ZERO, D3D12_BLEND_OP_ADD,
|
||||
D3D12_BLEND_ONE, D3D12_BLEND_ZERO, D3D12_BLEND_OP_ADD,
|
||||
D3D12_LOGIC_OP_NOOP,
|
||||
D3D12_COLOR_WRITE_ENABLE_ALL,
|
||||
};
|
||||
|
||||
D3D12_BLEND_DESC blendDesc =
|
||||
static const D3D12_BLEND_DESC blendDesc =
|
||||
{
|
||||
.AlphaToCoverageEnable = FALSE,
|
||||
.IndependentBlendEnable = FALSE,
|
||||
.RenderTarget[0] = defaultRenderTargetBlendDesc,
|
||||
.RenderTarget[0] =
|
||||
{
|
||||
.BlendEnable = TRUE, .LogicOpEnable = 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,
|
||||
},
|
||||
};
|
||||
|
||||
if (!d3d_compile(stock, sizeof(stock), "VSMain", "vs_5_0", &vs_code))
|
||||
@ -388,7 +410,7 @@ bool d3d12_init_pipeline(d3d12_video_t *d3d12)
|
||||
void d3d12_create_vertex_buffer(D3D12Device device, D3D12_VERTEX_BUFFER_VIEW *view,
|
||||
D3D12Resource *vbo)
|
||||
{
|
||||
D3D12_HEAP_PROPERTIES heap_props =
|
||||
static const D3D12_HEAP_PROPERTIES heap_props =
|
||||
{
|
||||
.Type = D3D12_HEAP_TYPE_UPLOAD,
|
||||
.CreationNodeMask = 1,
|
||||
@ -411,7 +433,7 @@ void d3d12_create_vertex_buffer(D3D12Device device, D3D12_VERTEX_BUFFER_VIEW *vi
|
||||
view->BufferLocation = D3D12GetGPUVirtualAddress(*vbo);
|
||||
}
|
||||
|
||||
void d3d12_create_texture(D3D12Device device, d3d12_descriptor_heap_t *heap, int heap_index,
|
||||
void d3d12_create_texture(D3D12Device device, d3d12_descriptor_heap_t *heap, descriptor_heap_slot_t heap_index,
|
||||
d3d12_texture_t *tex)
|
||||
{
|
||||
{
|
||||
@ -453,7 +475,7 @@ void d3d12_create_texture(D3D12Device device, d3d12_descriptor_heap_t *heap, int
|
||||
.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D,
|
||||
.Texture2D.MipLevels = tex->desc.MipLevels,
|
||||
};
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE handle = {heap->cpu.ptr + heap_index *heap->stride};
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE handle = {heap->cpu.ptr + heap_index * heap->stride};
|
||||
D3D12CreateShaderResourceView(device, tex->handle, &view_desc, handle);
|
||||
tex->gpu_descriptor.ptr = heap->gpu.ptr + heap_index * heap->stride;
|
||||
}
|
||||
@ -476,13 +498,37 @@ void d3d12_upload_texture(D3D12GraphicsCommandList cmd, d3d12_texture_t *texture
|
||||
.SubresourceIndex = 0,
|
||||
};
|
||||
|
||||
d3d12_transition(cmd, texture->handle,
|
||||
d3d12_resource_transition(cmd, texture->handle,
|
||||
D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE, D3D12_RESOURCE_STATE_COPY_DEST);
|
||||
|
||||
D3D12CopyTextureRegion(cmd, &dst, 0, 0, 0, &src, NULL);
|
||||
|
||||
d3d12_transition(cmd, texture->handle,
|
||||
d3d12_resource_transition(cmd, texture->handle,
|
||||
D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE);
|
||||
|
||||
texture->dirty = false;
|
||||
}
|
||||
|
||||
void d3d12_create_fullscreen_quad_vbo(D3D12Device device, D3D12_VERTEX_BUFFER_VIEW *view, D3D12Resource *vbo)
|
||||
{
|
||||
static const d3d12_vertex_t vertices[] =
|
||||
{
|
||||
{{ -1.0f, -1.0f}, {0.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
|
||||
{{ -1.0f, 1.0f}, {0.0f, 0.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
|
||||
{{ 1.0f, -1.0f}, {1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
|
||||
{{ 1.0f, 1.0f}, {1.0f, 0.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
|
||||
};
|
||||
|
||||
view->SizeInBytes = sizeof(vertices);
|
||||
view->StrideInBytes = sizeof(*vertices);
|
||||
d3d12_create_vertex_buffer(device, view, vbo);
|
||||
|
||||
{
|
||||
void *vertex_data_begin;
|
||||
D3D12_RANGE read_range = {0, 0};
|
||||
|
||||
D3D12Map(*vbo, 0, &read_range, &vertex_data_begin);
|
||||
memcpy(vertex_data_begin, vertices, sizeof(vertices));
|
||||
D3D12Unmap(*vbo, 0, NULL);
|
||||
}
|
||||
}
|
||||
|
@ -892,6 +892,7 @@ typedef struct
|
||||
D3D12RootSignature rootSignature; /* descriptor layout */
|
||||
d3d12_descriptor_heap_t srv_heap; /* ShaderResouceView descritor heap */
|
||||
d3d12_descriptor_heap_t rtv_heap; /* RenderTargetView descritor heap */
|
||||
d3d12_descriptor_heap_t sampler_heap;
|
||||
}pipe;
|
||||
|
||||
struct
|
||||
@ -911,6 +912,7 @@ typedef struct
|
||||
D3D12Resource vbo;
|
||||
D3D12_VERTEX_BUFFER_VIEW vbo_view;
|
||||
d3d12_texture_t tex;
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE sampler;
|
||||
bool rgb32;
|
||||
}frame;
|
||||
|
||||
@ -919,29 +921,51 @@ typedef struct
|
||||
D3D12Resource vbo;
|
||||
D3D12_VERTEX_BUFFER_VIEW vbo_view;
|
||||
d3d12_texture_t tex;
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE sampler;
|
||||
|
||||
float alpha;
|
||||
bool enabled;
|
||||
bool fullscreen;
|
||||
}menu;
|
||||
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE sampler_linear;
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE sampler_nearest;
|
||||
|
||||
#ifdef DEBUG
|
||||
D3D12Debug debugController;
|
||||
#endif
|
||||
} d3d12_video_t;
|
||||
|
||||
enum
|
||||
{
|
||||
DESC_TABLE_INDEX_SRV_TEXTURE = 0,
|
||||
DESC_TABLE_INDEX_SAMPLER,
|
||||
};
|
||||
typedef enum
|
||||
{
|
||||
SAMPLER_HEAP_SLOT_LINEAR = 0,
|
||||
SAMPLER_HEAP_SLOT_NEAREST,
|
||||
SAMPLER_HEAP_SLOT_MAX,
|
||||
|
||||
bool d3d12_init_context(d3d12_video_t* d3d12);
|
||||
SRV_HEAP_SLOT_FRAME_TEXTURE = 0,
|
||||
SRV_HEAP_SLOT_MENU_TEXTURE,
|
||||
SRV_HEAP_SLOT_CUSTOM,
|
||||
SRV_HEAP_SLOT_MAX = 16
|
||||
}descriptor_heap_slot_t;
|
||||
|
||||
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_swapchain(d3d12_video_t* d3d12, int width, int height, HWND hwnd);
|
||||
bool d3d12_init_queue(d3d12_video_t *d3d12);
|
||||
|
||||
void d3d12_create_vertex_buffer(D3D12Device device, D3D12_VERTEX_BUFFER_VIEW* view, D3D12Resource* vbo);
|
||||
void d3d12_create_texture(D3D12Device device, d3d12_descriptor_heap_t* heap, int heap_index, d3d12_texture_t *tex);
|
||||
void d3d12_create_texture(D3D12Device device, d3d12_descriptor_heap_t* heap, descriptor_heap_slot_t heap_index, d3d12_texture_t *tex);
|
||||
void d3d12_upload_texture(D3D12GraphicsCommandList cmd, d3d12_texture_t* texture);
|
||||
|
||||
static inline d3d12_transition(D3D12GraphicsCommandList cmd, D3D12Resource resource,
|
||||
void d3d12_create_fullscreen_quad_vbo(D3D12Device device, D3D12_VERTEX_BUFFER_VIEW *view, D3D12Resource *vbo);
|
||||
|
||||
static inline d3d12_resource_transition(D3D12GraphicsCommandList cmd, D3D12Resource resource,
|
||||
D3D12_RESOURCE_STATES state_before, D3D12_RESOURCE_STATES state_after)
|
||||
{
|
||||
D3D12_RESOURCE_BARRIER barrier =
|
||||
@ -955,3 +979,14 @@ static inline d3d12_transition(D3D12GraphicsCommandList cmd, D3D12Resource resou
|
||||
};
|
||||
D3D12ResourceBarrier(cmd, 1, &barrier);
|
||||
}
|
||||
|
||||
static inline d3d12_set_texture(D3D12GraphicsCommandList cmd, const d3d12_texture_t* texture)
|
||||
{
|
||||
D3D12SetGraphicsRootDescriptorTable(cmd, DESC_TABLE_INDEX_SRV_TEXTURE, texture->gpu_descriptor);
|
||||
}
|
||||
|
||||
static inline d3d12_set_sampler(D3D12GraphicsCommandList cmd, D3D12_GPU_DESCRIPTOR_HANDLE sampler)
|
||||
{
|
||||
D3D12SetGraphicsRootDescriptorTable(cmd, DESC_TABLE_INDEX_SAMPLER, sampler);
|
||||
}
|
||||
|
||||
|
@ -591,6 +591,7 @@ LRESULT CALLBACK WndProcD3D(HWND hwnd, UINT message,
|
||||
case WM_CLOSE:
|
||||
case WM_DESTROY:
|
||||
case WM_QUIT:
|
||||
case WM_SIZE:
|
||||
case WM_COMMAND:
|
||||
ret = WndProcCommon(&quit, hwnd, message, wparam, lparam);
|
||||
if (quit)
|
||||
|
@ -109,39 +109,36 @@ static void* d3d11_gfx_init(const video_info_t* video,
|
||||
.SampleDesc.Count = 1,
|
||||
.SampleDesc.Quality = 0,
|
||||
.Windowed = TRUE,
|
||||
#if 0
|
||||
.SwapEffect = DXGI_SWAP_EFFECT_DISCARD,
|
||||
#endif
|
||||
.SwapEffect = DXGI_SWAP_EFFECT_SEQUENTIAL,
|
||||
#if 0
|
||||
.SwapEffect = DXGI_SWAP_EFFECT_DISCARD,
|
||||
.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL,
|
||||
.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD,
|
||||
#endif
|
||||
};
|
||||
|
||||
/* #ifdef DEBUG */
|
||||
#ifdef DEBUG
|
||||
flags |= D3D11_CREATE_DEVICE_DEBUG;
|
||||
/* #endif */
|
||||
#endif
|
||||
|
||||
D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, flags,
|
||||
&requested_feature_level, 1, D3D11_SDK_VERSION, &desc,
|
||||
(IDXGISwapChain**)&d3d11->swapChain, &d3d11->device, &d3d11->supportedFeatureLevel, &d3d11->context);
|
||||
}
|
||||
|
||||
#if 0
|
||||
d3d = *device->lpVtbl;
|
||||
ctx = *context->lpVtbl;
|
||||
dxgi = *swapChain->lpVtbl;
|
||||
#endif
|
||||
{
|
||||
D3D11Texture2D backBuffer;
|
||||
DXGIGetSwapChainBufferD3D11(d3d11->swapChain, 0, &backBuffer);
|
||||
D3D11CreateTexture2DRenderTargetView(d3d11->device, backBuffer, NULL, &d3d11->renderTargetView);
|
||||
Release(backBuffer);
|
||||
}
|
||||
|
||||
D3D11Texture2D backBuffer;
|
||||
DXGIGetSwapChainBufferD3D11(d3d11->swapChain, 0, &backBuffer);
|
||||
D3D11CreateTexture2DRenderTargetView(d3d11->device, backBuffer, NULL, &d3d11->renderTargetView);
|
||||
Release(backBuffer);
|
||||
D3D11SetRenderTargets(d3d11->context, 1, &d3d11->renderTargetView, NULL);
|
||||
|
||||
D3D11_VIEWPORT vp = {0, 0, video->width, video->height, 0.0f, 1.0f};
|
||||
D3D11SetViewports(d3d11->context, 1, &vp);
|
||||
{
|
||||
D3D11_VIEWPORT vp = {0, 0, video->width, video->height, 0.0f, 1.0f};
|
||||
D3D11SetViewports(d3d11->context, 1, &vp);
|
||||
}
|
||||
|
||||
|
||||
d3d11->frame_width = video->input_scale * RARCH_SCALE_BASE;
|
||||
@ -184,21 +181,17 @@ static void* d3d11_gfx_init(const video_info_t* video,
|
||||
{
|
||||
D3D11_SAMPLER_DESC desc =
|
||||
{
|
||||
.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR,
|
||||
.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT,
|
||||
.AddressU = D3D11_TEXTURE_ADDRESS_BORDER,
|
||||
.AddressV = D3D11_TEXTURE_ADDRESS_BORDER,
|
||||
.AddressW = D3D11_TEXTURE_ADDRESS_BORDER,
|
||||
.MipLODBias = 0.0f,
|
||||
.MaxAnisotropy = 1,
|
||||
.ComparisonFunc = D3D11_COMPARISON_NEVER,
|
||||
.BorderColor[0] = 0.0f,
|
||||
.BorderColor[1] = 0.0f,
|
||||
.BorderColor[2] = 0.0f,
|
||||
.BorderColor[3] = 0.0f,
|
||||
.MinLOD = -D3D11_FLOAT32_MAX,
|
||||
.MaxLOD = D3D11_FLOAT32_MAX,
|
||||
};
|
||||
D3D11CreateSamplerState(d3d11->device, &desc, &d3d11->sampler_nearest);
|
||||
|
||||
desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
|
||||
D3D11CreateSamplerState(d3d11->device, &desc, &d3d11->sampler_linear);
|
||||
}
|
||||
@ -367,9 +360,6 @@ static bool d3d11_gfx_frame(void* data, const void* frame,
|
||||
if(msg && *msg)
|
||||
gfx_ctx_d3d.update_window_title(NULL, video_info);
|
||||
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -386,8 +376,13 @@ static bool d3d11_gfx_alive(void* data)
|
||||
bool resize;
|
||||
unsigned width;
|
||||
unsigned height;
|
||||
|
||||
win32_check_window(&quit, &resize, &width, &height);
|
||||
return true;
|
||||
|
||||
if (width != 0 && height != 0)
|
||||
video_driver_set_size(&width, &height);
|
||||
|
||||
return !quit;
|
||||
}
|
||||
|
||||
static bool d3d11_gfx_focus(void* data)
|
||||
|
@ -25,6 +25,16 @@
|
||||
#include "gfx/common/d3d12_common.h"
|
||||
#include "gfx/common/d3dcompiler_common.h"
|
||||
|
||||
static void d3d12_set_filtering(void *data, unsigned index, bool smooth)
|
||||
{
|
||||
d3d12_video_t *d3d12 = (d3d12_video_t *)data;
|
||||
|
||||
if (smooth)
|
||||
d3d12->frame.sampler = d3d12->sampler_linear;
|
||||
else
|
||||
d3d12->frame.sampler = d3d12->sampler_nearest;
|
||||
}
|
||||
|
||||
static void *d3d12_gfx_init(const video_info_t *video,
|
||||
const input_driver_t **input, void **input_data)
|
||||
{
|
||||
@ -52,7 +62,7 @@ static void *d3d12_gfx_init(const video_info_t *video,
|
||||
d3d12->chain.vsync = video->vsync;
|
||||
d3d12->frame.rgb32 = video->rgb32;
|
||||
|
||||
if (!d3d12_init_context(d3d12))
|
||||
if (!d3d12_init_base(d3d12))
|
||||
goto error;
|
||||
|
||||
if (!d3d12_init_descriptors(d3d12))
|
||||
@ -61,36 +71,17 @@ static void *d3d12_gfx_init(const video_info_t *video,
|
||||
if (!d3d12_init_pipeline(d3d12))
|
||||
goto error;
|
||||
|
||||
if(!d3d12_init_queue(d3d12))
|
||||
return false;
|
||||
if (!d3d12_init_queue(d3d12))
|
||||
goto error;
|
||||
|
||||
if (!d3d12_init_swapchain(d3d12, video->width, video->height, main_window.hwnd))
|
||||
goto error;
|
||||
|
||||
d3d12_create_fullscreen_quad_vbo(d3d12->device, &d3d12->frame.vbo_view, &d3d12->frame.vbo);
|
||||
d3d12_create_fullscreen_quad_vbo(d3d12->device, &d3d12->menu.vbo_view, &d3d12->menu.vbo);
|
||||
|
||||
{
|
||||
d3d12_vertex_t vertices[] =
|
||||
{
|
||||
{{ -1.0f, -1.0f}, {0.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
|
||||
{{ -1.0f, 1.0f}, {0.0f, 0.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
|
||||
{{ 1.0f, -1.0f}, {1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
|
||||
{{ 1.0f, 1.0f}, {1.0f, 0.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
|
||||
};
|
||||
d3d12_set_filtering(d3d12, 0, video->smooth);
|
||||
|
||||
d3d12->frame.vbo_view.SizeInBytes = sizeof(vertices);
|
||||
d3d12->frame.vbo_view.StrideInBytes = sizeof(*vertices);
|
||||
d3d12_create_vertex_buffer(d3d12->device, &d3d12->frame.vbo_view, &d3d12->frame.vbo);
|
||||
|
||||
{
|
||||
void *vertex_data_begin;
|
||||
D3D12_RANGE read_range = {0, 0};
|
||||
|
||||
D3D12Map(d3d12->frame.vbo, 0, &read_range, &vertex_data_begin);
|
||||
memcpy(vertex_data_begin, vertices, sizeof(vertices));
|
||||
D3D12Unmap(d3d12->frame.vbo, 0, NULL);
|
||||
}
|
||||
|
||||
}
|
||||
return d3d12;
|
||||
|
||||
error:
|
||||
@ -104,20 +95,21 @@ static bool d3d12_gfx_frame(void *data, const void *frame,
|
||||
unsigned width, unsigned height, uint64_t frame_count,
|
||||
unsigned pitch, const char *msg, video_frame_info_t *video_info)
|
||||
{
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE rtvHandle;
|
||||
d3d12_video_t *d3d12 = (d3d12_video_t *)data;
|
||||
|
||||
(void)msg;
|
||||
(void)rtvHandle;
|
||||
|
||||
D3D12ResetCommandAllocator(d3d12->queue.allocator);
|
||||
|
||||
D3D12ResetGraphicsCommandList(d3d12->queue.cmd, d3d12->queue.allocator, d3d12->pipe.handle);
|
||||
D3D12SetGraphicsRootSignature(d3d12->queue.cmd, d3d12->pipe.rootSignature);
|
||||
D3D12SetDescriptorHeaps(d3d12->queue.cmd, 1, &d3d12->pipe.srv_heap.handle);
|
||||
{
|
||||
D3D12DescriptorHeap desc_heaps [] = {d3d12->pipe.srv_heap.handle, d3d12->pipe.sampler_heap.handle};
|
||||
D3D12SetDescriptorHeaps(d3d12->queue.cmd, countof(desc_heaps), desc_heaps);
|
||||
}
|
||||
|
||||
d3d12_transition(d3d12->queue.cmd, d3d12->chain.renderTargets[d3d12->chain.frame_index],
|
||||
D3D12_RESOURCE_STATE_PRESENT, D3D12_RESOURCE_STATE_RENDER_TARGET);
|
||||
d3d12_resource_transition(d3d12->queue.cmd, d3d12->chain.renderTargets[d3d12->chain.frame_index],
|
||||
D3D12_RESOURCE_STATE_PRESENT, D3D12_RESOURCE_STATE_RENDER_TARGET);
|
||||
|
||||
D3D12RSSetViewports(d3d12->queue.cmd, 1, &d3d12->chain.viewport);
|
||||
D3D12RSSetScissorRects(d3d12->queue.cmd, 1, &d3d12->chain.scissorRect);
|
||||
@ -131,7 +123,7 @@ static bool d3d12_gfx_frame(void *data, const void *frame,
|
||||
if (data && width && height)
|
||||
{
|
||||
if (!d3d12->frame.tex.handle || (d3d12->frame.tex.desc.Width != width)
|
||||
|| (d3d12->frame.tex.desc.Height = height))
|
||||
|| (d3d12->frame.tex.desc.Height != height))
|
||||
{
|
||||
if (d3d12->frame.tex.handle)
|
||||
Release(d3d12->frame.tex.handle);
|
||||
@ -143,15 +135,18 @@ static bool d3d12_gfx_frame(void *data, const void *frame,
|
||||
d3d12->frame.tex.desc.Height = height;
|
||||
d3d12->frame.tex.desc.Format = d3d12->frame.rgb32 ? DXGI_FORMAT_B8G8R8A8_UNORM :
|
||||
DXGI_FORMAT_B5G6R5_UNORM;
|
||||
d3d12_create_texture(d3d12->device, &d3d12->pipe.srv_heap, 0, &d3d12->frame.tex);
|
||||
d3d12_create_texture(d3d12->device, &d3d12->pipe.srv_heap, SRV_HEAP_SLOT_FRAME_TEXTURE,
|
||||
&d3d12->frame.tex);
|
||||
}
|
||||
|
||||
{
|
||||
unsigned i;
|
||||
D3D12_RANGE read_range = {0, 0};
|
||||
const uint8_t *in = frame;
|
||||
uint8_t *out = NULL;
|
||||
|
||||
D3D12Map(d3d12->frame.tex.upload_buffer, 0, NULL, &out);
|
||||
|
||||
D3D12Map(d3d12->frame.tex.upload_buffer, 0, &read_range, &out);
|
||||
out += d3d12->frame.tex.layout.Offset;
|
||||
|
||||
for (i = 0; i < height; i++)
|
||||
@ -165,28 +160,27 @@ static bool d3d12_gfx_frame(void *data, const void *frame,
|
||||
}
|
||||
|
||||
d3d12_upload_texture(d3d12->queue.cmd, &d3d12->frame.tex);
|
||||
|
||||
d3d12_set_texture(d3d12->queue.cmd, &d3d12->frame.tex);
|
||||
d3d12_set_sampler(d3d12->queue.cmd, d3d12->frame.sampler);
|
||||
D3D12IASetVertexBuffers(d3d12->queue.cmd, 0, 1, &d3d12->frame.vbo_view);
|
||||
D3D12SetGraphicsRootDescriptorTable(d3d12->queue.cmd, 0,
|
||||
d3d12->frame.tex.gpu_descriptor); /* set texture */
|
||||
D3D12DrawInstanced(d3d12->queue.cmd, 4, 1, 0, 0);
|
||||
}
|
||||
|
||||
|
||||
if (d3d12->menu.enabled && d3d12->menu.tex.handle)
|
||||
{
|
||||
if(d3d12->menu.tex.dirty)
|
||||
if (d3d12->menu.tex.dirty)
|
||||
d3d12_upload_texture(d3d12->queue.cmd, &d3d12->menu.tex);
|
||||
#if 0
|
||||
D3D12IASetVertexBuffers(d3d12->queue.cmd, 0, 1, &d3d12->frame.vbo_view);
|
||||
#endif
|
||||
D3D12SetGraphicsRootDescriptorTable(d3d12->queue.cmd, 0,
|
||||
d3d12->menu.tex.gpu_descriptor); /* set texture */
|
||||
|
||||
d3d12_set_texture(d3d12->queue.cmd, &d3d12->menu.tex);
|
||||
d3d12_set_sampler(d3d12->queue.cmd, d3d12->menu.sampler);
|
||||
D3D12IASetVertexBuffers(d3d12->queue.cmd, 0, 1, &d3d12->menu.vbo_view);
|
||||
D3D12DrawInstanced(d3d12->queue.cmd, 4, 1, 0, 0);
|
||||
}
|
||||
|
||||
|
||||
d3d12_transition(d3d12->queue.cmd, d3d12->chain.renderTargets[d3d12->chain.frame_index],
|
||||
D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_PRESENT);
|
||||
d3d12_resource_transition(d3d12->queue.cmd, d3d12->chain.renderTargets[d3d12->chain.frame_index],
|
||||
D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_PRESENT);
|
||||
D3D12CloseGraphicsCommandList(d3d12->queue.cmd);
|
||||
|
||||
D3D12ExecuteGraphicsCommandLists(d3d12->queue.handle, 1, &d3d12->queue.cmd);
|
||||
@ -229,8 +223,13 @@ static bool d3d12_gfx_alive(void *data)
|
||||
bool resize;
|
||||
unsigned width;
|
||||
unsigned height;
|
||||
|
||||
win32_check_window(&quit, &resize, &width, &height);
|
||||
return true;
|
||||
|
||||
if (width != 0 && height != 0)
|
||||
video_driver_set_size(&width, &height);
|
||||
|
||||
return !quit;
|
||||
}
|
||||
|
||||
static bool d3d12_gfx_focus(void *data)
|
||||
@ -256,10 +255,14 @@ static void d3d12_gfx_free(void *data)
|
||||
d3d12_video_t *d3d12 = (d3d12_video_t *)data;
|
||||
|
||||
Release(d3d12->frame.vbo);
|
||||
|
||||
if (d3d12->frame.tex.handle)
|
||||
Release(d3d12->frame.tex.handle);
|
||||
Release(d3d12->frame.tex.handle);
|
||||
|
||||
if (d3d12->frame.tex.upload_buffer)
|
||||
Release(d3d12->frame.tex.upload_buffer);
|
||||
Release(d3d12->frame.tex.upload_buffer);
|
||||
|
||||
Release(d3d12->menu.vbo);
|
||||
|
||||
if (d3d12->menu.tex.handle)
|
||||
Release(d3d12->menu.tex.handle);
|
||||
@ -267,6 +270,7 @@ static void d3d12_gfx_free(void *data)
|
||||
if (d3d12->menu.tex.handle)
|
||||
Release(d3d12->menu.tex.upload_buffer);
|
||||
|
||||
Release(d3d12->pipe.sampler_heap.handle);
|
||||
Release(d3d12->pipe.srv_heap.handle);
|
||||
Release(d3d12->pipe.rtv_heap.handle);
|
||||
Release(d3d12->pipe.rootSignature);
|
||||
@ -341,19 +345,22 @@ static void d3d12_set_menu_texture_frame(void *data,
|
||||
d3d12->menu.tex.desc.Width = width;
|
||||
d3d12->menu.tex.desc.Height = height;
|
||||
d3d12->menu.tex.desc.Format = rgb32 ? DXGI_FORMAT_B8G8R8A8_UNORM : DXGI_FORMAT_B4G4R4A4_UNORM;
|
||||
d3d12_create_texture(d3d12->device, &d3d12->pipe.srv_heap, 1, &d3d12->menu.tex);
|
||||
d3d12_create_texture(d3d12->device, &d3d12->pipe.srv_heap, SRV_HEAP_SLOT_MENU_TEXTURE,
|
||||
&d3d12->menu.tex);
|
||||
}
|
||||
|
||||
{
|
||||
{
|
||||
unsigned i, j;
|
||||
D3D12_RANGE read_range = {0, 0};
|
||||
uint8_t *out = NULL;
|
||||
|
||||
D3D12Map(d3d12->menu.tex.upload_buffer, 0, NULL, &out);
|
||||
D3D12Map(d3d12->menu.tex.upload_buffer, 0, &read_range, &out);
|
||||
out += d3d12->menu.tex.layout.Offset;
|
||||
|
||||
if(rgb32)
|
||||
if (rgb32)
|
||||
{
|
||||
const uint32_t *in = frame;
|
||||
|
||||
for (i = 0; i < height; i++)
|
||||
{
|
||||
memcpy(out, in, width * sizeof(*in));
|
||||
@ -364,6 +371,7 @@ static void d3d12_set_menu_texture_frame(void *data,
|
||||
else
|
||||
{
|
||||
const uint16_t *in = frame;
|
||||
|
||||
for (i = 0; i < height; i++)
|
||||
{
|
||||
for (j = 0; j < width; j++)
|
||||
@ -373,8 +381,9 @@ static void d3d12_set_menu_texture_frame(void *data,
|
||||
unsigned b = ((in[j] >> 4) & 0xF);
|
||||
unsigned a = ((in[j] >> 0) & 0xF);
|
||||
|
||||
((uint16_t*)out)[j] = (b << 0) | (g << 4) | (r << 8) |(a << 12);
|
||||
((uint16_t *)out)[j] = (b << 0) | (g << 4) | (r << 8) | (a << 12);
|
||||
}
|
||||
|
||||
in += width;
|
||||
out += d3d12->menu.tex.layout.Footprint.RowPitch;
|
||||
}
|
||||
@ -383,8 +392,23 @@ static void d3d12_set_menu_texture_frame(void *data,
|
||||
|
||||
D3D12Unmap(d3d12->menu.tex.upload_buffer, 0, NULL);
|
||||
}
|
||||
|
||||
d3d12->menu.tex.dirty = true;
|
||||
d3d12->menu.alpha = alpha;
|
||||
|
||||
{
|
||||
D3D12_RANGE read_range = {0, 0};
|
||||
d3d12_vertex_t *v;
|
||||
|
||||
D3D12Map(d3d12->menu.vbo, 0, &read_range, &v);
|
||||
v[0].color[3] = alpha;
|
||||
v[1].color[3] = alpha;
|
||||
v[2].color[3] = alpha;
|
||||
v[3].color[3] = alpha;
|
||||
D3D12Unmap(d3d12->menu.vbo, 0, NULL);
|
||||
}
|
||||
d3d12->menu.sampler = config_get_ptr()->bools.menu_linear_filter ?
|
||||
d3d12->sampler_linear : d3d12->sampler_nearest;
|
||||
}
|
||||
static void d3d12_set_menu_texture_enable(void *data,
|
||||
bool state, bool full_screen)
|
||||
@ -395,7 +419,6 @@ static void d3d12_set_menu_texture_enable(void *data,
|
||||
d3d12->menu.fullscreen = full_screen;
|
||||
}
|
||||
|
||||
|
||||
static const video_poke_interface_t d3d12_poke_interface =
|
||||
{
|
||||
NULL, /* set_coords */
|
||||
|
Loading…
x
Reference in New Issue
Block a user