Compare commits

...

10 Commits

10 changed files with 2551 additions and 9 deletions

3
.gitmodules vendored
View File

@ -1,3 +1,6 @@
[submodule "Vulkan-Headers"] [submodule "Vulkan-Headers"]
path = Vulkan-Headers path = Vulkan-Headers
url = https://github.com/KhronosGroup/Vulkan-Headers.git url = https://github.com/KhronosGroup/Vulkan-Headers.git
[submodule "SPIRV-Cross"]
path = SPIRV-Cross
url = https://github.com/KhronosGroup/SPIRV-Cross

View File

@ -40,6 +40,11 @@ endif()
add_definitions( add_definitions(
-DREFRESH_DRIVER_VULKAN -DREFRESH_DRIVER_VULKAN
) )
if (WIN32)
add_definitions(
-DREFRESH_DRIVER_D3D11
)
endif()
# Source lists # Source lists
add_library(Refresh add_library(Refresh
@ -49,8 +54,10 @@ add_library(Refresh
# Internal Headers # Internal Headers
src/Refresh_Driver.h src/Refresh_Driver.h
src/Refresh_Driver_Vulkan_vkfuncs.h src/Refresh_Driver_Vulkan_vkfuncs.h
src/Refresh_Driver_D3D11_cdefines.h
# Source Files # Source Files
src/Refresh.c src/Refresh.c
src/Refresh_Driver_D3D11.c
src/Refresh_Driver_Vulkan.c src/Refresh_Driver_Vulkan.c
src/Refresh_Image.c src/Refresh_Image.c
) )

1
SPIRV-Cross Submodule

@ -0,0 +1 @@
Subproject commit d5c3bd8b5e7db9e2d7fe809944b47b8f88e1c732

View File

@ -34,7 +34,12 @@
/* Drivers */ /* Drivers */
static const Refresh_Driver *drivers[] = { static const Refresh_Driver *drivers[] = {
#if REFRESH_DRIVER_VULKAN
&VulkanDriver, &VulkanDriver,
#endif
#if REFRESH_DRIVER_D3D11
&D3D11Driver,
#endif
NULL NULL
}; };
@ -124,21 +129,42 @@ uint32_t Refresh_LinkedVersion(void)
/* Driver Functions */ /* Driver Functions */
static int32_t selectedDriver = 0; static int32_t selectedDriver = -1;
Refresh_Device* Refresh_CreateDevice( Refresh_Device* Refresh_CreateDevice(
Refresh_PresentationParameters *presentationParameters, Refresh_PresentationParameters *presentationParameters,
uint8_t debugMode uint8_t debugMode
) { ) {
if (selectedDriver < 0) uint32_t result = 0;
uint32_t i;
const char *hint = SDL_GetHint("REFRESH_FORCE_DRIVER");
for (i = 0; drivers[i] != NULL; i += 1)
{ {
return NULL; if (hint != NULL)
{
if (SDL_strcmp(hint, drivers[i]->Name) != 0)
{
continue;
}
} }
/* FIXME: add fallback driver handling */
break;
}
if (drivers[i] == NULL)
{
Refresh_LogError("No supported Refresh driver found!");
return NULL;
}
else
{
selectedDriver = i;
return drivers[selectedDriver]->CreateDevice( return drivers[selectedDriver]->CreateDevice(
presentationParameters, presentationParameters,
debugMode debugMode
); );
}
} }
void Refresh_DestroyDevice(Refresh_Device *device) void Refresh_DestroyDevice(Refresh_Device *device)

View File

@ -522,6 +522,7 @@ typedef struct Refresh_Driver
} Refresh_Driver; } Refresh_Driver;
extern Refresh_Driver VulkanDriver; extern Refresh_Driver VulkanDriver;
extern Refresh_Driver D3D11Driver;
#endif /* REFRESH_DRIVER_H */ #endif /* REFRESH_DRIVER_H */

