Merge pull request #6148 from aliaspider/master

(D3D11/D3D12) initial video driver implementation.
This commit is contained in:
Twinaphex 2018-01-21 04:59:18 +01:00 committed by GitHub
commit ffff5df787
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 5940 additions and 8 deletions

View File

@ -1289,6 +1289,32 @@ endif
endif
endif
ifeq ($(HAVE_D3D11), 1)
OBJ += gfx/drivers/d3d11.o gfx/common/d3d11_common.o
DEFINES += -DHAVE_D3D11
# LIBS += -ld3d11
WANT_DXGI = 1
WANT_D3DCOMPILER = 1
endif
ifeq ($(HAVE_D3D12), 1)
OBJ += gfx/drivers/d3d12.o gfx/common/d3d12_common.o
DEFINES += -DHAVE_D3D12
# LIBS += -ld3d12
WANT_DXGI = 1
WANT_D3DCOMPILER = 1
endif
ifeq ($(WANT_D3DCOMPILER), 1)
OBJ += gfx/common/d3dcompiler_common.o
# LIBS += -ld3dcompiler
endif
ifeq ($(WANT_DXGI), 1)
OBJ += gfx/common/dxgi_common.o
# LIBS += -ldxgi
endif
ifeq ($(HAVE_D3D8), 1)
HAVE_D3D_COMMON = 1
HAVE_DX_COMMON = 1

271
Makefile.msvc Normal file
View File

@ -0,0 +1,271 @@
TARGET := retroarch.exe
DEBUG = 0
GRIFFIN_BUILD = 0
OS = Win32
ARCH = amd64
#TARGET_ARCH = x86
BUILD_DIR = objs/msvc
HAVE_D3DX := 1
HAVE_D3D8 := 0
HAVE_D3D9 := 1
HAVE_D3D11 := 1
HAVE_D3D12 := 1
HAVE_CG := 1
HAVE_OPENGL := 1
HAVE_RPNG := 1
HAVE_ZLIB := 1
WANT_ZLIB := 1
HAVE_RGUI := 1
HAVE_XMB := 1
HAVE_MATERIALUI := 1
HAVE_STB_FONT := 1
HAVE_THREADS := 1
HAVE_LIBRETRODB := 1
HAVE_COMMAND := 1
HAVE_STDIN_CMD := 1
HAVE_CMD := 1
HAVE_DYLIB := 1
HAVE_DYNAMIC := 1
HAVE_DINPUT := 1
HAVE_MENU_COMMON := 1
HAVE_BUILTINZLIB := 1
HAVE_RJPEG := 1
HAVE_RBMP := 1
HAVE_RTGA := 1
HAVE_7ZIP := 1
HAVE_NETWORKING := 1
HAVE_NETWORK_CMD := 1
HAVE_OVERLAY := 1
HAVE_LANGEXTRA := 1
HAVE_CHEEVOS := 1
HAVE_KEYMAPPER := 1
ifeq ($(ARCH),x64)
ARCH := amd64
endif
ARCH2 := $(ARCH)
ifeq ($(ARCH),amd64)
ARCH2 := x64
endif
ifeq ($(TARGET_ARCH),)
TARGET_ARCH = $(ARCH)
endif
ifeq ($(TARGET_ARCH),x64)
TARGET_ARCH = amd64
endif
TARGET_ARCH2 = $(TARGET_ARCH)
ifeq ($(TARGET_ARCH2),amd64)
TARGET_ARCH2 = x64
endif
CROSS = $(ARCH)
ifeq ($(ARCH),x86)
CROSS =
endif
WindowsSdkDir = C:\Program Files (x86)\Windows Kits\10\$(NOTHING)
WindowsSDKVersion := 10.0.14393.0\$(NOTHING)
VCINSTALLDIR := C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\$(NOTHING)
INCLUDE := $(VCINSTALLDIR)include;$(VCINSTALLDIR)atlmfc\include;$(WindowsSdkDir)include\$(WindowsSDKVersion)ucrt;$(WindowsSdkDir)include\$(WindowsSDKVersion)shared;$(WindowsSdkDir)include\$(WindowsSDKVersion)um;
LIB := $(VCINSTALLDIR)LIB\$(CROSS);$(VCINSTALLDIR)atlmfc\lib\$(CROSS);$(WindowsSdkDir)lib\$(WindowsSDKVersion)ucrt\$(TARGET_ARCH2);$(WindowsSdkDir)lib\$(WindowsSDKVersion)um\$(TARGET_ARCH2);C:\Program Files (x86)\NVIDIA Corporation\Cg\lib.$(TARGET_ARCH2);C:\Program Files (x86)\Microsoft DirectX SDK (February 2010)\Lib\$(TARGET_ARCH2);
LIBPATH := $(VCINSTALLDIR)LIB\$(CROSS);$(VCINSTALLDIR)atlmfc\lib\$(CROSS);
PATH := $(shell IFS=$$'\n'; cygpath "$(VCINSTALLDIR)bin\\$(CROSS)"):$(shell IFS=$$'\n'; cygpath "$(WindowsSdkDir)\bin\\$(ARCH2)"):$(PATH)
export INCLUDE := $(INCLUDE)
export LIB := $(LIB)
export LIBPATH := $(LIBPATH)
export PATH := $(PATH)
#$(info WindowsSdkDir : $(WindowsSdkDir))
#$(info WindowsSDKVersion : $(WindowsSDKVersion))
#$(info VCINSTALLDIR : $(VCINSTALLDIR))
#$(info INCLUDE : $(INCLUDE))
#$(info LIB : $(LIB))
#$(info LIBPATH : $(LIBPATH))
#$(info PATH : $(PATH))
#$(error end)
DEFINES :=
ifeq ($(TARGET_ARCH),x64)
DEFINES += -D__x86_64__
else
#DEFINES += -D__i686__
endif
FLAGS += -nologo -MP
FLAGS += -Gm- -Zc:inline -fp:precise -Zc:forScope -GR- -Gd -Oi -volatile:iso
#FLAGS += -Zc:wchar_t -Zp16 -Z7
#FLAGS += -utf-8
#FLAGS += -source-charset:utf-8
CFLAGS += -TC
CXXFLAGS += -TP
WARNINGS += -WX -W3
WARNINGS += -wd4101 -wd4996 -wd4244 -wd4267 -wd4090 -wd4305 -wd4146 -wd4334 -wd4018
CC = cl.exe
CXX = cl.exe
LD = link.exe
RC = rc.exe
LIBS += shell32.lib user32.lib gdi32.lib comdlg32.lib winmm.lib ole32.lib
LDFLAGS += -nologo -wx -nxcompat -machine:$(TARGET_ARCH2)
ifeq ($(DEBUG),1)
FLAGS += -GS -Gy -Od -RTC1 -D_SECURE_SCL=1 -Zi
FLAGS += -MDd
LDFLAGS += -DEBUG
DEFINES += -DDEBUG -D_DEBUG
#LIBS += -ld3d9 -ld3dx9d
else
FLAGS += -GS- -Gy- -O2 -Ob2 -GF -GT -Oy -Ot -D_SECURE_SCL=0
FLAGS += -MD
#LIBS += -ld3d9 -ld3dx9
endif
ifeq ($(DEBUG),1)
BUILD_DIR := $(BUILD_DIR)-debug
endif
ifeq ($(GRIFFIN_BUILD),1)
BUILD_DIR := $(BUILD_DIR)-griffin
endif
BUILD_DIR := $(BUILD_DIR)-$(TARGET_ARCH2)
ifneq ($(V), 1)
Q := @
endif
OBJ :=
include Makefile.common
ifeq ($(GRIFFIN_BUILD), 1)
OBJ := griffin/griffin.o
DEFINES_BLACKLIST := -DHAVE_COMPRESSION
DEFINES := $(filter-out $(DEFINES_BLACKLIST),$(DEFINES))
DEFINES += -DHAVE_GRIFFIN -DUSE_MATH_DEFINES
else
DEFINES += -DJSON_STATIC
BLACKLIST :=
OBJ := $(filter-out $(BLACKLIST),$(OBJ))
endif
DEFINES += -DRARCH_INTERNAL -DHAVE_DYNAMIC
INCLUDE_DIRS += -I. -Igfx/include
#OBJ := version_git.o
OBJ := $(patsubst %rarch.o,%rarch.res,$(OBJ))
OBJ := $(addprefix $(BUILD_DIR)/,$(OBJ))
OBJ := $(OBJ:.o=.obj)
#INCDIRS := -I. -Ideps -Ideps/stb -Ideps/libz -Ideps/7zip -Ilibretro-common/include
#CFLAGS = $(FLAGS)
#CXXFLAGS = $(FLAGS)
LDFLAGS += -WX -SUBSYSTEM:WINDOWS -ENTRY:mainCRTStartup
DEFINES := $(patsubst -f%,,$(DEFINES))
LDFLAGS := $(patsubst -l%,%.lib,$(LDFLAGS))
LIBS := $(filter-out -lm,$(LIBS))
LIBS := $(patsubst -l%,%.lib,$(LIBS))
#$(info INCLUDE_DIRS : $(INCLUDE_DIRS))
#$(info DEFINES : $(DEFINES))
#$(info CFLAGS : $(CFLAGS))
#$(info CXXFLAGS : $(CXXFLAGS))
#$(info LDFLAGS : $(LDFLAGS))
#$(info LIBS : $(LIBS))
#$(info OBJ : $(OBJ))
#$(info target : $(TARGET))
#$(info flags : $(FLAGS))
#$(info INCLUDE : $(INCLUDE))
#$(info LIB : $(LIB))
#$(info LIBPATH : $(LIBPATH))
#$(error end)
$(info os : $(OS))
$(info host : $(ARCH))
$(info target : $(TARGET_ARCH))
all: $(TARGET)
%: $(BUILD_DIR)/%
cp $< $@
ifeq ($(DEBUG),1)
%.exe: $(BUILD_DIR)/%.exe
cp $< $@
cp $(BUILD_DIR)/$*.pdb $*.pbd
endif
SHELL:=$(SHELL) -o pipefail
DEPFLAGS = -showIncludes | tee $(BUILD_DIR)/$*.dtemp | sed /'Note: including file:'/d
MAKEDEPS = echo $@: $< \\ > $(BUILD_DIR)/$*.depend && \
grep 'Note: including file:' $(BUILD_DIR)/$*.dtemp \
| sed '/$(subst \,\\,$(WindowsSdkDir))/Id; /$(subst \,\\,$(VCINSTALLDIR))/Id; s/Note: including file:[ ]*//g; s/\\/\//g; s/ /\\ /g; s/.*/ & \\/g' \
>> $(BUILD_DIR)/$*.depend && \
rm -f $(BUILD_DIR)/$*.dtemp
#DEPFLAGS :=
#MAKEDEPS :=
$(BUILD_DIR)/%.obj: %.cpp
@$(if $(Q), echo CXX $<,)
@mkdir -p $(dir $@)
$(Q)$(CXX) -c -Fo:$@ $< $(FLAGS) $(CXXFLAGS) $(DEFINES) $(INCLUDE_DIRS) $(WARNINGS) $(DEPFLAGS)
@$(MAKEDEPS)
$(BUILD_DIR)/%.obj: %.c
@$(if $(Q), echo CC $<,)
@mkdir -p $(dir $@)
$(Q)$(CC) -c -Fo:$@ $< $(FLAGS) $(CFLAGS) $(DEFINES) $(INCLUDE_DIRS) $(WARNINGS) $(DEPFLAGS)
@$(MAKEDEPS)
$(BUILD_DIR)/%.res: %.rc
@$(if $(Q), echo RC $<,)
@mkdir -p $(dir $@)
$(Q)$(RC) $<
$(Q)mv $*.res $@
$(BUILD_DIR)/$(TARGET): $(OBJ) .$(TARGET).last
@$(if $(Q), echo LD $@,)
@touch .$(TARGET).last
$(Q)$(LD) $(OBJ) $(LDFLAGS) $(LIBS) -out:$(BUILD_DIR)/$(TARGET)
%.depend: ;
%.last: ;
clean:
rm -f $(OBJ) $(TARGET)
rm -f $(BUILD_DIR)/$(TARGET)
rm -f .$(TARGET).last
rm -f $(OBJ:.obj=.depend)
.PHONY: clean all
.PRECIOUS: %.depend %.last
-include $(patsubst %.obj,%.depend,$(filter %.obj,$(OBJ)))

View File

@ -132,6 +132,8 @@ enum video_driver_enum
VIDEO_CTR,
VIDEO_SWITCH,
VIDEO_D3D9,
VIDEO_D3D11,
VIDEO_D3D12,
VIDEO_VG,
VIDEO_OMAP,
VIDEO_EXYNOS,
@ -695,6 +697,10 @@ const char *config_get_default_video(void)
case VIDEO_XDK_D3D:
case VIDEO_D3D9:
return "d3d";
case VIDEO_D3D11:
return "d3d11";
case VIDEO_D3D12:
return "d3d12";
case VIDEO_PSP1:
return "psp1";
case VIDEO_VITA2D:

View File

@ -1,4 +1,4 @@
//
//
// peglib.h
//
// Copyright (c) 2015-17 Yuji Hirose. All rights reserved.
@ -2238,6 +2238,20 @@ struct AstBase : public Annotation
std::vector<std::shared_ptr<AstBase<Annotation>>> nodes;
std::shared_ptr<AstBase<Annotation>> parent;
static peg::AstBase<Annotation> empty;
AstBase<Annotation>& operator [] (const char* name)
{
for(std::shared_ptr<AstBase<Annotation>>& node : nodes)
{
if(node->name == name)
return *node;
}
return empty;
}
operator const char *()
{
return token.c_str();
}
};
template <typename T>
@ -2770,6 +2784,14 @@ private:
} // namespace peg
template<class _Elem, class _Traits, typename Annotation>
std::basic_ios<_Elem, _Traits> &operator << (std::basic_ios<_Elem, _Traits> &ios,
peg::AstBase<Annotation> &node)
{
return ios << node.token.c_str();
}
#endif
// vim: et ts=4 sw=4 cin cino={1s ff=unix

43
gfx/common/d3d11_common.c Normal file
View File

@ -0,0 +1,43 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2014-2018 - Ali Bouhlel
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "d3d11_common.h"
#include <dynamic/dylib.h>
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)
{
static PFN_D3D11_CREATE_DEVICE_AND_SWAP_CHAIN fp;
if(!d3d11_dll)
d3d11_dll = dylib_load("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)
return TYPE_E_CANTLOADLIBRARY;
return fp(pAdapter,DriverType,Software, Flags,pFeatureLevels, FeatureLevels, SDKVersion, pSwapChainDesc,
ppSwapChain, ppDevice, pFeatureLevel, ppImmediateContext);
}

1391
gfx/common/d3d11_common.h Normal file

File diff suppressed because it is too large Load Diff

482
gfx/common/d3d12_common.c Normal file
View File

@ -0,0 +1,482 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2014-2018 - Ali Bouhlel
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <dynamic/dylib.h>
#include "d3d12_common.h"
#include "dxgi_common.h"
#include "d3dcompiler_common.h"
#include "verbosity.h"
static dylib_t d3d12_dll;
static const char *d3d12_dll_name = "d3d12.dll";
HRESULT WINAPI
D3D12CreateDevice(IUnknown *pAdapter,
D3D_FEATURE_LEVEL MinimumFeatureLevel,
REFIID riid, void **ppDevice)
{
if (!d3d12_dll)
d3d12_dll = dylib_load(d3d12_dll_name);
if (d3d12_dll)
{
static PFN_D3D12_CREATE_DEVICE fp;
if (!fp)
fp = (PFN_D3D12_CREATE_DEVICE)dylib_proc(d3d12_dll, "D3D12CreateDevice");
if (fp)
return fp(pAdapter, MinimumFeatureLevel, riid, ppDevice);
}
return TYPE_E_CANTLOADLIBRARY;
}
HRESULT WINAPI
D3D12GetDebugInterface(REFIID riid, void **ppvDebug)
{
if (!d3d12_dll)
d3d12_dll = dylib_load(d3d12_dll_name);
if (d3d12_dll)
{
static PFN_D3D12_GET_DEBUG_INTERFACE fp;
if (!fp)
fp = (PFN_D3D12_GET_DEBUG_INTERFACE)dylib_proc(d3d12_dll, "D3D12GetDebugInterface");
if (fp)
return fp(riid, ppvDebug);
}
return TYPE_E_CANTLOADLIBRARY;
}
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);
if (d3d12_dll)
{
static PFN_D3D12_SERIALIZE_ROOT_SIGNATURE fp;
if (!fp)
fp = (PFN_D3D12_SERIALIZE_ROOT_SIGNATURE)dylib_proc(d3d12_dll, "D3D12SerializeRootSignature");
if (fp)
return fp(pRootSignature, Version, ppBlob, ppErrorBlob);
}
return TYPE_E_CANTLOADLIBRARY;
}
HRESULT WINAPI
D3D12SerializeVersionedRootSignature(const D3D12_VERSIONED_ROOT_SIGNATURE_DESC *pRootSignature,
ID3DBlob **ppBlob, ID3DBlob **ppErrorBlob)
{
if (!d3d12_dll)
d3d12_dll = dylib_load(d3d12_dll_name);
if (d3d12_dll)
{
static PFN_D3D12_SERIALIZE_VERSIONED_ROOT_SIGNATURE fp;
if (!fp)
fp = (PFN_D3D12_SERIALIZE_VERSIONED_ROOT_SIGNATURE)dylib_proc(d3d12_dll,
"D3D12SerializeRootSignature");
if (fp)
return fp(pRootSignature, ppBlob, ppErrorBlob);
}
return TYPE_E_CANTLOADLIBRARY;
}
#include <wiiu/wiiu_dbg.h>
bool d3d12_init_context(d3d12_video_t *d3d12)
{
#ifdef DEBUG
D3D12GetDebugInterface_(&d3d12->debugController);
D3D12EnableDebugLayer(d3d12->debugController);
#endif
DXGICreateFactory(&d3d12->factory);
{
int i = 0;
while (true)
{
if (FAILED(DXGIEnumAdapters(d3d12->factory, i++, &d3d12->adapter)))
return false;
if (SUCCEEDED(D3D12CreateDevice_(d3d12->adapter, D3D_FEATURE_LEVEL_11_0, &d3d12->device)))
break;
Release(d3d12->adapter);
}
}
return true;
}
bool d3d12_init_queue(d3d12_video_t *d3d12)
{
{
D3D12_COMMAND_QUEUE_DESC desc =
{
.Type = D3D12_COMMAND_LIST_TYPE_DIRECT,
.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE,
};
D3D12CreateCommandQueue(d3d12->device, &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);
D3D12CloseGraphicsCommandList(d3d12->queue.cmd);
D3D12CreateFence(d3d12->device, 0, D3D12_FENCE_FLAG_NONE, &d3d12->queue.fence);
d3d12->queue.fenceValue = 1;
d3d12->queue.fenceEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
return true;
}
bool d3d12_init_swapchain(d3d12_video_t *d3d12, int width, int height, HWND hwnd)
{
{
DXGI_SWAP_CHAIN_DESC desc =
{
.BufferCount = countof(d3d12->chain.renderTargets),
.BufferDesc.Width = width,
.BufferDesc.Height = height,
.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM,
.SampleDesc.Count = 1,
// .BufferDesc.RefreshRate.Numerator = 60,
// .BufferDesc.RefreshRate.Denominator = 1,
// .SampleDesc.Quality = 0,
.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT,
.OutputWindow = hwnd,
.Windowed = TRUE,
.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL,
// .SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD,
};
DXGICreateSwapChain(d3d12->factory, d3d12->queue.handle, &desc, &d3d12->chain.handle);
}
DXGIMakeWindowAssociation(d3d12->factory, hwnd, DXGI_MWA_NO_ALT_ENTER);
d3d12->chain.frame_index = DXGIGetCurrentBackBufferIndex(d3d12->chain.handle);
for (int i = 0; i < countof(d3d12->chain.renderTargets); i++)
{
d3d12->chain.desc_handles[i].ptr = d3d12->pipe.rtv_heap.cpu.ptr + i * d3d12->pipe.rtv_heap.stride;
DXGIGetSwapChainBuffer(d3d12->chain.handle, i, &d3d12->chain.renderTargets[i]);
D3D12CreateRenderTargetView(d3d12->device, d3d12->chain.renderTargets[i],
NULL, d3d12->chain.desc_handles[i]);
}
d3d12->chain.viewport.Width = width;
d3d12->chain.viewport.Height = height;
d3d12->chain.scissorRect.right = width;
d3d12->chain.scissorRect.bottom = height;
return true;
}
static void d3d12_init_descriptor_heap(D3D12Device device, d3d12_descriptor_heap_t *out)
{
D3D12CreateDescriptorHeap(device, &out->desc, &out->handle);
out->cpu = D3D12GetCPUDescriptorHandleForHeapStart(out->handle);
out->gpu = D3D12GetGPUDescriptorHandleForHeapStart(out->handle);
out->stride = D3D12GetDescriptorHandleIncrementSize(device, out->desc.Type);
}
bool d3d12_init_descriptors(d3d12_video_t *d3d12)
{
static const D3D12_DESCRIPTOR_RANGE desc_table[] =
{
{
.RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_SRV,
.NumDescriptors = 1,
.BaseShaderRegister = 0,
.RegisterSpace = 0,
// .Flags = D3D12_DESCRIPTOR_RANGE_FLAG_DATA_STATIC, /* version 1_1 only */
.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},
.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,
.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,
};
{
D3DBlob signature;
D3DBlob error;
D3D12SerializeRootSignature(&desc, D3D_ROOT_SIGNATURE_VERSION_1, &signature, &error);
if (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);
Release(signature);
}
d3d12->pipe.rtv_heap.desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV;
d3d12->pipe.rtv_heap.desc.NumDescriptors = countof(d3d12->chain.renderTargets);
d3d12->pipe.rtv_heap.desc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
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.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
d3d12_init_descriptor_heap(d3d12->device, &d3d12->pipe.srv_heap);
return true;
}
bool d3d12_init_pipeline(d3d12_video_t *d3d12)
{
D3DBlob vs_code;
D3DBlob ps_code;
static const char stock [] =
#include "gfx/drivers/d3d_shaders/opaque_sm5.hlsl.h"
;
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},
};
D3D12_RASTERIZER_DESC rasterizerDesc =
{
.FillMode = D3D12_FILL_MODE_SOLID,
.CullMode = D3D12_CULL_MODE_BACK,
.FrontCounterClockwise = FALSE,
.DepthBias = D3D12_DEFAULT_DEPTH_BIAS,
.DepthBiasClamp = D3D12_DEFAULT_DEPTH_BIAS_CLAMP,
.SlopeScaledDepthBias = D3D12_DEFAULT_SLOPE_SCALED_DEPTH_BIAS,
.DepthClipEnable = TRUE,
.MultisampleEnable = FALSE,
.AntialiasedLineEnable = FALSE,
.ForcedSampleCount = 0,
.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 =
{
.AlphaToCoverageEnable = FALSE,
.IndependentBlendEnable = FALSE,
.RenderTarget[0] = defaultRenderTargetBlendDesc,
};
if (!d3d_compile(stock, sizeof(stock), "VSMain", "vs_5_0", &vs_code))
return false;
if (!d3d_compile(stock, sizeof(stock), "PSMain", "ps_5_0", &ps_code))
return false;
{
D3D12_GRAPHICS_PIPELINE_STATE_DESC psodesc =
{
.pRootSignature = d3d12->pipe.rootSignature,
.VS.pShaderBytecode = D3DGetBufferPointer(vs_code), D3DGetBufferSize(vs_code),
.PS.pShaderBytecode = D3DGetBufferPointer(ps_code), D3DGetBufferSize(ps_code),
.BlendState = blendDesc,
.SampleMask = UINT_MAX,
.RasterizerState = rasterizerDesc,
.DepthStencilState.DepthEnable = FALSE,
.DepthStencilState.StencilEnable = FALSE,
.InputLayout.pInputElementDescs = inputElementDesc, countof(inputElementDesc),
.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE,
.NumRenderTargets = 1,
.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM,
.SampleDesc.Count = 1,
};
D3D12CreateGraphicsPipelineState(d3d12->device, &psodesc, &d3d12->pipe.handle);
}
Release(vs_code);
Release(ps_code);
return true;
}
void d3d12_create_vertex_buffer(D3D12Device device, D3D12_VERTEX_BUFFER_VIEW *view,
D3D12Resource *vbo)
{
D3D12_HEAP_PROPERTIES heap_props =
{
.Type = D3D12_HEAP_TYPE_UPLOAD,
.CreationNodeMask = 1,
.VisibleNodeMask = 1,
};
D3D12_RESOURCE_DESC resource_desc =
{
.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER,
.Width = view->SizeInBytes,
.Height = 1,
.DepthOrArraySize = 1,
.MipLevels = 1,
.SampleDesc.Count = 1,
.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR,
};
D3D12CreateCommittedResource(device, &heap_props, D3D12_HEAP_FLAG_NONE, &resource_desc,
D3D12_RESOURCE_STATE_GENERIC_READ, NULL, vbo);
view->BufferLocation = D3D12GetGPUVirtualAddress(*vbo);
}
void d3d12_create_texture(D3D12Device device, d3d12_descriptor_heap_t *heap, int heap_index,
d3d12_texture_t *tex)
{
{
tex->desc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
tex->desc.DepthOrArraySize = 1;
tex->desc.MipLevels = 1;
tex->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, &tex->desc,
D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE, NULL, &tex->handle);
}
D3D12GetCopyableFootprints(device, &tex->desc, 0, 1, 0, &tex->layout, &tex->num_rows,
&tex->row_size_in_bytes, &tex->total_bytes);
{
D3D12_RESOURCE_DESC buffer_desc =
{
.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER,
.Width = tex->total_bytes,
.Height = 1,
.DepthOrArraySize = 1,
.MipLevels = 1,
.SampleDesc.Count = 1,
.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR,
};
D3D12_HEAP_PROPERTIES heap_props = {D3D12_HEAP_TYPE_UPLOAD, 0, 0, 1, 1};
D3D12CreateCommittedResource(device, &heap_props, D3D12_HEAP_FLAG_NONE, &buffer_desc,
D3D12_RESOURCE_STATE_GENERIC_READ, NULL, &tex->upload_buffer);
}
{
D3D12_SHADER_RESOURCE_VIEW_DESC view_desc =
{
.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING,
.Format = tex->desc.Format,
.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D,
.Texture2D.MipLevels = tex->desc.MipLevels,
};
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;
}
}
void d3d12_upload_texture(D3D12GraphicsCommandList cmd, d3d12_texture_t *texture)
{
D3D12_TEXTURE_COPY_LOCATION src =
{
.pResource = texture->upload_buffer,
.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT,
.PlacedFootprint = texture->layout,
};
D3D12_TEXTURE_COPY_LOCATION dst =
{
.pResource = texture->handle,
.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX,
.SubresourceIndex = 0,
};
d3d12_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_STATE_COPY_DEST, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE);
texture->dirty = false;
}

