Compare commits

...

28 Commits

Author SHA1 Message Date
Caleb Cornett f91c18e85c Fixed uniform offsets, removed a bunch of code from cdefines.h 2023-11-05 19:20:37 -06:00
Caleb Cornett ff0f30a986 Uniform buffer infrastructure, still missing offset support 2023-11-05 14:17:23 -06:00
Caleb Cornett bf4b640937 Fix texture conversion array 2023-10-26 23:03:05 -05:00
Caleb Cornett 01aff2e5f1 Fix command buffer memory leak 2023-10-26 21:39:15 -05:00
Caleb Cornett 3966614681 CreateTexture, SetTextureData, BindIndexBuffer, BindFragmentSamplers, QueueDestroyTexture, DrawIndexedPrimitives, DrawInstancedPrimitives 2023-10-26 21:25:03 -05:00
Caleb Cornett 21c5ded803 Fix redundant error code printing 2023-10-26 20:37:27 -05:00
Caleb Cornett 5ba865489b QueueDestroySampler 2023-10-12 22:12:55 -05:00
Caleb Cornett 595c15a087 Add a border color conversion function 2023-10-12 22:11:55 -05:00
Caleb Cornett 50730bd52d CreateSampler 2023-10-12 22:07:46 -05:00
Caleb Cornett e3748391fe CreateBuffer, QueueDestroyBuffer, SetBufferData, BindVertexBuffers 2023-10-12 21:31:04 -05:00
Caleb Cornett 5c6d32e21a Initial work on DestroyDevice 2023-10-12 08:42:32 -05:00
Caleb Cornett 0555023100 Implement SetViewport and SetScissor 2023-10-12 08:18:53 -05:00
Caleb Cornett 3c22699dbb Style cleanups + added FIXME note for shader compilation 2023-10-12 08:18:39 -05:00
Caleb Cornett 509bd278c7 shaderc now flips Y values in the vertex shader 2023-10-10 21:51:34 -05:00
Caleb Cornett e17f86724a DrawPrimitives, BindGraphicsPipeline, misc cleanup 2023-10-10 21:45:32 -05:00
Caleb Cornett c327c3547a Implement CreateShaderModule 2023-10-10 21:32:12 -05:00
Caleb Cornett e7b2542bc0 Pipeline creation copied over from old work + shaderc update 2023-10-10 21:27:36 -05:00
Caleb Cornett e48941eb48 Fix for command pool crash, fix for hanging on Wait 2023-10-08 16:16:11 -05:00
Caleb Cornett 4fecc829bf Reworked Wait and Submit logic to use D3D11 Query objects as fences 2023-10-08 16:05:33 -05:00
Caleb Cornett ff41afb04a Stub out D3D11_Wait, fix crash when unclaiming windows, fix backend order 2023-10-08 15:14:43 -05:00
Caleb Cornett cb467c7b1a UnclaimWindow, swapchain destruction, fixed template signature 2023-10-08 15:14:43 -05:00
Caleb Cornett d5a3438547 Implemented BeginRenderPass and Submit, ClearScreen works now! 2023-10-08 15:14:43 -05:00
Caleb Cornett 287d3a7a6e More swapchain setup 2023-10-08 15:14:43 -05:00
Caleb Cornett 433c70eb8c Apply swapchainDesc fix from FNA3D, add cdefines.h to CMakeLists 2023-10-08 15:14:43 -05:00
Caleb Cornett 8c98889f46 Implemented AcquireCommandBuffer (from old D3D11 work) 2023-10-08 15:14:43 -05:00
Caleb Cornett 0e5da8a2ea Implement ClaimWindow, mostly copied from Vulkan and FNA3D D3D11 2023-10-08 15:14:43 -05:00
Caleb Cornett 8b999aca93 Remove old stuff, flesh out PrepareDriver 2023-10-08 15:14:43 -05:00
Caleb Cornett 2498e2d7c4 Groundwork for D3D11. Yoinked most of this from the prior work, but updated the ABI 2023-10-08 15:13:08 -05:00
9 changed files with 3333 additions and 11 deletions

View File

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

View File

@ -330,6 +330,7 @@ typedef enum Refresh_Backend
{
REFRESH_BACKEND_DONTCARE,
REFRESH_BACKEND_VULKAN,
REFRESH_BACKEND_D3D11,
REFRESH_BACKEND_PS5,
REFRESH_BACKEND_INVALID
} Refresh_Backend;

View File