2234
src/Refresh_Driver_D3D11.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,215 @@
/* Refresh - XNA-inspired 3D Graphics Library with modern capabilities
*
* Copyright (c) 2020 Evan Hemsley
*
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from
* the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software in a
* product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source distribution.
*
* Evan "cosmonaut" Hemsley <evan@moonside.games>
*
*/
/* Function Pointer Signatures */
typedef HRESULT(WINAPI* PFN_CREATE_DXGI_FACTORY)(const GUID* riid, void** ppFactory);
/* IIDs (from https://magnumdb.com) */
static const IID D3D_IID_IDXGIFactory1 = { 0x770aae78,0xf26f,0x4dba,{0xa8,0x29,0x25,0x3c,0x83,0xd1,0xb3,0x87} };
static const IID D3D_IID_IDXGIFactory6 = { 0xc1b6694f,0xff09,0x44a9,{0xb0,0x3c,0x77,0x90,0x0a,0x0a,0x1d,0x17} };
static const IID D3D_IID_IDXGIAdapter1 = { 0x29038f61,0x3839,0x4626,{0x91,0xfd,0x08,0x68,0x79,0x01,0x1a,0x05} };
static const IID D3D_IID_ID3D11Texture2D = { 0x6f15aaf2,0xd208,0x4e89,{0x9a,0xb4,0x48,0x95,0x35,0xd3,0x4f,0x9c} };
/* IDXGIFactory6 (taken from dxgi1_6.h, cleaned up a bit) */
typedef enum
{
DXGI_FEATURE_PRESENT_ALLOW_TEARING = 0
} DXGI_FEATURE;
typedef enum
{
DXGI_GPU_PREFERENCE_UNSPECIFIED = 0,
DXGI_GPU_PREFERENCE_MINIMUM_POWER = (DXGI_GPU_PREFERENCE_UNSPECIFIED + 1),
DXGI_GPU_PREFERENCE_HIGH_PERFORMANCE = (DXGI_GPU_PREFERENCE_MINIMUM_POWER + 1)
} DXGI_GPU_PREFERENCE;
typedef struct IDXGIFactory6 IDXGIFactory6;
typedef struct IDXGIFactory6Vtbl
{
HRESULT(STDMETHODCALLTYPE* QueryInterface)(
IDXGIFactory6* This,
REFIID riid,
void** ppvObject);
ULONG(STDMETHODCALLTYPE* AddRef)(
IDXGIFactory6* This);
ULONG(STDMETHODCALLTYPE* Release)(
IDXGIFactory6* This);
HRESULT(STDMETHODCALLTYPE* SetPrivateData)(
IDXGIFactory6* This,
REFGUID Name,
UINT DataSize,
const void* pData);
HRESULT(STDMETHODCALLTYPE* SetPrivateDataInterface)(
IDXGIFactory6* This,
REFGUID Name,
const IUnknown* pUnknown);
HRESULT(STDMETHODCALLTYPE* GetPrivateData)(
IDXGIFactory6* This,
REFGUID Name,
UINT* pDataSize,
void* pData);
HRESULT(STDMETHODCALLTYPE* GetParent)(
IDXGIFactory6* This,
REFIID riid,
void** ppParent);
HRESULT(STDMETHODCALLTYPE* EnumAdapters)(
IDXGIFactory6* This,
UINT Adapter,
IDXGIAdapter** ppAdapter);
HRESULT(STDMETHODCALLTYPE* MakeWindowAssociation)(
IDXGIFactory6* This,
HWND WindowHandle,
UINT Flags);
HRESULT(STDMETHODCALLTYPE* GetWindowAssociation)(
IDXGIFactory6* This,
HWND* pWindowHandle);
HRESULT(STDMETHODCALLTYPE* CreateSwapChain)(
IDXGIFactory6* This,
IUnknown* pDevice,
DXGI_SWAP_CHAIN_DESC* pDesc,
IDXGISwapChain** ppSwapChain);
HRESULT(STDMETHODCALLTYPE* CreateSoftwareAdapter)(
IDXGIFactory6* This,
HMODULE Module,
IDXGIAdapter** ppAdapter);
HRESULT(STDMETHODCALLTYPE* EnumAdapters1)(
IDXGIFactory6* This,
UINT Adapter,
IDXGIAdapter1** ppAdapter);
BOOL(STDMETHODCALLTYPE* IsCurrent)(
IDXGIFactory6* This);
BOOL(STDMETHODCALLTYPE* IsWindowedStereoEnabled)(
IDXGIFactory6* This);
HRESULT(STDMETHODCALLTYPE* CreateSwapChainForHwnd)(
IDXGIFactory6* This,
IUnknown* pDevice,
HWND hWnd,
void* pDesc,
void* pFullscreenDesc,
void* pRestrictToOutput,
void** ppSwapChain);
HRESULT(STDMETHODCALLTYPE* CreateSwapChainForCoreWindow)(
IDXGIFactory6* This,
IUnknown* pDevice,
IUnknown* pWindow,
void* pDesc,
void* pRestrictToOutput,
void** ppSwapChain);
HRESULT(STDMETHODCALLTYPE* GetSharedResourceAdapterLuid)(
IDXGIFactory6* This,
HANDLE hResource,
LUID* pLuid);
HRESULT(STDMETHODCALLTYPE* RegisterStereoStatusWindow)(
IDXGIFactory6* This,
HWND WindowHandle,
UINT wMsg,
DWORD* pdwCookie);
HRESULT(STDMETHODCALLTYPE* RegisterStereoStatusEvent)(
IDXGIFactory6* This,
HANDLE hEvent,
DWORD* pdwCookie);
void (STDMETHODCALLTYPE* UnregisterStereoStatus)(
IDXGIFactory6* This,
DWORD dwCookie);
HRESULT(STDMETHODCALLTYPE* RegisterOcclusionStatusWindow)(
IDXGIFactory6* This,
HWND WindowHandle,
UINT wMsg,
DWORD* pdwCookie);
HRESULT(STDMETHODCALLTYPE* RegisterOcclusionStatusEvent)(
IDXGIFactory6* This,
HANDLE hEvent,
DWORD* pdwCookie);
void (STDMETHODCALLTYPE* UnregisterOcclusionStatus)(
IDXGIFactory6* This,
DWORD dwCookie);
HRESULT(STDMETHODCALLTYPE* CreateSwapChainForComposition)(
IDXGIFactory6* This,
IUnknown* pDevice,
void* pDesc,
void* pRestrictToOutput,
void** ppSwapChain);
UINT(STDMETHODCALLTYPE* GetCreationFlags)(
IDXGIFactory6* This);
HRESULT(STDMETHODCALLTYPE* EnumAdapterByLuid)(
IDXGIFactory6* This,
LUID AdapterLuid,
REFIID riid,
void** ppvAdapter);
HRESULT(STDMETHODCALLTYPE* EnumWarpAdapter)(
IDXGIFactory6* This,
REFIID riid,
void** ppvAdapter);
HRESULT(STDMETHODCALLTYPE* CheckFeatureSupport)(
IDXGIFactory6* This,
DXGI_FEATURE Feature,
void* pFeatureSupportData,
UINT FeatureSupportDataSize);
HRESULT(STDMETHODCALLTYPE* EnumAdapterByGpuPreference)(
IDXGIFactory6* This,
UINT Adapter,
DXGI_GPU_PREFERENCE GpuPreference,
REFIID riid,
void** ppvAdapter);
} IDXGIFactory6Vtbl;
struct IDXGIFactory6
{
struct IDXGIFactory6Vtbl* lpVtbl;
};
#define IDXGIFactory6_EnumAdapterByGpuPreference(This,Adapter,GpuPreference,riid,ppvAdapter) \
( (This)->lpVtbl -> EnumAdapterByGpuPreference(This,Adapter,GpuPreference,riid,ppvAdapter) )