957
gfx/common/d3d12_common.h Normal file
View File

@ -0,0 +1,957 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2014-2018 - Ali Bouhlel
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#ifdef __MINGW32__
#define __REQUIRED_RPCNDR_H_VERSION__ 475
#define _In_
#define _In_opt_
#define _Null_
#define _Out_writes_bytes_opt_(s)
#endif
#define CINTERFACE
#include <d3d12.h>
#include "dxgi_common.h"
#ifndef countof
#define countof(a) (sizeof(a)/ sizeof(*a))
#endif
#ifndef __uuidof
#define __uuidof(type) &IID_##type
#endif
#ifndef COM_RELEASE_DECLARED
#define COM_RELEASE_DECLARED
#if defined(__cplusplus) && !defined(CINTERFACE)
static inline ULONG Release(IUnknown* object)
{
return object->Release();
}
#else
static inline ULONG Release(void* object)
{
return ((IUnknown*)object)->lpVtbl->Release(object);
}
#endif
#endif
/* auto-generated */
typedef ID3D12Object* D3D12Object;
typedef ID3D12DeviceChild* D3D12DeviceChild;
typedef ID3D12RootSignature* D3D12RootSignature;
typedef ID3D12RootSignatureDeserializer* D3D12RootSignatureDeserializer;
typedef ID3D12VersionedRootSignatureDeserializer* D3D12VersionedRootSignatureDeserializer;
typedef ID3D12Pageable* D3D12Pageable;
typedef ID3D12Heap* D3D12Heap;
typedef ID3D12Resource* D3D12Resource;
typedef ID3D12CommandAllocator* D3D12CommandAllocator;
typedef ID3D12Fence* D3D12Fence;
typedef ID3D12PipelineState* D3D12PipelineState;
typedef ID3D12DescriptorHeap* D3D12DescriptorHeap;
typedef ID3D12QueryHeap* D3D12QueryHeap;
typedef ID3D12CommandSignature* D3D12CommandSignature;
typedef ID3D12CommandList* D3D12CommandList;
typedef ID3D12GraphicsCommandList* D3D12GraphicsCommandList;
typedef ID3D12CommandQueue* D3D12CommandQueue;
typedef ID3D12Device* D3D12Device;
typedef ID3D12PipelineLibrary* D3D12PipelineLibrary;
typedef ID3D12Debug* D3D12Debug;
typedef ID3D12DebugDevice* D3D12DebugDevice;
typedef ID3D12DebugCommandQueue* D3D12DebugCommandQueue;
typedef ID3D12DebugCommandList* D3D12DebugCommandList;
typedef ID3D12InfoQueue* D3D12InfoQueue;
static inline ULONG D3D12Release(void* object)
{
return ((ID3D12Object*)object)->lpVtbl->Release(object);
}
static inline ULONG D3D12ReleaseDeviceChild(D3D12DeviceChild device_child)
{
return device_child->lpVtbl->Release(device_child);
}
static inline ULONG D3D12ReleaseRootSignature(D3D12RootSignature root_signature)
{
return root_signature->lpVtbl->Release(root_signature);
}
static inline ULONG D3D12ReleaseRootSignatureDeserializer(D3D12RootSignatureDeserializer root_signature_deserializer)
{
return root_signature_deserializer->lpVtbl->Release(root_signature_deserializer);
}
static inline const D3D12_ROOT_SIGNATURE_DESC * D3D12GetRootSignatureDesc(D3D12RootSignatureDeserializer root_signature_deserializer)
{
return root_signature_deserializer->lpVtbl->GetRootSignatureDesc(root_signature_deserializer);
}
static inline ULONG D3D12ReleaseVersionedRootSignatureDeserializer(D3D12VersionedRootSignatureDeserializer versioned_root_signature_deserializer)
{
return versioned_root_signature_deserializer->lpVtbl->Release(versioned_root_signature_deserializer);
}
static inline HRESULT D3D12GetRootSignatureDescAtVersion(D3D12VersionedRootSignatureDeserializer versioned_root_signature_deserializer, D3D_ROOT_SIGNATURE_VERSION convert_to_version, const D3D12_VERSIONED_ROOT_SIGNATURE_DESC** desc)
{
return versioned_root_signature_deserializer->lpVtbl->GetRootSignatureDescAtVersion(versioned_root_signature_deserializer, convert_to_version, desc);
}
static inline const D3D12_VERSIONED_ROOT_SIGNATURE_DESC * D3D12GetUnconvertedRootSignatureDesc(D3D12VersionedRootSignatureDeserializer versioned_root_signature_deserializer)
{
return versioned_root_signature_deserializer->lpVtbl->GetUnconvertedRootSignatureDesc(versioned_root_signature_deserializer);
}
static inline ULONG D3D12ReleasePageable(D3D12Pageable pageable)
{
return pageable->lpVtbl->Release(pageable);
}
static inline ULONG D3D12ReleaseHeap(D3D12Heap heap)
{
return heap->lpVtbl->Release(heap);
}
static inline ULONG D3D12ReleaseResource(void* resource)
{
return ((ID3D12Resource*)resource)->lpVtbl->Release(resource);
}
static inline HRESULT D3D12Map(void* resource, UINT subresource, D3D12_RANGE* read_range, void** data)
{
return ((ID3D12Resource*)resource)->lpVtbl->Map(resource, subresource, read_range, data);
}
static inline void D3D12Unmap(void* resource, UINT subresource, D3D12_RANGE* written_range)
{
((ID3D12Resource*)resource)->lpVtbl->Unmap(resource, subresource, written_range);
}
static inline D3D12_GPU_VIRTUAL_ADDRESS D3D12GetGPUVirtualAddress(void* resource)
{
return ((ID3D12Resource*)resource)->lpVtbl->GetGPUVirtualAddress(resource);
}
static inline HRESULT D3D12WriteToSubresource(void* resource, UINT dst_subresource, D3D12_BOX* dst_box, void* src_data, UINT src_row_pitch, UINT src_depth_pitch)
{
return ((ID3D12Resource*)resource)->lpVtbl->WriteToSubresource(resource, dst_subresource, dst_box, src_data, src_row_pitch, src_depth_pitch);
}
static inline HRESULT D3D12ReadFromSubresource(void* resource, void* dst_data, UINT dst_row_pitch, UINT dst_depth_pitch, UINT src_subresource, D3D12_BOX* src_box)
{
return ((ID3D12Resource*)resource)->lpVtbl->ReadFromSubresource(resource, dst_data, dst_row_pitch, dst_depth_pitch, src_subresource, src_box);
}
static inline HRESULT D3D12GetHeapProperties(void* resource, D3D12_HEAP_PROPERTIES* heap_properties, D3D12_HEAP_FLAGS* heap_flags)
{
return ((ID3D12Resource*)resource)->lpVtbl->GetHeapProperties(resource, heap_properties, heap_flags);
}
static inline ULONG D3D12ReleaseCommandAllocator(D3D12CommandAllocator command_allocator)
{
return command_allocator->lpVtbl->Release(command_allocator);
}
static inline HRESULT D3D12ResetCommandAllocator(D3D12CommandAllocator command_allocator)
{
return command_allocator->lpVtbl->Reset(command_allocator);
}
static inline ULONG D3D12ReleaseFence(D3D12Fence fence)
{
return fence->lpVtbl->Release(fence);
}
static inline UINT64 D3D12GetCompletedValue(D3D12Fence fence)
{
return fence->lpVtbl->GetCompletedValue(fence);
}
static inline HRESULT D3D12SetEventOnCompletion(D3D12Fence fence, UINT64 value, HANDLE h_event)
{
return fence->lpVtbl->SetEventOnCompletion(fence, value, h_event);
}
static inline HRESULT D3D12SignalFence(D3D12Fence fence, UINT64 value)
{
return fence->lpVtbl->Signal(fence, value);
}
static inline ULONG D3D12ReleasePipelineState(D3D12PipelineState pipeline_state)
{
return pipeline_state->lpVtbl->Release(pipeline_state);
}
static inline HRESULT D3D12GetCachedBlob(D3D12PipelineState pipeline_state, ID3DBlob** blob)
{
return pipeline_state->lpVtbl->GetCachedBlob(pipeline_state, blob);
}
static inline ULONG D3D12ReleaseDescriptorHeap(D3D12DescriptorHeap descriptor_heap)
{
return descriptor_heap->lpVtbl->Release(descriptor_heap);
}
static inline ULONG D3D12ReleaseQueryHeap(D3D12QueryHeap query_heap)
{
return query_heap->lpVtbl->Release(query_heap);
}
static inline ULONG D3D12ReleaseCommandSignature(D3D12CommandSignature command_signature)
{
return command_signature->lpVtbl->Release(command_signature);
}
static inline ULONG D3D12ReleaseCommandList(D3D12CommandList command_list)
{
return command_list->lpVtbl->Release(command_list);
}
static inline ULONG D3D12ReleaseGraphicsCommandList(D3D12GraphicsCommandList graphics_command_list)
{
return graphics_command_list->lpVtbl->Release(graphics_command_list);
}
static inline HRESULT D3D12CloseGraphicsCommandList(D3D12GraphicsCommandList graphics_command_list)
{
return graphics_command_list->lpVtbl->Close(graphics_command_list);
}
static inline HRESULT D3D12ResetGraphicsCommandList(D3D12GraphicsCommandList graphics_command_list, D3D12CommandAllocator allocator, D3D12PipelineState initial_state)
{
return graphics_command_list->lpVtbl->Reset(graphics_command_list, allocator, initial_state);
}
static inline void D3D12ClearState(D3D12GraphicsCommandList graphics_command_list, D3D12PipelineState pipeline_state)
{
graphics_command_list->lpVtbl->ClearState(graphics_command_list, pipeline_state);
}
static inline void D3D12DrawInstanced(D3D12GraphicsCommandList graphics_command_list, UINT vertex_count_per_instance, UINT instance_count, UINT start_vertex_location, UINT start_instance_location)
{
graphics_command_list->lpVtbl->DrawInstanced(graphics_command_list, vertex_count_per_instance, instance_count, start_vertex_location, start_instance_location);
}
static inline void D3D12DrawIndexedInstanced(D3D12GraphicsCommandList graphics_command_list, UINT index_count_per_instance, UINT instance_count, UINT start_index_location, INT base_vertex_location, UINT start_instance_location)
{
graphics_command_list->lpVtbl->DrawIndexedInstanced(graphics_command_list, index_count_per_instance, instance_count, start_index_location, base_vertex_location, start_instance_location);
}
static inline void D3D12Dispatch(D3D12GraphicsCommandList graphics_command_list, UINT thread_group_count_x, UINT thread_group_count_y, UINT thread_group_count_z)
{
graphics_command_list->lpVtbl->Dispatch(graphics_command_list, thread_group_count_x, thread_group_count_y, thread_group_count_z);
}
static inline void D3D12CopyBufferRegion(D3D12GraphicsCommandList graphics_command_list, D3D12Resource dst_buffer, UINT64 dst_offset, D3D12Resource src_buffer, UINT64 src_offset, UINT64 num_bytes)
{
graphics_command_list->lpVtbl->CopyBufferRegion(graphics_command_list, dst_buffer, dst_offset, (ID3D12Resource*)src_buffer, src_offset, num_bytes);
}
static inline void D3D12CopyTextureRegion(D3D12GraphicsCommandList graphics_command_list, D3D12_TEXTURE_COPY_LOCATION* dst, UINT dst_x, UINT dst_y, UINT dst_z, D3D12_TEXTURE_COPY_LOCATION* src, D3D12_BOX* src_box)
{
graphics_command_list->lpVtbl->CopyTextureRegion(graphics_command_list, dst, dst_x, dst_y, dst_z, src, src_box);
}
static inline void D3D12CopyResource(D3D12GraphicsCommandList graphics_command_list, void* dst_resource, void* src_resource)
{
graphics_command_list->lpVtbl->CopyResource(graphics_command_list, (ID3D12Resource*)dst_resource, (ID3D12Resource*)src_resource);
}
static inline void D3D12CopyTiles(D3D12GraphicsCommandList graphics_command_list, void* tiled_resource, D3D12_TILED_RESOURCE_COORDINATE* tile_region_start_coordinate, D3D12_TILE_REGION_SIZE* tile_region_size, void* buffer, UINT64 buffer_start_offset_in_bytes, D3D12_TILE_COPY_FLAGS flags)
{
graphics_command_list->lpVtbl->CopyTiles(graphics_command_list, (ID3D12Resource*)tiled_resource, tile_region_start_coordinate, tile_region_size, (ID3D12Resource*)buffer, buffer_start_offset_in_bytes, flags);
}
static inline void D3D12ResolveSubresource(D3D12GraphicsCommandList graphics_command_list, void* dst_resource, UINT dst_subresource, void* src_resource, UINT src_subresource, DXGI_FORMAT format)
{
graphics_command_list->lpVtbl->ResolveSubresource(graphics_command_list, (ID3D12Resource*)dst_resource, dst_subresource, (ID3D12Resource*)src_resource, src_subresource, format);
}
static inline void D3D12IASetPrimitiveTopology(D3D12GraphicsCommandList graphics_command_list, D3D12_PRIMITIVE_TOPOLOGY primitive_topology)
{
graphics_command_list->lpVtbl->IASetPrimitiveTopology(graphics_command_list, primitive_topology);
}
static inline void D3D12RSSetViewports(D3D12GraphicsCommandList graphics_command_list, UINT num_viewports, D3D12_VIEWPORT* viewports)
{
graphics_command_list->lpVtbl->RSSetViewports(graphics_command_list, num_viewports, viewports);
}
static inline void D3D12RSSetScissorRects(D3D12GraphicsCommandList graphics_command_list, UINT num_rects, D3D12_RECT* rects)
{
graphics_command_list->lpVtbl->RSSetScissorRects(graphics_command_list, num_rects, rects);
}
static inline void D3D12OMSetStencilRef(D3D12GraphicsCommandList graphics_command_list, UINT stencil_ref)
{
graphics_command_list->lpVtbl->OMSetStencilRef(graphics_command_list, stencil_ref);
}
static inline void D3D12SetPipelineState(D3D12GraphicsCommandList graphics_command_list, D3D12PipelineState pipeline_state)
{
graphics_command_list->lpVtbl->SetPipelineState(graphics_command_list, pipeline_state);
}
static inline void D3D12ResourceBarrier(D3D12GraphicsCommandList graphics_command_list, UINT num_barriers, D3D12_RESOURCE_BARRIER* barriers)
{
graphics_command_list->lpVtbl->ResourceBarrier(graphics_command_list, num_barriers, barriers);
}
static inline void D3D12ExecuteBundle(D3D12GraphicsCommandList graphics_command_list, D3D12GraphicsCommandList command_list)
{
graphics_command_list->lpVtbl->ExecuteBundle(graphics_command_list, command_list);
}
static inline void D3D12SetComputeRootSignature(D3D12GraphicsCommandList graphics_command_list, D3D12RootSignature root_signature)
{
graphics_command_list->lpVtbl->SetComputeRootSignature(graphics_command_list, root_signature);
}
static inline void D3D12SetGraphicsRootSignature(D3D12GraphicsCommandList graphics_command_list, D3D12RootSignature root_signature)
{
graphics_command_list->lpVtbl->SetGraphicsRootSignature(graphics_command_list, root_signature);
}
static inline void D3D12SetComputeRootDescriptorTable(D3D12GraphicsCommandList graphics_command_list, UINT root_parameter_index, D3D12_GPU_DESCRIPTOR_HANDLE base_descriptor)
{
graphics_command_list->lpVtbl->SetComputeRootDescriptorTable(graphics_command_list, root_parameter_index, base_descriptor);
}
static inline void D3D12SetGraphicsRootDescriptorTable(D3D12GraphicsCommandList graphics_command_list, UINT root_parameter_index, D3D12_GPU_DESCRIPTOR_HANDLE base_descriptor)
{
graphics_command_list->lpVtbl->SetGraphicsRootDescriptorTable(graphics_command_list, root_parameter_index, base_descriptor);
}
static inline void D3D12SetComputeRoot32BitConstant(D3D12GraphicsCommandList graphics_command_list, UINT root_parameter_index, UINT src_data, UINT dest_offset_in32_bit_values)
{
graphics_command_list->lpVtbl->SetComputeRoot32BitConstant(graphics_command_list, root_parameter_index, src_data, dest_offset_in32_bit_values);
}
static inline void D3D12SetGraphicsRoot32BitConstant(D3D12GraphicsCommandList graphics_command_list, UINT root_parameter_index, UINT src_data, UINT dest_offset_in32_bit_values)
{
graphics_command_list->lpVtbl->SetGraphicsRoot32BitConstant(graphics_command_list, root_parameter_index, src_data, dest_offset_in32_bit_values);
}
static inline void D3D12SetComputeRoot32BitConstants(D3D12GraphicsCommandList graphics_command_list, UINT root_parameter_index, UINT num32_bit_values_to_set, void* src_data, UINT dest_offset_in32_bit_values)
{
graphics_command_list->lpVtbl->SetComputeRoot32BitConstants(graphics_command_list, root_parameter_index, num32_bit_values_to_set, src_data, dest_offset_in32_bit_values);
}
static inline void D3D12SetGraphicsRoot32BitConstants(D3D12GraphicsCommandList graphics_command_list, UINT root_parameter_index, UINT num32_bit_values_to_set, void* src_data, UINT dest_offset_in32_bit_values)
{
graphics_command_list->lpVtbl->SetGraphicsRoot32BitConstants(graphics_command_list, root_parameter_index, num32_bit_values_to_set, src_data, dest_offset_in32_bit_values);
}
static inline void D3D12SetComputeRootConstantBufferView(D3D12GraphicsCommandList graphics_command_list, UINT root_parameter_index, D3D12_GPU_VIRTUAL_ADDRESS buffer_location)
{
graphics_command_list->lpVtbl->SetComputeRootConstantBufferView(graphics_command_list, root_parameter_index, buffer_location);
}
static inline void D3D12SetGraphicsRootConstantBufferView(D3D12GraphicsCommandList graphics_command_list, UINT root_parameter_index, D3D12_GPU_VIRTUAL_ADDRESS buffer_location)
{
graphics_command_list->lpVtbl->SetGraphicsRootConstantBufferView(graphics_command_list, root_parameter_index, buffer_location);
}
static inline void D3D12SetComputeRootShaderResourceView(D3D12GraphicsCommandList graphics_command_list, UINT root_parameter_index, D3D12_GPU_VIRTUAL_ADDRESS buffer_location)
{
graphics_command_list->lpVtbl->SetComputeRootShaderResourceView(graphics_command_list, root_parameter_index, buffer_location);
}
static inline void D3D12SetGraphicsRootShaderResourceView(D3D12GraphicsCommandList graphics_command_list, UINT root_parameter_index, D3D12_GPU_VIRTUAL_ADDRESS buffer_location)
{
graphics_command_list->lpVtbl->SetGraphicsRootShaderResourceView(graphics_command_list, root_parameter_index, buffer_location);
}
static inline void D3D12SetComputeRootUnorderedAccessView(D3D12GraphicsCommandList graphics_command_list, UINT root_parameter_index, D3D12_GPU_VIRTUAL_ADDRESS buffer_location)
{
graphics_command_list->lpVtbl->SetComputeRootUnorderedAccessView(graphics_command_list, root_parameter_index, buffer_location);
}
static inline void D3D12SetGraphicsRootUnorderedAccessView(D3D12GraphicsCommandList graphics_command_list, UINT root_parameter_index, D3D12_GPU_VIRTUAL_ADDRESS buffer_location)
{
graphics_command_list->lpVtbl->SetGraphicsRootUnorderedAccessView(graphics_command_list, root_parameter_index, buffer_location);
}
static inline void D3D12IASetIndexBuffer(D3D12GraphicsCommandList graphics_command_list, D3D12_INDEX_BUFFER_VIEW* view)
{
graphics_command_list->lpVtbl->IASetIndexBuffer(graphics_command_list, view);
}
static inline void D3D12IASetVertexBuffers(D3D12GraphicsCommandList graphics_command_list, UINT start_slot, UINT num_views, D3D12_VERTEX_BUFFER_VIEW* views)
{
graphics_command_list->lpVtbl->IASetVertexBuffers(graphics_command_list, start_slot, num_views, views);
}
static inline void D3D12SOSetTargets(D3D12GraphicsCommandList graphics_command_list, UINT start_slot, UINT num_views, D3D12_STREAM_OUTPUT_BUFFER_VIEW* views)
{
graphics_command_list->lpVtbl->SOSetTargets(graphics_command_list, start_slot, num_views, views);
}
static inline void D3D12OMSetRenderTargets(D3D12GraphicsCommandList graphics_command_list, UINT num_render_target_descriptors, D3D12_CPU_DESCRIPTOR_HANDLE* render_target_descriptors, BOOL r_ts_single_handle_to_descriptor_range, D3D12_CPU_DESCRIPTOR_HANDLE* depth_stencil_descriptor)
{
graphics_command_list->lpVtbl->OMSetRenderTargets(graphics_command_list, num_render_target_descriptors, render_target_descriptors, r_ts_single_handle_to_descriptor_range, depth_stencil_descriptor);
}
static inline void D3D12ClearDepthStencilView(D3D12GraphicsCommandList graphics_command_list, D3D12_CPU_DESCRIPTOR_HANDLE depth_stencil_view, D3D12_CLEAR_FLAGS clear_flags, FLOAT depth, UINT8 stencil, UINT num_rects, D3D12_RECT* rects)
{
graphics_command_list->lpVtbl->ClearDepthStencilView(graphics_command_list, depth_stencil_view, clear_flags, depth, stencil, num_rects, rects);
}
static inline void D3D12DiscardResource(D3D12GraphicsCommandList graphics_command_list, void* resource, D3D12_DISCARD_REGION* region)
{
graphics_command_list->lpVtbl->DiscardResource(graphics_command_list, (ID3D12Resource*)resource, region);
}
static inline void D3D12BeginQuery(D3D12GraphicsCommandList graphics_command_list, D3D12QueryHeap query_heap, D3D12_QUERY_TYPE type, UINT index)
{
graphics_command_list->lpVtbl->BeginQuery(graphics_command_list, query_heap, type, index);
}
static inline void D3D12EndQuery(D3D12GraphicsCommandList graphics_command_list, D3D12QueryHeap query_heap, D3D12_QUERY_TYPE type, UINT index)
{
graphics_command_list->lpVtbl->EndQuery(graphics_command_list, query_heap, type, index);
}
static inline void D3D12ResolveQueryData(D3D12GraphicsCommandList graphics_command_list, D3D12QueryHeap query_heap, D3D12_QUERY_TYPE type, UINT start_index, UINT num_queries, void* destination_buffer, UINT64 aligned_destination_buffer_offset)
{
graphics_command_list->lpVtbl->ResolveQueryData(graphics_command_list, query_heap, type, start_index, num_queries, (ID3D12Resource*)destination_buffer, aligned_destination_buffer_offset);
}
static inline void D3D12SetPredication(D3D12GraphicsCommandList graphics_command_list, void* buffer, UINT64 aligned_buffer_offset, D3D12_PREDICATION_OP operation)
{
graphics_command_list->lpVtbl->SetPredication(graphics_command_list, (ID3D12Resource*)buffer, aligned_buffer_offset, operation);
}
static inline void D3D12SetGraphicsCommandListMarker(D3D12GraphicsCommandList graphics_command_list, UINT metadata, void* data, UINT size)
{
graphics_command_list->lpVtbl->SetMarker(graphics_command_list, metadata, data, size);
}
static inline void D3D12BeginGraphicsCommandListEvent(D3D12GraphicsCommandList graphics_command_list, UINT metadata, void* data, UINT size)
{
graphics_command_list->lpVtbl->BeginEvent(graphics_command_list, metadata, data, size);
}
static inline void D3D12EndGraphicsCommandListEvent(D3D12GraphicsCommandList graphics_command_list)
{
graphics_command_list->lpVtbl->EndEvent(graphics_command_list);
}
static inline void D3D12ExecuteIndirect(D3D12GraphicsCommandList graphics_command_list, D3D12CommandSignature command_signature, UINT max_command_count, void* argument_buffer, UINT64 argument_buffer_offset, void* count_buffer, UINT64 count_buffer_offset)
{
graphics_command_list->lpVtbl->ExecuteIndirect(graphics_command_list, command_signature, max_command_count, (ID3D12Resource*)argument_buffer, argument_buffer_offset, (ID3D12Resource*)count_buffer, count_buffer_offset);
}
static inline ULONG D3D12ReleaseCommandQueue(D3D12CommandQueue command_queue)
{
return command_queue->lpVtbl->Release(command_queue);
}
static inline void D3D12UpdateTileMappings(D3D12CommandQueue command_queue, void* resource, UINT num_resource_regions, D3D12_TILED_RESOURCE_COORDINATE* resource_region_start_coordinates, D3D12_TILE_REGION_SIZE* resource_region_sizes, D3D12Heap heap, UINT num_ranges, D3D12_TILE_RANGE_FLAGS* range_flags, UINT* heap_range_start_offsets, UINT* range_tile_counts, D3D12_TILE_MAPPING_FLAGS flags)
{
command_queue->lpVtbl->UpdateTileMappings(command_queue, (ID3D12Resource*)resource, num_resource_regions, resource_region_start_coordinates, resource_region_sizes, heap, num_ranges, range_flags, heap_range_start_offsets, range_tile_counts, flags);
}
static inline void D3D12CopyTileMappings(D3D12CommandQueue command_queue, void* dst_resource, D3D12_TILED_RESOURCE_COORDINATE* dst_region_start_coordinate, void* src_resource, D3D12_TILED_RESOURCE_COORDINATE* src_region_start_coordinate, D3D12_TILE_REGION_SIZE* region_size, D3D12_TILE_MAPPING_FLAGS flags)
{
command_queue->lpVtbl->CopyTileMappings(command_queue, (ID3D12Resource*)dst_resource, dst_region_start_coordinate, (ID3D12Resource*)src_resource, src_region_start_coordinate, region_size, flags);
}
static inline void D3D12SetCommandQueueMarker(D3D12CommandQueue command_queue, UINT metadata, void* data, UINT size)
{
command_queue->lpVtbl->SetMarker(command_queue, metadata, data, size);
}
static inline void D3D12BeginCommandQueueEvent(D3D12CommandQueue command_queue, UINT metadata, void* data, UINT size)
{
command_queue->lpVtbl->BeginEvent(command_queue, metadata, data, size);
}
static inline void D3D12EndCommandQueueEvent(D3D12CommandQueue command_queue)
{
command_queue->lpVtbl->EndEvent(command_queue);
}
static inline HRESULT D3D12SignalCommandQueue(D3D12CommandQueue command_queue, D3D12Fence fence, UINT64 value)
{
return command_queue->lpVtbl->Signal(command_queue, fence, value);
}
static inline HRESULT D3D12Wait(D3D12CommandQueue command_queue, D3D12Fence fence, UINT64 value)
{
return command_queue->lpVtbl->Wait(command_queue, fence, value);
}
static inline HRESULT D3D12GetTimestampFrequency(D3D12CommandQueue command_queue, UINT64* frequency)
{
return command_queue->lpVtbl->GetTimestampFrequency(command_queue, frequency);
}
static inline HRESULT D3D12GetClockCalibration(D3D12CommandQueue command_queue, UINT64* gpu_timestamp, UINT64* cpu_timestamp)
{
return command_queue->lpVtbl->GetClockCalibration(command_queue, gpu_timestamp, cpu_timestamp);
}
static inline ULONG D3D12ReleaseDevice(D3D12Device device)
{
return device->lpVtbl->Release(device);
}
static inline UINT D3D12GetNodeCount(D3D12Device device)
{
return device->lpVtbl->GetNodeCount(device);
}
static inline HRESULT D3D12CreateCommandQueue(D3D12Device device, D3D12_COMMAND_QUEUE_DESC* desc, ID3D12CommandQueue** out)
{
return device->lpVtbl->CreateCommandQueue(device, desc, __uuidof(ID3D12CommandQueue), (void**)out);
}
static inline HRESULT D3D12CreateCommandAllocator(D3D12Device device, D3D12_COMMAND_LIST_TYPE type, ID3D12CommandAllocator** out)
{
return device->lpVtbl->CreateCommandAllocator(device, type, __uuidof(ID3D12CommandAllocator), (void**)out);
}
static inline HRESULT D3D12CreateGraphicsPipelineState(D3D12Device device, D3D12_GRAPHICS_PIPELINE_STATE_DESC* desc, ID3D12PipelineState** out)
{
return device->lpVtbl->CreateGraphicsPipelineState(device, desc, __uuidof(ID3D12PipelineState), (void**)out);
}
static inline HRESULT D3D12CreateComputePipelineState(D3D12Device device, D3D12_COMPUTE_PIPELINE_STATE_DESC* desc, ID3D12PipelineState** out)
{
return device->lpVtbl->CreateComputePipelineState(device, desc, __uuidof(ID3D12PipelineState), (void**)out);
}
static inline HRESULT D3D12CreateCommandList(D3D12Device device, UINT node_mask, D3D12_COMMAND_LIST_TYPE type, D3D12CommandAllocator command_allocator, D3D12PipelineState initial_state, ID3D12CommandList** out)
{
return device->lpVtbl->CreateCommandList(device, node_mask, type, command_allocator, initial_state, __uuidof(ID3D12CommandList), (void**)out);
}
static inline HRESULT D3D12CheckFeatureSupport(D3D12Device device, D3D12_FEATURE feature, void* feature_support_data, UINT feature_support_data_size)
{
return device->lpVtbl->CheckFeatureSupport(device, feature, feature_support_data, feature_support_data_size);
}
static inline HRESULT D3D12CreateDescriptorHeap(D3D12Device device, D3D12_DESCRIPTOR_HEAP_DESC* descriptor_heap_desc, D3D12DescriptorHeap* out)
{
return device->lpVtbl->CreateDescriptorHeap(device, descriptor_heap_desc, __uuidof(ID3D12DescriptorHeap), (void**)out);
}
static inline UINT D3D12GetDescriptorHandleIncrementSize(D3D12Device device, D3D12_DESCRIPTOR_HEAP_TYPE descriptor_heap_type)
{
return device->lpVtbl->GetDescriptorHandleIncrementSize(device, descriptor_heap_type);
}
static inline HRESULT D3D12CreateRootSignature(D3D12Device device, UINT node_mask, void* blob_with_root_signature, SIZE_T blob_length_in_bytes, ID3D12RootSignature** out)
{
return device->lpVtbl->CreateRootSignature(device, node_mask, blob_with_root_signature, blob_length_in_bytes, __uuidof(ID3D12RootSignature), (void**)out);
}
static inline void D3D12CreateConstantBufferView(D3D12Device device, D3D12_CONSTANT_BUFFER_VIEW_DESC* desc, D3D12_CPU_DESCRIPTOR_HANDLE dest_descriptor)
{
device->lpVtbl->CreateConstantBufferView(device, desc, dest_descriptor);
}
static inline void D3D12CreateShaderResourceView(D3D12Device device, D3D12Resource resource, D3D12_SHADER_RESOURCE_VIEW_DESC* desc, D3D12_CPU_DESCRIPTOR_HANDLE dest_descriptor)
{
device->lpVtbl->CreateShaderResourceView(device, resource, desc, dest_descriptor);
}
static inline void D3D12CreateUnorderedAccessView(D3D12Device device, void* resource, void* counter_resource, D3D12_UNORDERED_ACCESS_VIEW_DESC* desc, D3D12_CPU_DESCRIPTOR_HANDLE dest_descriptor)
{
device->lpVtbl->CreateUnorderedAccessView(device, (ID3D12Resource*)resource, (ID3D12Resource*)counter_resource, desc, dest_descriptor);
}
static inline void D3D12CreateRenderTargetView(D3D12Device device, void* resource, D3D12_RENDER_TARGET_VIEW_DESC* desc, D3D12_CPU_DESCRIPTOR_HANDLE dest_descriptor)
{
device->lpVtbl->CreateRenderTargetView(device, (ID3D12Resource*)resource, desc, dest_descriptor);
}
static inline void D3D12CreateDepthStencilView(D3D12Device device, void* resource, D3D12_DEPTH_STENCIL_VIEW_DESC* desc, D3D12_CPU_DESCRIPTOR_HANDLE dest_descriptor)
{
device->lpVtbl->CreateDepthStencilView(device, (ID3D12Resource*)resource, desc, dest_descriptor);
}
static inline void D3D12CreateSampler(D3D12Device device, D3D12_SAMPLER_DESC* desc, D3D12_CPU_DESCRIPTOR_HANDLE dest_descriptor)
{
device->lpVtbl->CreateSampler(device, desc, dest_descriptor);
}
static inline void D3D12CopyDescriptors(D3D12Device device, UINT num_dest_descriptor_ranges, D3D12_CPU_DESCRIPTOR_HANDLE* dest_descriptor_range_starts, UINT* dest_descriptor_range_sizes, UINT num_src_descriptor_ranges, D3D12_CPU_DESCRIPTOR_HANDLE* src_descriptor_range_starts, UINT* src_descriptor_range_sizes, D3D12_DESCRIPTOR_HEAP_TYPE descriptor_heaps_type)
{
device->lpVtbl->CopyDescriptors(device, num_dest_descriptor_ranges, dest_descriptor_range_starts, dest_descriptor_range_sizes, num_src_descriptor_ranges, src_descriptor_range_starts, src_descriptor_range_sizes, descriptor_heaps_type);
}
static inline void D3D12CopyDescriptorsSimple(D3D12Device device, UINT num_descriptors, D3D12_CPU_DESCRIPTOR_HANDLE dest_descriptor_range_start, D3D12_CPU_DESCRIPTOR_HANDLE src_descriptor_range_start, D3D12_DESCRIPTOR_HEAP_TYPE descriptor_heaps_type)
{
device->lpVtbl->CopyDescriptorsSimple(device, num_descriptors, dest_descriptor_range_start, src_descriptor_range_start, descriptor_heaps_type);
}
static inline D3D12_RESOURCE_ALLOCATION_INFO D3D12GetResourceAllocationInfo(D3D12Device device, UINT visible_mask, UINT num_resource_descs, D3D12_RESOURCE_DESC* resource_descs)
{
return device->lpVtbl->GetResourceAllocationInfo(device, visible_mask, num_resource_descs, resource_descs);
}
static inline D3D12_HEAP_PROPERTIES D3D12GetCustomHeapProperties(D3D12Device device, UINT node_mask, D3D12_HEAP_TYPE heap_type)
{
return device->lpVtbl->GetCustomHeapProperties(device, node_mask, heap_type);
}
static inline HRESULT D3D12CreateCommittedResource(D3D12Device device, D3D12_HEAP_PROPERTIES* heap_properties, D3D12_HEAP_FLAGS heap_flags, D3D12_RESOURCE_DESC* desc, D3D12_RESOURCE_STATES initial_resource_state, D3D12_CLEAR_VALUE* optimized_clear_value, ID3D12Resource** out)
{
return device->lpVtbl->CreateCommittedResource(device, heap_properties, heap_flags, desc, initial_resource_state, optimized_clear_value, __uuidof(ID3D12Resource), (void**)out);
}
static inline HRESULT D3D12CreateHeap(D3D12Device device, D3D12_HEAP_DESC* desc, ID3D12Heap** out)
{
return device->lpVtbl->CreateHeap(device, desc, __uuidof(ID3D12Heap), (void**)out);
}
static inline HRESULT D3D12CreatePlacedResource(D3D12Device device, D3D12Heap heap, UINT64 heap_offset, D3D12_RESOURCE_DESC* desc, D3D12_RESOURCE_STATES initial_state, D3D12_CLEAR_VALUE* optimized_clear_value, ID3D12Resource** out)
{
return device->lpVtbl->CreatePlacedResource(device, heap, heap_offset, desc, initial_state, optimized_clear_value, __uuidof(ID3D12Resource), (void**)out);
}
static inline HRESULT D3D12CreateReservedResource(D3D12Device device, D3D12_RESOURCE_DESC* desc, D3D12_RESOURCE_STATES initial_state, D3D12_CLEAR_VALUE* optimized_clear_value, ID3D12Resource** out)
{
return device->lpVtbl->CreateReservedResource(device, desc, initial_state, optimized_clear_value, __uuidof(ID3D12Resource), (void**)out);
}
static inline HRESULT D3D12CreateFence(D3D12Device device, UINT64 initial_value, D3D12_FENCE_FLAGS flags, ID3D12Fence** out)
{
return device->lpVtbl->CreateFence(device, initial_value, flags, __uuidof(ID3D12Fence), (void**)out);
}
static inline HRESULT D3D12GetDeviceRemovedReason(D3D12Device device)
{
return device->lpVtbl->GetDeviceRemovedReason(device);
}
static inline void D3D12GetCopyableFootprints(D3D12Device device, D3D12_RESOURCE_DESC* resource_desc, UINT first_subresource, UINT num_subresources, UINT64 base_offset, D3D12_PLACED_SUBRESOURCE_FOOTPRINT* layouts, UINT* num_rows, UINT64* row_size_in_bytes, UINT64* total_bytes)
{
device->lpVtbl->GetCopyableFootprints(device, resource_desc, first_subresource, num_subresources, base_offset, layouts, num_rows, row_size_in_bytes, total_bytes);
}
static inline HRESULT D3D12CreateQueryHeap(D3D12Device device, D3D12_QUERY_HEAP_DESC* desc, ID3D12Heap** out)
{
return device->lpVtbl->CreateQueryHeap(device, desc, __uuidof(ID3D12Heap), (void**)out);
}
static inline HRESULT D3D12SetStablePowerState(D3D12Device device, BOOL enable)
{
return device->lpVtbl->SetStablePowerState(device, enable);
}
static inline HRESULT D3D12CreateCommandSignature(D3D12Device device, D3D12_COMMAND_SIGNATURE_DESC* desc, D3D12RootSignature root_signature, ID3D12CommandSignature** out)
{
return device->lpVtbl->CreateCommandSignature(device, desc, root_signature, __uuidof(ID3D12CommandSignature), (void**)out);
}
static inline void D3D12GetResourceTiling(D3D12Device device, void* tiled_resource, UINT* num_tiles_for_entire_resource, D3D12_PACKED_MIP_INFO* packed_mip_desc, D3D12_TILE_SHAPE* standard_tile_shape_for_non_packed_mips, UINT* num_subresource_tilings, UINT first_subresource_tiling_to_get, D3D12_SUBRESOURCE_TILING* subresource_tilings_for_non_packed_mips)
{
device->lpVtbl->GetResourceTiling(device, (ID3D12Resource*)tiled_resource, num_tiles_for_entire_resource, packed_mip_desc, standard_tile_shape_for_non_packed_mips, num_subresource_tilings, first_subresource_tiling_to_get, subresource_tilings_for_non_packed_mips);
}
static inline LUID D3D12GetAdapterLuid(D3D12Device device)
{
return device->lpVtbl->GetAdapterLuid(device);
}
static inline ULONG D3D12ReleasePipelineLibrary(D3D12PipelineLibrary pipeline_library)
{
return pipeline_library->lpVtbl->Release(pipeline_library);
}
static inline HRESULT D3D12StorePipeline(D3D12PipelineLibrary pipeline_library, LPCWSTR name, D3D12PipelineState pipeline)
{
return pipeline_library->lpVtbl->StorePipeline(pipeline_library, name, pipeline);
}
static inline HRESULT D3D12LoadGraphicsPipeline(D3D12PipelineLibrary pipeline_library, LPCWSTR name, D3D12_GRAPHICS_PIPELINE_STATE_DESC* desc, ID3D12PipelineState** out)
{
return pipeline_library->lpVtbl->LoadGraphicsPipeline(pipeline_library, name, desc, __uuidof(ID3D12PipelineState), (void**)out);
}
static inline HRESULT D3D12LoadComputePipeline(D3D12PipelineLibrary pipeline_library, LPCWSTR name, D3D12_COMPUTE_PIPELINE_STATE_DESC* desc, ID3D12PipelineState** out)
{
return pipeline_library->lpVtbl->LoadComputePipeline(pipeline_library, name, desc, __uuidof(ID3D12PipelineState), (void**)out);
}
static inline SIZE_T D3D12GetSerializedSize(D3D12PipelineLibrary pipeline_library)
{
return pipeline_library->lpVtbl->GetSerializedSize(pipeline_library);
}
static inline HRESULT D3D12Serialize(D3D12PipelineLibrary pipeline_library, void* data, SIZE_T data_size_in_bytes)
{
return pipeline_library->lpVtbl->Serialize(pipeline_library, data, data_size_in_bytes);
}
static inline ULONG D3D12ReleaseDebug(D3D12Debug debug)
{
return debug->lpVtbl->Release(debug);
}
static inline void D3D12EnableDebugLayer(D3D12Debug debug)
{
debug->lpVtbl->EnableDebugLayer(debug);
}
static inline ULONG D3D12ReleaseDebugDevice(D3D12DebugDevice debug_device)
{
return debug_device->lpVtbl->Release(debug_device);
}
static inline HRESULT D3D12SetDebugDeviceFeatureMask(D3D12DebugDevice debug_device, D3D12_DEBUG_FEATURE mask)
{
return debug_device->lpVtbl->SetFeatureMask(debug_device, mask);
}
static inline D3D12_DEBUG_FEATURE D3D12GetDebugDeviceFeatureMask(D3D12DebugDevice debug_device)
{
return debug_device->lpVtbl->GetFeatureMask(debug_device);
}
static inline HRESULT D3D12ReportLiveDeviceObjects(D3D12DebugDevice debug_device, D3D12_RLDO_FLAGS flags)
{
return debug_device->lpVtbl->ReportLiveDeviceObjects(debug_device, flags);
}
static inline ULONG D3D12ReleaseDebugCommandQueue(D3D12DebugCommandQueue debug_command_queue)
{
return debug_command_queue->lpVtbl->Release(debug_command_queue);
}
static inline BOOL D3D12AssertDebugCommandQueueResourceState(D3D12DebugCommandQueue debug_command_queue, void* resource, UINT subresource, UINT state)
{
return debug_command_queue->lpVtbl->AssertResourceState(debug_command_queue, (ID3D12Resource*)resource, subresource, state);
}
static inline ULONG D3D12ReleaseDebugCommandList(D3D12DebugCommandList debug_command_list)
{
return debug_command_list->lpVtbl->Release(debug_command_list);
}
static inline BOOL D3D12AssertDebugCommandListResourceState(D3D12DebugCommandList debug_command_list, void* resource, UINT subresource, UINT state)
{
return debug_command_list->lpVtbl->AssertResourceState(debug_command_list, (ID3D12Resource*)resource, subresource, state);
}
static inline HRESULT D3D12SetDebugCommandListFeatureMask(D3D12DebugCommandList debug_command_list, D3D12_DEBUG_FEATURE mask)
{
return debug_command_list->lpVtbl->SetFeatureMask(debug_command_list, mask);
}
static inline D3D12_DEBUG_FEATURE D3D12GetDebugCommandListFeatureMask(D3D12DebugCommandList debug_command_list)
{
return debug_command_list->lpVtbl->GetFeatureMask(debug_command_list);
}
static inline ULONG D3D12ReleaseInfoQueue(D3D12InfoQueue info_queue)
{
return info_queue->lpVtbl->Release(info_queue);
}
static inline HRESULT D3D12SetMessageCountLimit(D3D12InfoQueue info_queue, UINT64 message_count_limit)
{
return info_queue->lpVtbl->SetMessageCountLimit(info_queue, message_count_limit);
}
static inline void D3D12ClearStoredMessages(D3D12InfoQueue info_queue)
{
info_queue->lpVtbl->ClearStoredMessages(info_queue);
}
static inline HRESULT D3D12GetMessageA(D3D12InfoQueue info_queue, UINT64 message_index, D3D12_MESSAGE* message, SIZE_T* message_byte_length)
{
return info_queue->lpVtbl->GetMessageA(info_queue, message_index, message, message_byte_length);
}
static inline UINT64 D3D12GetNumMessagesAllowedByStorageFilter(D3D12InfoQueue info_queue)
{
return info_queue->lpVtbl->GetNumMessagesAllowedByStorageFilter(info_queue);
}
static inline UINT64 D3D12GetNumMessagesDeniedByStorageFilter(D3D12InfoQueue info_queue)
{
return info_queue->lpVtbl->GetNumMessagesDeniedByStorageFilter(info_queue);
}
static inline UINT64 D3D12GetNumStoredMessages(D3D12InfoQueue info_queue)
{
return info_queue->lpVtbl->GetNumStoredMessages(info_queue);
}
static inline UINT64 D3D12GetNumStoredMessagesAllowedByRetrievalFilter(D3D12InfoQueue info_queue)
{
return info_queue->lpVtbl->GetNumStoredMessagesAllowedByRetrievalFilter(info_queue);
}
static inline UINT64 D3D12GetNumMessagesDiscardedByMessageCountLimit(D3D12InfoQueue info_queue)
{
return info_queue->lpVtbl->GetNumMessagesDiscardedByMessageCountLimit(info_queue);
}
static inline UINT64 D3D12GetMessageCountLimit(D3D12InfoQueue info_queue)
{
return info_queue->lpVtbl->GetMessageCountLimit(info_queue);
}
static inline HRESULT D3D12AddStorageFilterEntries(D3D12InfoQueue info_queue, D3D12_INFO_QUEUE_FILTER* filter)
{
return info_queue->lpVtbl->AddStorageFilterEntries(info_queue, filter);
}
static inline HRESULT D3D12GetStorageFilter(D3D12InfoQueue info_queue, D3D12_INFO_QUEUE_FILTER* filter, SIZE_T* filter_byte_length)
{
return info_queue->lpVtbl->GetStorageFilter(info_queue, filter, filter_byte_length);
}
static inline void D3D12ClearStorageFilter(D3D12InfoQueue info_queue)
{
info_queue->lpVtbl->ClearStorageFilter(info_queue);
}
static inline HRESULT D3D12PushEmptyStorageFilter(D3D12InfoQueue info_queue)
{
return info_queue->lpVtbl->PushEmptyStorageFilter(info_queue);
}
static inline HRESULT D3D12PushCopyOfStorageFilter(D3D12InfoQueue info_queue)
{
return info_queue->lpVtbl->PushCopyOfStorageFilter(info_queue);
}
static inline HRESULT D3D12PushStorageFilter(D3D12InfoQueue info_queue, D3D12_INFO_QUEUE_FILTER* filter)
{
return info_queue->lpVtbl->PushStorageFilter(info_queue, filter);
}
static inline void D3D12PopStorageFilter(D3D12InfoQueue info_queue)
{
info_queue->lpVtbl->PopStorageFilter(info_queue);
}
static inline UINT D3D12GetStorageFilterStackSize(D3D12InfoQueue info_queue)
{
return info_queue->lpVtbl->GetStorageFilterStackSize(info_queue);
}
static inline HRESULT D3D12AddRetrievalFilterEntries(D3D12InfoQueue info_queue, D3D12_INFO_QUEUE_FILTER* filter)
{
return info_queue->lpVtbl->AddRetrievalFilterEntries(info_queue, filter);
}
static inline HRESULT D3D12GetRetrievalFilter(D3D12InfoQueue info_queue, D3D12_INFO_QUEUE_FILTER* filter, SIZE_T* filter_byte_length)
{
return info_queue->lpVtbl->GetRetrievalFilter(info_queue, filter, filter_byte_length);
}
static inline void D3D12ClearRetrievalFilter(D3D12InfoQueue info_queue)
{
info_queue->lpVtbl->ClearRetrievalFilter(info_queue);
}
static inline HRESULT D3D12PushEmptyRetrievalFilter(D3D12InfoQueue info_queue)
{
return info_queue->lpVtbl->PushEmptyRetrievalFilter(info_queue);
}
static inline HRESULT D3D12PushCopyOfRetrievalFilter(D3D12InfoQueue info_queue)
{
return info_queue->lpVtbl->PushCopyOfRetrievalFilter(info_queue);
}
static inline HRESULT D3D12PushRetrievalFilter(D3D12InfoQueue info_queue, D3D12_INFO_QUEUE_FILTER* filter)
{
return info_queue->lpVtbl->PushRetrievalFilter(info_queue, filter);
}
static inline void D3D12PopRetrievalFilter(D3D12InfoQueue info_queue)
{
info_queue->lpVtbl->PopRetrievalFilter(info_queue);
}
static inline UINT D3D12GetRetrievalFilterStackSize(D3D12InfoQueue info_queue)
{
return info_queue->lpVtbl->GetRetrievalFilterStackSize(info_queue);
}
static inline HRESULT D3D12AddMessage(D3D12InfoQueue info_queue, D3D12_MESSAGE_CATEGORY category, D3D12_MESSAGE_SEVERITY severity, D3D12_MESSAGE_ID i_d, LPCSTR description)
{
return info_queue->lpVtbl->AddMessage(info_queue, category, severity, i_d, description);
}
static inline HRESULT D3D12AddApplicationMessage(D3D12InfoQueue info_queue, D3D12_MESSAGE_SEVERITY severity, LPCSTR description)
{
return info_queue->lpVtbl->AddApplicationMessage(info_queue, severity, description);
}
static inline HRESULT D3D12SetBreakOnCategory(D3D12InfoQueue info_queue, D3D12_MESSAGE_CATEGORY category, BOOL b_enable)
{
return info_queue->lpVtbl->SetBreakOnCategory(info_queue, category, b_enable);
}
static inline HRESULT D3D12SetBreakOnSeverity(D3D12InfoQueue info_queue, D3D12_MESSAGE_SEVERITY severity, BOOL b_enable)
{
return info_queue->lpVtbl->SetBreakOnSeverity(info_queue, severity, b_enable);
}
static inline HRESULT D3D12SetBreakOnID(D3D12InfoQueue info_queue, D3D12_MESSAGE_ID i_d, BOOL b_enable)
{
return info_queue->lpVtbl->SetBreakOnID(info_queue, i_d, b_enable);
}
static inline BOOL D3D12GetBreakOnCategory(D3D12InfoQueue info_queue, D3D12_MESSAGE_CATEGORY category)
{
return info_queue->lpVtbl->GetBreakOnCategory(info_queue, category);
}
static inline BOOL D3D12GetBreakOnSeverity(D3D12InfoQueue info_queue, D3D12_MESSAGE_SEVERITY severity)
{
return info_queue->lpVtbl->GetBreakOnSeverity(info_queue, severity);
}
static inline BOOL D3D12GetBreakOnID(D3D12InfoQueue info_queue, D3D12_MESSAGE_ID i_d)
{
return info_queue->lpVtbl->GetBreakOnID(info_queue, i_d);
}
static inline void D3D12SetMuteDebugOutput(D3D12InfoQueue info_queue, BOOL b_mute)
{
info_queue->lpVtbl->SetMuteDebugOutput(info_queue, b_mute);
}
static inline BOOL D3D12GetMuteDebugOutput(D3D12InfoQueue info_queue)
{
return info_queue->lpVtbl->GetMuteDebugOutput(info_queue);
}
/* end of auto-generated */
static inline HRESULT D3D12GetDebugInterface_(D3D12Debug* out )
{
return D3D12GetDebugInterface(__uuidof(ID3D12Debug), (void**)out);
}
static inline HRESULT D3D12CreateDevice_(DXGIAdapter adapter, D3D_FEATURE_LEVEL MinimumFeatureLevel, D3D12Device* out)
{
return D3D12CreateDevice((IUnknown*)adapter, MinimumFeatureLevel, __uuidof(ID3D12Device), (void**)out);
}
static inline HRESULT D3D12CreateGraphicsCommandList(D3D12Device device, UINT node_mask, D3D12_COMMAND_LIST_TYPE type, D3D12CommandAllocator command_allocator, D3D12PipelineState initial_state, D3D12GraphicsCommandList* out)
{
return device->lpVtbl->CreateCommandList(device, node_mask, type, command_allocator, initial_state, __uuidof(ID3D12GraphicsCommandList), (void**)out);
}
static inline void D3D12ClearRenderTargetView(D3D12GraphicsCommandList command_list, D3D12_CPU_DESCRIPTOR_HANDLE render_target_view, const FLOAT colorRGBA[4], UINT num_rects, const D3D12_RECT *rects)
{
command_list->lpVtbl->ClearRenderTargetView(command_list, render_target_view, colorRGBA, num_rects, rects);
}
static inline void D3D12ExecuteCommandLists(D3D12CommandQueue command_queue, UINT num_command_lists, const D3D12CommandList* command_lists)
{
command_queue->lpVtbl->ExecuteCommandLists(command_queue, num_command_lists, command_lists);
}
static inline void D3D12ExecuteGraphicsCommandLists(D3D12CommandQueue command_queue, UINT num_command_lists, const D3D12GraphicsCommandList* command_lists)
{
command_queue->lpVtbl->ExecuteCommandLists(command_queue, num_command_lists, (ID3D12CommandList*const *)command_lists);
}
static inline HRESULT DXGIGetSwapChainBuffer(DXGISwapChain swapchain, UINT buffer, D3D12Resource* surface)
{
return swapchain->lpVtbl->GetBuffer(swapchain, buffer, __uuidof(ID3D12Resource), (void **)surface);
}
static inline void D3D12SetDescriptorHeaps(D3D12GraphicsCommandList command_list, UINT num_descriptor_heaps, const D3D12DescriptorHeap* descriptor_heaps)
{
command_list->lpVtbl->SetDescriptorHeaps(command_list, num_descriptor_heaps, descriptor_heaps);
}
#if 0 /* function prototype is wrong ... */
static inline D3D12_CPU_DESCRIPTOR_HANDLE D3D12GetCPUDescriptorHandleForHeapStart(D3D12DescriptorHeap descriptor_heap)
{
return descriptor_heap->lpVtbl->GetCPUDescriptorHandleForHeapStart(descriptor_heap);
}
static inline D3D12_GPU_DESCRIPTOR_HANDLE D3D12GetGPUDescriptorHandleForHeapStart(D3D12DescriptorHeap descriptor_heap)
{
return descriptor_heap->lpVtbl->GetGPUDescriptorHandleForHeapStart(descriptor_heap);
}
#else
static inline D3D12_CPU_DESCRIPTOR_HANDLE D3D12GetCPUDescriptorHandleForHeapStart(D3D12DescriptorHeap descriptor_heap)
{
D3D12_CPU_DESCRIPTOR_HANDLE out;
((void (STDMETHODCALLTYPE *)(ID3D12DescriptorHeap*, D3D12_CPU_DESCRIPTOR_HANDLE*))
descriptor_heap->lpVtbl->GetCPUDescriptorHandleForHeapStart)(descriptor_heap, &out);
return out;
}
static inline D3D12_GPU_DESCRIPTOR_HANDLE D3D12GetGPUDescriptorHandleForHeapStart(D3D12DescriptorHeap descriptor_heap)
{
D3D12_GPU_DESCRIPTOR_HANDLE out;
((void (STDMETHODCALLTYPE *)(ID3D12DescriptorHeap*, D3D12_GPU_DESCRIPTOR_HANDLE*))
descriptor_heap->lpVtbl->GetGPUDescriptorHandleForHeapStart)(descriptor_heap, &out);
return out;
}
#endif
/* internal */
typedef struct d3d12_vertex_t
{
float position[2];
float texcoord[2];
float color[4];
} d3d12_vertex_t;
typedef struct
{
D3D12DescriptorHeap handle; /* descriptor pool */
D3D12_DESCRIPTOR_HEAP_DESC desc;
D3D12_CPU_DESCRIPTOR_HANDLE cpu; /* descriptor */
D3D12_GPU_DESCRIPTOR_HANDLE gpu; /* descriptor */
UINT stride;
UINT count;
}d3d12_descriptor_heap_t;
typedef struct
{
D3D12Resource handle;
D3D12Resource upload_buffer;
D3D12_RESOURCE_DESC desc;
D3D12_GPU_DESCRIPTOR_HANDLE gpu_descriptor;
D3D12_PLACED_SUBRESOURCE_FOOTPRINT layout;
UINT num_rows;
UINT64 row_size_in_bytes;
UINT64 total_bytes;
bool dirty;
}d3d12_texture_t;
typedef struct
{
unsigned cur_mon_id;
DXGIFactory factory;
DXGIAdapter adapter;
D3D12Device device;
struct
{
D3D12CommandQueue handle;
D3D12CommandAllocator allocator;
D3D12GraphicsCommandList cmd;
D3D12Fence fence;
HANDLE fenceEvent;
UINT64 fenceValue;
}queue;
struct
{
D3D12PipelineState handle;
D3D12RootSignature rootSignature; /* descriptor layout */
d3d12_descriptor_heap_t srv_heap; /* ShaderResouceView descritor heap */
d3d12_descriptor_heap_t rtv_heap; /* RenderTargetView descritor heap */
}pipe;
struct
{
DXGISwapChain handle;
D3D12Resource renderTargets[2];
D3D12_CPU_DESCRIPTOR_HANDLE desc_handles[2];
D3D12_VIEWPORT viewport;
D3D12_RECT scissorRect;
float clearcolor[4];
int frame_index;
bool vsync;
}chain;
struct
{
D3D12Resource vbo;
D3D12_VERTEX_BUFFER_VIEW vbo_view;
d3d12_texture_t tex;
bool rgb32;
}frame;
struct
{
D3D12Resource vbo;
D3D12_VERTEX_BUFFER_VIEW vbo_view;
d3d12_texture_t tex;
float alpha;
bool enabled;
bool fullscreen;
}menu;
#ifdef DEBUG
D3D12Debug debugController;
#endif
} d3d12_video_t;
bool d3d12_init_context(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_upload_texture(D3D12GraphicsCommandList cmd, d3d12_texture_t* texture);
static inline d3d12_transition(D3D12GraphicsCommandList cmd, D3D12Resource resource,
D3D12_RESOURCE_STATES state_before, D3D12_RESOURCE_STATES state_after)
{
D3D12_RESOURCE_BARRIER barrier =
{
.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION,
.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE,
.Transition.pResource = resource,
.Transition.StateBefore = state_before,
.Transition.StateAfter = state_after,
.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES,
};
D3D12ResourceBarrier(cmd, 1, &barrier);
}

View File

@ -0,0 +1,88 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2014-2018 - Ali Bouhlel
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <dynamic/dylib.h>
#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)
{
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;
while (!d3dcompiler_dll && *dll_name)
d3dcompiler_dll = dylib_load(*dll_name++);
if (d3dcompiler_dll)
{
static pD3DCompile fp;
if (!fp)
fp = (pD3DCompile)dylib_proc(d3dcompiler_dll, "D3DCompile");
if (fp)
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)
{
D3DBlob error_msg;
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)))
return false;
if (error_msg)
{
RARCH_ERR("D3DCompile failed :\n%s\n", (const char *)D3DGetBufferPointer(error_msg));
Release(error_msg);
return false;
}
return true;
}