@ -200,20 +200,20 @@ partial class Program
WriteShaderBlob(writer, inputPath, 1);
}
if (data.d3d11)
{
string inputPath = Path.Combine(tempDir, $"{shaderName}.hlsl");
WriteShaderBlob(writer, inputPath, 2);
}
#if PS5
if (data.ps5)
{
string ext = GetPS5ShaderFileExtension();
string inputPath = Path.Combine(tempDir, $"{shaderName}{ext}");
WriteShaderBlob(writer, inputPath, 2);
}
#endif
if (data.d3d11)
{
string inputPath = Path.Combine(tempDir, $"{shaderName}.hlsl");
WriteShaderBlob(writer, inputPath, 3);
}
#endif
}
}
@ -254,7 +254,7 @@ partial class Program
{
Process spirvcross = Process.Start(
"spirv-cross",
$"""{spirvPath}"" --hlsl --shader-model 50 --output ""{outputPath}"""
$"""{spirvPath}"" --hlsl --flip-vert-y --shader-model 50 --output ""{outputPath}"""
);
spirvcross.WaitForExit();
if (spirvcross.ExitCode != 0)

View File

@ -39,6 +39,12 @@
#define VULKAN_DRIVER NULL
#endif
#ifdef REFRESH_DRIVER_D3D11
#define D3D11_DRIVER &D3D11Driver
#else
#define D3D11_DRIVER NULL
#endif
#ifdef REFRESH_DRIVER_PS5
#define PS5_DRIVER &PS5Driver
#else
@ -48,6 +54,7 @@
static const Refresh_Driver *backends[] = {
NULL,
VULKAN_DRIVER,
D3D11_DRIVER,
PS5_DRIVER
};

View File

@ -48,6 +48,46 @@ void Refresh_LogError(const char *fmt, ...);
/* Internal Helper Utilities */
static inline int32_t Texture_GetBlockSize(
Refresh_TextureFormat format
) {
switch (format)
{
case REFRESH_TEXTUREFORMAT_BC1:
case REFRESH_TEXTUREFORMAT_BC2:
case REFRESH_TEXTUREFORMAT_BC3:
case REFRESH_TEXTUREFORMAT_BC7:
return 4;
case REFRESH_TEXTUREFORMAT_R8:
case REFRESH_TEXTUREFORMAT_R8_UINT:
case REFRESH_TEXTUREFORMAT_R5G6B5:
case REFRESH_TEXTUREFORMAT_B4G4R4A4:
case REFRESH_TEXTUREFORMAT_A1R5G5B5:
case REFRESH_TEXTUREFORMAT_R16_SFLOAT:
case REFRESH_TEXTUREFORMAT_R8G8_SNORM:
case REFRESH_TEXTUREFORMAT_R8G8_UINT:
case REFRESH_TEXTUREFORMAT_R16_UINT:
case REFRESH_TEXTUREFORMAT_R8G8B8A8:
case REFRESH_TEXTUREFORMAT_R32_SFLOAT:
case REFRESH_TEXTUREFORMAT_R16G16_SFLOAT:
case REFRESH_TEXTUREFORMAT_R8G8B8A8_SNORM:
case REFRESH_TEXTUREFORMAT_A2R10G10B10:
case REFRESH_TEXTUREFORMAT_R8G8B8A8_UINT:
case REFRESH_TEXTUREFORMAT_R16G16_UINT:
case REFRESH_TEXTUREFORMAT_R16G16B16A16_SFLOAT:
case REFRESH_TEXTUREFORMAT_R16G16B16A16:
case REFRESH_TEXTUREFORMAT_R32G32_SFLOAT:
case REFRESH_TEXTUREFORMAT_R16G16B16A16_UINT:
case REFRESH_TEXTUREFORMAT_R32G32B32A32_SFLOAT:
return 1;
default:
Refresh_LogError(
"Unrecognized TextureFormat!"
);
return 0;
}
}
static inline uint32_t Texture_GetFormatSize(
Refresh_TextureFormat format
) {
@ -87,7 +127,7 @@ static inline uint32_t Texture_GetFormatSize(
return 16;
default:
Refresh_LogError(
"Unrecognized SurfaceFormat!"
"Unrecognized TextureFormat!"
);
return 0;
}
@ -597,6 +637,7 @@ typedef struct Refresh_Driver
} Refresh_Driver;
extern Refresh_Driver VulkanDriver;
extern Refresh_Driver D3D11Driver;
extern Refresh_Driver PS5Driver;
#endif /* REFRESH_DRIVER_H */

3221
src/Refresh_Driver_D3D11.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,36 @@
/* 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_FACTORY1)(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} };
static const IID D3D_IID_ID3D11Device1 = { 0xa04bfb29,0x08ef,0x43d6,{0xa4,0x9c,0xa9,0xbd,0xbd,0xcb,0xe6,0x86} };

View File

@ -61,7 +61,7 @@
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>REFRESH_DRIVER_VULKAN;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>REFRESH_DRIVER_VULKAN;REFRESH_DRIVER_D3D11;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<GenerateDebugInformation>DebugFull</GenerateDebugInformation>
@ -72,7 +72,7 @@
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<PreprocessorDefinitions>REFRESH_DRIVER_VULKAN;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>REFRESH_DRIVER_VULKAN;REFRESH_DRIVER_D3D11;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
</ClCompile>
@ -84,6 +84,7 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\src\Refresh.c" />
<ClCompile Include="..\src\Refresh_Driver_D3D11.c" />
<ClCompile Include="..\src\Refresh_Driver_Vulkan.c" />
<ClCompile Include="..\src\Refresh_Image.c" />
</ItemGroup>
@ -91,6 +92,7 @@
<ClInclude Include="..\include\Refresh.h" />
<ClInclude Include="..\include\Refresh_Image.h" />
<ClInclude Include="..\src\Refresh_Driver.h" />
<ClInclude Include="..\src\Refresh_Driver_D3D11_cdefines.h" />
<ClInclude Include="..\src\Refresh_Driver_Vulkan_vkfuncs.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

View File

@ -10,6 +10,9 @@
<ClCompile Include="..\src\Refresh_Image.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\Refresh_Driver_D3D11.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\include\Refresh.h">
@ -24,6 +27,9 @@
<ClInclude Include="..\include\Refresh_Image.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\src\Refresh_Driver_D3D11_cdefines.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="Header Files">