View File

@ -8,19 +8,29 @@ EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64 Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
MinSizeRel|x64 = MinSizeRel|x64 MinSizeRel|x64 = MinSizeRel|x64
MinSizeRel|x86 = MinSizeRel|x86
Release|x64 = Release|x64 Release|x64 = Release|x64
Release|x86 = Release|x86
RelWithDebInfo|x64 = RelWithDebInfo|x64 RelWithDebInfo|x64 = RelWithDebInfo|x64
RelWithDebInfo|x86 = RelWithDebInfo|x86
EndGlobalSection EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6DB15344-E000-45CB-A48A-1D72F7D6E945}.Debug|x64.ActiveCfg = Debug|x64 {6DB15344-E000-45CB-A48A-1D72F7D6E945}.Debug|x64.ActiveCfg = Debug|x64
{6DB15344-E000-45CB-A48A-1D72F7D6E945}.Debug|x64.Build.0 = Debug|x64 {6DB15344-E000-45CB-A48A-1D72F7D6E945}.Debug|x64.Build.0 = Debug|x64
{6DB15344-E000-45CB-A48A-1D72F7D6E945}.Debug|x86.ActiveCfg = Debug|Win32
{6DB15344-E000-45CB-A48A-1D72F7D6E945}.Debug|x86.Build.0 = Debug|Win32
{6DB15344-E000-45CB-A48A-1D72F7D6E945}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64 {6DB15344-E000-45CB-A48A-1D72F7D6E945}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64
{6DB15344-E000-45CB-A48A-1D72F7D6E945}.MinSizeRel|x64.Build.0 = MinSizeRel|x64 {6DB15344-E000-45CB-A48A-1D72F7D6E945}.MinSizeRel|x64.Build.0 = MinSizeRel|x64
{6DB15344-E000-45CB-A48A-1D72F7D6E945}.MinSizeRel|x86.ActiveCfg = MinSizeRel|x64
{6DB15344-E000-45CB-A48A-1D72F7D6E945}.Release|x64.ActiveCfg = Release|x64 {6DB15344-E000-45CB-A48A-1D72F7D6E945}.Release|x64.ActiveCfg = Release|x64
{6DB15344-E000-45CB-A48A-1D72F7D6E945}.Release|x64.Build.0 = Release|x64 {6DB15344-E000-45CB-A48A-1D72F7D6E945}.Release|x64.Build.0 = Release|x64
{6DB15344-E000-45CB-A48A-1D72F7D6E945}.Release|x86.ActiveCfg = Release|Win32
{6DB15344-E000-45CB-A48A-1D72F7D6E945}.Release|x86.Build.0 = Release|Win32
{6DB15344-E000-45CB-A48A-1D72F7D6E945}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64 {6DB15344-E000-45CB-A48A-1D72F7D6E945}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64
{6DB15344-E000-45CB-A48A-1D72F7D6E945}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64 {6DB15344-E000-45CB-A48A-1D72F7D6E945}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64
{6DB15344-E000-45CB-A48A-1D72F7D6E945}.RelWithDebInfo|x86.ActiveCfg = RelWithDebInfo|x64
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@ -61,7 +61,8 @@
<ClCompile> <ClCompile>
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
<PreprocessorDefinitions>REFRESH_DRIVER_VULKAN;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>REFRESH_DRIVER_D3D11;REFRESH_DRIVER_VULKAN;SPIRV_CROSS_C_API_GLSL;SPIRV_CROSS_C_API_HLSL;SPIRV_CROSS_C_API_REFLECT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">..\SPIRV-Cross;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
<Link> <Link>
<GenerateDebugInformation>DebugFull</GenerateDebugInformation> <GenerateDebugInformation>DebugFull</GenerateDebugInformation>
@ -72,9 +73,10 @@
<ClCompile> <ClCompile>
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization> <Optimization>MaxSpeed</Optimization>
<PreprocessorDefinitions>REFRESH_DRIVER_VULKAN;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>REFRESH_DRIVER_D3D11;REFRESH_DRIVER_VULKAN;SPIRV_CROSS_C_API_GLSL;SPIRV_CROSS_C_API_HLSL;SPIRV_CROSS_C_API_REFLECT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<FunctionLevelLinking>true</FunctionLevelLinking> <FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions> <IntrinsicFunctions>true</IntrinsicFunctions>
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\SPIRV-Cross;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
<Link> <Link>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
@ -83,7 +85,16 @@
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\SPIRV-Cross\spirv_cfg.cpp" />
<ClCompile Include="..\SPIRV-Cross\spirv_cross.cpp" />
<ClCompile Include="..\SPIRV-Cross\spirv_cross_c.cpp" />
<ClCompile Include="..\SPIRV-Cross\spirv_cross_parsed_ir.cpp" />
<ClCompile Include="..\SPIRV-Cross\spirv_glsl.cpp" />
<ClCompile Include="..\SPIRV-Cross\spirv_hlsl.cpp" />
<ClCompile Include="..\SPIRV-Cross\spirv_parser.cpp" />
<ClCompile Include="..\SPIRV-Cross\spirv_reflect.cpp" />
<ClCompile Include="..\src\Refresh.c" /> <ClCompile Include="..\src\Refresh.c" />
<ClCompile Include="..\src\Refresh_Driver_D3D11.c" />
<ClCompile Include="..\src\Refresh_Driver_Vulkan.c" /> <ClCompile Include="..\src\Refresh_Driver_Vulkan.c" />
<ClCompile Include="..\src\Refresh_Image.c" /> <ClCompile Include="..\src\Refresh_Image.c" />
</ItemGroup> </ItemGroup>
@ -91,6 +102,7 @@
<ClInclude Include="..\include\Refresh.h" /> <ClInclude Include="..\include\Refresh.h" />
<ClInclude Include="..\include\Refresh_Image.h" /> <ClInclude Include="..\include\Refresh_Image.h" />
<ClInclude Include="..\src\Refresh_Driver.h" /> <ClInclude Include="..\src\Refresh_Driver.h" />
<ClInclude Include="..\src\Refresh_Driver_D3D11_cdefines.h" />
<ClInclude Include="..\src\Refresh_Driver_Vulkan_vkfuncs.h" /> <ClInclude Include="..\src\Refresh_Driver_Vulkan_vkfuncs.h" />
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