View File

@ -0,0 +1,88 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2014-2018 - Ali Bouhlel
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#ifdef __MINGW32__
#define __REQUIRED_RPCNDR_H_VERSION__ 475
#define _In_
#define _In_opt_
#define _Null_
#define _Out_writes_bytes_opt_(s)
#endif
#define CINTERFACE
#include <d3dcommon.h>
#include <d3dcompiler.h>
#ifndef countof
#define countof(a) (sizeof(a)/ sizeof(*a))
#endif
#ifndef __uuidof
#define __uuidof(type) &IID_##type
#endif
#ifndef COM_RELEASE_DECLARED
#define COM_RELEASE_DECLARED
#if defined(__cplusplus) && !defined(CINTERFACE)
static inline ULONG Release(IUnknown* object)
{
return object->Release();
}
#else
static inline ULONG Release(void* object)
{
return ((IUnknown*)object)->lpVtbl->Release(object);
}
#endif
#endif
/* auto-generated */
typedef ID3DBlob* D3DBlob;
typedef ID3DDestructionNotifier* D3DDestructionNotifier;
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)
{
return destruction_notifier->lpVtbl->Release(destruction_notifier);
}
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);
}
static inline HRESULT D3DUnregisterDestructionCallback(D3DDestructionNotifier destruction_notifier, UINT 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);

