(d3d10/11/12) reformat some files.

This commit is contained in:
aliaspider 2018-01-24 07:45:45 +01:00
parent cba3c5b68c
commit a6b24ce995
9 changed files with 746 additions and 481 deletions

View File

@ -19,107 +19,122 @@
static dylib_t d3d10_dll;
typedef HRESULT (WINAPI *PFN_D3D10_CREATE_DEVICE_AND_SWAP_CHAIN)(
IDXGIAdapter *pAdapter,
D3D10_DRIVER_TYPE DriverType,
HMODULE Software,
UINT Flags,
UINT SDKVersion,
DXGI_SWAP_CHAIN_DESC *pSwapChainDesc,
IDXGISwapChain **ppSwapChain,
ID3D10Device **ppDevice);
typedef HRESULT(WINAPI* PFN_D3D10_CREATE_DEVICE_AND_SWAP_CHAIN)(
IDXGIAdapter* pAdapter,
D3D10_DRIVER_TYPE DriverType,
HMODULE Software,
UINT Flags,
UINT SDKVersion,
DXGI_SWAP_CHAIN_DESC* pSwapChainDesc,
IDXGISwapChain** ppSwapChain,
ID3D10Device** ppDevice);
HRESULT WINAPI D3D10CreateDeviceAndSwapChain(
IDXGIAdapter *pAdapter,
D3D10_DRIVER_TYPE DriverType,
HMODULE Software,
UINT Flags,
UINT SDKVersion,
DXGI_SWAP_CHAIN_DESC *pSwapChainDesc,
IDXGISwapChain **ppSwapChain,
ID3D10Device **ppDevice)
IDXGIAdapter* pAdapter,
D3D10_DRIVER_TYPE DriverType,
HMODULE Software,
UINT Flags,
UINT SDKVersion,
DXGI_SWAP_CHAIN_DESC* pSwapChainDesc,
IDXGISwapChain** ppSwapChain,
ID3D10Device** ppDevice)
{
static PFN_D3D10_CREATE_DEVICE_AND_SWAP_CHAIN fp;
if(!d3d10_dll)
if (!d3d10_dll)
d3d10_dll = dylib_load("d3d10.dll");
if(!d3d10_dll)
if (!d3d10_dll)
return TYPE_E_CANTLOADLIBRARY;
if(!fp)
fp = (PFN_D3D10_CREATE_DEVICE_AND_SWAP_CHAIN)dylib_proc(d3d10_dll, "D3D10CreateDeviceAndSwapChain");
if (!fp)
fp = (PFN_D3D10_CREATE_DEVICE_AND_SWAP_CHAIN)dylib_proc(
d3d10_dll, "D3D10CreateDeviceAndSwapChain");
if(!fp)
if (!fp)
return TYPE_E_CANTLOADLIBRARY;
return fp(pAdapter,DriverType,Software, Flags, SDKVersion, pSwapChainDesc, ppSwapChain, ppDevice);
return fp(
pAdapter, DriverType, Software, Flags, SDKVersion, pSwapChainDesc, ppSwapChain, ppDevice);
}
void d3d10_init_texture(D3D10Device device, d3d10_texture_t* texture)
{
Release(texture->handle);
Release(texture->staging);
Release(texture->view);
// .Usage = D3D10_USAGE_DYNAMIC,
// .CPUAccessFlags = D3D10_CPU_ACCESS_WRITE,
// .Usage = D3D10_USAGE_DYNAMIC,
// .CPUAccessFlags = D3D10_CPU_ACCESS_WRITE,
texture->desc.MipLevels = 1;
texture->desc.ArraySize = 1;
texture->desc.SampleDesc.Count = 1;
texture->desc.MipLevels = 1;
texture->desc.ArraySize = 1;
texture->desc.SampleDesc.Count = 1;
texture->desc.SampleDesc.Quality = 0;
texture->desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
texture->desc.CPUAccessFlags = 0;
texture->desc.MiscFlags = 0;
texture->desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
texture->desc.CPUAccessFlags = 0;
texture->desc.MiscFlags = 0;
D3D10CreateTexture2D(device, &texture->desc, NULL, &texture->handle);
{
D3D10_SHADER_RESOURCE_VIEW_DESC view_desc =
{
.Format = texture->desc.Format,
.ViewDimension = D3D_SRV_DIMENSION_TEXTURE2D,
D3D10_SHADER_RESOURCE_VIEW_DESC view_desc = {
.Format = texture->desc.Format,
.ViewDimension = D3D_SRV_DIMENSION_TEXTURE2D,
.Texture2D.MostDetailedMip = 0,
.Texture2D.MipLevels = -1,
.Texture2D.MipLevels = -1,
};
D3D10CreateTexture2DShaderResourceView(device, texture->handle, &view_desc, &texture->view);
}
{
D3D10_TEXTURE2D_DESC desc = texture->desc;
desc.BindFlags = 0;
desc.Usage = D3D10_USAGE_STAGING;
desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
desc.BindFlags = 0;
desc.Usage = D3D10_USAGE_STAGING;
desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
D3D10CreateTexture2D(device, &desc, NULL, &texture->staging);
}
}
void d3d10_update_texture(int width, int height, int pitch, DXGI_FORMAT format, const void* data, d3d10_texture_t* texture)
#include <gfx/scaler/pixconv.h>
void d3d10_update_texture(
int width,
int height,
int pitch,
DXGI_FORMAT format,
const void* data,
d3d10_texture_t* texture)
{
D3D10_MAPPED_TEXTURE2D mapped_texture;
D3D10MapTexture2D(texture->staging, 0, D3D10_MAP_WRITE, 0, &mapped_texture);
dxgi_copy(width, height, format, pitch, data, texture->desc.Format, mapped_texture.RowPitch, mapped_texture.pData);
#if 0
PERF_START();
conv_rgb565_argb8888(mapped_texture.pData, data, width, height, mapped_texture.RowPitch, pitch);
PERF_STOP();
#else
dxgi_copy(
width, height, format, pitch, data, texture->desc.Format, mapped_texture.RowPitch,
mapped_texture.pData);
#endif
D3D10UnmapTexture2D(texture->staging, 0);
if(texture->desc.Usage == D3D10_USAGE_DEFAULT)
if (texture->desc.Usage == D3D10_USAGE_DEFAULT)
texture->dirty = true;
}
DXGI_FORMAT d3d10_get_closest_match(D3D10Device device, DXGI_FORMAT desired_format, UINT desired_format_support)
DXGI_FORMAT
d3d10_get_closest_match(D3D10Device device, DXGI_FORMAT desired_format, UINT desired_format_support)
{
DXGI_FORMAT* format = dxgi_get_format_fallback_list(desired_format);
UINT format_support;
UINT format_support;
while(*format != DXGI_FORMAT_UNKNOWN)
while (*format != DXGI_FORMAT_UNKNOWN)
{
if(SUCCEEDED(D3D10CheckFormatSupport(device, *format, &format_support))
&& ((format_support & desired_format_support) == desired_format_support))
if (SUCCEEDED(D3D10CheckFormatSupport(device, *format, &format_support)) &&
((format_support & desired_format_support) == desired_format_support))
break;
format++;
}

View File

@ -19,27 +19,38 @@
static dylib_t d3d11_dll;
HRESULT WINAPI D3D11CreateDeviceAndSwapChain( IDXGIAdapter* pAdapter,D3D_DRIVER_TYPE DriverType, HMODULE Software, UINT Flags,
CONST D3D_FEATURE_LEVEL* pFeatureLevels, UINT FeatureLevels, UINT SDKVersion, CONST DXGI_SWAP_CHAIN_DESC* pSwapChainDesc,
IDXGISwapChain** ppSwapChain, ID3D11Device** ppDevice, D3D_FEATURE_LEVEL* pFeatureLevel, ID3D11DeviceContext** ppImmediateContext)
HRESULT WINAPI D3D11CreateDeviceAndSwapChain(
IDXGIAdapter* pAdapter,
D3D_DRIVER_TYPE DriverType,
HMODULE Software,
UINT Flags,
CONST D3D_FEATURE_LEVEL* pFeatureLevels,
UINT FeatureLevels,
UINT SDKVersion,
CONST DXGI_SWAP_CHAIN_DESC* pSwapChainDesc,
IDXGISwapChain** ppSwapChain,
ID3D11Device** ppDevice,
D3D_FEATURE_LEVEL* pFeatureLevel,
ID3D11DeviceContext** ppImmediateContext)
{
static PFN_D3D11_CREATE_DEVICE_AND_SWAP_CHAIN fp;
if(!d3d11_dll)
if (!d3d11_dll)
d3d11_dll = dylib_load("d3d11.dll");
if(!d3d11_dll)
if (!d3d11_dll)
return TYPE_E_CANTLOADLIBRARY;
if(!fp)
fp = (PFN_D3D11_CREATE_DEVICE_AND_SWAP_CHAIN)dylib_proc(d3d11_dll, "D3D11CreateDeviceAndSwapChain");
if (!fp)
fp = (PFN_D3D11_CREATE_DEVICE_AND_SWAP_CHAIN)dylib_proc(
d3d11_dll, "D3D11CreateDeviceAndSwapChain");
if(!fp)
if (!fp)
return TYPE_E_CANTLOADLIBRARY;
return fp(pAdapter,DriverType,Software, Flags,pFeatureLevels, FeatureLevels, SDKVersion, pSwapChainDesc,
ppSwapChain, ppDevice, pFeatureLevel, ppImmediateContext);
return fp(
pAdapter, DriverType, Software, Flags, pFeatureLevels, FeatureLevels, SDKVersion,
pSwapChainDesc, ppSwapChain, ppDevice, pFeatureLevel, ppImmediateContext);
}
void d3d11_init_texture(D3D11Device device, d3d11_texture_t* texture)
@ -48,61 +59,69 @@ void d3d11_init_texture(D3D11Device device, d3d11_texture_t* texture)
Release(texture->staging);
Release(texture->view);
// .Usage = D3D11_USAGE_DYNAMIC,
// .CPUAccessFlags = D3D11_CPU_ACCESS_WRITE,
// .Usage = D3D11_USAGE_DYNAMIC,
// .CPUAccessFlags = D3D11_CPU_ACCESS_WRITE,
texture->desc.MipLevels = 1;
texture->desc.ArraySize = 1;
texture->desc.SampleDesc.Count = 1;
texture->desc.MipLevels = 1;
texture->desc.ArraySize = 1;
texture->desc.SampleDesc.Count = 1;
texture->desc.SampleDesc.Quality = 0;
texture->desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
texture->desc.CPUAccessFlags = 0;
texture->desc.MiscFlags = 0;
texture->desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
texture->desc.CPUAccessFlags = 0;
texture->desc.MiscFlags = 0;
D3D11CreateTexture2D(device, &texture->desc, NULL, &texture->handle);
{
D3D11_SHADER_RESOURCE_VIEW_DESC view_desc =
{
.Format = texture->desc.Format,
.ViewDimension = D3D_SRV_DIMENSION_TEXTURE2D,
D3D11_SHADER_RESOURCE_VIEW_DESC view_desc = {
.Format = texture->desc.Format,
.ViewDimension = D3D_SRV_DIMENSION_TEXTURE2D,
.Texture2D.MostDetailedMip = 0,
.Texture2D.MipLevels = -1,
.Texture2D.MipLevels = -1,
};
D3D11CreateTexture2DShaderResourceView(device, texture->handle, &view_desc, &texture->view);
}
{
D3D11_TEXTURE2D_DESC desc = texture->desc;
desc.BindFlags = 0;
desc.Usage = D3D11_USAGE_STAGING;
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
desc.BindFlags = 0;
desc.Usage = D3D11_USAGE_STAGING;
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
D3D11CreateTexture2D(device, &desc, NULL, &texture->staging);
}
}
void d3d11_update_texture(D3D11DeviceContext ctx, int width, int height, int pitch, DXGI_FORMAT format, const void* data, d3d11_texture_t* texture)
void d3d11_update_texture(
D3D11DeviceContext ctx,
int width,
int height,
int pitch,
DXGI_FORMAT format,
const void* data,
d3d11_texture_t* texture)
{
D3D11_MAPPED_SUBRESOURCE mapped_texture;
D3D11MapTexture2D(ctx, texture->staging, 0, D3D11_MAP_WRITE, 0, &mapped_texture);
dxgi_copy(width, height, format, pitch, data, texture->desc.Format, mapped_texture.RowPitch, mapped_texture.pData);
dxgi_copy(
width, height, format, pitch, data, texture->desc.Format, mapped_texture.RowPitch,
mapped_texture.pData);
D3D11UnmapTexture2D(ctx, texture->staging, 0);
if(texture->desc.Usage == D3D11_USAGE_DEFAULT)
if (texture->desc.Usage == D3D11_USAGE_DEFAULT)
texture->dirty = true;
}
DXGI_FORMAT d3d11_get_closest_match(D3D11Device device, DXGI_FORMAT desired_format, UINT desired_format_support)
DXGI_FORMAT
d3d11_get_closest_match(D3D11Device device, DXGI_FORMAT desired_format, UINT desired_format_support)
{
DXGI_FORMAT* format = dxgi_get_format_fallback_list(desired_format);
UINT format_support;
while(*format != DXGI_FORMAT_UNKNOWN)
UINT format_support;
while (*format != DXGI_FORMAT_UNKNOWN)
{
if(SUCCEEDED(D3D11CheckFormatSupport(device, *format, &format_support))
&& ((format_support & desired_format_support) == desired_format_support))
if (SUCCEEDED(D3D11CheckFormatSupport(device, *format, &format_support)) &&
((format_support & desired_format_support) == desired_format_support))
break;
format++;
}

View File

@ -22,6 +22,7 @@
#include "verbosity.h"
#ifdef __MINGW32__
/* clang-format off */
#define DEFINE_GUIDW(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) const GUID DECLSPEC_SELECTANY name = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } }
DEFINE_GUIDW(IID_ID3D12PipelineState, 0x765a30f3, 0xf624, 0x4c6f, 0xa8, 0x28, 0xac, 0xe9, 0x48, 0x62, 0x24, 0x45);
@ -51,13 +52,14 @@ DEFINE_GUIDW(IID_ID3D12DebugDevice, 0x3febd6dd, 0x4973, 0x4787, 0x81, 0x94, 0xe4
DEFINE_GUIDW(IID_ID3D12DebugCommandQueue, 0x09e0bf36, 0x54ac, 0x484f, 0x88, 0x47, 0x4b, 0xae, 0xea, 0xb6, 0x05, 0x3a);
DEFINE_GUIDW(IID_ID3D12DebugCommandList1, 0x102ca951, 0x311b, 0x4b01, 0xb1, 0x1f, 0xec, 0xb8, 0x3e, 0x06, 0x1b, 0x37);
DEFINE_GUIDW(IID_ID3D12DebugCommandList, 0x09e0bf36, 0x54ac, 0x484f, 0x88, 0x47, 0x4b, 0xae, 0xea, 0xb6, 0x05, 0x3f);
/* clang-format on */
#endif
static dylib_t d3d12_dll;
static const char *d3d12_dll_name = "d3d12.dll";
static const char* d3d12_dll_name = "d3d12.dll";
HRESULT WINAPI D3D12CreateDevice(
IUnknown *pAdapter, D3D_FEATURE_LEVEL MinimumFeatureLevel, REFIID riid, void **ppDevice)
IUnknown* pAdapter, D3D_FEATURE_LEVEL MinimumFeatureLevel, REFIID riid, void** ppDevice)
{
if (!d3d12_dll)
d3d12_dll = dylib_load(d3d12_dll_name);
@ -76,7 +78,7 @@ HRESULT WINAPI D3D12CreateDevice(
return TYPE_E_CANTLOADLIBRARY;
}
HRESULT WINAPI D3D12GetDebugInterface(REFIID riid, void **ppvDebug)
HRESULT WINAPI D3D12GetDebugInterface(REFIID riid, void** ppvDebug)
{
if (!d3d12_dll)
d3d12_dll = dylib_load(d3d12_dll_name);
@ -95,10 +97,11 @@ HRESULT WINAPI D3D12GetDebugInterface(REFIID riid, void **ppvDebug)
return TYPE_E_CANTLOADLIBRARY;
}
HRESULT WINAPI D3D12SerializeRootSignature(const D3D12_ROOT_SIGNATURE_DESC *pRootSignature,
D3D_ROOT_SIGNATURE_VERSION Version,
ID3DBlob ** ppBlob,
ID3DBlob ** ppErrorBlob)
HRESULT WINAPI D3D12SerializeRootSignature(
const D3D12_ROOT_SIGNATURE_DESC* pRootSignature,
D3D_ROOT_SIGNATURE_VERSION Version,
ID3DBlob** ppBlob,
ID3DBlob** ppErrorBlob)
{
if (!d3d12_dll)
d3d12_dll = dylib_load(d3d12_dll_name);
@ -119,9 +122,9 @@ HRESULT WINAPI D3D12SerializeRootSignature(const D3D12_ROOT_SIGNATURE_DESC *pRoo
}
HRESULT WINAPI D3D12SerializeVersionedRootSignature(
const D3D12_VERSIONED_ROOT_SIGNATURE_DESC *pRootSignature,
ID3DBlob ** ppBlob,
ID3DBlob ** ppErrorBlob)
const D3D12_VERSIONED_ROOT_SIGNATURE_DESC* pRootSignature,
ID3DBlob** ppBlob,
ID3DBlob** ppErrorBlob)
{
if (!d3d12_dll)
d3d12_dll = dylib_load(d3d12_dll_name);
@ -143,7 +146,7 @@ HRESULT WINAPI D3D12SerializeVersionedRootSignature(
#include <wiiu/wiiu_dbg.h>
bool d3d12_init_base(d3d12_video_t *d3d12)
bool d3d12_init_base(d3d12_video_t* d3d12)
{
#ifdef DEBUG
@ -171,21 +174,23 @@ bool d3d12_init_base(d3d12_video_t *d3d12)
return true;
}
bool d3d12_init_queue(d3d12_video_t *d3d12)
bool d3d12_init_queue(d3d12_video_t* d3d12)
{
{
static const D3D12_COMMAND_QUEUE_DESC desc = {
.Type = D3D12_COMMAND_LIST_TYPE_DIRECT,
.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE,
};
D3D12CreateCommandQueue(d3d12->device, (D3D12_COMMAND_QUEUE_DESC*)&desc, &d3d12->queue.handle);
D3D12CreateCommandQueue(
d3d12->device, (D3D12_COMMAND_QUEUE_DESC*)&desc, &d3d12->queue.handle);
}
D3D12CreateCommandAllocator(
d3d12->device, D3D12_COMMAND_LIST_TYPE_DIRECT, &d3d12->queue.allocator);
D3D12CreateGraphicsCommandList(d3d12->device, 0, D3D12_COMMAND_LIST_TYPE_DIRECT,
d3d12->queue.allocator, d3d12->pipe.handle, &d3d12->queue.cmd);
D3D12CreateGraphicsCommandList(
d3d12->device, 0, D3D12_COMMAND_LIST_TYPE_DIRECT, d3d12->queue.allocator,
d3d12->pipe.handle, &d3d12->queue.cmd);
D3D12CloseGraphicsCommandList(d3d12->queue.cmd);
@ -196,7 +201,7 @@ bool d3d12_init_queue(d3d12_video_t *d3d12)
return true;
}
bool d3d12_init_swapchain(d3d12_video_t *d3d12, int width, int height, HWND hwnd)
bool d3d12_init_swapchain(d3d12_video_t* d3d12, int width, int height, HWND hwnd)
{
{
DXGI_SWAP_CHAIN_DESC desc = {
@ -243,7 +248,7 @@ bool d3d12_init_swapchain(d3d12_video_t *d3d12, int width, int height, HWND hwnd
return true;
}
static void d3d12_init_descriptor_heap(D3D12Device device, d3d12_descriptor_heap_t *out)
static void d3d12_init_descriptor_heap(D3D12Device device, d3d12_descriptor_heap_t* out)
{
D3D12CreateDescriptorHeap(device, &out->desc, &out->handle);
out->cpu = D3D12GetCPUDescriptorHandleForHeapStart(out->handle);
@ -251,12 +256,13 @@ 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)
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,
@ -275,7 +281,7 @@ static void d3d12_init_sampler(D3D12Device device,
dst->ptr = heap->gpu.ptr + heap_index * heap->stride;
}
bool d3d12_init_descriptors(d3d12_video_t *d3d12)
bool d3d12_init_descriptors(d3d12_video_t* d3d12)
{
static const D3D12_DESCRIPTOR_RANGE srv_table[] = {
{
@ -324,14 +330,16 @@ bool d3d12_init_descriptors(d3d12_video_t *d3d12)
if (error)
{
RARCH_ERR("[D3D12]: CreateRootSignature failed :\n%s\n",
(const char *)D3DGetBufferPointer(error));
RARCH_ERR(
"[D3D12]: CreateRootSignature failed :\n%s\n",
(const char*)D3DGetBufferPointer(error));
Release(error);
return false;
}
D3D12CreateRootSignature(d3d12->device, 0, D3DGetBufferPointer(signature),
D3DGetBufferSize(signature), &d3d12->pipe.rootSignature);
D3D12CreateRootSignature(
d3d12->device, 0, D3DGetBufferPointer(signature), D3DGetBufferSize(signature),
&d3d12->pipe.rootSignature);
Release(signature);
}
@ -350,16 +358,18 @@ bool d3d12_init_descriptors(d3d12_video_t *d3d12)
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_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_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;
}
bool d3d12_init_pipeline(d3d12_video_t *d3d12)
bool d3d12_init_pipeline(d3d12_video_t* d3d12)
{
D3DBlob vs_code;
D3DBlob ps_code;
@ -370,11 +380,11 @@ bool d3d12_init_pipeline(d3d12_video_t *d3d12)
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 },
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 },
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 },
D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 },
};
static const D3D12_RASTERIZER_DESC rasterizerDesc = {
@ -445,7 +455,7 @@ bool d3d12_init_pipeline(d3d12_video_t *d3d12)
}
void d3d12_create_vertex_buffer(
D3D12Device device, D3D12_VERTEX_BUFFER_VIEW *view, D3D12Resource *vbo)
D3D12Device device, D3D12_VERTEX_BUFFER_VIEW* view, D3D12Resource* vbo)
{
static const D3D12_HEAP_PROPERTIES heap_props = {
.Type = D3D12_HEAP_TYPE_UPLOAD,
@ -463,17 +473,17 @@ void d3d12_create_vertex_buffer(
.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR,
};
D3D12CreateCommittedResource(device,
(D3D12_HEAP_PROPERTIES*)&heap_props,
D3D12_HEAP_FLAG_NONE, &resource_desc,
D3D12CreateCommittedResource(
device, (D3D12_HEAP_PROPERTIES*)&heap_props, D3D12_HEAP_FLAG_NONE, &resource_desc,
D3D12_RESOURCE_STATE_GENERIC_READ, NULL, vbo);
view->BufferLocation = D3D12GetGPUVirtualAddress(*vbo);
}
void d3d12_init_texture(D3D12Device device,
d3d12_descriptor_heap_t * heap,
descriptor_heap_slot_t heap_index,
d3d12_texture_t * texture)
void d3d12_init_texture(
D3D12Device device,
d3d12_descriptor_heap_t* heap,
descriptor_heap_slot_t heap_index,
d3d12_texture_t* texture)
{
Release(texture->handle);
Release(texture->upload_buffer);
@ -485,11 +495,13 @@ void d3d12_init_texture(D3D12Device device,
texture->desc.SampleDesc.Count = 1;
D3D12_HEAP_PROPERTIES heap_props = { D3D12_HEAP_TYPE_DEFAULT, 0, 0, 1, 1 };
D3D12CreateCommittedResource(device, &heap_props, D3D12_HEAP_FLAG_NONE, &texture->desc,
D3D12CreateCommittedResource(
device, &heap_props, D3D12_HEAP_FLAG_NONE, &texture->desc,
D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE, NULL, &texture->handle);
}
D3D12GetCopyableFootprints(device, &texture->desc, 0, 1, 0, &texture->layout, &texture->num_rows,
D3D12GetCopyableFootprints(
device, &texture->desc, 0, 1, 0, &texture->layout, &texture->num_rows,
&texture->row_size_in_bytes, &texture->total_bytes);
{
@ -504,7 +516,8 @@ void d3d12_init_texture(D3D12Device device,
};
D3D12_HEAP_PROPERTIES heap_props = { D3D12_HEAP_TYPE_UPLOAD, 0, 0, 1, 1 };
D3D12CreateCommittedResource(device, &heap_props, D3D12_HEAP_FLAG_NONE, &buffer_desc,
D3D12CreateCommittedResource(
device, &heap_props, D3D12_HEAP_FLAG_NONE, &buffer_desc,
D3D12_RESOURCE_STATE_GENERIC_READ, NULL, &texture->upload_buffer);
}
@ -521,7 +534,7 @@ void d3d12_init_texture(D3D12Device device,
}
}
void d3d12_upload_texture(D3D12GraphicsCommandList cmd, d3d12_texture_t *texture)
void d3d12_upload_texture(D3D12GraphicsCommandList cmd, d3d12_texture_t* texture)
{
D3D12_TEXTURE_COPY_LOCATION src = {
.pResource = texture->upload_buffer,
@ -535,19 +548,21 @@ void d3d12_upload_texture(D3D12GraphicsCommandList cmd, d3d12_texture_t *texture
.SubresourceIndex = 0,
};
d3d12_resource_transition(cmd, texture->handle, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE,
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_resource_transition(cmd, texture->handle, D3D12_RESOURCE_STATE_COPY_DEST,
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)
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 } },
@ -561,7 +576,7 @@ void d3d12_create_fullscreen_quad_vbo(
d3d12_create_vertex_buffer(device, view, vbo);
{
void * vertex_data_begin;
void* vertex_data_begin;
D3D12_RANGE read_range = { 0, 0 };
D3D12Map(*vbo, 0, &read_range, &vertex_data_begin);
@ -573,14 +588,14 @@ void d3d12_create_fullscreen_quad_vbo(
DXGI_FORMAT d3d12_get_closest_match(
D3D12Device device, DXGI_FORMAT desired_format, D3D12_FORMAT_SUPPORT1 desired_format_support)
{
DXGI_FORMAT *format = dxgi_get_format_fallback_list(desired_format);
DXGI_FORMAT* format = dxgi_get_format_fallback_list(desired_format);
UINT format_support;
while (*format != DXGI_FORMAT_UNKNOWN)
{
D3D12_FEATURE_DATA_FORMAT_SUPPORT format_support = { *format };
if (SUCCEEDED(D3D12CheckFeatureSupport(
device, D3D12_FEATURE_FORMAT_SUPPORT, &format_support, sizeof(format_support))) &&
((format_support.Support1 & desired_format_support) == desired_format_support))
((format_support.Support1 & desired_format_support) == desired_format_support))
break;
format++;
}

File diff suppressed because it is too large Load Diff

View File

@ -19,32 +19,27 @@
#include "gfx/common/d3dcompiler_common.h"
#include "verbosity.h"
HRESULT WINAPI
D3DCompile(LPCVOID pSrcData, SIZE_T SrcDataSize, LPCSTR pSourceName,
CONST D3D_SHADER_MACRO *pDefines, ID3DInclude *pInclude, LPCSTR pEntrypoint,
LPCSTR pTarget, UINT Flags1, UINT Flags2, ID3DBlob **ppCode, ID3DBlob **ppErrorMsgs)
HRESULT WINAPI D3DCompile(
LPCVOID pSrcData,
SIZE_T SrcDataSize,
LPCSTR pSourceName,
CONST D3D_SHADER_MACRO* pDefines,
ID3DInclude* pInclude,
LPCSTR pEntrypoint,
LPCSTR pTarget,
UINT Flags1,
UINT Flags2,
ID3DBlob** ppCode,
ID3DBlob** ppErrorMsgs)
{
static dylib_t d3dcompiler_dll;
static const char *dll_list[] =
{
"D3DCompiler_47.dll",
"D3DCompiler_46.dll",
"D3DCompiler_45.dll",
"D3DCompiler_44.dll",
"D3DCompiler_43.dll",
"D3DCompiler_42.dll",
"D3DCompiler_41.dll",
"D3DCompiler_40.dll",
"D3DCompiler_39.dll",
"D3DCompiler_38.dll",
"D3DCompiler_37.dll",
"D3DCompiler_36.dll",
"D3DCompiler_35.dll",
"D3DCompiler_34.dll",
"D3DCompiler_33.dll",
NULL,
static dylib_t d3dcompiler_dll;
static const char* dll_list[] = {
"D3DCompiler_47.dll", "D3DCompiler_46.dll", "D3DCompiler_45.dll", "D3DCompiler_44.dll",
"D3DCompiler_43.dll", "D3DCompiler_42.dll", "D3DCompiler_41.dll", "D3DCompiler_40.dll",
"D3DCompiler_39.dll", "D3DCompiler_38.dll", "D3DCompiler_37.dll", "D3DCompiler_36.dll",
"D3DCompiler_35.dll", "D3DCompiler_34.dll", "D3DCompiler_33.dll", NULL,
};
const char **dll_name = dll_list;
const char** dll_name = dll_list;
while (!d3dcompiler_dll && *dll_name)
d3dcompiler_dll = dylib_load(*dll_name++);
@ -57,29 +52,30 @@ D3DCompile(LPCVOID pSrcData, SIZE_T SrcDataSize, LPCSTR pSourceName,
fp = (pD3DCompile)dylib_proc(d3dcompiler_dll, "D3DCompile");
if (fp)
return fp(pSrcData, SrcDataSize, pSourceName, pDefines, pInclude, pEntrypoint, pTarget, Flags1,
Flags2, ppCode, ppErrorMsgs);
return fp(
pSrcData, SrcDataSize, pSourceName, pDefines, pInclude, pEntrypoint, pTarget, Flags1,
Flags2, ppCode, ppErrorMsgs);
}
return TYPE_E_CANTLOADLIBRARY;
}
bool d3d_compile(const char *src, size_t size, LPCSTR entrypoint, LPCSTR target, D3DBlob *out)
bool d3d_compile(const char* src, size_t size, LPCSTR entrypoint, LPCSTR target, D3DBlob* out)
{
D3DBlob error_msg;
UINT compileflags = 0;
UINT compileflags = 0;
#ifdef DEBUG
compileflags |= D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION;
#endif
if(FAILED(D3DCompile(src, size, NULL, NULL, NULL, entrypoint, target, compileflags, 0, out, &error_msg)))
if (FAILED(D3DCompile(
src, size, NULL, NULL, NULL, entrypoint, target, compileflags, 0, out, &error_msg)))
return false;
if (error_msg)
{
RARCH_ERR("D3DCompile failed :\n%s\n", (const char *)D3DGetBufferPointer(error_msg));
RARCH_ERR("D3DCompile failed :\n%s\n", (const char*)D3DGetBufferPointer(error_msg));
Release(error_msg);
return false;
}

View File

@ -29,11 +29,11 @@
#include <d3dcompiler.h>
#ifndef countof
#define countof(a) (sizeof(a)/ sizeof(*a))
#define countof(a) (sizeof(a) / sizeof(*a))
#endif
#ifndef __uuidof
#define __uuidof(type) &IID_##type
#define __uuidof(type) & IID_##type
#endif
#ifndef COM_RELEASE_DECLARED
@ -41,12 +41,16 @@
#if defined(__cplusplus) && !defined(CINTERFACE)
static inline ULONG Release(IUnknown* object)
{
return object->Release();
if (object)
return object->Release();
return 0;
}
#else
static inline ULONG Release(void* object)
{
return ((IUnknown*)object)->lpVtbl->Release(object);
if (object)
return ((IUnknown*)object)->lpVtbl->Release(object);
return 0;
}
#endif
#endif
@ -56,33 +60,32 @@ static inline ULONG Release(void* object)
typedef ID3DBlob* D3DBlob;
typedef ID3DDestructionNotifier* D3DDestructionNotifier;
static inline ULONG D3DReleaseBlob(D3DBlob blob)
{
return blob->lpVtbl->Release(blob);
}
static inline ULONG D3DReleaseBlob(D3DBlob blob) { return blob->lpVtbl->Release(blob); }
static inline LPVOID D3DGetBufferPointer(D3DBlob blob)
{
return blob->lpVtbl->GetBufferPointer(blob);
}
static inline SIZE_T D3DGetBufferSize(D3DBlob blob)
{
return blob->lpVtbl->GetBufferSize(blob);
}
static inline ULONG D3DReleaseDestructionNotifier(D3DDestructionNotifier destruction_notifier)
static inline SIZE_T D3DGetBufferSize(D3DBlob blob) { return blob->lpVtbl->GetBufferSize(blob); }
static inline ULONG D3DReleaseDestructionNotifier(D3DDestructionNotifier destruction_notifier)
{
return destruction_notifier->lpVtbl->Release(destruction_notifier);
}
static inline HRESULT D3DRegisterDestructionCallback(D3DDestructionNotifier destruction_notifier, PFN_DESTRUCTION_CALLBACK callback_fn, void* data, UINT* callback_id)
static inline HRESULT D3DRegisterDestructionCallback(
D3DDestructionNotifier destruction_notifier,
PFN_DESTRUCTION_CALLBACK callback_fn,
void* data,
UINT* callback_id)
{
return destruction_notifier->lpVtbl->RegisterDestructionCallback(destruction_notifier, callback_fn, data, callback_id);
return destruction_notifier->lpVtbl->RegisterDestructionCallback(
destruction_notifier, callback_fn, data, callback_id);
}
static inline HRESULT D3DUnregisterDestructionCallback(D3DDestructionNotifier destruction_notifier, UINT callback_id)
static inline HRESULT
D3DUnregisterDestructionCallback(D3DDestructionNotifier destruction_notifier, UINT callback_id)
{
return destruction_notifier->lpVtbl->UnregisterDestructionCallback(destruction_notifier, callback_id);
return destruction_notifier->lpVtbl->UnregisterDestructionCallback(
destruction_notifier, callback_id);
}
/* end of auto-generated */
bool d3d_compile(const char* src, size_t size, LPCSTR entrypoint, LPCSTR target, D3DBlob* out);

View File

@ -18,10 +18,10 @@
#include "dxgi_common.h"
HRESULT WINAPI CreateDXGIFactory1(REFIID riid, void **ppFactory)
HRESULT WINAPI CreateDXGIFactory1(REFIID riid, void** ppFactory)
{
static dylib_t dxgi_dll;
static HRESULT(WINAPI * fp)(REFIID, void **);
static HRESULT(WINAPI * fp)(REFIID, void**);
if (!dxgi_dll)
dxgi_dll = dylib_load("dxgi.dll");
@ -30,7 +30,7 @@ HRESULT WINAPI CreateDXGIFactory1(REFIID riid, void **ppFactory)
return TYPE_E_CANTLOADLIBRARY;
if (!fp)
fp = (HRESULT(WINAPI *)(REFIID, void **))dylib_proc(dxgi_dll, "CreateDXGIFactory1");
fp = (HRESULT(WINAPI*)(REFIID, void**))dylib_proc(dxgi_dll, "CreateDXGIFactory1");
if (!fp)
return TYPE_E_CANTLOADLIBRARY;
@ -38,7 +38,7 @@ HRESULT WINAPI CreateDXGIFactory1(REFIID riid, void **ppFactory)
return fp(riid, ppFactory);
}
DXGI_FORMAT *dxgi_get_format_fallback_list(DXGI_FORMAT format)
DXGI_FORMAT* dxgi_get_format_fallback_list(DXGI_FORMAT format)
{
static DXGI_FORMAT format_unknown = DXGI_FORMAT_UNKNOWN;
@ -92,8 +92,8 @@ DXGI_FORMAT *dxgi_get_format_fallback_list(DXGI_FORMAT format)
((src_bs == dst_bs && src_bb == dst_bb) || !dst_bb) && \
((src_as == dst_as && src_ab == dst_ab) || !dst_ab)) \
{ \
const UINT8 *in = src_data; \
UINT8 * out = dst_data; \
const UINT8* in = src_data; \
UINT8* out = dst_data; \
for (i = 0; i < height; i++) \
{ \
memcpy(out, in, width * sizeof(src_type)); \
@ -103,8 +103,8 @@ DXGI_FORMAT *dxgi_get_format_fallback_list(DXGI_FORMAT format)
} \
else \
{ \
const src_type *src_ptr = (const src_type *)src_data; \
dst_type * dst_ptr = (dst_type *)dst_data; \
const src_type* src_ptr = (const src_type*)src_data; \
dst_type* dst_ptr = (dst_type*)dst_data; \
if (src_pitch) \
src_pitch -= width * sizeof(*src_ptr); \
if (dst_pitch) \
@ -151,8 +151,8 @@ DXGI_FORMAT *dxgi_get_format_fallback_list(DXGI_FORMAT format)
((src_bb ? b : 0) << dst_bs) | \
((src_ab ? a : ((1 << dst_ab) - 1)) << dst_as); \
} \
src_ptr = (src_type *)((UINT8 *)src_ptr + src_pitch); \
dst_ptr = (dst_type *)((UINT8 *)dst_ptr + dst_pitch); \
src_ptr = (src_type*)((UINT8*)src_ptr + src_pitch); \
dst_ptr = (dst_type*)((UINT8*)dst_ptr + dst_pitch); \
} \
} \
} while (0)
@ -179,7 +179,8 @@ DXGI_FORMAT *dxgi_get_format_fallback_list(DXGI_FORMAT format)
break; \
}
/* r, g, b, a r, g, b, a */
/* clang-format off */
/* r, g, b, a, r, g, b, a */
#define DXGI_FORMAT_R8G8B8A8_UNORM_DESCS UINT32, 8, 8, 8, 8, 0, 8, 16, 24
#define DXGI_FORMAT_B8G8R8X8_UNORM_DESCS UINT32, 8, 8, 8, 0, 16, 8, 0, 0
#define DXGI_FORMAT_B8G8R8A8_UNORM_DESCS UINT32, 8, 8, 8, 8, 16, 8, 0, 24
@ -205,6 +206,7 @@ DXGI_FORMAT *dxgi_get_format_fallback_list(DXGI_FORMAT format)
FORMAT_DST(srcfmt, DXGI_FORMAT_B4G4R4A4_UNORM); \
FORMAT_DST(srcfmt, DXGI_FORMAT_B8G8R8A8_UNORM); \
FORMAT_DST(srcfmt, DXGI_FORMAT_EX_A4R4G4B4_UNORM)
/* clang-format on */
#ifdef _MSC_VER
#pragma warning(disable : 4293)
@ -214,10 +216,10 @@ void dxgi_copy(
int height,
DXGI_FORMAT src_format,
int src_pitch,
const void *src_data,
const void* src_data,
DXGI_FORMAT dst_format,
int dst_pitch,
void * dst_data)
void* dst_data)
{
int i, j;
#if defined(PERF_START) && defined(PERF_STOP)

View File

@ -227,7 +227,8 @@ static bool d3d10_gfx_frame(
DXGIResizeBuffers(d3d10->swapChain, 0, 0, 0, 0, 0);
DXGIGetSwapChainBufferD3D10(d3d10->swapChain, 0, &backBuffer);
D3D10CreateTexture2DRenderTargetView(d3d10->device, backBuffer, NULL, &d3d10->renderTargetView);
D3D10CreateTexture2DRenderTargetView(
d3d10->device, backBuffer, NULL, &d3d10->renderTargetView);
Release(backBuffer);
D3D10SetRenderTargets(d3d10->device, 1, &d3d10->renderTargetView, NULL);
@ -236,7 +237,6 @@ static bool d3d10_gfx_frame(
d3d10->need_resize = false;
}
PERF_START();
D3D10ClearRenderTargetView(d3d10->device, d3d10->renderTargetView, d3d10->clearcolor);

View File

@ -240,7 +240,8 @@ static bool d3d11_gfx_frame(
DXGIResizeBuffers(d3d11->swapChain, 0, 0, 0, 0, 0);
DXGIGetSwapChainBufferD3D11(d3d11->swapChain, 0, &backBuffer);
D3D11CreateTexture2DRenderTargetView(d3d11->device, backBuffer, NULL, &d3d11->renderTargetView);
D3D11CreateTexture2DRenderTargetView(
d3d11->device, backBuffer, NULL, &d3d11->renderTargetView);
Release(backBuffer);
D3D11SetRenderTargets(d3d11->ctx, 1, &d3d11->renderTargetView, NULL);