View File

@ -10,6 +10,33 @@
<ClCompile Include="..\src\Refresh_Image.c"> <ClCompile Include="..\src\Refresh_Image.c">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\src\Refresh_Driver_D3D11.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\SPIRV-Cross\spirv_cfg.cpp">
<Filter>Source Files\spirv-cross</Filter>
</ClCompile>
<ClCompile Include="..\SPIRV-Cross\spirv_cross.cpp">
<Filter>Source Files\spirv-cross</Filter>
</ClCompile>
<ClCompile Include="..\SPIRV-Cross\spirv_cross_c.cpp">
<Filter>Source Files\spirv-cross</Filter>
</ClCompile>
<ClCompile Include="..\SPIRV-Cross\spirv_cross_parsed_ir.cpp">
<Filter>Source Files\spirv-cross</Filter>
</ClCompile>
<ClCompile Include="..\SPIRV-Cross\spirv_glsl.cpp">
<Filter>Source Files\spirv-cross</Filter>
</ClCompile>
<ClCompile Include="..\SPIRV-Cross\spirv_hlsl.cpp">
<Filter>Source Files\spirv-cross</Filter>
</ClCompile>
<ClCompile Include="..\SPIRV-Cross\spirv_parser.cpp">
<Filter>Source Files\spirv-cross</Filter>
</ClCompile>
<ClCompile Include="..\SPIRV-Cross\spirv_reflect.cpp">
<Filter>Source Files\spirv-cross</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\include\Refresh.h"> <ClInclude Include="..\include\Refresh.h">
@ -24,6 +51,9 @@
<ClInclude Include="..\include\Refresh_Image.h"> <ClInclude Include="..\include\Refresh_Image.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\src\Refresh_Driver_D3D11_cdefines.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Filter Include="Header Files"> <Filter Include="Header Files">
@ -32,5 +62,8 @@
<Filter Include="Source Files"> <Filter Include="Source Files">
<UniqueIdentifier>{B2BA146C-CAA1-30BE-B7A9-F8D02673EA0C}</UniqueIdentifier> <UniqueIdentifier>{B2BA146C-CAA1-30BE-B7A9-F8D02673EA0C}</UniqueIdentifier>
</Filter> </Filter>
<Filter Include="Source Files\spirv-cross">
<UniqueIdentifier>{4764626f-fd8b-4a1c-8c20-fd92a1f3cb4b}</UniqueIdentifier>
</Filter>
</ItemGroup> </ItemGroup>
</Project> </Project>