39
gfx/common/dxgi_common.c Normal file
View File

@ -0,0 +1,39 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2014-2018 - Ali Bouhlel
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <dynamic/dylib.h>
#include "dxgi_common.h"
HRESULT WINAPI CreateDXGIFactory1(REFIID riid, void **ppFactory)
{
static dylib_t dxgi_dll;
static HRESULT (WINAPI *fp)(REFIID, void **);
if(!dxgi_dll)
dxgi_dll = dylib_load("dxgi.dll");
if(!dxgi_dll)
return TYPE_E_CANTLOADLIBRARY;
if(!fp)
fp = (HRESULT (WINAPI *)(REFIID, void **))dylib_proc(dxgi_dll, "CreateDXGIFactory1");
if(!fp)
return TYPE_E_CANTLOADLIBRARY;
return fp(riid, ppFactory);
}

450
gfx/common/dxgi_common.h Normal file
View File

@ -0,0 +1,450 @@
#pragma once
#ifdef __MINGW32__
#define __REQUIRED_RPCNDR_H_VERSION__ 475
#define _In_
#define _In_opt_
#define _Null_
#define _Out_writes_bytes_opt_(s)
#endif
#define CINTERFACE
#include <dxgi1_5.h>
#ifndef countof
#define countof(a) (sizeof(a)/ sizeof(*a))
#endif
#ifndef __uuidof
#define __uuidof(type) &IID_##type
#endif
#ifndef COM_RELEASE_DECLARED
#define COM_RELEASE_DECLARED
#if defined(__cplusplus) && !defined(CINTERFACE)
static inline ULONG Release(IUnknown* object)
{
return object->Release();
}
#else
static inline ULONG Release(void* object)
{
return ((IUnknown*)object)->lpVtbl->Release(object);
}
#endif
#endif
/* auto-generated */
typedef IDXGIObject* DXGIObject;
typedef IDXGIDeviceSubObject* DXGIDeviceSubObject;
typedef IDXGIResource* DXGIResource;
typedef IDXGIKeyedMutex* DXGIKeyedMutex;
typedef IDXGISurface1* DXGISurface;
typedef IDXGIOutput* DXGIOutput;
typedef IDXGIDevice* DXGIDevice;
typedef IDXGIFactory1* DXGIFactory;
typedef IDXGIAdapter1* DXGIAdapter;
typedef IDXGIDisplayControl* DXGIDisplayControl;
typedef IDXGIOutputDuplication* DXGIOutputDuplication;
typedef IDXGIDecodeSwapChain* DXGIDecodeSwapChain;
typedef IDXGIFactoryMedia* DXGIFactoryMedia;
typedef IDXGISwapChainMedia* DXGISwapChainMedia;
typedef IDXGISwapChain3* DXGISwapChain;
static inline ULONG DXGIReleaseDeviceSubObject(DXGIDeviceSubObject device_sub_object)
{
return device_sub_object->lpVtbl->Release(device_sub_object);
}
static inline HRESULT DXGIGetSharedHandle(void* resource, HANDLE* shared_handle)
{
return ((IDXGIResource*)resource)->lpVtbl->GetSharedHandle(resource, shared_handle);
}
static inline HRESULT DXGIGetUsage(void* resource, DXGI_USAGE* usage)
{
return ((IDXGIResource*)resource)->lpVtbl->GetUsage(resource, usage);
}
static inline HRESULT DXGISetEvictionPriority(void* resource, UINT eviction_priority)
{
return ((IDXGIResource*)resource)->lpVtbl->SetEvictionPriority(resource, eviction_priority);
}
static inline HRESULT DXGIGetEvictionPriority(void* resource, UINT* eviction_priority)
{
return ((IDXGIResource*)resource)->lpVtbl->GetEvictionPriority(resource, eviction_priority);
}
static inline ULONG DXGIReleaseKeyedMutex(DXGIKeyedMutex keyed_mutex)
{
return keyed_mutex->lpVtbl->Release(keyed_mutex);
}
static inline HRESULT DXGIAcquireSync(DXGIKeyedMutex keyed_mutex, UINT64 key, DWORD dw_milliseconds)
{
return keyed_mutex->lpVtbl->AcquireSync(keyed_mutex, key, dw_milliseconds);
}
static inline HRESULT DXGIReleaseSync(DXGIKeyedMutex keyed_mutex, UINT64 key)
{
return keyed_mutex->lpVtbl->ReleaseSync(keyed_mutex, key);
}
static inline ULONG DXGIReleaseSurface(DXGISurface surface)
{
return surface->lpVtbl->Release(surface);
}
static inline HRESULT DXGIMap(DXGISurface surface, DXGI_MAPPED_RECT* locked_rect, UINT map_flags)
{
return surface->lpVtbl->Map(surface, locked_rect, map_flags);
}
static inline HRESULT DXGIUnmap(DXGISurface surface)
{
return surface->lpVtbl->Unmap(surface);
}
static inline HRESULT DXGIGetDC(DXGISurface surface, BOOL discard, HDC* hdc)
{
return surface->lpVtbl->GetDC(surface, discard, hdc);
}
static inline HRESULT DXGIReleaseDC(DXGISurface surface, RECT* dirty_rect)
{
return surface->lpVtbl->ReleaseDC(surface, dirty_rect);
}
static inline ULONG DXGIReleaseOutput(DXGIOutput output)
{
return output->lpVtbl->Release(output);
}
static inline HRESULT DXGIGetDisplayModeList(DXGIOutput output, DXGI_FORMAT enum_format, UINT flags, UINT* num_modes, DXGI_MODE_DESC* desc)
{
return output->lpVtbl->GetDisplayModeList(output, enum_format, flags, num_modes, desc);
}
static inline HRESULT DXGIFindClosestMatchingMode(DXGIOutput output, DXGI_MODE_DESC* mode_to_match, DXGI_MODE_DESC* closest_match, void* concerned_device)
{
return output->lpVtbl->FindClosestMatchingMode(output, mode_to_match, closest_match, (IUnknown*)concerned_device);
}
static inline HRESULT DXGIWaitForVBlank(DXGIOutput output)
{
return output->lpVtbl->WaitForVBlank(output);
}
static inline HRESULT DXGITakeOwnership(DXGIOutput output, void* device, BOOL exclusive)
{
return output->lpVtbl->TakeOwnership(output, (IUnknown*)device, exclusive);
}
static inline void DXGIReleaseOwnership(DXGIOutput output)
{
output->lpVtbl->ReleaseOwnership(output);
}
static inline HRESULT DXGIGetGammaControlCapabilities(DXGIOutput output, DXGI_GAMMA_CONTROL_CAPABILITIES* gamma_caps)
{
return output->lpVtbl->GetGammaControlCapabilities(output, gamma_caps);
}
static inline HRESULT DXGISetGammaControl(DXGIOutput output, DXGI_GAMMA_CONTROL* array)
{
return output->lpVtbl->SetGammaControl(output, array);
}
static inline HRESULT DXGIGetGammaControl(DXGIOutput output, DXGI_GAMMA_CONTROL* array)
{
return output->lpVtbl->GetGammaControl(output, array);
}
static inline HRESULT DXGISetDisplaySurface(DXGIOutput output, DXGISurface scanout_surface)
{
return output->lpVtbl->SetDisplaySurface(output, (IDXGISurface*)scanout_surface);
}
static inline HRESULT DXGIGetDisplaySurfaceData(DXGIOutput output, DXGISurface destination)
{
return output->lpVtbl->GetDisplaySurfaceData(output, (IDXGISurface*)destination);
}
static inline ULONG DXGIReleaseDevice(DXGIDevice device)
{
return device->lpVtbl->Release(device);
}
static inline HRESULT DXGICreateSurface(DXGIDevice device, DXGI_SURFACE_DESC* desc, UINT num_surfaces, DXGI_USAGE usage, DXGI_SHARED_RESOURCE* shared_resource, DXGISurface* surface)
{
return device->lpVtbl->CreateSurface(device, desc, num_surfaces, usage, shared_resource, (IDXGISurface**)surface);
}
static inline HRESULT DXGISetGPUThreadPriority(DXGIDevice device, INT priority)
{
return device->lpVtbl->SetGPUThreadPriority(device, priority);
}
static inline HRESULT DXGIGetGPUThreadPriority(DXGIDevice device, INT* priority)
{
return device->lpVtbl->GetGPUThreadPriority(device, priority);
}
static inline ULONG DXGIReleaseFactory(DXGIFactory factory)
{
return factory->lpVtbl->Release(factory);
}
static inline HRESULT DXGIMakeWindowAssociation(DXGIFactory factory, HWND window_handle, UINT flags)
{
return factory->lpVtbl->MakeWindowAssociation(factory, window_handle, flags);
}
static inline HRESULT DXGIGetWindowAssociation(DXGIFactory factory, HWND* window_handle)
{
return factory->lpVtbl->GetWindowAssociation(factory, window_handle);
}
static inline HRESULT DXGICreateSwapChain(DXGIFactory factory, void* device, DXGI_SWAP_CHAIN_DESC* desc, DXGISwapChain* swap_chain)
{
return factory->lpVtbl->CreateSwapChain(factory, (IUnknown*)device, desc, (IDXGISwapChain**)swap_chain);
}
static inline HRESULT DXGICreateSoftwareAdapter(DXGIFactory factory, HMODULE module, DXGIAdapter* adapter)
{
return factory->lpVtbl->CreateSoftwareAdapter(factory, module, (IDXGIAdapter**)adapter);
}
static inline HRESULT DXGIEnumAdapters(DXGIFactory factory, UINT id, DXGIAdapter* adapter)
{
return factory->lpVtbl->EnumAdapters1(factory, id, adapter);
}
static inline BOOL DXGIIsCurrent(DXGIFactory factory)
{
return factory->lpVtbl->IsCurrent(factory);
}
static inline ULONG DXGIReleaseAdapter(DXGIAdapter adapter)
{
return adapter->lpVtbl->Release(adapter);
}
static inline HRESULT DXGIEnumOutputs(DXGIAdapter adapter, UINT id, DXGIOutput* output)
{
return adapter->lpVtbl->EnumOutputs(adapter, id, output);
}
static inline HRESULT DXGICheckInterfaceSupport(DXGIAdapter adapter, REFGUID interface_name, LARGE_INTEGER* u_m_d_version)
{
return adapter->lpVtbl->CheckInterfaceSupport(adapter, interface_name, u_m_d_version);
}
static inline HRESULT DXGIGetAdapterDesc1(DXGIAdapter adapter, DXGI_ADAPTER_DESC1* desc)
{
return adapter->lpVtbl->GetDesc1(adapter, desc);
}
static inline ULONG DXGIReleaseDisplayControl(DXGIDisplayControl display_control)
{
return display_control->lpVtbl->Release(display_control);
}
static inline BOOL DXGIIsStereoEnabled(DXGIDisplayControl display_control)
{
return display_control->lpVtbl->IsStereoEnabled(display_control);
}
static inline void DXGISetStereoEnabled(DXGIDisplayControl display_control, BOOL enabled)
{
display_control->lpVtbl->SetStereoEnabled(display_control, enabled);
}
static inline ULONG DXGIReleaseOutputDuplication(DXGIOutputDuplication output_duplication)
{
return output_duplication->lpVtbl->Release(output_duplication);
}
static inline HRESULT DXGIAcquireNextFrame(DXGIOutputDuplication output_duplication, UINT timeout_in_milliseconds, DXGI_OUTDUPL_FRAME_INFO* frame_info, void* desktop_resource)
{
return output_duplication->lpVtbl->AcquireNextFrame(output_duplication, timeout_in_milliseconds, frame_info, (IDXGIResource**)desktop_resource);
}
static inline HRESULT DXGIGetFrameDirtyRects(DXGIOutputDuplication output_duplication, UINT dirty_rects_buffer_size, RECT* dirty_rects_buffer, UINT* dirty_rects_buffer_size_required)
{
return output_duplication->lpVtbl->GetFrameDirtyRects(output_duplication, dirty_rects_buffer_size, dirty_rects_buffer, dirty_rects_buffer_size_required);
}
static inline HRESULT DXGIGetFrameMoveRects(DXGIOutputDuplication output_duplication, UINT move_rects_buffer_size, DXGI_OUTDUPL_MOVE_RECT* move_rect_buffer, UINT* move_rects_buffer_size_required)
{
return output_duplication->lpVtbl->GetFrameMoveRects(output_duplication, move_rects_buffer_size, move_rect_buffer, move_rects_buffer_size_required);
}
static inline HRESULT DXGIGetFramePointerShape(DXGIOutputDuplication output_duplication, UINT pointer_shape_buffer_size, void* pointer_shape_buffer, UINT* pointer_shape_buffer_size_required, DXGI_OUTDUPL_POINTER_SHAPE_INFO* pointer_shape_info)
{
return output_duplication->lpVtbl->GetFramePointerShape(output_duplication, pointer_shape_buffer_size, pointer_shape_buffer, pointer_shape_buffer_size_required, pointer_shape_info);
}
static inline HRESULT DXGIMapDesktopSurface(DXGIOutputDuplication output_duplication, DXGI_MAPPED_RECT* locked_rect)
{
return output_duplication->lpVtbl->MapDesktopSurface(output_duplication, locked_rect);
}
static inline HRESULT DXGIUnMapDesktopSurface(DXGIOutputDuplication output_duplication)
{
return output_duplication->lpVtbl->UnMapDesktopSurface(output_duplication);
}
static inline HRESULT DXGIReleaseFrame(DXGIOutputDuplication output_duplication)
{
return output_duplication->lpVtbl->ReleaseFrame(output_duplication);
}
static inline ULONG DXGIReleaseDecodeSwapChain(DXGIDecodeSwapChain decode_swap_chain)
{
return decode_swap_chain->lpVtbl->Release(decode_swap_chain);
}
static inline HRESULT DXGIPresentBuffer(DXGIDecodeSwapChain decode_swap_chain, UINT buffer_to_present, UINT sync_interval, UINT flags)
{
return decode_swap_chain->lpVtbl->PresentBuffer(decode_swap_chain, buffer_to_present, sync_interval, flags);
}
static inline HRESULT DXGISetSourceRect(DXGIDecodeSwapChain decode_swap_chain, RECT* rect)
{
return decode_swap_chain->lpVtbl->SetSourceRect(decode_swap_chain, rect);
}
static inline HRESULT DXGISetTargetRect(DXGIDecodeSwapChain decode_swap_chain, RECT* rect)
{
return decode_swap_chain->lpVtbl->SetTargetRect(decode_swap_chain, rect);
}
static inline HRESULT DXGISetDestSize(DXGIDecodeSwapChain decode_swap_chain, UINT width, UINT height)
{
return decode_swap_chain->lpVtbl->SetDestSize(decode_swap_chain, width, height);
}
static inline HRESULT DXGIGetSourceRect(DXGIDecodeSwapChain decode_swap_chain, RECT* rect)
{
return decode_swap_chain->lpVtbl->GetSourceRect(decode_swap_chain, rect);
}
static inline HRESULT DXGIGetTargetRect(DXGIDecodeSwapChain decode_swap_chain, RECT* rect)
{
return decode_swap_chain->lpVtbl->GetTargetRect(decode_swap_chain, rect);
}
static inline HRESULT DXGIGetDestSize(DXGIDecodeSwapChain decode_swap_chain, UINT* width, UINT* height)
{
return decode_swap_chain->lpVtbl->GetDestSize(decode_swap_chain, width, height);
}
static inline HRESULT DXGISetColorSpace(DXGIDecodeSwapChain decode_swap_chain, DXGI_MULTIPLANE_OVERLAY_YCbCr_FLAGS color_space)
{
return decode_swap_chain->lpVtbl->SetColorSpace(decode_swap_chain, color_space);
}
static inline DXGI_MULTIPLANE_OVERLAY_YCbCr_FLAGS DXGIGetColorSpace(DXGIDecodeSwapChain decode_swap_chain)
{
return decode_swap_chain->lpVtbl->GetColorSpace(decode_swap_chain);
}
static inline ULONG DXGIReleaseFactoryMedia(DXGIFactoryMedia factory_media)
{
return factory_media->lpVtbl->Release(factory_media);
}
static inline HRESULT DXGICreateSwapChainForCompositionSurfaceHandle(DXGIFactoryMedia factory_media, void* device, HANDLE h_surface, DXGI_SWAP_CHAIN_DESC1* desc, DXGIOutput restrict_to_output, DXGISwapChain* swap_chain)
{
return factory_media->lpVtbl->CreateSwapChainForCompositionSurfaceHandle(factory_media, (IUnknown*)device, h_surface, desc, restrict_to_output, (IDXGISwapChain1**)swap_chain);
}
static inline HRESULT DXGICreateDecodeSwapChainForCompositionSurfaceHandle(DXGIFactoryMedia factory_media, void* device, HANDLE h_surface, DXGI_DECODE_SWAP_CHAIN_DESC* desc, void* yuv_decode_buffers, DXGIOutput restrict_to_output, DXGIDecodeSwapChain* swap_chain)
{
return factory_media->lpVtbl->CreateDecodeSwapChainForCompositionSurfaceHandle(factory_media, (IUnknown*)device, h_surface, desc, (IDXGIResource*)yuv_decode_buffers, restrict_to_output, swap_chain);
}
static inline ULONG DXGIReleaseSwapChainMedia(DXGISwapChainMedia swap_chain_media)
{
return swap_chain_media->lpVtbl->Release(swap_chain_media);
}
static inline HRESULT DXGIGetFrameStatisticsMedia(DXGISwapChainMedia swap_chain_media, DXGI_FRAME_STATISTICS_MEDIA* stats)
{
return swap_chain_media->lpVtbl->GetFrameStatisticsMedia(swap_chain_media, stats);
}
static inline HRESULT DXGISetPresentDuration(DXGISwapChainMedia swap_chain_media, UINT duration)
{
return swap_chain_media->lpVtbl->SetPresentDuration(swap_chain_media, duration);
}
static inline HRESULT DXGICheckPresentDurationSupport(DXGISwapChainMedia swap_chain_media, UINT desired_present_duration, UINT* closest_smaller_present_duration, UINT* closest_larger_present_duration)
{
return swap_chain_media->lpVtbl->CheckPresentDurationSupport(swap_chain_media, desired_present_duration, closest_smaller_present_duration, closest_larger_present_duration);
}
static inline ULONG DXGIReleaseSwapChain(DXGISwapChain swap_chain)
{
return swap_chain->lpVtbl->Release(swap_chain);
}
static inline HRESULT DXGIPresent(DXGISwapChain swap_chain, UINT sync_interval, UINT flags)
{
return swap_chain->lpVtbl->Present(swap_chain, sync_interval, flags);
}
static inline HRESULT DXGIGetBuffer(DXGISwapChain swap_chain, UINT buffer, IDXGISurface** out)
{
return swap_chain->lpVtbl->GetBuffer(swap_chain, buffer, __uuidof(IDXGISurface), (void**)out);
}
static inline HRESULT DXGISetFullscreenState(DXGISwapChain swap_chain, BOOL fullscreen, DXGIOutput target)
{
return swap_chain->lpVtbl->SetFullscreenState(swap_chain, fullscreen, target);
}
static inline HRESULT DXGIGetFullscreenState(DXGISwapChain swap_chain, BOOL* fullscreen, DXGIOutput* target)
{
return swap_chain->lpVtbl->GetFullscreenState(swap_chain, fullscreen, target);
}
static inline HRESULT DXGIResizeBuffers(DXGISwapChain swap_chain, UINT buffer_count, UINT width, UINT height, DXGI_FORMAT new_format, UINT swap_chain_flags)
{
return swap_chain->lpVtbl->ResizeBuffers(swap_chain, buffer_count, width, height, new_format, swap_chain_flags);
}
static inline HRESULT DXGIResizeTarget(DXGISwapChain swap_chain, DXGI_MODE_DESC* new_target_parameters)
{
return swap_chain->lpVtbl->ResizeTarget(swap_chain, new_target_parameters);
}
static inline HRESULT DXGIGetContainingOutput(DXGISwapChain swap_chain, DXGIOutput* output)
{
return swap_chain->lpVtbl->GetContainingOutput(swap_chain, output);
}
static inline HRESULT DXGIGetFrameStatistics(DXGISwapChain swap_chain, DXGI_FRAME_STATISTICS* stats)
{
return swap_chain->lpVtbl->GetFrameStatistics(swap_chain, stats);
}
static inline HRESULT DXGIGetLastPresentCount(DXGISwapChain swap_chain, UINT* last_present_count)
{
return swap_chain->lpVtbl->GetLastPresentCount(swap_chain, last_present_count);
}
static inline HRESULT DXGIGetSwapChainDesc1(DXGISwapChain swap_chain, DXGI_SWAP_CHAIN_DESC1* desc)
{
return swap_chain->lpVtbl->GetDesc1(swap_chain, desc);
}
static inline HRESULT DXGIGetFullscreenDesc(DXGISwapChain swap_chain, DXGI_SWAP_CHAIN_FULLSCREEN_DESC* desc)
{
return swap_chain->lpVtbl->GetFullscreenDesc(swap_chain, desc);
}
static inline HRESULT DXGIGetHwnd(DXGISwapChain swap_chain, HWND* hwnd)
{
return swap_chain->lpVtbl->GetHwnd(swap_chain, hwnd);
}
static inline HRESULT DXGIPresent1(DXGISwapChain swap_chain, UINT sync_interval, UINT present_flags, DXGI_PRESENT_PARAMETERS* present_parameters)
{
return swap_chain->lpVtbl->Present1(swap_chain, sync_interval, present_flags, present_parameters);
}
static inline BOOL DXGIIsTemporaryMonoSupported(DXGISwapChain swap_chain)
{
return swap_chain->lpVtbl->IsTemporaryMonoSupported(swap_chain);
}
static inline HRESULT DXGIGetRestrictToOutput(DXGISwapChain swap_chain, DXGIOutput* restrict_to_output)
{
return swap_chain->lpVtbl->GetRestrictToOutput(swap_chain, restrict_to_output);
}
static inline HRESULT DXGISetBackgroundColor(DXGISwapChain swap_chain, DXGI_RGBA* color)
{
return swap_chain->lpVtbl->SetBackgroundColor(swap_chain, color);
}
static inline HRESULT DXGIGetBackgroundColor(DXGISwapChain swap_chain, DXGI_RGBA* color)
{
return swap_chain->lpVtbl->GetBackgroundColor(swap_chain, color);
}
static inline HRESULT DXGISetRotation(DXGISwapChain swap_chain, DXGI_MODE_ROTATION rotation)
{
return swap_chain->lpVtbl->SetRotation(swap_chain, rotation);
}
static inline HRESULT DXGIGetRotation(DXGISwapChain swap_chain, DXGI_MODE_ROTATION* rotation)
{
return swap_chain->lpVtbl->GetRotation(swap_chain, rotation);
}
static inline HRESULT DXGISetSourceSize(DXGISwapChain swap_chain, UINT width, UINT height)
{
return swap_chain->lpVtbl->SetSourceSize(swap_chain, width, height);
}
static inline HRESULT DXGIGetSourceSize(DXGISwapChain swap_chain, UINT* width, UINT* height)
{
return swap_chain->lpVtbl->GetSourceSize(swap_chain, width, height);
}
static inline HRESULT DXGISetMaximumFrameLatency(DXGISwapChain swap_chain, UINT max_latency)
{
return swap_chain->lpVtbl->SetMaximumFrameLatency(swap_chain, max_latency);
}
static inline HRESULT DXGIGetMaximumFrameLatency(DXGISwapChain swap_chain, UINT* max_latency)
{
return swap_chain->lpVtbl->GetMaximumFrameLatency(swap_chain, max_latency);
}
static inline HANDLE DXGIGetFrameLatencyWaitableObject(DXGISwapChain swap_chain)
{
return swap_chain->lpVtbl->GetFrameLatencyWaitableObject(swap_chain);
}
static inline HRESULT DXGISetMatrixTransform(DXGISwapChain swap_chain, DXGI_MATRIX_3X2_F* matrix)
{
return swap_chain->lpVtbl->SetMatrixTransform(swap_chain, matrix);
}
static inline HRESULT DXGIGetMatrixTransform(DXGISwapChain swap_chain, DXGI_MATRIX_3X2_F* matrix)
{
return swap_chain->lpVtbl->GetMatrixTransform(swap_chain, matrix);
}
static inline UINT DXGIGetCurrentBackBufferIndex(DXGISwapChain swap_chain)
{
return swap_chain->lpVtbl->GetCurrentBackBufferIndex(swap_chain);
}
static inline HRESULT DXGICheckColorSpaceSupport(DXGISwapChain swap_chain, DXGI_COLOR_SPACE_TYPE color_space, UINT* color_space_support)
{
return swap_chain->lpVtbl->CheckColorSpaceSupport(swap_chain, color_space, color_space_support);
}
static inline HRESULT DXGISetColorSpace1(DXGISwapChain swap_chain, DXGI_COLOR_SPACE_TYPE color_space)
{
return swap_chain->lpVtbl->SetColorSpace1(swap_chain, color_space);
}
/* end of auto-generated */
static inline HRESULT DXGICreateFactory(DXGIFactory* factory)
{
return CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)factory);
}

