D3D11 #52
|
@ -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
|
||||
src/Refresh_Driver_D3D11_cdefines.h
|
||||
# Source Files
|
||||
src/Refresh.c
|
||||
src/Refresh_Driver_D3D11.c
|
||||
src/Refresh_Driver_Vulkan.c
|
||||
src/Refresh_Image.c
|
||||
)
|
||||
|
|
|
@ -343,6 +343,7 @@ typedef enum Refresh_Backend
|
|||
{
|
||||
REFRESH_BACKEND_DONTCARE,
|
||||
REFRESH_BACKEND_VULKAN,
|
||||
REFRESH_BACKEND_D3D11,
|
||||
REFRESH_BACKEND_PS5,
|
||||
REFRESH_BACKEND_INVALID
|
||||
} Refresh_Backend;
|
||||
|
@ -1192,46 +1193,6 @@ REFRESHAPI void Refresh_UploadToBuffer(
|
|||
Refresh_WriteOptions writeOption
|
||||
);
|
||||
|
||||
/* GPU-to-CPU copies occur on the GPU timeline.
|
||||
*
|
||||
* You may NOT assume that the data in the TransferBuffer is fully copied
|
||||
* until the command buffer has finished execution.
|
||||
*/
|
||||
|
||||
/*
|
||||
* transferOption:
|
||||
* SAFEDISCARD:
|
||||
* If this TransferBuffer has been used in commands that have not completed,
|
||||
* the issued commands will still be valid at the cost of increased memory usage.
|
||||
* You may NOT assume that any of the previous data is retained.
|
||||
* If the TransferBuffer was not in use, this option is equivalent to OVERWRITE.
|
||||
* It is not recommended to use this option with large TransferBuffers.
|
||||
*
|
||||
* OVERWRITE:
|
||||
* Overwrites the data regardless of whether a command has been issued.
|
||||
* Use this option with great care, as it can cause data races to occur!
|
||||
*/
|
||||
|
||||
/* Downloads data from a texture to a TransferBuffer. */
|
||||
REFRESHAPI void Refresh_DownloadFromTexture(
|
||||
Refresh_Device *device,
|
||||
Refresh_CommandBuffer *commandBuffer,
|
||||
Refresh_TextureRegion *textureRegion,
|
||||
Refresh_TransferBuffer *transferBuffer,
|
||||
Refresh_BufferImageCopy *copyParams,
|
||||
Refresh_TransferOptions transferOption
|
||||
);
|
||||
|
||||
/* Downloads data from a GpuBuffer object. */
|
||||
REFRESHAPI void Refresh_DownloadFromBuffer(
|
||||
Refresh_Device *device,
|
||||
Refresh_CommandBuffer *commandBuffer,
|
||||
Refresh_GpuBuffer *gpuBuffer,
|
||||
Refresh_TransferBuffer *transferBuffer,
|
||||
Refresh_BufferCopy *copyParams,
|
||||
Refresh_TransferOptions transferOption
|
||||
);
|
||||
|
||||
/* GPU-to-GPU copies occur on the GPU timeline,
|
||||
* and you may assume the copy has finished in subsequent commands.
|
||||
*/
|
||||
|
@ -1259,26 +1220,6 @@ REFRESHAPI void Refresh_CopyTextureToTexture(
|
|||
Refresh_WriteOptions writeOption
|
||||
);
|
||||
|
||||
/* Copies image data from a texture slice into a buffer. */
|
||||
REFRESHAPI void Refresh_CopyTextureToBuffer(
|
||||
Refresh_Device *device,
|
||||
Refresh_CommandBuffer *commandBuffer,
|
||||
Refresh_TextureRegion *textureRegion,
|
||||
Refresh_GpuBuffer *gpuBuffer,
|
||||
Refresh_BufferImageCopy *copyParams,
|
||||
Refresh_WriteOptions writeOption
|
||||
);
|
||||
|
||||
/* Copies data from a buffer to a texture slice. */
|
||||
REFRESHAPI void Refresh_CopyBufferToTexture(
|
||||
Refresh_Device *device,
|
||||
Refresh_CommandBuffer *commandBuffer,
|
||||
Refresh_GpuBuffer *gpuBuffer,
|
||||
Refresh_TextureRegion *textureRegion,
|
||||
Refresh_BufferImageCopy *copyParams,
|
||||
Refresh_WriteOptions writeOption
|
||||
);
|
||||
|
||||
/* Copies data from a buffer to a buffer. */
|
||||
REFRESHAPI void Refresh_CopyBufferToBuffer(
|
||||
Refresh_Device *device,
|
||||
|
@ -1420,6 +1361,49 @@ REFRESHAPI void Refresh_ReleaseFence(
|
|||
Refresh_Fence *fence
|
||||
);
|
||||
|
||||
/* Readback */
|
||||
|
||||
/* GPU-to-CPU copies occur immediately on the CPU timeline.
|
||||
*
|
||||
* If you modify data on the GPU and then call these functions without calling Wait or WaitForFences first,
|
||||
* the data will be undefined!
|
||||
*
|
||||
* Readback forces a sync point and is generally a bad thing to do.
|
||||
* Only use these functions if you have exhausted all other options.
|
||||
*/
|
||||
|
||||
/*
|
||||
* transferOption:
|
||||
* SAFEDISCARD:
|
||||
* If this TransferBuffer has been used in commands that have not completed,
|
||||
* the issued commands will still be valid at the cost of increased memory usage.
|
||||
* You may NOT assume that any of the previous data is retained.
|
||||
* If the TransferBuffer was not in use, this option is equivalent to OVERWRITE.
|
||||
* It is not recommended to use this option with large TransferBuffers.
|
||||
*
|
||||
* OVERWRITE:
|
||||
* Overwrites the data regardless of whether a command has been issued.
|
||||
* Use this option with great care, as it can cause data races to occur!
|
||||
*/
|
||||
|
||||
/* Downloads data from a texture to a TransferBuffer. */
|
||||
REFRESHAPI void Refresh_DownloadFromTexture(
|
||||
Refresh_Device *device,
|
||||
Refresh_TextureRegion *textureRegion,
|
||||
Refresh_TransferBuffer *transferBuffer,
|
||||
Refresh_BufferImageCopy *copyParams,
|
||||
Refresh_TransferOptions transferOption
|
||||
);
|
||||
|
||||
/* Downloads data from a GpuBuffer object. */
|
||||
REFRESHAPI void Refresh_DownloadFromBuffer(
|
||||
Refresh_Device *device,
|
||||
Refresh_GpuBuffer *gpuBuffer,
|
||||
Refresh_TransferBuffer *transferBuffer,
|
||||
Refresh_BufferCopy *copyParams,
|
||||
Refresh_TransferOptions transferOption
|
||||
);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
|
|
@ -194,26 +194,37 @@ partial class Program
|
|||
// Magic
|
||||
writer.Write(new char[] { 'R', 'F', 'S', 'H'});
|
||||
|
||||
// Type
|
||||
uint shaderTypeIndex;
|
||||
switch (shaderType)
|
||||
{
|
||||
default:
|
||||
case ".vert": shaderTypeIndex = 0; break;
|
||||
case ".frag": shaderTypeIndex = 1; break;
|
||||
case ".comp": shaderTypeIndex = 2; break;
|
||||
}
|
||||
writer.Write(shaderTypeIndex);
|
||||
|
||||
if (data.vulkan)
|
||||
{
|
||||
string inputPath = Path.Combine(tempDir, $"{shaderName}.spv");
|
||||
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 +265,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)
|
||||
|
|
139
src/Refresh.c
139
src/Refresh.c
|
@ -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
|
||||
};
|
||||
|
||||
|
@ -235,7 +242,7 @@ Refresh_ShaderModule* Refresh_CreateShaderModule(
|
|||
Refresh_Device *device,
|
||||
Refresh_ShaderModuleCreateInfo *shaderModuleCreateInfo
|
||||
) {
|
||||
Refresh_ShaderModuleCreateInfo driverSpecificCreateInfo = { 0, NULL };
|
||||
Refresh_Driver_ShaderModuleCreateInfo driverSpecificCreateInfo = { 0, NULL, 0 };
|
||||
uint8_t *bytes;
|
||||
uint32_t i, size;
|
||||
|
||||
|
@ -245,12 +252,24 @@ Refresh_ShaderModule* Refresh_CreateShaderModule(
|
|||
bytes = (uint8_t*) shaderModuleCreateInfo->byteCode;
|
||||
if (bytes[0] != 'R' || bytes[1] != 'F' || bytes[2] != 'S' || bytes[3] != 'H')
|
||||
{
|
||||
Refresh_LogError("Cannot parse malformed Refresh shader blob!");
|
||||
Refresh_LogError("Cannot parse malformed Refresh shader blob: Incorrect magic number");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* get the type of shader */
|
||||
driverSpecificCreateInfo.type = (Refresh_Driver_ShaderType) *((uint32_t*) &bytes[4]);
|
||||
if ( driverSpecificCreateInfo.type < 0 ||
|
||||
driverSpecificCreateInfo.type > REFRESH_DRIVER_SHADERTYPE_COMPUTE )
|
||||
{
|
||||
Refresh_LogError(
|
||||
"Cannot parse malformed Refresh shader blob: Unknown shader type (%d)",
|
||||
driverSpecificCreateInfo.type
|
||||
);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* find the code for the selected backend */
|
||||
i = 4;
|
||||
i = 8;
|
||||
while (i < shaderModuleCreateInfo->codeSize)
|
||||
{
|
||||
size = *((uint32_t*) &bytes[i + 1]);
|
||||
|
@ -805,44 +824,6 @@ void Refresh_UploadToBuffer(
|
|||
);
|
||||
}
|
||||
|
||||
void Refresh_DownloadFromTexture(
|
||||
Refresh_Device *device,
|
||||
Refresh_CommandBuffer *commandBuffer,
|
||||
Refresh_TextureRegion *textureRegion,
|
||||
Refresh_TransferBuffer *transferBuffer,
|
||||
Refresh_BufferImageCopy *copyParams,
|
||||
Refresh_TransferOptions transferOption
|
||||
) {
|
||||
NULL_RETURN(device);
|
||||
device->DownloadFromTexture(
|
||||
device->driverData,
|
||||
commandBuffer,
|
||||
textureRegion,
|
||||
transferBuffer,
|
||||
copyParams,
|
||||
transferOption
|
||||
);
|
||||
}
|
||||
|
||||
void Refresh_DownloadFromBuffer(
|
||||
Refresh_Device *device,
|
||||
Refresh_CommandBuffer *commandBuffer,
|
||||
Refresh_GpuBuffer *gpuBuffer,
|
||||
Refresh_TransferBuffer *transferBuffer,
|
||||
Refresh_BufferCopy *copyParams,
|
||||
Refresh_TransferOptions transferOption
|
||||
) {
|
||||
NULL_RETURN(device);
|
||||
device->DownloadFromBuffer(
|
||||
device->driverData,
|
||||
commandBuffer,
|
||||
gpuBuffer,
|
||||
transferBuffer,
|
||||
copyParams,
|
||||
transferOption
|
||||
);
|
||||
}
|
||||
|
||||
void Refresh_CopyTextureToTexture(
|
||||
Refresh_Device *device,
|
||||
Refresh_CommandBuffer *commandBuffer,
|
||||
|
@ -860,44 +841,6 @@ void Refresh_CopyTextureToTexture(
|
|||
);
|
||||
}
|
||||
|
||||
void Refresh_CopyTextureToBuffer(
|
||||
Refresh_Device *device,
|
||||
Refresh_CommandBuffer *commandBuffer,
|
||||
Refresh_TextureRegion *textureRegion,
|
||||
Refresh_GpuBuffer *gpuBuffer,
|
||||
Refresh_BufferImageCopy *copyParameters,
|
||||
Refresh_WriteOptions writeOption
|
||||
) {
|
||||
NULL_RETURN(device);
|
||||
device->CopyTextureToBuffer(
|
||||
device->driverData,
|
||||
commandBuffer,
|
||||
textureRegion,
|
||||
gpuBuffer,
|
||||
copyParameters,
|
||||
writeOption
|
||||
);
|
||||
}
|
||||
|
||||
void Refresh_CopyBufferToTexture(
|
||||
Refresh_Device *device,
|
||||
Refresh_CommandBuffer *commandBuffer,
|
||||
Refresh_GpuBuffer *gpuBuffer,
|
||||
Refresh_TextureRegion *textureRegion,
|
||||
Refresh_BufferImageCopy *copyParams,
|
||||
Refresh_WriteOptions writeOption
|
||||
) {
|
||||
NULL_RETURN(device);
|
||||
device->CopyBufferToTexture(
|
||||
device->driverData,
|
||||
commandBuffer,
|
||||
gpuBuffer,
|
||||
textureRegion,
|
||||
copyParams,
|
||||
writeOption
|
||||
);
|
||||
}
|
||||
|
||||
void Refresh_CopyBufferToBuffer(
|
||||
Refresh_Device *device,
|
||||
Refresh_CommandBuffer *commandBuffer,
|
||||
|
@ -1067,9 +1010,7 @@ int Refresh_QueryFence(
|
|||
Refresh_Device *device,
|
||||
Refresh_Fence *fence
|
||||
) {
|
||||
if (device == NULL) {
|
||||
return 0;
|
||||
}
|
||||
if (device == NULL) { return 0; }
|
||||
|
||||
return device->QueryFence(
|
||||
device->driverData,
|
||||
|
@ -1088,4 +1029,38 @@ void Refresh_ReleaseFence(
|
|||
);
|
||||
}
|
||||
|
||||
void Refresh_DownloadFromTexture(
|
||||
Refresh_Device *device,
|
||||
Refresh_TextureRegion *textureRegion,
|
||||
Refresh_TransferBuffer *transferBuffer,
|
||||
Refresh_BufferImageCopy *copyParams,
|
||||
Refresh_TransferOptions transferOption
|
||||
) {
|
||||
NULL_RETURN(device);
|
||||
device->DownloadFromTexture(
|
||||
device->driverData,
|
||||
textureRegion,
|
||||
transferBuffer,
|
||||
copyParams,
|
||||
transferOption
|
||||
);
|
||||
}
|
||||
|
||||
void Refresh_DownloadFromBuffer(
|
||||
Refresh_Device *device,
|
||||
Refresh_GpuBuffer *gpuBuffer,
|
||||
Refresh_TransferBuffer *transferBuffer,
|
||||
Refresh_BufferCopy *copyParams,
|
||||
Refresh_TransferOptions transferOption
|
||||
) {
|
||||
NULL_RETURN(device);
|
||||
device->DownloadFromBuffer(
|
||||
device->driverData,
|
||||
gpuBuffer,
|
||||
transferBuffer,
|
||||
copyParams,
|
||||
transferOption
|
||||
);
|
||||
}
|
||||
|
||||
/* vim: set noexpandtab shiftwidth=8 tabstop=8: */
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
@ -171,6 +211,22 @@ static inline int32_t BytesPerImage(
|
|||
#define MAX_COLOR_TARGET_BINDINGS 4
|
||||
#define MAX_PRESENT_COUNT 16
|
||||
|
||||
/* Internal Shader Module Create Info */
|
||||
|
||||
typedef enum Refresh_Driver_ShaderType
|
||||
{
|
||||
REFRESH_DRIVER_SHADERTYPE_VERTEX,
|
||||
REFRESH_DRIVER_SHADERTYPE_FRAGMENT,
|
||||
REFRESH_DRIVER_SHADERTYPE_COMPUTE
|
||||
} Refresh_Driver_ShaderType;
|
||||
|
||||
typedef struct Refresh_Driver_ShaderModuleCreateInfo
|
||||
{
|
||||
size_t codeSize;
|
||||
const uint32_t* byteCode;
|
||||
Refresh_Driver_ShaderType type;
|
||||
} Refresh_Driver_ShaderModuleCreateInfo;
|
||||
|
||||
/* Refresh_Device Definition */
|
||||
|
||||
typedef struct Refresh_Renderer Refresh_Renderer;
|
||||
|
@ -200,7 +256,7 @@ struct Refresh_Device
|
|||
|
||||
Refresh_ShaderModule* (*CreateShaderModule)(
|
||||
Refresh_Renderer *driverData,
|
||||
Refresh_ShaderModuleCreateInfo *shaderModuleCreateInfo
|
||||
Refresh_Driver_ShaderModuleCreateInfo *shaderModuleCreateInfo
|
||||
);
|
||||
|
||||
Refresh_Texture* (*CreateTexture)(
|
||||
|
@ -450,24 +506,6 @@ struct Refresh_Device
|
|||
Refresh_WriteOptions writeOption
|
||||
);
|
||||
|
||||
void (*DownloadFromTexture)(
|
||||
Refresh_Renderer *driverData,
|
||||
Refresh_CommandBuffer *commandBuffer,
|
||||
Refresh_TextureRegion *textureSlice,
|
||||
Refresh_TransferBuffer *transferBuffer,
|
||||
Refresh_BufferImageCopy *copyParams,
|
||||
Refresh_TransferOptions transferOption
|
||||
);
|
||||
|
||||
void (*DownloadFromBuffer)(
|
||||
Refresh_Renderer *driverData,
|
||||
Refresh_CommandBuffer *commandBuffer,
|
||||
Refresh_GpuBuffer *gpuBuffer,
|
||||
Refresh_TransferBuffer *transferBuffer,
|
||||
Refresh_BufferCopy *copyParams,
|
||||
Refresh_TransferOptions transferOption
|
||||
);
|
||||
|
||||
void (*CopyTextureToTexture)(
|
||||
Refresh_Renderer *driverData,
|
||||
Refresh_CommandBuffer *commandBuffer,
|
||||
|
@ -476,24 +514,6 @@ struct Refresh_Device
|
|||
Refresh_WriteOptions writeOption
|
||||
);
|
||||
|
||||
void (*CopyTextureToBuffer)(
|
||||
Refresh_Renderer *driverData,
|
||||
Refresh_CommandBuffer *commandBuffer,
|
||||
Refresh_TextureRegion *textureSlice,
|
||||
Refresh_GpuBuffer *gpuBuffer,
|
||||
Refresh_BufferImageCopy *copyParams,
|
||||
Refresh_WriteOptions writeOption
|
||||
);
|
||||
|
||||
void (*CopyBufferToTexture)(
|
||||
Refresh_Renderer *driverData,
|
||||
Refresh_CommandBuffer *commandBuffer,
|
||||
Refresh_GpuBuffer *gpuBuffer,
|
||||
Refresh_TextureRegion *textureSlice,
|
||||
Refresh_BufferImageCopy *copyParams,
|
||||
Refresh_WriteOptions writeOption
|
||||
);
|
||||
|
||||
void (*CopyBufferToBuffer)(
|
||||
Refresh_Renderer *driverData,
|
||||
Refresh_CommandBuffer *commandBuffer,
|
||||
|
@ -581,6 +601,22 @@ struct Refresh_Device
|
|||
Refresh_Fence *fence
|
||||
);
|
||||
|
||||
void (*DownloadFromTexture)(
|
||||
Refresh_Renderer *driverData,
|
||||
Refresh_TextureRegion *textureSlice,
|
||||
Refresh_TransferBuffer *transferBuffer,
|
||||
Refresh_BufferImageCopy *copyParams,
|
||||
Refresh_TransferOptions transferOption
|
||||
);
|
||||
|
||||
void (*DownloadFromBuffer)(
|
||||
Refresh_Renderer *driverData,
|
||||
Refresh_GpuBuffer *gpuBuffer,
|
||||
Refresh_TransferBuffer *transferBuffer,
|
||||
Refresh_BufferCopy *copyParams,
|
||||
Refresh_TransferOptions transferOption
|
||||
);
|
||||
|
||||
/* Opaque pointer for the Driver */
|
||||
Refresh_Renderer *driverData;
|
||||
};
|
||||
|
@ -633,8 +669,6 @@ struct Refresh_Device
|
|||
ASSIGN_DRIVER_FUNC(DownloadFromTexture, name) \
|
||||
ASSIGN_DRIVER_FUNC(DownloadFromBuffer, name) \
|
||||
ASSIGN_DRIVER_FUNC(CopyTextureToTexture, name) \
|
||||
ASSIGN_DRIVER_FUNC(CopyTextureToBuffer, name) \
|
||||
ASSIGN_DRIVER_FUNC(CopyBufferToTexture, name) \
|
||||
ASSIGN_DRIVER_FUNC(CopyBufferToBuffer, name) \
|
||||
ASSIGN_DRIVER_FUNC(GenerateMipmaps, name) \
|
||||
ASSIGN_DRIVER_FUNC(EndCopyPass, name) \
|
||||
|
@ -661,6 +695,7 @@ typedef struct Refresh_Driver
|
|||
} Refresh_Driver;
|
||||
|
||||
extern Refresh_Driver VulkanDriver;
|
||||
extern Refresh_Driver D3D11Driver;
|
||||
extern Refresh_Driver PS5Driver;
|
||||
|
||||
#endif /* REFRESH_DRIVER_H */
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,42 @@
|
|||
/* 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);
|
||||
typedef HRESULT(WINAPI* PFN_DXGI_GET_DEBUG_INTERFACE)(const GUID* riid, void** ppDebug);
|
||||
|
||||
/* 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_IDXGIFactory4 = { 0x1bc6ea02,0xef36,0x464f,{0xbf,0x0c,0x21,0xca,0x39,0xe5,0x16,0x8a} };
|
||||
static const IID D3D_IID_IDXGIFactory5 = { 0x7632e1f5,0xee65,0x4dca,{0x87,0xfd,0x84,0xcd,0x75,0xf8,0x83,0x8d} };
|
||||
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} };
|
||||
static const IID D3D_IID_IDXGIDebug = { 0x119e7452,0xde9e,0x40fe,{0x88,0x06,0x88,0xf9,0x0c,0x12,0xb4,0x41} };
|
||||
static const IID D3D_IID_IDXGIInfoQueue = { 0xd67441c7,0x672a,0x476f,{0x9e,0x82,0xcd,0x55,0xb4,0x49,0x49,0xce} };
|
||||
|
||||
static const GUID D3D_IID_DXGI_DEBUG_ALL = { 0xe48ae283,0xda80,0x490b,{0x87,0xe6,0x43,0xe9,0xa9,0xcf,0xda,0x08} };
|
|
@ -318,7 +318,7 @@ static Refresh_Sampler* TEMPLATE_CreateSampler(
|
|||
|
||||
static Refresh_ShaderModule* TEMPLATE_CreateShaderModule(
|
||||
Refresh_Renderer *driverData,
|
||||
Refresh_ShaderModuleCreateInfo *shaderModuleCreateInfo
|
||||
Refresh_Driver_ShaderModuleCreateInfo *shaderModuleCreateInfo
|
||||
) {
|
||||
NOT_IMPLEMENTED
|
||||
}
|
||||
|
|
|
@ -6670,7 +6670,7 @@ static Refresh_Sampler* VULKAN_CreateSampler(
|
|||
|
||||
static Refresh_ShaderModule* VULKAN_CreateShaderModule(
|
||||
Refresh_Renderer *driverData,
|
||||
Refresh_ShaderModuleCreateInfo *shaderModuleCreateInfo
|
||||
Refresh_Driver_ShaderModuleCreateInfo *shaderModuleCreateInfo
|
||||
) {
|
||||
VulkanShaderModule *vulkanShaderModule = SDL_malloc(sizeof(VulkanShaderModule));
|
||||
VkResult vulkanResult;
|
||||
|
@ -8550,130 +8550,6 @@ static void VULKAN_UploadToBuffer(
|
|||
VULKAN_INTERNAL_TrackCopiedBuffer(renderer, vulkanCommandBuffer, gpuBufferContainer->activeBufferHandle->vulkanBuffer);
|
||||
}
|
||||
|
||||
static void VULKAN_DownloadFromTexture(
|
||||
Refresh_Renderer *driverData,
|
||||
Refresh_CommandBuffer *commandBuffer,
|
||||
Refresh_TextureRegion *textureRegion,
|
||||
Refresh_TransferBuffer *transferBuffer,
|
||||
Refresh_BufferImageCopy *copyParams,
|
||||
Refresh_TransferOptions transferOption
|
||||
) {
|
||||
VulkanRenderer *renderer = (VulkanRenderer*) driverData;
|
||||
VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer*) commandBuffer;
|
||||
VulkanTextureSlice *vulkanTextureSlice;
|
||||
VulkanBufferContainer *transferBufferContainer = (VulkanBufferContainer*) transferBuffer;
|
||||
VkBufferImageCopy imageCopy;
|
||||
|
||||
vulkanTextureSlice = VULKAN_INTERNAL_RefreshToVulkanTextureSlice(&textureRegion->textureSlice);
|
||||
|
||||
if (
|
||||
transferOption == REFRESH_TRANSFEROPTIONS_SAFEDISCARD &&
|
||||
SDL_AtomicGet(&transferBufferContainer->activeBufferHandle->vulkanBuffer->referenceCount) > 0
|
||||
) {
|
||||
VULKAN_INTERNAL_DiscardActiveBuffer(
|
||||
renderer,
|
||||
transferBufferContainer
|
||||
);
|
||||
vulkanTextureSlice = VULKAN_INTERNAL_RefreshToVulkanTextureSlice(&textureRegion->textureSlice);
|
||||
}
|
||||
|
||||
VULKAN_INTERNAL_BufferMemoryBarrier(
|
||||
renderer,
|
||||
vulkanCommandBuffer->commandBuffer,
|
||||
RESOURCE_ACCESS_TRANSFER_WRITE,
|
||||
transferBufferContainer->activeBufferHandle->vulkanBuffer
|
||||
);
|
||||
|
||||
VULKAN_INTERNAL_ImageMemoryBarrier(
|
||||
renderer,
|
||||
vulkanCommandBuffer->commandBuffer,
|
||||
RESOURCE_ACCESS_TRANSFER_READ,
|
||||
vulkanTextureSlice
|
||||
);
|
||||
|
||||
imageCopy.imageExtent.width = textureRegion->w;
|
||||
imageCopy.imageExtent.height = textureRegion->h;
|
||||
imageCopy.imageExtent.depth = textureRegion->d;
|
||||
imageCopy.imageOffset.x = textureRegion->x;
|
||||
imageCopy.imageOffset.y = textureRegion->y;
|
||||
imageCopy.imageOffset.z = textureRegion->z;
|
||||
imageCopy.imageSubresource.aspectMask = vulkanTextureSlice->parent->aspectFlags;
|
||||
imageCopy.imageSubresource.baseArrayLayer = textureRegion->textureSlice.layer;
|
||||
imageCopy.imageSubresource.layerCount = 1;
|
||||
imageCopy.imageSubresource.mipLevel = textureRegion->textureSlice.mipLevel;
|
||||
imageCopy.bufferOffset = copyParams->bufferOffset;
|
||||
imageCopy.bufferRowLength = copyParams->bufferStride;
|
||||
imageCopy.bufferImageHeight = copyParams->bufferImageHeight;
|
||||
|
||||
renderer->vkCmdCopyImageToBuffer(
|
||||
vulkanCommandBuffer->commandBuffer,
|
||||
vulkanTextureSlice->parent->image,
|
||||
AccessMap[vulkanTextureSlice->resourceAccessType].imageLayout,
|
||||
transferBufferContainer->activeBufferHandle->vulkanBuffer->buffer,
|
||||
1,
|
||||
&imageCopy
|
||||
);
|
||||
|
||||
VULKAN_INTERNAL_TrackBuffer(renderer, vulkanCommandBuffer, transferBufferContainer->activeBufferHandle->vulkanBuffer);
|
||||
VULKAN_INTERNAL_TrackTextureSlice(renderer, vulkanCommandBuffer, vulkanTextureSlice);
|
||||
VULKAN_INTERNAL_TrackCopiedTextureSlice(renderer, vulkanCommandBuffer, vulkanTextureSlice);
|
||||
}
|
||||
|
||||
static void VULKAN_DownloadFromBuffer(
|
||||
Refresh_Renderer *driverData,
|
||||
Refresh_CommandBuffer *commandBuffer,
|
||||
Refresh_GpuBuffer *gpuBuffer,
|
||||
Refresh_TransferBuffer *transferBuffer,
|
||||
Refresh_BufferCopy *copyParams,
|
||||
Refresh_TransferOptions transferOption
|
||||
) {
|
||||
VulkanRenderer *renderer = (VulkanRenderer*) driverData;
|
||||
VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer*) commandBuffer;
|
||||
VulkanBufferContainer *gpuBufferContainer = (VulkanBufferContainer*) gpuBuffer;
|
||||
VulkanBufferContainer *transferBufferContainer = (VulkanBufferContainer*) transferBuffer;
|
||||
VkBufferCopy bufferCopy;
|
||||
|
||||
if (
|
||||
transferOption == REFRESH_TRANSFEROPTIONS_SAFEDISCARD &&
|
||||
SDL_AtomicGet(&transferBufferContainer->activeBufferHandle->vulkanBuffer->referenceCount) > 0
|
||||
) {
|
||||
VULKAN_INTERNAL_DiscardActiveBuffer(
|
||||
renderer,
|
||||
transferBufferContainer
|
||||
);
|
||||
}
|
||||
|
||||
VULKAN_INTERNAL_BufferMemoryBarrier(
|
||||
renderer,
|
||||
vulkanCommandBuffer->commandBuffer,
|
||||
RESOURCE_ACCESS_TRANSFER_WRITE,
|
||||
transferBufferContainer->activeBufferHandle->vulkanBuffer
|
||||
);
|
||||
|
||||
VULKAN_INTERNAL_BufferMemoryBarrier(
|
||||
renderer,
|
||||
vulkanCommandBuffer->commandBuffer,
|
||||
RESOURCE_ACCESS_TRANSFER_READ,
|
||||
gpuBufferContainer->activeBufferHandle->vulkanBuffer
|
||||
);
|
||||
|
||||
bufferCopy.srcOffset = copyParams->srcOffset;
|
||||
bufferCopy.dstOffset = copyParams->dstOffset;
|
||||
bufferCopy.size = copyParams->size;
|
||||
|
||||
renderer->vkCmdCopyBuffer(
|
||||
vulkanCommandBuffer->commandBuffer,
|
||||
gpuBufferContainer->activeBufferHandle->vulkanBuffer->buffer,
|
||||
transferBufferContainer->activeBufferHandle->vulkanBuffer->buffer,
|
||||
1,
|
||||
&bufferCopy
|
||||
);
|
||||
|
||||
VULKAN_INTERNAL_TrackBuffer(renderer, vulkanCommandBuffer, transferBufferContainer->activeBufferHandle->vulkanBuffer);
|
||||
VULKAN_INTERNAL_TrackBuffer(renderer, vulkanCommandBuffer, gpuBufferContainer->activeBufferHandle->vulkanBuffer);
|
||||
VULKAN_INTERNAL_TrackCopiedBuffer(renderer, vulkanCommandBuffer, gpuBufferContainer->activeBufferHandle->vulkanBuffer);
|
||||
}
|
||||
|
||||
static void VULKAN_CopyTextureToTexture(
|
||||
Refresh_Renderer *driverData,
|
||||
Refresh_CommandBuffer *commandBuffer,
|
||||
|
@ -8751,147 +8627,6 @@ static void VULKAN_CopyTextureToTexture(
|
|||
VULKAN_INTERNAL_TrackCopiedTextureSlice(renderer, vulkanCommandBuffer, dstSlice);
|
||||
}
|
||||
|
||||
static void VULKAN_CopyTextureToBuffer(
|
||||
Refresh_Renderer *driverData,
|
||||
Refresh_CommandBuffer *commandBuffer,
|
||||
Refresh_TextureRegion *textureRegion,
|
||||
Refresh_GpuBuffer *gpuBuffer,
|
||||
Refresh_BufferImageCopy *copyParams,
|
||||
Refresh_WriteOptions writeOption
|
||||
) {
|
||||
VulkanRenderer *renderer = (VulkanRenderer*) driverData;
|
||||
VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer*) commandBuffer;
|
||||
VulkanTextureSlice *vulkanTextureSlice;
|
||||
VulkanBufferContainer *bufferContainer = (VulkanBufferContainer*) gpuBuffer;
|
||||
VkBufferImageCopy imageCopy;
|
||||
|
||||
vulkanTextureSlice = VULKAN_INTERNAL_RefreshToVulkanTextureSlice(&textureRegion->textureSlice);
|
||||
|
||||
if (
|
||||
writeOption == REFRESH_WRITEOPTIONS_SAFEDISCARD &&
|
||||
SDL_AtomicGet(&bufferContainer->activeBufferHandle->vulkanBuffer->referenceCount) > 0
|
||||
) {
|
||||
VULKAN_INTERNAL_DiscardActiveBuffer(
|
||||
renderer,
|
||||
bufferContainer
|
||||
);
|
||||
}
|
||||
|
||||
VULKAN_INTERNAL_ImageMemoryBarrier(
|
||||
renderer,
|
||||
vulkanCommandBuffer->commandBuffer,
|
||||
RESOURCE_ACCESS_TRANSFER_READ,
|
||||
vulkanTextureSlice
|
||||
);
|
||||
|
||||
VULKAN_INTERNAL_BufferMemoryBarrier(
|
||||
renderer,
|
||||
vulkanCommandBuffer->commandBuffer,
|
||||
RESOURCE_ACCESS_TRANSFER_WRITE,
|
||||
bufferContainer->activeBufferHandle->vulkanBuffer
|
||||
);
|
||||
|
||||
imageCopy.imageExtent.width = textureRegion->w;
|
||||
imageCopy.imageExtent.height = textureRegion->h;
|
||||
imageCopy.imageExtent.depth = textureRegion->d;
|
||||
imageCopy.imageOffset.x = textureRegion->x;
|
||||
imageCopy.imageOffset.y = textureRegion->y;
|
||||
imageCopy.imageOffset.z = textureRegion->z;
|
||||
imageCopy.imageSubresource.aspectMask = vulkanTextureSlice->parent->aspectFlags;
|
||||
imageCopy.imageSubresource.baseArrayLayer = textureRegion->textureSlice.layer;
|
||||
imageCopy.imageSubresource.layerCount = 1;
|
||||
imageCopy.imageSubresource.mipLevel = textureRegion->textureSlice.mipLevel;
|
||||
imageCopy.bufferOffset = copyParams->bufferOffset;
|
||||
imageCopy.bufferRowLength = copyParams->bufferStride;
|
||||
imageCopy.bufferImageHeight = copyParams->bufferImageHeight;
|
||||
|
||||
renderer->vkCmdCopyImageToBuffer(
|
||||
vulkanCommandBuffer->commandBuffer,
|
||||
vulkanTextureSlice->parent->image,
|
||||
AccessMap[vulkanTextureSlice->resourceAccessType].imageLayout,
|
||||
bufferContainer->activeBufferHandle->vulkanBuffer->buffer,
|
||||
1,
|
||||
&imageCopy
|
||||
);
|
||||
|
||||
VULKAN_INTERNAL_TrackBuffer(renderer, vulkanCommandBuffer, bufferContainer->activeBufferHandle->vulkanBuffer);
|
||||
VULKAN_INTERNAL_TrackTextureSlice(renderer, vulkanCommandBuffer, vulkanTextureSlice);
|
||||
VULKAN_INTERNAL_TrackCopiedBuffer(renderer, vulkanCommandBuffer, bufferContainer->activeBufferHandle->vulkanBuffer);
|
||||
VULKAN_INTERNAL_TrackCopiedTextureSlice(renderer, vulkanCommandBuffer, vulkanTextureSlice);
|
||||
}
|
||||
|
||||
static void VULKAN_CopyBufferToTexture(
|
||||
Refresh_Renderer *driverData,
|
||||
Refresh_CommandBuffer *commandBuffer,
|
||||
Refresh_GpuBuffer *gpuBuffer,
|
||||
Refresh_TextureRegion *textureRegion,
|
||||
Refresh_BufferImageCopy *copyParams,
|
||||
Refresh_WriteOptions writeOption
|
||||
) {
|
||||
VulkanRenderer *renderer = (VulkanRenderer*) driverData;
|
||||
VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer*) commandBuffer;
|
||||
VulkanBufferContainer *bufferContainer = (VulkanBufferContainer*) gpuBuffer;
|
||||
VulkanTextureContainer *textureContainer = (VulkanTextureContainer*) textureRegion->textureSlice.texture;
|
||||
VulkanTextureSlice *vulkanTextureSlice;
|
||||
VkBufferImageCopy imageCopy;
|
||||
|
||||
vulkanTextureSlice = VULKAN_INTERNAL_RefreshToVulkanTextureSlice(&textureRegion->textureSlice);
|
||||
|
||||
if (
|
||||
writeOption == REFRESH_WRITEOPTIONS_SAFEDISCARD &&
|
||||
textureContainer->canBeDiscarded &&
|
||||
SDL_AtomicGet(&vulkanTextureSlice->referenceCount) > 0
|
||||
) {
|
||||
VULKAN_INTERNAL_DiscardActiveTexture(
|
||||
renderer,
|
||||
textureContainer
|
||||
);
|
||||
vulkanTextureSlice = VULKAN_INTERNAL_RefreshToVulkanTextureSlice(&textureRegion->textureSlice);
|
||||
}
|
||||
|
||||
VULKAN_INTERNAL_BufferMemoryBarrier(
|
||||
renderer,
|
||||
vulkanCommandBuffer->commandBuffer,
|
||||
RESOURCE_ACCESS_TRANSFER_READ,
|
||||
bufferContainer->activeBufferHandle->vulkanBuffer
|
||||
);
|
||||
|
||||
VULKAN_INTERNAL_ImageMemoryBarrier(
|
||||
renderer,
|
||||
vulkanCommandBuffer->commandBuffer,
|
||||
RESOURCE_ACCESS_TRANSFER_WRITE,
|
||||
vulkanTextureSlice
|
||||
);
|
||||
|
||||
imageCopy.imageExtent.width = textureRegion->w;
|
||||
imageCopy.imageExtent.height = textureRegion->h;
|
||||
imageCopy.imageExtent.depth = textureRegion->d;
|
||||
imageCopy.imageOffset.x = textureRegion->x;
|
||||
imageCopy.imageOffset.y = textureRegion->y;
|
||||
imageCopy.imageOffset.z = textureRegion->z;
|
||||
imageCopy.imageSubresource.aspectMask = vulkanTextureSlice->parent->aspectFlags;
|
||||
imageCopy.imageSubresource.baseArrayLayer = textureRegion->textureSlice.layer;
|
||||
imageCopy.imageSubresource.layerCount = 1;
|
||||
imageCopy.imageSubresource.mipLevel = textureRegion->textureSlice.mipLevel;
|
||||
imageCopy.bufferOffset = copyParams->bufferOffset;
|
||||
imageCopy.bufferRowLength = copyParams->bufferStride;
|
||||
imageCopy.bufferImageHeight = copyParams->bufferImageHeight;
|
||||
|
||||
renderer->vkCmdCopyBufferToImage(
|
||||
vulkanCommandBuffer->commandBuffer,
|
||||
bufferContainer->activeBufferHandle->vulkanBuffer->buffer,
|
||||
vulkanTextureSlice->parent->image,
|
||||
AccessMap[vulkanTextureSlice->resourceAccessType].imageLayout,
|
||||
1,
|
||||
&imageCopy
|
||||
);
|
||||
|
||||
VULKAN_INTERNAL_TrackBuffer(renderer, vulkanCommandBuffer, bufferContainer->activeBufferHandle->vulkanBuffer);
|
||||
VULKAN_INTERNAL_TrackTextureSlice(renderer, vulkanCommandBuffer, vulkanTextureSlice);
|
||||
VULKAN_INTERNAL_TrackCopiedBuffer(renderer, vulkanCommandBuffer, bufferContainer->activeBufferHandle->vulkanBuffer);
|
||||
VULKAN_INTERNAL_TrackCopiedTextureSlice(renderer, vulkanCommandBuffer, vulkanTextureSlice);
|
||||
}
|
||||
|
||||
static void VULKAN_CopyBufferToBuffer(
|
||||
Refresh_Renderer *driverData,
|
||||
Refresh_CommandBuffer *commandBuffer,
|
||||
|
@ -10461,6 +10196,175 @@ static void VULKAN_ReleaseFence(
|
|||
VULKAN_INTERNAL_ReturnFenceToPool((VulkanRenderer*) driverData, (VkFence) fence);
|
||||
}
|
||||
|
||||
/* Readback */
|
||||
|
||||
static void VULKAN_DownloadFromTexture(
|
||||
Refresh_Renderer *driverData,
|
||||
Refresh_TextureRegion *textureRegion,
|
||||
Refresh_TransferBuffer *transferBuffer,
|
||||
Refresh_BufferImageCopy *copyParams,
|
||||
Refresh_TransferOptions transferOption
|
||||
) {
|
||||
VulkanRenderer *renderer = (VulkanRenderer*) driverData;
|
||||
VulkanTextureSlice *vulkanTextureSlice;
|
||||
VulkanBufferContainer *transferBufferContainer = (VulkanBufferContainer*) transferBuffer;
|
||||
VkBufferImageCopy imageCopy;
|
||||
vulkanTextureSlice = VULKAN_INTERNAL_RefreshToVulkanTextureSlice(&textureRegion->textureSlice);
|
||||
Refresh_Fence *fence;
|
||||
VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer*) VULKAN_AcquireCommandBuffer(driverData);
|
||||
VulkanResourceAccessType originalTextureSliceAccessType;
|
||||
VulkanResourceAccessType originalBufferAccessType;
|
||||
|
||||
if (
|
||||
transferOption == REFRESH_TRANSFEROPTIONS_SAFEDISCARD &&
|
||||
SDL_AtomicGet(&transferBufferContainer->activeBufferHandle->vulkanBuffer->referenceCount) > 0
|
||||
) {
|
||||
VULKAN_INTERNAL_DiscardActiveBuffer(
|
||||
renderer,
|
||||
transferBufferContainer
|
||||
);
|
||||
vulkanTextureSlice = VULKAN_INTERNAL_RefreshToVulkanTextureSlice(&textureRegion->textureSlice);
|
||||
}
|
||||
|
||||
originalTextureSliceAccessType = vulkanTextureSlice->resourceAccessType;
|
||||
originalBufferAccessType = transferBufferContainer->activeBufferHandle->vulkanBuffer->resourceAccessType;
|
||||
|
||||
VULKAN_INTERNAL_BufferMemoryBarrier(
|
||||
renderer,
|
||||
vulkanCommandBuffer->commandBuffer,
|
||||
RESOURCE_ACCESS_TRANSFER_WRITE,
|
||||
transferBufferContainer->activeBufferHandle->vulkanBuffer
|
||||
);
|
||||
|
||||
VULKAN_INTERNAL_ImageMemoryBarrier(
|
||||
renderer,
|
||||
vulkanCommandBuffer->commandBuffer,
|
||||
RESOURCE_ACCESS_TRANSFER_READ,
|
||||
vulkanTextureSlice
|
||||
);
|
||||
|
||||
imageCopy.imageExtent.width = textureRegion->w;
|
||||
imageCopy.imageExtent.height = textureRegion->h;
|
||||
imageCopy.imageExtent.depth = textureRegion->d;
|
||||
imageCopy.imageOffset.x = textureRegion->x;
|
||||
imageCopy.imageOffset.y = textureRegion->y;
|
||||
imageCopy.imageOffset.z = textureRegion->z;
|
||||
imageCopy.imageSubresource.aspectMask = vulkanTextureSlice->parent->aspectFlags;
|
||||
imageCopy.imageSubresource.baseArrayLayer = textureRegion->textureSlice.layer;
|
||||
imageCopy.imageSubresource.layerCount = 1;
|
||||
imageCopy.imageSubresource.mipLevel = textureRegion->textureSlice.mipLevel;
|
||||
imageCopy.bufferOffset = copyParams->bufferOffset;
|
||||
imageCopy.bufferRowLength = copyParams->bufferStride;
|
||||
imageCopy.bufferImageHeight = copyParams->bufferImageHeight;
|
||||
|
||||
renderer->vkCmdCopyImageToBuffer(
|
||||
vulkanCommandBuffer->commandBuffer,
|
||||
vulkanTextureSlice->parent->image,
|
||||
AccessMap[vulkanTextureSlice->resourceAccessType].imageLayout,
|
||||
transferBufferContainer->activeBufferHandle->vulkanBuffer->buffer,
|
||||
1,
|
||||
&imageCopy
|
||||
);
|
||||
|
||||
VULKAN_INTERNAL_ImageMemoryBarrier(
|
||||
renderer,
|
||||
vulkanCommandBuffer->commandBuffer,
|
||||
originalTextureSliceAccessType,
|
||||
vulkanTextureSlice
|
||||
);
|
||||
|
||||
VULKAN_INTERNAL_BufferMemoryBarrier(
|
||||
renderer,
|
||||
vulkanCommandBuffer->commandBuffer,
|
||||
originalBufferAccessType,
|
||||
transferBufferContainer->activeBufferHandle->vulkanBuffer);
|
||||
|
||||
VULKAN_INTERNAL_TrackBuffer(renderer, vulkanCommandBuffer, transferBufferContainer->activeBufferHandle->vulkanBuffer);
|
||||
VULKAN_INTERNAL_TrackTextureSlice(renderer, vulkanCommandBuffer, vulkanTextureSlice);
|
||||
VULKAN_INTERNAL_TrackCopiedTextureSlice(renderer, vulkanCommandBuffer, vulkanTextureSlice);
|
||||
|
||||
fence = VULKAN_SubmitAndAcquireFence(driverData, (Refresh_CommandBuffer*) vulkanCommandBuffer);
|
||||
VULKAN_WaitForFences(driverData, 1, 1, &fence);
|
||||
VULKAN_ReleaseFence(driverData, fence);
|
||||
}
|
||||
|
||||
static void VULKAN_DownloadFromBuffer(
|
||||
Refresh_Renderer *driverData,
|
||||
Refresh_GpuBuffer *gpuBuffer,
|
||||
Refresh_TransferBuffer *transferBuffer,
|
||||
Refresh_BufferCopy *copyParams,
|
||||
Refresh_TransferOptions transferOption
|
||||
) {
|
||||
VulkanRenderer *renderer = (VulkanRenderer*) driverData;
|
||||
VulkanBufferContainer *gpuBufferContainer = (VulkanBufferContainer*) gpuBuffer;
|
||||
VulkanBufferContainer *transferBufferContainer = (VulkanBufferContainer*) transferBuffer;
|
||||
VkBufferCopy bufferCopy;
|
||||
Refresh_Fence *fence;
|
||||
VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer*) VULKAN_AcquireCommandBuffer(driverData);
|
||||
VulkanResourceAccessType originalTransferBufferAccessType;
|
||||
VulkanResourceAccessType originalGpuBufferAccessType;
|
||||
|
||||
if (
|
||||
transferOption == REFRESH_TRANSFEROPTIONS_SAFEDISCARD &&
|
||||
SDL_AtomicGet(&transferBufferContainer->activeBufferHandle->vulkanBuffer->referenceCount) > 0
|
||||
) {
|
||||
VULKAN_INTERNAL_DiscardActiveBuffer(
|
||||
renderer,
|
||||
transferBufferContainer
|
||||
);
|
||||
}
|
||||
|
||||
originalTransferBufferAccessType = transferBufferContainer->activeBufferHandle->vulkanBuffer->resourceAccessType;
|
||||
originalGpuBufferAccessType = gpuBufferContainer->activeBufferHandle->vulkanBuffer->resourceAccessType;
|
||||
|
||||
VULKAN_INTERNAL_BufferMemoryBarrier(
|
||||
renderer,
|
||||
vulkanCommandBuffer->commandBuffer,
|
||||
RESOURCE_ACCESS_TRANSFER_WRITE,
|
||||
transferBufferContainer->activeBufferHandle->vulkanBuffer
|
||||
);
|
||||
|
||||
VULKAN_INTERNAL_BufferMemoryBarrier(
|
||||
renderer,
|
||||
vulkanCommandBuffer->commandBuffer,
|
||||
RESOURCE_ACCESS_TRANSFER_READ,
|
||||
gpuBufferContainer->activeBufferHandle->vulkanBuffer
|
||||
);
|
||||
|
||||
bufferCopy.srcOffset = copyParams->srcOffset;
|
||||
bufferCopy.dstOffset = copyParams->dstOffset;
|
||||
bufferCopy.size = copyParams->size;
|
||||
|
||||
renderer->vkCmdCopyBuffer(
|
||||
vulkanCommandBuffer->commandBuffer,
|
||||
gpuBufferContainer->activeBufferHandle->vulkanBuffer->buffer,
|
||||
transferBufferContainer->activeBufferHandle->vulkanBuffer->buffer,
|
||||
1,
|
||||
&bufferCopy
|
||||
);
|
||||
|
||||
VULKAN_INTERNAL_BufferMemoryBarrier(
|
||||
renderer,
|
||||
vulkanCommandBuffer->commandBuffer,
|
||||
originalTransferBufferAccessType,
|
||||
transferBufferContainer->activeBufferHandle->vulkanBuffer
|
||||
);
|
||||
|
||||
VULKAN_INTERNAL_BufferMemoryBarrier(
|
||||
renderer,
|
||||
vulkanCommandBuffer->commandBuffer,
|
||||
originalGpuBufferAccessType,
|
||||
gpuBufferContainer->activeBufferHandle->vulkanBuffer);
|
||||
|
||||
VULKAN_INTERNAL_TrackBuffer(renderer, vulkanCommandBuffer, transferBufferContainer->activeBufferHandle->vulkanBuffer);
|
||||
VULKAN_INTERNAL_TrackBuffer(renderer, vulkanCommandBuffer, gpuBufferContainer->activeBufferHandle->vulkanBuffer);
|
||||
VULKAN_INTERNAL_TrackCopiedBuffer(renderer, vulkanCommandBuffer, gpuBufferContainer->activeBufferHandle->vulkanBuffer);
|
||||
|
||||
fence = VULKAN_SubmitAndAcquireFence(driverData, (Refresh_CommandBuffer*) vulkanCommandBuffer);
|
||||
VULKAN_WaitForFences(driverData, 1, 1, &fence);
|
||||
VULKAN_ReleaseFence(driverData, fence);
|
||||
}
|
||||
|
||||
/* Device instantiation */
|
||||
|
||||
static inline uint8_t CheckDeviceExtensions(
|
||||
|
|
|
@ -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" />
|
||||
|
|
|
@ -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">
|
||||
|
|
Loading…
Reference in New Issue