614
gfx/drivers/d3d11.c Normal file
View File

@ -0,0 +1,614 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2014-2018 - Ali Bouhlel
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <assert.h>
#include <string/stdstring.h>
#include "driver.h"
#include "verbosity.h"
#include "configuration.h"
#include "gfx/video_driver.h"
#include "gfx/common/win32_common.h"
#include "gfx/common/d3d11_common.h"
#include "gfx/common/dxgi_common.h"
#include "gfx/common/d3dcompiler_common.h"
typedef struct d3d11_vertex_t
{
float position[2];
float texcoord[2];
float color[4];
} d3d11_vertex_t;
typedef struct
{
unsigned cur_mon_id;
DXGISwapChain swapChain;
D3D11Device device;
D3D_FEATURE_LEVEL supportedFeatureLevel;
D3D11DeviceContext context;
D3D11RenderTargetView renderTargetView;
D3D11Buffer vertexBuffer;
D3D11InputLayout layout;
D3D11VertexShader vs;
D3D11PixelShader ps;
D3D11SamplerState sampler_nearest;
D3D11SamplerState sampler_linear;
D3D11Texture2D frame_default;
D3D11Texture2D frame_staging;
struct
{
D3D11Texture2D tex;
D3D11ShaderResourceView view;
D3D11Buffer vbo;
int width;
int height;
bool enabled;
bool fullscreen;
} menu;
int frame_width;
int frame_height;
D3D11ShaderResourceView frame_view;
float clearcolor[4];
bool vsync;
bool rgb32;
} d3d11_video_t;
static void* d3d11_gfx_init(const video_info_t* video,
const input_driver_t** input, void** input_data)
{
WNDCLASSEX wndclass = {0};
settings_t* settings = config_get_ptr();
gfx_ctx_input_t inp = {input, input_data};
d3d11_video_t* d3d11 = (d3d11_video_t*)calloc(1, sizeof(*d3d11));
if (!d3d11)
return NULL;
win32_window_reset();
win32_monitor_init();
wndclass.lpfnWndProc = WndProcD3D;
win32_window_init(&wndclass, true, NULL);
if (!win32_set_video_mode(d3d11, video->width, video->height, video->fullscreen))
{
RARCH_ERR("[D3D11]: win32_set_video_mode failed.\n");
goto error;
}
gfx_ctx_d3d.input_driver(NULL, settings->arrays.input_joypad_driver, input, input_data);
d3d11->rgb32 = video->rgb32;
d3d11->vsync = video->vsync;
{
UINT flags = 0;
D3D_FEATURE_LEVEL requested_feature_level = D3D_FEATURE_LEVEL_11_0;
DXGI_SWAP_CHAIN_DESC desc =
{
.BufferCount = 1,
.BufferDesc.Width = video->width,
.BufferDesc.Height = video->height,
.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM,
.BufferDesc.RefreshRate.Numerator = 60,
.BufferDesc.RefreshRate.Denominator = 1,
.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT,
.OutputWindow = main_window.hwnd,
.SampleDesc.Count = 1,
.SampleDesc.Quality = 0,
.Windowed = TRUE,
// .SwapEffect = DXGI_SWAP_EFFECT_DISCARD,
.SwapEffect = DXGI_SWAP_EFFECT_SEQUENTIAL,
// .SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL,
// .SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD,
};
//#ifdef DEBUG
flags |= D3D11_CREATE_DEVICE_DEBUG;
//#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);
}
// d3d = *device->lpVtbl;
// ctx = *context->lpVtbl;
// dxgi = *swapChain->lpVtbl;
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->frame_width = video->input_scale * RARCH_SCALE_BASE;
d3d11->frame_height = video->input_scale * RARCH_SCALE_BASE;
{
D3D11_TEXTURE2D_DESC desc =
{
.Width = d3d11->frame_width,
.Height = d3d11->frame_height,
.MipLevels = 1,
.ArraySize = 1,
.Format = DXGI_FORMAT_B8G8R8A8_UNORM,
// .Format = d3d11->rgb32? DXGI_FORMAT_B8G8R8X8_UNORM : DXGI_FORMAT_B5G6R5_UNORM,
.SampleDesc.Count = 1,
.SampleDesc.Quality = 0,
.Usage = D3D11_USAGE_DEFAULT,
.BindFlags = D3D11_BIND_SHADER_RESOURCE,
.CPUAccessFlags = 0,
.MiscFlags = 0,
};
D3D11_SHADER_RESOURCE_VIEW_DESC view_desc =
{
.Format = desc.Format,
.ViewDimension = D3D_SRV_DIMENSION_TEXTURE2D,
.Texture2D.MostDetailedMip = 0,
.Texture2D.MipLevels = -1,
};
D3D11CreateTexture2D(d3d11->device, &desc, NULL, &d3d11->frame_default);
D3D11CreateTexture2DShaderResourceView(d3d11->device, d3d11->frame_default, &view_desc, &d3d11->frame_view);
desc.Format = desc.Format;
desc.BindFlags = 0;
desc.Usage = D3D11_USAGE_STAGING;
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
D3D11CreateTexture2D(d3d11->device, &desc, NULL, &d3d11->frame_staging);
}
{
D3D11_SAMPLER_DESC desc =
{
.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR,
.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);
}
{
d3d11_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}},
};
{
D3D11_BUFFER_DESC desc =
{
.Usage = D3D11_USAGE_DYNAMIC,
.ByteWidth = sizeof(vertices),
.BindFlags = D3D11_BIND_VERTEX_BUFFER,
.StructureByteStride = 0, /* sizeof(Vertex) ? */
.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE,
};
D3D11_SUBRESOURCE_DATA vertexData = {vertices};
D3D11CreateBuffer(d3d11->device, &desc, &vertexData, &d3d11->vertexBuffer);
desc.Usage = D3D11_USAGE_IMMUTABLE;
desc.CPUAccessFlags = 0;
D3D11CreateBuffer(d3d11->device, &desc, &vertexData, &d3d11->menu.vbo);
}
D3D11SetPrimitiveTopology(d3d11->context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
}
{
D3DBlob vs_code;
D3DBlob ps_code;
static const char stock [] =
#include "d3d_shaders/opaque_sm5.hlsl.h"
;
D3D11_INPUT_ELEMENT_DESC desc[] =
{
{"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, offsetof(d3d11_vertex_t, position), D3D11_INPUT_PER_VERTEX_DATA, 0},
{"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, offsetof(d3d11_vertex_t, texcoord), D3D11_INPUT_PER_VERTEX_DATA, 0},
{"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, offsetof(d3d11_vertex_t, color), D3D11_INPUT_PER_VERTEX_DATA, 0},
};
d3d_compile(stock, sizeof(stock), "VSMain", "vs_5_0", &vs_code);
d3d_compile(stock, sizeof(stock), "PSMain", "ps_5_0", &ps_code);
D3D11CreateVertexShader(d3d11->device, D3DGetBufferPointer(vs_code), D3DGetBufferSize(vs_code),
NULL, &d3d11->vs);
D3D11CreatePixelShader(d3d11->device, D3DGetBufferPointer(ps_code), D3DGetBufferSize(ps_code),
NULL, &d3d11->ps);
D3D11CreateInputLayout(d3d11->device, desc, countof(desc),
D3DGetBufferPointer(vs_code), D3DGetBufferSize(vs_code), &d3d11->layout);
Release(vs_code);
Release(ps_code);
}
D3D11SetInputLayout(d3d11->context, d3d11->layout);
D3D11SetVShader(d3d11->context, d3d11->vs, NULL, 0);
D3D11SetPShader(d3d11->context, d3d11->ps, NULL, 0);
return d3d11;
error:
free(d3d11);
return NULL;
}
static bool d3d11_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)
{
(void)msg;
d3d11_video_t* d3d11 = (d3d11_video_t*)data;
#if 1
if(frame && width && height)
{
D3D11_MAPPED_SUBRESOURCE mapped_frame;
D3D11MapTexture2D(d3d11->context, d3d11->frame_staging, 0, D3D11_MAP_WRITE, 0, &mapped_frame);
{
int i, j;
if (d3d11->rgb32)
{
const uint8_t* in = frame;
uint8_t* out = mapped_frame.pData;
for (i = 0; i < height; i++)
{
memcpy(out, in, width * (d3d11->rgb32? 4 : 2));
in += pitch;
out += mapped_frame.RowPitch;
}
}
else
{
const uint16_t* in = frame;
uint32_t* out = mapped_frame.pData;
for (i = 0; i < height; i++)
{
for (j = 0; j < width; j++)
{
unsigned b = ((in[j] >> 11) & 0x1F);
unsigned g = ((in[j] >> 5) & 0x3F);
unsigned r = ((in[j] >> 0) & 0x1F);
out[j] = ((r >> 2) << 0) | (r << 3) |((g >> 4) << 8) | (g << 10) |((b >> 2) << 16) | (b << 19);
}
in += width;
out += mapped_frame.RowPitch / 4;
}
}
}
D3D11UnmapTexture2D(d3d11->context, d3d11->frame_staging, 0);
D3D11_BOX frame_box = {0, 0, 0, width, height, 1};
D3D11CopyTexture2DSubresourceRegion(d3d11->context, d3d11->frame_default, 0, 0 , 0 , 0,
d3d11->frame_staging, 0, &frame_box);
{
D3D11_MAPPED_SUBRESOURCE mapped_vbo;
D3D11MapBuffer(d3d11->context, d3d11->vertexBuffer, 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0,
&mapped_vbo);
{
d3d11_vertex_t* vbo = mapped_vbo.pData;
vbo[0].texcoord[0] = 0.0f * (width / (float)d3d11->frame_width);
vbo[0].texcoord[1] = 1.0f * (height / (float)d3d11->frame_height);
vbo[1].texcoord[0] = 0.0f * (width / (float)d3d11->frame_width);
vbo[1].texcoord[1] = 0.0f * (height / (float)d3d11->frame_height);
vbo[2].texcoord[0] = 1.0f * (width / (float)d3d11->frame_width);
vbo[2].texcoord[1] = 1.0f * (height / (float)d3d11->frame_height);
vbo[3].texcoord[0] = 1.0f * (width / (float)d3d11->frame_width);
vbo[3].texcoord[1] = 0.0f * (height / (float)d3d11->frame_height);
}
D3D11UnmapBuffer(d3d11->context, d3d11->vertexBuffer, 0);
}
}
D3D11ClearRenderTargetView(d3d11->context, d3d11->renderTargetView, d3d11->clearcolor);
{
UINT stride = sizeof(d3d11_vertex_t);
UINT offset = 0;
D3D11SetVertexBuffers(d3d11->context, 0, 1, &d3d11->vertexBuffer, &stride, &offset);
D3D11SetPShaderResources(d3d11->context, 0, 1, &d3d11->frame_view);
D3D11SetPShaderSamplers(d3d11->context, 0, 1, &d3d11->sampler_linear);
D3D11Draw(d3d11->context, 4, 0);
if (d3d11->menu.enabled)
{
D3D11SetVertexBuffers(d3d11->context, 0, 1, &d3d11->menu.vbo, &stride, &offset);
D3D11SetPShaderResources(d3d11->context, 0, 1, &d3d11->menu.view);
D3D11SetPShaderSamplers(d3d11->context, 0, 1, &d3d11->sampler_linear);
D3D11Draw(d3d11->context, 4, 0);
}
}
DXGIPresent(d3d11->swapChain, !!d3d11->vsync, 0);
#endif
if(msg && *msg)
gfx_ctx_d3d.update_window_title(NULL, video_info);
return true;
}
static void d3d11_gfx_set_nonblock_state(void* data, bool toggle)
{
d3d11_video_t* d3d11 = (d3d11_video_t*)data;
d3d11->vsync = !toggle;
}
static bool d3d11_gfx_alive(void* data)
{
(void)data;
bool quit;
bool resize;
unsigned width;
unsigned height;
win32_check_window(&quit, &resize, &width, &height);
return true;
}
static bool d3d11_gfx_focus(void* data)
{
return win32_has_focus();
}
static bool d3d11_gfx_suppress_screensaver(void* data, bool enable)
{
(void)data;
(void)enable;
return false;
}
static bool d3d11_gfx_has_windowed(void* data)
{
(void)data;
return true;
}
static void d3d11_gfx_free(void* data)
{
d3d11_video_t* d3d11 = (d3d11_video_t*)data;
if(d3d11->menu.tex)
Release(d3d11->menu.tex);
if(d3d11->menu.view)
Release(d3d11->menu.view);
Release(d3d11->menu.vbo);
Release(d3d11->sampler_nearest);
Release(d3d11->sampler_linear);
Release(d3d11->frame_view);
Release(d3d11->frame_default);
Release(d3d11->frame_staging);
Release(d3d11->ps);
Release(d3d11->vs);
Release(d3d11->vertexBuffer);
Release(d3d11->layout);
Release(d3d11->renderTargetView);
Release(d3d11->swapChain);
Release(d3d11->context);
Release(d3d11->device);
win32_monitor_from_window();
win32_destroy_window();
free(d3d11);
}
static bool d3d11_gfx_set_shader(void* data,
enum rarch_shader_type type, const char* path)
{
(void)data;
(void)type;
(void)path;
return false;
}
static void d3d11_gfx_set_rotation(void* data,
unsigned rotation)
{
(void)data;
(void)rotation;
}
static void d3d11_gfx_viewport_info(void* data,
struct video_viewport* vp)
{
(void)data;
(void)vp;
}
static bool d3d11_gfx_read_viewport(void* data, uint8_t* buffer, bool is_idle)
{
(void)data;
(void)buffer;
return true;
}
static void d3d11_set_menu_texture_frame(void* data,
const void* frame, bool rgb32, unsigned width, unsigned height,
float alpha)
{
d3d11_video_t* d3d11 = (d3d11_video_t*)data;
if (d3d11->menu.tex && (d3d11->menu.width != width || d3d11->menu.height != height))
{
Release(d3d11->menu.tex);
d3d11->menu.tex = NULL;
}
if (!d3d11->menu.tex)
{
d3d11->menu.width = width;
d3d11->menu.height = height;
D3D11_TEXTURE2D_DESC desc =
{
.Width = d3d11->menu.width,
.Height = d3d11->menu.height,
.MipLevels = 1,
.ArraySize = 1,
.Format = DXGI_FORMAT_R8G8B8A8_UNORM,
.SampleDesc.Count = 1,
.SampleDesc.Quality = 0,
.Usage = D3D11_USAGE_DYNAMIC,
.BindFlags = D3D11_BIND_SHADER_RESOURCE,
.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE,
.MiscFlags = 0,
};
D3D11_SHADER_RESOURCE_VIEW_DESC view_desc =
{
.Format = desc.Format,
.ViewDimension = D3D_SRV_DIMENSION_TEXTURE2D,
.Texture2D.MostDetailedMip = 0,
.Texture2D.MipLevels = -1,
};
D3D11CreateTexture2D(d3d11->device, &desc, NULL, &d3d11->menu.tex);
D3D11CreateTexture2DShaderResourceView(d3d11->device, d3d11->menu.tex, &view_desc, &d3d11->menu.view);
}
{
D3D11_MAPPED_SUBRESOURCE mapped_frame;
D3D11MapTexture2D(d3d11->context, d3d11->menu.tex, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_frame);
{
int i,j;
if (rgb32)
{
const uint32_t* in = frame;
uint32_t* out = mapped_frame.pData;
for (i = 0; i < height; i++)
{
memcpy(out, in, width * 4);
in += width;
out += mapped_frame.RowPitch / 4;
}
}
else
{
const uint16_t* in = frame;
uint32_t* out = mapped_frame.pData;
for (i = 0; i < height; i++)
{
for (j = 0; j < width; j++)
{
unsigned r = ((in[j] >> 12) & 0xF);
unsigned g = ((in[j] >> 8) & 0xF);
unsigned b = ((in[j] >> 4) & 0xF);
unsigned a = ((in[j] >> 0) & 0xF);
out[j] = (r << 0) | (r << 4) |(g << 8) | (g << 12) |(b << 16) | (b << 20) |(a << 24) | (a << 28);
}
in += width;
out += mapped_frame.RowPitch / 4;
}
}
}
D3D11UnmapTexture2D(d3d11->context, d3d11->menu.tex, 0);
}
}
static void d3d11_set_menu_texture_enable(void* data,
bool state, bool full_screen)
{
d3d11_video_t* d3d11 = (d3d11_video_t*)data;
d3d11->menu.enabled = state;
d3d11->menu.fullscreen = full_screen;
}
static const video_poke_interface_t d3d11_poke_interface =
{
NULL, /* set_coords */
NULL, /* set_mvp */
NULL, /* load_texture */
NULL, /* unload_texture */
NULL, /* set_video_mode */
NULL, /* set_filtering */
NULL, /* get_video_output_size */
NULL, /* get_video_output_prev */
NULL, /* get_video_output_next */
NULL, /* get_current_framebuffer */
NULL, /* get_proc_address */
NULL, /* set_aspect_ratio */
NULL, /* apply_state_changes */
d3d11_set_menu_texture_frame, /* set_texture_frame */
d3d11_set_menu_texture_enable, /* set_texture_enable */
NULL, /* set_osd_msg */
NULL, /* show_mouse */
NULL, /* grab_mouse_toggle */
NULL, /* get_current_shader */
NULL, /* get_current_software_framebuffer */
NULL, /* get_hw_render_interface */
};
static void d3d11_gfx_get_poke_interface(void* data,
const video_poke_interface_t** iface)
{
*iface = &d3d11_poke_interface;
}
video_driver_t video_d3d11 =
{
d3d11_gfx_init,
d3d11_gfx_frame,
d3d11_gfx_set_nonblock_state,
d3d11_gfx_alive,
d3d11_gfx_focus,
d3d11_gfx_suppress_screensaver,
d3d11_gfx_has_windowed,
d3d11_gfx_set_shader,
d3d11_gfx_free,
"d3d11",
NULL, /* set_viewport */
d3d11_gfx_set_rotation,
d3d11_gfx_viewport_info,
d3d11_gfx_read_viewport,
NULL, /* read_frame_raw */
#ifdef HAVE_OVERLAY
NULL, /* overlay_interface */
#endif
d3d11_gfx_get_poke_interface,
};

449
gfx/drivers/d3d12.c Normal file
View File

@ -0,0 +1,449 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2014-2018 - Ali Bouhlel
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <assert.h>
#include <string/stdstring.h>
#include "driver.h"
#include "verbosity.h"
#include "configuration.h"
#include "gfx/video_driver.h"
#include "gfx/common/win32_common.h"
#include "gfx/common/dxgi_common.h"
#include "gfx/common/d3d12_common.h"
#include "gfx/common/d3dcompiler_common.h"
static void *d3d12_gfx_init(const video_info_t *video,
const input_driver_t **input, void **input_data)
{
WNDCLASSEX wndclass = {0};
settings_t *settings = config_get_ptr();
gfx_ctx_input_t inp = {input, input_data};
d3d12_video_t *d3d12 = (d3d12_video_t *)calloc(1, sizeof(*d3d12));
if (!d3d12)
return NULL;
win32_window_reset();
win32_monitor_init();
wndclass.lpfnWndProc = WndProcD3D;
win32_window_init(&wndclass, true, NULL);
if (!win32_set_video_mode(d3d12, video->width, video->height, video->fullscreen))
{
RARCH_ERR("[D3D12]: win32_set_video_mode failed.\n");
goto error;
}
gfx_ctx_d3d.input_driver(NULL, settings->arrays.input_joypad_driver, input, input_data);
d3d12->chain.vsync = video->vsync;
d3d12->frame.rgb32 = video->rgb32;
if (!d3d12_init_context(d3d12))
goto error;
if (!d3d12_init_descriptors(d3d12))
goto error;
if (!d3d12_init_pipeline(d3d12))
goto error;
if(!d3d12_init_queue(d3d12))
return false;
if (!d3d12_init_swapchain(d3d12, video->width, video->height, main_window.hwnd))
goto error;
{
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->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:
RARCH_ERR("[D3D12]: failed to init video driver.\n");
free(d3d12);
return NULL;
}
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)
{
(void)msg;
d3d12_video_t *d3d12 = (d3d12_video_t *)data;
D3D12_CPU_DESCRIPTOR_HANDLE 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);
d3d12_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);
D3D12OMSetRenderTargets(d3d12->queue.cmd, 1, &d3d12->chain.desc_handles[d3d12->chain.frame_index],
FALSE, NULL);
D3D12ClearRenderTargetView(d3d12->queue.cmd, d3d12->chain.desc_handles[d3d12->chain.frame_index],
d3d12->chain.clearcolor, 0, NULL);
D3D12IASetPrimitiveTopology(d3d12->queue.cmd, D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
if (data && width && height)
{
if (!d3d12->frame.tex.handle || (d3d12->frame.tex.desc.Width != width)
|| (d3d12->frame.tex.desc.Height = height))
{
if (d3d12->frame.tex.handle)
Release(d3d12->frame.tex.handle);
if (d3d12->frame.tex.upload_buffer)
Release(d3d12->frame.tex.upload_buffer);
d3d12->frame.tex.desc.Width = width;
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);
}
{
int i, j;
const uint8_t *in = frame;
uint8_t *out;
D3D12Map(d3d12->frame.tex.upload_buffer, 0, NULL, &out);
out += d3d12->frame.tex.layout.Offset;
for (i = 0; i < height; i++)
{
memcpy(out, in, width * (d3d12->frame.rgb32 ? 4 : 2));
in += pitch;
out += d3d12->frame.tex.layout.Footprint.RowPitch;
}
D3D12Unmap(d3d12->frame.tex.upload_buffer, 0, NULL);
}
d3d12_upload_texture(d3d12->queue.cmd, &d3d12->frame.tex);
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)
d3d12_upload_texture(d3d12->queue.cmd, &d3d12->menu.tex);
// D3D12IASetVertexBuffers(d3d12->queue.cmd, 0, 1, &d3d12->frame.vbo_view);
D3D12SetGraphicsRootDescriptorTable(d3d12->queue.cmd, 0,
d3d12->menu.tex.gpu_descriptor); /* set texture */
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);
D3D12CloseGraphicsCommandList(d3d12->queue.cmd);
D3D12ExecuteGraphicsCommandLists(d3d12->queue.handle, 1, &d3d12->queue.cmd);
#if 1
DXGIPresent(d3d12->chain.handle, !!d3d12->chain.vsync, 0);
#else
DXGI_PRESENT_PARAMETERS pp = {0};
DXGIPresent1(d3d12->swapchain, 0, 0, &pp);
#endif
/* wait_for_previous_frame */
D3D12SignalCommandQueue(d3d12->queue.handle, d3d12->queue.fence, d3d12->queue.fenceValue);
if (D3D12GetCompletedValue(d3d12->queue.fence) < d3d12->queue.fenceValue)
{
D3D12SetEventOnCompletion(d3d12->queue.fence, d3d12->queue.fenceValue, d3d12->queue.fenceEvent);
WaitForSingleObject(d3d12->queue.fenceEvent, INFINITE);
}
d3d12->queue.fenceValue++;
d3d12->chain.frame_index = DXGIGetCurrentBackBufferIndex(d3d12->chain.handle);
if (msg && *msg)
gfx_ctx_d3d.update_window_title(NULL, video_info);
return true;
}
static void d3d12_gfx_set_nonblock_state(void *data, bool toggle)
{
d3d12_video_t *d3d12 = (d3d12_video_t *)data;
d3d12->chain.vsync = !toggle;
}
static bool d3d12_gfx_alive(void *data)
{
(void)data;
bool quit;
bool resize;
unsigned width;
unsigned height;
win32_check_window(&quit, &resize, &width, &height);
return true;
}
static bool d3d12_gfx_focus(void *data)
{
return win32_has_focus();
}
static bool d3d12_gfx_suppress_screensaver(void *data, bool enable)
{
(void)data;
(void)enable;
return false;
}
static bool d3d12_gfx_has_windowed(void *data)
{
(void)data;
return true;
}
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);
if (d3d12->frame.tex.upload_buffer)
Release(d3d12->frame.tex.upload_buffer);
if (d3d12->menu.tex.handle)
Release(d3d12->menu.tex.handle);
if (d3d12->menu.tex.handle)
Release(d3d12->menu.tex.upload_buffer);
Release(d3d12->pipe.srv_heap.handle);
Release(d3d12->pipe.rtv_heap.handle);
Release(d3d12->pipe.rootSignature);
Release(d3d12->pipe.handle);
Release(d3d12->queue.fence);
Release(d3d12->chain.renderTargets[0]);
Release(d3d12->chain.renderTargets[1]);
Release(d3d12->chain.handle);
Release(d3d12->queue.cmd);
Release(d3d12->queue.allocator);
Release(d3d12->queue.handle);
Release(d3d12->factory);
Release(d3d12->device);
Release(d3d12->adapter);
win32_monitor_from_window();
win32_destroy_window();
free(d3d12);
}
static bool d3d12_gfx_set_shader(void *data,
enum rarch_shader_type type, const char *path)
{
(void)data;
(void)type;
(void)path;
return false;
}
static void d3d12_gfx_set_rotation(void *data,
unsigned rotation)
{
(void)data;
(void)rotation;
}
static void d3d12_gfx_viewport_info(void *data,
struct video_viewport *vp)
{
(void)data;
(void)vp;
}
static bool d3d12_gfx_read_viewport(void *data, uint8_t *buffer, bool is_idle)
{
(void)data;
(void)buffer;
return true;
}
static void d3d12_set_menu_texture_frame(void *data,
const void *frame, bool rgb32, unsigned width, unsigned height,
float alpha)
{
d3d12_video_t *d3d12 = (d3d12_video_t *)data;
if (!d3d12->menu.tex.handle || (d3d12->menu.tex.desc.Width != width)
|| (d3d12->menu.tex.desc.Height = height))
{
if (d3d12->menu.tex.handle)
Release(d3d12->menu.tex.handle);
if (d3d12->menu.tex.upload_buffer)
Release(d3d12->menu.tex.upload_buffer);
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);
}
{
int i, j;
uint8_t *out;
D3D12Map(d3d12->menu.tex.upload_buffer, 0, NULL, &out);
out += d3d12->menu.tex.layout.Offset;
if(rgb32)
{
const uint32_t *in = frame;
for (i = 0; i < height; i++)
{
memcpy(out, in, width * sizeof(*in));
in += width;
out += d3d12->menu.tex.layout.Footprint.RowPitch;
}
}
else
{
const uint16_t *in = frame;
for (i = 0; i < height; i++)
{
for (j = 0; j < width; j++)
{
unsigned r = ((in[j] >> 12) & 0xF);
unsigned g = ((in[j] >> 8) & 0xF);
unsigned b = ((in[j] >> 4) & 0xF);
unsigned a = ((in[j] >> 0) & 0xF);
((uint16_t*)out)[j] = (b << 0) | (g << 4) | (r << 8) |(a << 12);
}
in += width;
out += d3d12->menu.tex.layout.Footprint.RowPitch;
}
}
D3D12Unmap(d3d12->menu.tex.upload_buffer, 0, NULL);
}
d3d12->menu.tex.dirty = true;
d3d12->menu.alpha = alpha;
}
static void d3d12_set_menu_texture_enable(void *data,
bool state, bool full_screen)
{
d3d12_video_t *d3d12 = (d3d12_video_t *)data;
d3d12->menu.enabled = state;
d3d12->menu.fullscreen = full_screen;
}
static const video_poke_interface_t d3d12_poke_interface =
{
NULL, /* set_coords */
NULL, /* set_mvp */
NULL, /* load_texture */
NULL, /* unload_texture */
NULL, /* set_video_mode */
NULL, /* set_filtering */
NULL, /* get_video_output_size */
NULL, /* get_video_output_prev */
NULL, /* get_video_output_next */
NULL, /* get_current_framebuffer */
NULL, /* get_proc_address */
NULL, /* set_aspect_ratio */
NULL, /* apply_state_changes */
d3d12_set_menu_texture_frame, /* set_texture_frame */
d3d12_set_menu_texture_enable, /* set_texture_enable */
NULL, /* set_osd_msg */
NULL, /* show_mouse */
NULL, /* grab_mouse_toggle */
NULL, /* get_current_shader */
NULL, /* get_current_software_framebuffer */
NULL, /* get_hw_render_interface */
};
static void d3d12_gfx_get_poke_interface(void *data,
const video_poke_interface_t **iface)
{
*iface = &d3d12_poke_interface;
}
video_driver_t video_d3d12 =
{
d3d12_gfx_init,
d3d12_gfx_frame,
d3d12_gfx_set_nonblock_state,
d3d12_gfx_alive,
d3d12_gfx_focus,
d3d12_gfx_suppress_screensaver,
d3d12_gfx_has_windowed,
d3d12_gfx_set_shader,
d3d12_gfx_free,
"d3d12",
NULL, /* set_viewport */
d3d12_gfx_set_rotation,
d3d12_gfx_viewport_info,
d3d12_gfx_read_viewport,
NULL, /* read_frame_raw */
#ifdef HAVE_OVERLAY
NULL, /* overlay_interface */
#endif
d3d12_gfx_get_poke_interface,
};

View File

@ -0,0 +1,25 @@
#define SRC(src) #src
SRC(
struct PSInput
{
float4 position : SV_POSITION;
float2 texcoord : TEXCOORD0;
float4 color : COLOR;
};
PSInput VSMain(float4 position : POSITION, float2 texcoord : TEXCOORD0, float4 color : COLOR)
{
PSInput result;
result.position = position;
result.texcoord = texcoord;
result.color = color;
return result;
}
uniform sampler s0;
uniform Texture2D <float4> t0;
float4 PSMain(PSInput input) : SV_TARGET
{
return input.color * t0.Sample(s0, input.texcoord);
// return input.color;
};
)

View File

@ -262,6 +262,12 @@ static const video_driver_t *video_drivers[] = {
#ifdef XENON
&video_xenon360,
#endif
#if defined(HAVE_D3D11)
&video_d3d11,
#endif
#if defined(HAVE_D3D12)
&video_d3d12,
#endif
#if defined(HAVE_D3D)
&video_d3d,
#endif

View File

@ -1336,6 +1336,8 @@ extern video_driver_t video_vita2d;
extern video_driver_t video_ctr;
extern video_driver_t video_switch;
extern video_driver_t video_d3d;
extern video_driver_t video_d3d11;
extern video_driver_t video_d3d12;
extern video_driver_t video_gx;
extern video_driver_t video_wiiu;
extern video_driver_t video_xenon360;

View File

@ -345,6 +345,14 @@ VIDEO DRIVER
#endif
#if defined(HAVE_D3D11)
#include "../gfx/drivers/d3d11.c"
#endif
#if defined(HAVE_D3D12)
#include "../gfx/drivers/d3d12.c"
#endif
#if defined(GEKKO)
#ifdef HW_RVL
#include "../gfx/drivers/gx_gfx_vi_encoder.c"

160
tools/com-parser/Makefile Normal file
View File

@ -0,0 +1,160 @@
TARGET = com-parse
DEBUG = 0
GENDEPS = 1
TARGET_ARCH = amd64
OS ?= win32
OBJ :=
OBJ += com-parse.o
EXE_EXT := $(suffix $(wildcard $(MAKE).*))
ifeq ($(compiler),)
ifeq ($(patsubst %.exe,%,$(basename $(CC))),cl)
compiler = msvc
else
compiler = gcc
endif
endif
CC_OUT = -o $(NOTHING)
CXX_OUT = $(CC_OUT)
LD_OUT = $(CC_OUT)
OBJ_EXT := o
ifeq ($(DEBUG),1)
DEFINES += -DDEBUG -D_DEBUG
endif
ifeq ($(compiler),msvc)
ARCH = amd64
ARCH2 = x64
TARGET_ARCH2 = x64
CROSS = amd64
WindowsSdkDir = C:\Program Files (x86)\Windows Kits\10\$(NOTHING)
WindowsSDKVersion := 10.0.14393.0\$(NOTHING)
VCINSTALLDIR := C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\$(NOTHING)
INCLUDE := $(VCINSTALLDIR)include;$(VCINSTALLDIR)atlmfc\include;$(WindowsSdkDir)include\$(WindowsSDKVersion)ucrt;$(WindowsSdkDir)include\$(WindowsSDKVersion)shared;$(WindowsSdkDir)include\$(WindowsSDKVersion)um;
LIB := $(VCINSTALLDIR)LIB\$(CROSS);$(VCINSTALLDIR)atlmfc\lib\$(CROSS);$(WindowsSdkDir)lib\$(WindowsSDKVersion)ucrt\$(TARGET_ARCH2);$(WindowsSdkDir)lib\$(WindowsSDKVersion)um\$(TARGET_ARCH2);C:\Program Files (x86)\NVIDIA Corporation\Cg\lib.$(TARGET_ARCH2);C:\Program Files (x86)\Microsoft DirectX SDK (February 2010)\Lib\$(TARGET_ARCH2);
LIBPATH := $(VCINSTALLDIR)LIB\$(CROSS);$(VCINSTALLDIR)atlmfc\lib\$(CROSS);
PATH := $(shell IFS=$$'\n'; cygpath "$(VCINSTALLDIR)bin\\$(CROSS)"):$(shell IFS=$$'\n'; cygpath "$(WindowsSdkDir)\bin\\$(ARCH2)"):$(PATH)
export INCLUDE := $(INCLUDE)
export LIB := $(LIB)
export LIBPATH := $(LIBPATH)
export PATH := $(PATH)
DEFINES :=
FLAGS += -nologo
FLAGS += -Gm- -Zc:inline -fp:precise -Zc:forScope -Gd -Oi -volatile:iso
#FLAGS += -GR-
CFLAGS += -TC
CXXFLAGS += -TP -EHsc
WARNINGS += -WX -W3
WARNINGS += -wd4101 -wd4996 -wd4244 -wd4267 -wd4090 -wd4305 -wd4146 -wd4334 -wd4018
CC = cl.exe
CXX = cl.exe
LD = link.exe
RC = rc.exe
LIBS += shell32.lib user32.lib gdi32.lib comdlg32.lib winmm.lib ole32.lib
LDFLAGS += -nologo -wx -nxcompat -machine:$(TARGET_ARCH2)
ifeq ($(DEBUG),1)
FLAGS += -GS -Gy -Od -RTC1 -D_SECURE_SCL=1 -Zi
FLAGS += -MDd
LDFLAGS += -DEBUG
DEFINES += -DDEBUG -D_DEBUG
else
FLAGS += -GS- -Gy- -O2 -Ob2 -GF -GT -Oy -Ot -D_SECURE_SCL=0
FLAGS += -MD
endif
OBJ := $(OBJ:.o=.obj)
LDFLAGS += -WX -SUBSYSTEM:WINDOWS -ENTRY:mainCRTStartup
DEFINES := $(patsubst -f%,,$(DEFINES))
LDFLAGS := $(patsubst -l%,%.lib,$(LDFLAGS))
LIBS := $(filter-out -lm,$(LIBS))
LIBS := $(patsubst -l%,%.lib,$(LIBS))
DEPFLAGS = -showIncludes | tee $*.dtemp | sed /'Note: including file:'/d
MAKEDEPS = echo $@: $< \\ > $*.depend && \
grep 'Note: including file:' $*.dtemp \
| sed '/$(subst \,\\,$(WindowsSdkDir))/Id; /$(subst \,\\,$(VCINSTALLDIR))/Id; s/Note: including file:[ ]*//g; s/\\/\//g; s/ /\\ /g; s/.*/ & \\/g' \
>> $*.depend && \
rm -f $*.dtemp
OBJ_EXT := obj
CC_OUT := -Fo:
CXX_OUT := $(CC_OUT)
LD_OUT := -out:
else
RC := windres
DEPFLAGS = -MT $@ -MMD -MP -MF $(BUILD_DIR)$*.depend
LD = $(CXX)
ifeq ($(DEBUG),1)
FLAGS += -g -O0
else
FLAGS += -O3
endif
endif
INCLUDE_DIRS += -I. -I../../deps/peglib
$(info os : $(OS))
$(info host : $(ARCH))
$(info target : $(TARGET_ARCH))
$(info compiler : $(compiler))
all: $(TARGET)$(EXE_EXT)
%.h:
touch $*.tmp
$(CXX) $*.tmp -DCINTERFACE -D_REFIID_DEFINED= -D_REFGUID_DEFINED= -D_HRESULT_DEFINED= \
-EP -FI $@ $(FLAGS) $(CXXFLAGS) $(DEFINES) $(INCLUDE_DIRS) $(WARNINGS) > $@
rm $*.tmp
SHELL:=$(SHELL) -o pipefail
ifeq ($(GENDEPS),0)
DEPFLAGS :=
MAKEDEPS :=
endif
%.$(OBJ_EXT): %.cpp
$(CXX) -c $(CXX_OUT)$@ $< $(FLAGS) $(CXXFLAGS) $(DEFINES) $(INCLUDE_DIRS) $(WARNINGS) $(DEPFLAGS)
@$(MAKEDEPS)
%.$(OBJ_EXT): %.c
$(CC) -c $(CC_OUT)$@ $< $(FLAGS) $(CFLAGS) $(DEFINES) $(INCLUDE_DIRS) $(WARNINGS) $(DEPFLAGS)
@$(MAKEDEPS)
%.res: %.rc
$(RC) $<
mv $*.res $@
$(TARGET)$(EXE_EXT): $(OBJ) .$(TARGET).last
@touch .$(TARGET).last
$(LD) $(OBJ) $(LDFLAGS) $(LIBS) $(LD_OUT)$@
%.depend: ;
%.last: ;
.FORCE:
clean:
rm -f $(OBJ) $(TARGET)$(EXE_EXT)
rm -f $(TARGET)
rm -f .$(TARGET).last
rm -f $(OBJ:.obj=.depend)
.PHONY: clean all
.PRECIOUS: %.depend %.last
-include $(patsubst %.obj,%.depend,$(filter %.obj,$(OBJ)))

View File

@ -0,0 +1,775 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2014-2018 - Ali Bouhlel
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <iostream>
#include <peglib.h>
#include <fstream>
#include <sstream>
#include <cstring>
using namespace peg;
using namespace std;
template <typename Annotation>
AstBase<Annotation> AstBase<Annotation>::empty = AstBase<Annotation>("", 0, 0, "", string(""));
//bool use_typedefs = false;
bool use_typedefs = true;
//const char* prefix_seperator = "_";
const char* prefix_seperator = "";
vector<string> ignored_fn_prefixes_list =
{
"OM",
"IA",
"RS",
};
vector<string> fn_prefixes_list =
{
"OM",
"IA",
"RS",
"VS",
"PS",
"GS",
"DS",
"CS",
};
bool move_fn_prefix_after_action = true;
vector<string> ignored_types_list =
{
"AsyncIUnknown",
"IMarshal",
"IMalloc",
"IEnumString",
"ISequentialStream",
"IStream",
"IRpcChannelBuffer",
"IAsyncRpcChannelBuffer",
"IRpcProxyBuffer",
"IServerSecurity",
"IRpcOptions",
"IGlobalOptions",
"ISurrogate",
"ISynchronize",
"ISynchronizeEvent",
"IDataObject",
"IDataAdviseHolder",
"IDirectWriterLock",
"IDummyHICONIncluder",
"IDispatch",
"IDropSource",
"IDropTarget",
"IDataFilter",
"IDropSourceNotify",
};
const char* required_prefix = "ID";
vector<string> ignored_functions_list =
{
"Release",
"QueryInterface",
"AddRef",
"GetParent",
"GetAdapter",
"GetDevice",
"GetDesc",
"GetType",
"SetName",
"SetPrivateDataInterface",
"SetPrivateData",
"GetPrivateData",
"OpenSharedHandle",
"CreateSharedHandle",
"OpenSharedHandleByName",
"SetTrackingOptions",
};
vector<string> overloaded_list =
{
"Release",
"QueryInterface",
"AddRef",
"GetParent",
"GetAdapter",
"GetDesc",
"GetType",
"SetName",
"SetPrivateDataInterface",
"SetPrivateData",
"GetPrivateData",
"Reset",
"Signal",
"BeginEvent",
"EndEvent",
"SetMarker",
"AssertResourceState",
"GetFeatureMask",
"SetFeatureMask",
"GetFrameStatistics",
"Close",
"SetEvictionPriority",
"GetEvictionPriority",
"GetResource",
"GetDataSize",
"GetContextFlags",
"GetCertificate",
"GetCertificateSize",
};
vector<string> action_list =
{
"Release",
"Get",
"Set",
"Enum",
"Get",
"Query",
"Add",
"Signal",
"Begin",
"End",
"Assert",
"Close",
"Map",
"Unmap"
};
vector<string> derived_types_list =
{
"ID3D12Device",
"ID3D12Debug",
"ID3D12DebugDevice",
"ID3D12DebugCommandList",
"IDXGIFactory1",
"IDXGIAdapter1",
"IDXGISurface1",
"IDXGISwapChain3",
"IDXGIOutput",
"IDXGIDevice",
};
vector<string> base_objects_list =
{
"IUnknown",
"ID3D12Object",
"ID3D12Resource",
"IDXGIObject",
"IDXGIResource",
"D3D11Resource",
};
//string insert_name(const char* fname, const char* name)
string insert_name(const string& fname, const string& name)
{
string str;
for(string action: action_list)
{
if(!strncmp(fname.c_str(), action.c_str(), action.length()))
{
if(name.length() == 2 && name[1] == 'S')
{
if(!strncmp(fname.c_str() + action.length(), "Shader", strlen("Shader")))
return action + name[0] + (fname.c_str() + action.length());
else
return action + name[0] + "Shader" + (fname.c_str() + action.length());
}
else
return action + name + (fname.c_str() + action.length());
}
}
return string(fname) + name;
}
//string insert_name(string fname, string name)
//{
// return insert_name(fname.c_str(), name.c_str());
//}
string get_derived_basename(const char *name)
{
string str = name;
if(::isdigit(str.back()))
str.pop_back();
return str;
}
string get_derived_basename(string name)
{
return get_derived_basename(name.c_str());
}
string get_prefix(const char *type)
{
string prefix;
if(*type != 'I')
return type;
type++;
while (::isalnum(*type) && !::islower(*type))
prefix.push_back(*type++);
prefix.pop_back();
return prefix;
}
string get_prefix(const string &type)
{
return get_prefix(type.c_str());
}
string clean_name(const char *name)
{
string str;
if (name[0] == 'p' && name[1] == 'p' && name[2] == 'v' && ::isupper(name[3]))
name += 3;
if (name[0] == 'p' && name[1] == 'p' && ::isupper(name[2]))
name += 2;
else if ((*name == 'p' || *name == 'b') && ::isupper(name[1]))
name ++;
bool was_upper = false;
if (*name)
{
if (::isupper(*name))
{
was_upper = true;
str = (char)::tolower(*name);
}
else
str = *name;
}
while (*++name)
{
if (::isupper(*name))
{
if(!was_upper && !::isdigit(str.back()))
str = str + '_';
was_upper = true;
str += (char)::tolower(*name);
}
else
{
was_upper = false;
str += *name;
}
}
if(str == "enum")
str = "enumerator";
return str;
}
struct name_pair{
string name;
string original;
};
class ComFunction
{
public:
struct param_t
{
name_pair type;
name_pair ptr;
name_pair name;
int array_size = 0;
bool const_ = false;
bool base = false;
bool derived = false;
};
param_t this_;
vector<param_t> params;
string riid;
string name;
string original_name;
string return_type;
string prefix;
bool overloaded = false;
bool ignored = false;
bool preferred = false;
ComFunction(Ast node)
{
original_name = node["FunctionName"];
return_type = node["ReturnType"];
for (auto param_ : node["Parameters"].nodes)
{
Ast &param = *param_;
param_t p;
p.type.original = param["Type"]["Name"];
p.const_ = param["Type"]["TypeQualifier"] == "const";
if(p.type.original == "REFIID")
{
riid = string("I") + prefix;
continue;
}
if(!riid.empty())
{
if(param["Name"][2] == 'v')
riid += param["Name"] + 3;
else
riid += param["Name"] + 2;
break;
}
p.ptr.original = param["Type"]["Pointer"];
p.ptr.name = p.ptr.original;
if(use_typedefs &&
(prefix.empty() || (p.type.original[0] == 'I' && !strncmp(p.type.original.c_str() + 1, prefix.c_str(), prefix.length())))
)
{
p.type.name = p.type.original.c_str() + 1;
if(::isdigit(p.type.name.back()))
p.type.name.pop_back();
if(!p.ptr.name.empty())
p.ptr.name.pop_back();
}
else
{
p.type.name = p.type.original;
p.ptr.name = p.ptr.name;
}
if (param.name == "This")
{
prefix = get_prefix(p.type.original);
p.name.original = param["Type"]["Name"] + 1 + prefix.length();
p.name.name = clean_name(p.name.original.c_str());
if(::isdigit(p.name.name.back()))
p.name.name.pop_back();
this_ = p;
}
else
{
p.name.original = param["Name"];
p.name.name = clean_name(p.name.original.c_str());
p.array_size = ::strtoul(param["ArraySize"], NULL, 10);
params.push_back(p);
}
}
if(original_name == "GetCPUDescriptorHandleForHeapStart")
{
param_t p;
p.type.name = p.type.original = return_type;
p.ptr.name = p.ptr.original = "*";
return_type = "void";
p.name.name = p.name.original = "out";
params.push_back(p);
}
for(string str : ignored_functions_list)
if(original_name == str)
ignored = true;
for(string str : ignored_types_list)
if(get_derived_basename(this_.type.original) == get_derived_basename(str))
ignored = true;
if(required_prefix)
if(strncmp(this_.type.original.c_str(), required_prefix, strlen(required_prefix)))
ignored = true;
for(string str : derived_types_list)
{
if(get_derived_basename(this_.type.original) == get_derived_basename(str))
{
this_.derived = true;
if(this_.type.original != str)
ignored = true;
}
for (param_t &param : params)
if(get_derived_basename(param.type.original) == get_derived_basename(str))
{
if(param.type.original != str)
param.derived = true;
else
{
// cout << param.type.original << endl;
preferred = true;
}
}
}
for(string str : overloaded_list)
if(original_name == str)
overloaded = true;
for(string str : base_objects_list)
{
if(this_.type.original == str)
this_.base = true;
for (param_t &param : params)
if(param.type.original == str)
param.base = true;
}
name = prefix + prefix_seperator;
if(overloaded && !this_.base)
{
name += insert_name(original_name, this_.name.original);
if(::isdigit(name.back()))
name.pop_back();
}
else
{
string fn_prefix;
for (string& str : ignored_fn_prefixes_list)
if(!strncmp(original_name.c_str(), str.c_str(), str.length()))
{
if(::isupper(original_name[str.length()]))
fn_prefix = str;
break;
}
if(!fn_prefix.empty())
{
name += original_name.c_str() + fn_prefix.length();
}
else
{
for (string str : fn_prefixes_list)
if(!strncmp(original_name.c_str(), str.c_str(), str.length()))
{
if(::isupper(original_name[str.length()]))
fn_prefix = str;
break;
}
if(!fn_prefix.empty())
name += insert_name(original_name.c_str() + fn_prefix.length(), fn_prefix.c_str());
else
name += original_name;
}
}
// if(original_name == "CreateCommandQueue" && ignored)
// cout << "ignored CreateCommandQueue !!" << __LINE__ << endl;
}
string str()
{
stringstream out;
out << "static inline " << return_type << " " << name << "(";
if(this_.base)
out << "void*";
else
out << this_.type.name << this_.ptr.name;
out << " " << this_.name.name;
for (param_t &param : params)
{
out << ", ";
if(param.const_)
out << "const ";
if(param.base)
out << "void*";
else
out << param.type.name << param.ptr.name;
out << " " << param.name.name;
if(param.array_size)
out << '[' << param.array_size << ']';
}
if(!riid.empty())
out << ", " << riid << "** out";
out << ")\n{\n";
out << " ";
if (return_type != "void")
out << "return ";
if(original_name == "GetCPUDescriptorHandleForHeapStart")
out << "((void (STDMETHODCALLTYPE *)(ID3D12DescriptorHeap*, D3D12_CPU_DESCRIPTOR_HANDLE*))\n ";
if(this_.base)
out << "((" << this_.type.original << this_.ptr.original << ')' << this_.name.name << ')';
else
out << this_.name.name;
out << "->lpVtbl->" << original_name;
if(original_name == "GetCPUDescriptorHandleForHeapStart")
out << ')';
out << '(' << this_.name.name;
for (param_t param : params)
{
out << ", ";
if(param.base || param.derived)
out << '(' << param.type.original << param.ptr.original << ')';
out << param.name.name;
}
if(!riid.empty())
out << ", __uuidof(" << riid << "), (void**)out";
out << ");\n";
out << "}\n";
return out.str();
}
};
class ComHeader
{
public:
shared_ptr<Ast> ast;
vector<ComFunction> functions;
vector<name_pair> types;
ComHeader(const char *filename)
{
string header;
{
ifstream fs(filename);
#if 0
stringstream ss;
ss << fs.rdbuf();
header = ss.str();
#else
while (!fs.eof())
{
char line[4096];
fs.getline(line, sizeof(line));
char* str = line;
while (*str && ::isspace(*str))
str++;
if (*str && !strncmp(str, "typedef struct ", strlen("typedef struct ")))
{
if(*str && strstr(str, "Vtbl"))
{
header += str;
header.push_back('\n');
while(*line)
{
fs.getline(line, sizeof(line));
str = line;
while (*str && ::isspace(*str))
str++;
if(*str)
{
header += str;
header.push_back('\n');
}
if(*str == '}')
break;
}
}
}
}
#endif
}
{
ofstream out("test.cpp.h");
out << header;
out.close();
}
string header_grammar;
{
ifstream fs("grammar.txt");
stringstream ss;
ss << fs.rdbuf();
header_grammar = ss.str();
}
parser parser;
parser.log = [&](size_t ln, size_t col, const string & msg)
{
cout << "Error parsing grammar:" << ln << ":" << col << ": " << msg << endl;
};
if (!parser.load_grammar(header_grammar.c_str()))
{
cout << "Failed to load grammar" << endl;
return;
}
parser.log = [&](size_t ln, size_t col, const string & msg)
{
cout << filename << ":" << ln << ":" << col << ": " << msg << endl;
};
parser.enable_ast();
if (!parser.parse_n(header.c_str(), header.size(), ast))
{
cout << "Error parsing header file: " << filename << endl;
return;
}
ast = AstOptimizer(false).optimize(ast);
if (ast->name != "Program")
{
cout << "Expected root node to be Program, not" << ast->name << endl;
return;
}
for (shared_ptr<Ast> node_ : ast->nodes)
{
Ast node = *node_;
if (node.name == "Function")
functions.push_back(node);
else if (node.name == "Line")
{
}
else if (node.name == "EndOfFile")
break;
else
{
// cout << "Unexcpected node " << node->name << endl;
}
}
for(ComFunction& fn : functions)
{
if(!fn.ignored && fn.preferred && ::isdigit(fn.name.back()))
{
fn.name.pop_back();
for(ComFunction& fn2 : functions)
if(&fn != &fn2 && !fn2.ignored && get_derived_basename(fn.original_name) == get_derived_basename(fn2.original_name))
{
// cout << &fn << &fn2 << fn.original_name << " " << fn2.original_name << endl;
// assert(fn2.preferred == false);
fn2.ignored = true;
// if(fn2.original_name == "CreateCommandQueue" && fn2.ignored)
// cout << "ignored CreateCommandQueue !!" << __LINE__ << endl;
}
}
}
for(ComFunction& fn : functions)
{
if(!fn.ignored)
{
bool known = false;
for(name_pair& known_type:types)
if (fn.this_.type.original == known_type.original)
{
known = true;
break;
}
if(!known)
types.push_back(fn.this_.type);
}
}
}
ComHeader(shared_ptr<Ast> ast_)
{
}
string str()
{
stringstream out;
int indent = 0;
for(name_pair known_type:types)
if (indent < known_type.original.length())
indent = known_type.original.length();
for(name_pair known_type:types)
{
out << "typedef " << known_type.original << '*' << string(indent + 1 - known_type.original.length(), ' ') << known_type.name << ";\n";
}
out << "\n\n";
for (ComFunction &fn : functions)
if(!fn.ignored)
out << fn.str();
return out.str();
}
};
template<class _Elem, class _Traits>
basic_ostream<_Elem, _Traits> &operator << (basic_ostream<_Elem, _Traits> &ios, ComHeader &header)
{
return ios << header.str();
}
int main(int argc, const char **argv)
{
const char *header_fn = argv[1];
ComHeader header(header_fn);
if (header.functions.empty())
return 1;
if (argc > 2)
cout << ast_to_s(header.ast) << flush;
ofstream out("test.h");
const char* basename = strrchr(argv[1], '/');
if(!basename)
basename = strrchr(argv[1], '\\');
if(basename)
basename++;
if(!basename)
basename = argv[1];
#if 1
out << "\n#include <" << basename << ">\n\n";
#else
out << "\n";
out << "#include <d3d12.h>\n";
out << "#include <dxgi1_5.h>\n";
out << "#include <d3dcompiler.h>\n\n";
#endif
out << header;
out.close();
return 0;
}

View File

@ -0,0 +1,30 @@
Program <- (Function / Comment / Line)* EndOfFile
Function <- _ ReturnType _ '(' _ FunctionName _ ')'_ Parameters
Parameters <- '('_ This _ ','? _ ( _ Param _ ','?)*_ ');'
FunctionName <- CallType _ '*' _ <Name>
This <- Type _ 'This'
Param <- InOut? _ Type _ Name _ ArraySize?
ReturnType <- <Type>
Type <- (TypeQualifier _)? Name Pointer?
TypeQualifier <- 'const'
~CallType <- '__export'? ('STDMETHODCALLTYPE' / 'STDMETHODVCALLTYPE' / 'STDAPICALLTYPE' / 'STDAPIVCALLTYPE' / '__cdecl' / '__stdcall')
~InOut <- '_'Name
ArraySize <- '[' _ <Number?> _ ']'
Pointer <- _<('*'/'const '/'const')+>
Name <- <([a-z]/[A-Z]/'_'/[0-9])+>
Number <- <[0-9]+>
~Line <- <(!EndOfLine !EndOfFile .)*> (EndOfLine / EndOfFile)
~EndOfStatement <- ';'
~EndOfLine <- '\r\n' / '\n' / '\r'
EndOfFile <- !.
End <- EndOfLine / EndOfFile
~_ <- (Comment / [ \t\r\n])*
Indent <- [ \t]
~Space <- [ \t]
Comment <- [ \t]*<('/*' (!'*/' .)* '*/' / '//') Line>

View File

@ -26,13 +26,13 @@ void DisassemblePPCRange(void *start, void *end, void* printf_func, void* GetSym
/* #define DEBUG_HOLD() do{printf("%s@%s:%d.\n",__FUNCTION__, __FILE__, __LINE__);fflush(stdout);wait_for_input();}while(0) */
#define DEBUG_LINE() do{printf("%s:%4d %s().\n", __FILE__, __LINE__, __FUNCTION__);fflush(stdout);}while(0)
#define DEBUG_STR(X) printf( "%s: %s\n", #X, (char*)(X))
#define DEBUG_VAR(X) printf( "%-20s: 0x%08" PRIX32 "\n", #X, (uint32_t)(X))
#define DEBUG_VAR2(X) printf( "%-20s: 0x%08" PRIX32 " (%i)\n", #X, (uint32_t)(X), (int)(X))
#define DEBUG_INT(X) printf( "%-20s: %10" PRIi32 "\n", #X, (int32_t)(X))
#define DEBUG_FLOAT(X) printf( "%-20s: %10.3f\n", #X, (float)(X))
#define DEBUG_VAR64(X) printf( #X"\r\t\t\t\t : 0x%016" PRIX64 "\n", (uint64_t)(X))
#define DEBUG_MAGIC(X) printf( "%-20s: '%c''%c''%c''%c' (0x%08X)\n", #X, (u32)(X)>>24, (u32)(X)>>16, (u32)(X)>>8, (u32)(X),(u32)(X))
#define DEBUG_STR(X) do{printf( "%s: %s\n", #X, (char*)(X));fflush(stdout);}while(0)
#define DEBUG_VAR(X) do{printf( "%-20s: 0x%08" PRIX32 "\n", #X, (uint32_t)(X));fflush(stdout);}while(0)
#define DEBUG_VAR2(X) do{printf( "%-20s: 0x%08" PRIX32 " (%i)\n", #X, (uint32_t)(X), (int)(X));fflush(stdout);}while(0)
#define DEBUG_INT(X) do{printf( "%-20s: %10" PRIi32 "\n", #X, (int32_t)(X));fflush(stdout);}while(0)
#define DEBUG_FLOAT(X) do{printf( "%-20s: %10.3f\n", #X, (float)(X));fflush(stdout);}while(0)
#define DEBUG_VAR64(X) do{printf( "%-20s: 0x%016" PRIX64 "\n", #X, (uint64_t)(X));fflush(stdout);}while(0)
#define DEBUG_MAGIC(X) do{printf( "%-20s: '%c''%c''%c''%c' (0x%08X)\n", #X, (u32)(X)>>24, (u32)(X)>>16, (u32)(X)>>8, (u32)(X),(u32)(X));fflush(stdout);}while(0)
/* #define DEBUG_ERROR(X) do{if(X)dump_result_value(X);}while(0) */
#define PRINTFPOS(X,Y) "\x1b["#X";"#Y"H"