|
|
|
@ -79,8 +79,8 @@ typedef struct VulkanExtensions
|
|
|
|
|
#define ALLOCATION_INCREMENT 16000000 /* 16MB */
|
|
|
|
|
#define TRANSFER_BUFFER_STARTING_SIZE 8000000 /* 8MB */
|
|
|
|
|
#define POOLED_TRANSFER_BUFFER_SIZE 16000000 /* 16MB */
|
|
|
|
|
#define UBO_BUFFER_SIZE 16000000 /* 16MB */
|
|
|
|
|
#define UBO_SECTION_SIZE 4000 /* 4KB */
|
|
|
|
|
#define UBO_BUFFER_SIZE 16777216 /* 16MB */
|
|
|
|
|
#define UBO_SECTION_SIZE 4096 /* 4KB */
|
|
|
|
|
#define DESCRIPTOR_POOL_STARTING_SIZE 128
|
|
|
|
|
#define DEFRAG_TIME 200
|
|
|
|
|
#define WINDOW_DATA "Refresh_VulkanWindowData"
|
|
|
|
@ -708,6 +708,7 @@ struct VulkanBuffer
|
|
|
|
|
VulkanResourceAccessType resourceAccessType;
|
|
|
|
|
VkBufferUsageFlags usage;
|
|
|
|
|
|
|
|
|
|
uint8_t requireHostVisible;
|
|
|
|
|
uint8_t preferDeviceLocal;
|
|
|
|
|
|
|
|
|
|
SDL_atomic_t referenceCount; /* Tracks command buffer usage */
|
|
|
|
@ -998,7 +999,6 @@ typedef struct RenderPassColorTargetDescription
|
|
|
|
|
Refresh_Vec4 clearColor;
|
|
|
|
|
Refresh_LoadOp loadOp;
|
|
|
|
|
Refresh_StoreOp storeOp;
|
|
|
|
|
VkImageLayout finalLayout;
|
|
|
|
|
} RenderPassColorTargetDescription;
|
|
|
|
|
|
|
|
|
|
typedef struct RenderPassDepthStencilTargetDescription
|
|
|
|
@ -1008,7 +1008,6 @@ typedef struct RenderPassDepthStencilTargetDescription
|
|
|
|
|
Refresh_StoreOp storeOp;
|
|
|
|
|
Refresh_LoadOp stencilLoadOp;
|
|
|
|
|
Refresh_StoreOp stencilStoreOp;
|
|
|
|
|
VkImageLayout finalLayout;
|
|
|
|
|
} RenderPassDepthStencilTargetDescription;
|
|
|
|
|
|
|
|
|
|
typedef struct RenderPassHash
|
|
|
|
@ -1072,11 +1071,6 @@ static inline uint8_t RenderPassHash_Compare(
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (a->colorTargetDescriptions[i].finalLayout != b->colorTargetDescriptions[i].finalLayout)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (a->depthStencilTargetDescription.format != b->depthStencilTargetDescription.format)
|
|
|
|
@ -1104,11 +1098,6 @@ static inline uint8_t RenderPassHash_Compare(
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (a->depthStencilTargetDescription.finalLayout != b->depthStencilTargetDescription.finalLayout)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -1991,59 +1980,51 @@ static inline uint32_t VULKAN_INTERNAL_BytesPerPixel(VkFormat format)
|
|
|
|
|
{
|
|
|
|
|
switch (format)
|
|
|
|
|
{
|
|
|
|
|
case VK_FORMAT_R8_UNORM:
|
|
|
|
|
case VK_FORMAT_R8_UINT:
|
|
|
|
|
return 1;
|
|
|
|
|
case VK_FORMAT_R5G6B5_UNORM_PACK16:
|
|
|
|
|
case VK_FORMAT_B4G4R4A4_UNORM_PACK16:
|
|
|
|
|
case VK_FORMAT_A1R5G5B5_UNORM_PACK16:
|
|
|
|
|
case VK_FORMAT_R16_SFLOAT:
|
|
|
|
|
case VK_FORMAT_R8G8_SNORM:
|
|
|
|
|
case VK_FORMAT_R8G8_UINT:
|
|
|
|
|
case VK_FORMAT_R16_UINT:
|
|
|
|
|
case VK_FORMAT_D16_UNORM:
|
|
|
|
|
return 2;
|
|
|
|
|
case VK_FORMAT_D16_UNORM_S8_UINT:
|
|
|
|
|
return 3;
|
|
|
|
|
case VK_FORMAT_R8G8B8A8_UNORM:
|
|
|
|
|
case VK_FORMAT_B8G8R8A8_UNORM:
|
|
|
|
|
case VK_FORMAT_R32_SFLOAT:
|
|
|
|
|
case VK_FORMAT_R16G16_UNORM:
|
|
|
|
|
case VK_FORMAT_R16G16_SFLOAT:
|
|
|
|
|
case VK_FORMAT_R8G8B8A8_SNORM:
|
|
|
|
|
case VK_FORMAT_A2R10G10B10_UNORM_PACK32:
|
|
|
|
|
case VK_FORMAT_R8G8B8A8_UINT:
|
|
|
|
|
case VK_FORMAT_R16G16_UINT:
|
|
|
|
|
case VK_FORMAT_D32_SFLOAT:
|
|
|
|
|
return 4;
|
|
|
|
|
case VK_FORMAT_D32_SFLOAT_S8_UINT:
|
|
|
|
|
return 5;
|
|
|
|
|
case VK_FORMAT_R16G16B16A16_SFLOAT:
|
|
|
|
|
case VK_FORMAT_R16G16B16A16_UNORM:
|
|
|
|
|
case VK_FORMAT_R32G32_SFLOAT:
|
|
|
|
|
case VK_FORMAT_R16G16B16A16_UINT:
|
|
|
|
|
case VK_FORMAT_BC1_RGBA_UNORM_BLOCK:
|
|
|
|
|
return 8;
|
|
|
|
|
case VK_FORMAT_R32G32B32A32_SFLOAT:
|
|
|
|
|
case VK_FORMAT_BC2_UNORM_BLOCK:
|
|
|
|
|
case VK_FORMAT_BC3_UNORM_BLOCK:
|
|
|
|
|
case VK_FORMAT_BC7_UNORM_BLOCK:
|
|
|
|
|
case VK_FORMAT_R16G16B16A16_UINT:
|
|
|
|
|
return 16;
|
|
|
|
|
|
|
|
|
|
case VK_FORMAT_R8G8B8A8_UNORM:
|
|
|
|
|
case VK_FORMAT_R8G8B8A8_SNORM:
|
|
|
|
|
case VK_FORMAT_B8G8R8A8_UNORM:
|
|
|
|
|
case VK_FORMAT_B8G8R8A8_SNORM:
|
|
|
|
|
case VK_FORMAT_A2R10G10B10_UNORM_PACK32:
|
|
|
|
|
case VK_FORMAT_R16G16_UNORM:
|
|
|
|
|
case VK_FORMAT_R16G16_SFLOAT:
|
|
|
|
|
case VK_FORMAT_R32_SFLOAT:
|
|
|
|
|
case VK_FORMAT_D32_SFLOAT:
|
|
|
|
|
case VK_FORMAT_R8G8B8A8_UINT:
|
|
|
|
|
case VK_FORMAT_R16G16_UINT:
|
|
|
|
|
return 4;
|
|
|
|
|
|
|
|
|
|
case VK_FORMAT_R5G6B5_UNORM_PACK16:
|
|
|
|
|
case VK_FORMAT_A1R5G5B5_UNORM_PACK16:
|
|
|
|
|
case VK_FORMAT_B4G4R4A4_UNORM_PACK16:
|
|
|
|
|
case VK_FORMAT_R8G8_SNORM:
|
|
|
|
|
case VK_FORMAT_R16_SFLOAT:
|
|
|
|
|
case VK_FORMAT_D16_UNORM:
|
|
|
|
|
case VK_FORMAT_R8G8_UINT:
|
|
|
|
|
case VK_FORMAT_R16_UINT:
|
|
|
|
|
return 2;
|
|
|
|
|
|
|
|
|
|
case VK_FORMAT_R16G16B16A16_UNORM:
|
|
|
|
|
case VK_FORMAT_R32G32_SFLOAT:
|
|
|
|
|
case VK_FORMAT_R16G16B16A16_SFLOAT:
|
|
|
|
|
case VK_FORMAT_BC1_RGBA_UNORM_BLOCK:
|
|
|
|
|
case VK_FORMAT_R8_UINT:
|
|
|
|
|
return 8;
|
|
|
|
|
|
|
|
|
|
case VK_FORMAT_R8_UNORM:
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
case VK_FORMAT_D16_UNORM_S8_UINT:
|
|
|
|
|
return 3;
|
|
|
|
|
|
|
|
|
|
case VK_FORMAT_D32_SFLOAT_S8_UINT:
|
|
|
|
|
return 5;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
Refresh_LogError("Invalid texture format!");
|
|
|
|
|
Refresh_LogError("Texture format not recognized!");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline uint32_t VULKAN_INTERNAL_GetTextureBlockSize(
|
|
|
|
|
static inline uint32_t VULKAN_INTERNAL_TextureBlockSize(
|
|
|
|
|
VkFormat format
|
|
|
|
|
) {
|
|
|
|
|
switch (format)
|
|
|
|
@ -2058,24 +2039,28 @@ static inline uint32_t VULKAN_INTERNAL_GetTextureBlockSize(
|
|
|
|
|
case VK_FORMAT_R5G6B5_UNORM_PACK16:
|
|
|
|
|
case VK_FORMAT_A1R5G5B5_UNORM_PACK16:
|
|
|
|
|
case VK_FORMAT_B4G4R4A4_UNORM_PACK16:
|
|
|
|
|
case VK_FORMAT_R8G8_SNORM:
|
|
|
|
|
case VK_FORMAT_R8G8B8A8_SNORM:
|
|
|
|
|
case VK_FORMAT_A2R10G10B10_UNORM_PACK32:
|
|
|
|
|
case VK_FORMAT_R16G16_UNORM:
|
|
|
|
|
case VK_FORMAT_R16G16B16A16_UNORM:
|
|
|
|
|
case VK_FORMAT_R8_UNORM:
|
|
|
|
|
case VK_FORMAT_R32_SFLOAT:
|
|
|
|
|
case VK_FORMAT_R32G32_SFLOAT:
|
|
|
|
|
case VK_FORMAT_R32G32B32A32_SFLOAT:
|
|
|
|
|
case VK_FORMAT_R8G8_SNORM:
|
|
|
|
|
case VK_FORMAT_R8G8B8A8_SNORM:
|
|
|
|
|
case VK_FORMAT_R16_SFLOAT:
|
|
|
|
|
case VK_FORMAT_R16G16_SFLOAT:
|
|
|
|
|
case VK_FORMAT_R16G16B16A16_SFLOAT:
|
|
|
|
|
case VK_FORMAT_R32_SFLOAT:
|
|
|
|
|
case VK_FORMAT_R32G32_SFLOAT:
|
|
|
|
|
case VK_FORMAT_R32G32B32A32_SFLOAT:
|
|
|
|
|
case VK_FORMAT_R8_UINT:
|
|
|
|
|
case VK_FORMAT_R8G8_UINT:
|
|
|
|
|
case VK_FORMAT_R8G8B8A8_UINT:
|
|
|
|
|
case VK_FORMAT_R16_UINT:
|
|
|
|
|
case VK_FORMAT_R16G16_UINT:
|
|
|
|
|
case VK_FORMAT_R16G16B16A16_UINT:
|
|
|
|
|
case VK_FORMAT_D16_UNORM:
|
|
|
|
|
case VK_FORMAT_D32_SFLOAT:
|
|
|
|
|
case VK_FORMAT_D16_UNORM_S8_UINT:
|
|
|
|
|
case VK_FORMAT_D32_SFLOAT_S8_UINT:
|
|
|
|
|
return 1;
|
|
|
|
|
default:
|
|
|
|
|
Refresh_LogError("Unrecognized texture format!");
|
|
|
|
@ -2088,17 +2073,8 @@ static inline VkDeviceSize VULKAN_INTERNAL_BytesPerImage(
|
|
|
|
|
uint32_t height,
|
|
|
|
|
VkFormat format
|
|
|
|
|
) {
|
|
|
|
|
uint32_t blocksPerRow = width;
|
|
|
|
|
uint32_t blocksPerColumn = height;
|
|
|
|
|
uint32_t blockSize = VULKAN_INTERNAL_GetTextureBlockSize(format);
|
|
|
|
|
|
|
|
|
|
if (blockSize > 1)
|
|
|
|
|
{
|
|
|
|
|
blocksPerRow = (width + blockSize - 1) / blockSize;
|
|
|
|
|
blocksPerColumn = (height + blockSize - 1) / blockSize;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return blocksPerRow * blocksPerColumn * VULKAN_INTERNAL_BytesPerPixel(format);
|
|
|
|
|
uint32_t blockSize = VULKAN_INTERNAL_TextureBlockSize(format);
|
|
|
|
|
return (width * height * VULKAN_INTERNAL_BytesPerPixel(format)) / (blockSize * blockSize);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline Refresh_SampleCount VULKAN_INTERNAL_GetMaxMultiSampleCount(
|
|
|
|
@ -2957,7 +2933,7 @@ static uint8_t VULKAN_INTERNAL_BindMemoryForImage(
|
|
|
|
|
{
|
|
|
|
|
memoryTypeIndex = 0;
|
|
|
|
|
requiredMemoryPropertyFlags = 0;
|
|
|
|
|
ignoredMemoryPropertyFlags = VK_MEMORY_HEAP_DEVICE_LOCAL_BIT;
|
|
|
|
|
ignoredMemoryPropertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
|
|
|
|
|
|
|
|
|
|
if (isRenderTarget)
|
|
|
|
|
{
|
|
|
|
@ -3003,23 +2979,32 @@ static uint8_t VULKAN_INTERNAL_BindMemoryForBuffer(
|
|
|
|
|
VulkanRenderer* renderer,
|
|
|
|
|
VkBuffer buffer,
|
|
|
|
|
VkDeviceSize size,
|
|
|
|
|
uint8_t requireHostVisible,
|
|
|
|
|
uint8_t preferDeviceLocal,
|
|
|
|
|
uint8_t dedicatedAllocation,
|
|
|
|
|
VulkanMemoryUsedRegion** usedRegion
|
|
|
|
|
) {
|
|
|
|
|
uint8_t bindResult = 0;
|
|
|
|
|
uint32_t memoryTypeIndex = 0;
|
|
|
|
|
VkMemoryPropertyFlags requiredMemoryPropertyFlags;
|
|
|
|
|
VkMemoryPropertyFlags ignoredMemoryPropertyFlags;
|
|
|
|
|
VkMemoryPropertyFlags requiredMemoryPropertyFlags = 0;
|
|
|
|
|
VkMemoryPropertyFlags ignoredMemoryPropertyFlags = 0;
|
|
|
|
|
VkMemoryRequirements2KHR memoryRequirements =
|
|
|
|
|
{
|
|
|
|
|
VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2_KHR,
|
|
|
|
|
NULL
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (requireHostVisible)
|
|
|
|
|
{
|
|
|
|
|
requiredMemoryPropertyFlags =
|
|
|
|
|
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
|
|
|
|
|
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ignoredMemoryPropertyFlags =
|
|
|
|
|
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (preferDeviceLocal)
|
|
|
|
|
{
|
|
|
|
@ -3058,9 +3043,10 @@ static uint8_t VULKAN_INTERNAL_BindMemoryForBuffer(
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Bind failed, try again if originally preferred device local */
|
|
|
|
|
if (bindResult != 1 && preferDeviceLocal)
|
|
|
|
|
if (bindResult != 1)
|
|
|
|
|
{
|
|
|
|
|
memoryTypeIndex = 0;
|
|
|
|
|
|
|
|
|
|
requiredMemoryPropertyFlags =
|
|
|
|
|
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
|
|
|
|
|
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
|
|
|
|
@ -4121,6 +4107,7 @@ static VulkanBuffer* VULKAN_INTERNAL_CreateBuffer(
|
|
|
|
|
VkDeviceSize size,
|
|
|
|
|
VulkanResourceAccessType resourceAccessType,
|
|
|
|
|
VkBufferUsageFlags usage,
|
|
|
|
|
uint8_t requireHostVisible,
|
|
|
|
|
uint8_t preferDeviceLocal,
|
|
|
|
|
uint8_t dedicatedAllocation
|
|
|
|
|
) {
|
|
|
|
@ -4134,6 +4121,7 @@ static VulkanBuffer* VULKAN_INTERNAL_CreateBuffer(
|
|
|
|
|
buffer->size = size;
|
|
|
|
|
buffer->resourceAccessType = resourceAccessType;
|
|
|
|
|
buffer->usage = usage;
|
|
|
|
|
buffer->requireHostVisible = requireHostVisible;
|
|
|
|
|
buffer->preferDeviceLocal = preferDeviceLocal;
|
|
|
|
|
|
|
|
|
|
bufferCreateInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
|
|
|
|
@ -4157,6 +4145,7 @@ static VulkanBuffer* VULKAN_INTERNAL_CreateBuffer(
|
|
|
|
|
renderer,
|
|
|
|
|
buffer->buffer,
|
|
|
|
|
buffer->size,
|
|
|
|
|
buffer->requireHostVisible,
|
|
|
|
|
buffer->preferDeviceLocal,
|
|
|
|
|
dedicatedAllocation,
|
|
|
|
|
&buffer->usedRegion
|
|
|
|
@ -4240,6 +4229,7 @@ static VulkanUniformBufferPool* VULKAN_INTERNAL_CreateUniformBufferPool(
|
|
|
|
|
UBO_BUFFER_SIZE,
|
|
|
|
|
resourceAccessType,
|
|
|
|
|
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
|
|
|
|
|
1,
|
|
|
|
|
0,
|
|
|
|
|
1
|
|
|
|
|
);
|
|
|
|
@ -4285,8 +4275,7 @@ static VulkanBufferContainer* VULKAN_INTERNAL_CreateBufferContainer(
|
|
|
|
|
VulkanRenderer *renderer,
|
|
|
|
|
uint32_t sizeInBytes,
|
|
|
|
|
VulkanResourceAccessType resourceAccessType,
|
|
|
|
|
VkBufferUsageFlags usageFlags,
|
|
|
|
|
uint8_t dedicated
|
|
|
|
|
VkBufferUsageFlags usageFlags
|
|
|
|
|
) {
|
|
|
|
|
VulkanBufferContainer* bufferContainer;
|
|
|
|
|
VulkanBuffer* buffer;
|
|
|
|
@ -4299,8 +4288,9 @@ static VulkanBufferContainer* VULKAN_INTERNAL_CreateBufferContainer(
|
|
|
|
|
sizeInBytes,
|
|
|
|
|
resourceAccessType,
|
|
|
|
|
usageFlags,
|
|
|
|
|
0,
|
|
|
|
|
1,
|
|
|
|
|
dedicated
|
|
|
|
|
0
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (buffer == NULL)
|
|
|
|
@ -4345,7 +4335,7 @@ static uint8_t VULKAN_INTERNAL_CreateUniformBuffer(
|
|
|
|
|
uniformBuffer->poolOffset = bufferPool->nextAvailableOffset;
|
|
|
|
|
uniformBuffer->offset = 0;
|
|
|
|
|
|
|
|
|
|
bufferPool->nextAvailableOffset += UBO_SECTION_SIZE;
|
|
|
|
|
bufferPool->nextAvailableOffset += VULKAN_INTERNAL_NextHighestAlignment(UBO_SECTION_SIZE, renderer->minUBOAlignment);
|
|
|
|
|
|
|
|
|
|
if (bufferPool->nextAvailableOffset >= UBO_BUFFER_SIZE)
|
|
|
|
|
{
|
|
|
|
@ -5959,41 +5949,6 @@ static VulkanRenderTarget* VULKAN_INTERNAL_FetchRenderTarget(
|
|
|
|
|
return renderTarget;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static VkImageLayout VULKAN_INTERNAL_GetRenderPassFinalLayout(
|
|
|
|
|
VulkanTexture *texture
|
|
|
|
|
) {
|
|
|
|
|
VkImageLayout finalLayout;
|
|
|
|
|
|
|
|
|
|
if (IsDepthFormat(texture->format))
|
|
|
|
|
{
|
|
|
|
|
if (texture->usageFlags & VK_IMAGE_USAGE_SAMPLED_BIT)
|
|
|
|
|
{
|
|
|
|
|
finalLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (texture->usageFlags & VK_IMAGE_USAGE_SAMPLED_BIT)
|
|
|
|
|
{
|
|
|
|
|
finalLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
|
|
|
|
}
|
|
|
|
|
else if (texture->usageFlags & VK_IMAGE_USAGE_STORAGE_BIT)
|
|
|
|
|
{
|
|
|
|
|
finalLayout = VK_IMAGE_LAYOUT_GENERAL;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return finalLayout;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static VkRenderPass VULKAN_INTERNAL_CreateRenderPass(
|
|
|
|
|
VulkanRenderer *renderer,
|
|
|
|
|
VulkanCommandBuffer *commandBuffer,
|
|
|
|
@ -6008,7 +5963,6 @@ static VkRenderPass VULKAN_INTERNAL_CreateRenderPass(
|
|
|
|
|
VkAttachmentReference depthStencilAttachmentReference;
|
|
|
|
|
VkRenderPassCreateInfo renderPassCreateInfo;
|
|
|
|
|
VkSubpassDescription subpass;
|
|
|
|
|
VkSubpassDependency dep[2];
|
|
|
|
|
VkRenderPass renderPass;
|
|
|
|
|
uint32_t i;
|
|
|
|
|
|
|
|
|
@ -6061,7 +6015,7 @@ static VkRenderPass VULKAN_INTERNAL_CreateRenderPass(
|
|
|
|
|
attachmentDescriptions[attachmentDescriptionCount].initialLayout =
|
|
|
|
|
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
|
|
|
|
attachmentDescriptions[attachmentDescriptionCount].finalLayout =
|
|
|
|
|
VULKAN_INTERNAL_GetRenderPassFinalLayout(texture);
|
|
|
|
|
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
|
|
|
|
|
|
|
|
|
resolveReferences[resolveReferenceCount].attachment =
|
|
|
|
|
attachmentDescriptionCount;
|
|
|
|
@ -6117,7 +6071,8 @@ static VkRenderPass VULKAN_INTERNAL_CreateRenderPass(
|
|
|
|
|
attachmentDescriptions[attachmentDescriptionCount].initialLayout =
|
|
|
|
|
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
|
|
|
|
attachmentDescriptions[attachmentDescriptionCount].finalLayout =
|
|
|
|
|
VULKAN_INTERNAL_GetRenderPassFinalLayout(texture);
|
|
|
|
|
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
colorAttachmentReferences[colorAttachmentReferenceCount].attachment = attachmentDescriptionCount;
|
|
|
|
|
colorAttachmentReferences[colorAttachmentReferenceCount].layout =
|
|
|
|
@ -6165,7 +6120,7 @@ static VkRenderPass VULKAN_INTERNAL_CreateRenderPass(
|
|
|
|
|
attachmentDescriptions[attachmentDescriptionCount].initialLayout =
|
|
|
|
|
VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
|
|
|
|
attachmentDescriptions[attachmentDescriptionCount].finalLayout =
|
|
|
|
|
VULKAN_INTERNAL_GetRenderPassFinalLayout(texture);
|
|
|
|
|
VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
|
|
|
|
|
|
|
|
|
depthStencilAttachmentReference.attachment =
|
|
|
|
|
attachmentDescriptionCount;
|
|
|
|
@ -6187,37 +6142,6 @@ static VkRenderPass VULKAN_INTERNAL_CreateRenderPass(
|
|
|
|
|
subpass.pResolveAttachments = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const VkPipelineStageFlags graphicsStages = 0
|
|
|
|
|
| VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT
|
|
|
|
|
| VK_PIPELINE_STAGE_VERTEX_INPUT_BIT
|
|
|
|
|
| VK_PIPELINE_STAGE_VERTEX_SHADER_BIT
|
|
|
|
|
| VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
|
|
|
|
|
| VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
|
|
|
|
|
| VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT
|
|
|
|
|
| VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
|
|
|
|
|
;
|
|
|
|
|
const VkPipelineStageFlags outsideStages = 0
|
|
|
|
|
| graphicsStages
|
|
|
|
|
| VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT
|
|
|
|
|
| VK_PIPELINE_STAGE_TRANSFER_BIT
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
dep[0].srcSubpass = VK_SUBPASS_EXTERNAL;
|
|
|
|
|
dep[0].dstSubpass = 0;
|
|
|
|
|
dep[0].srcStageMask = outsideStages;
|
|
|
|
|
dep[0].dstStageMask = graphicsStages;
|
|
|
|
|
dep[0].srcAccessMask = VK_ACCESS_MEMORY_WRITE_BIT;
|
|
|
|
|
dep[0].dstAccessMask = VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT;
|
|
|
|
|
dep[0].dependencyFlags = 0;
|
|
|
|
|
|
|
|
|
|
dep[1].srcSubpass = 0;
|
|
|
|
|
dep[1].dstSubpass = VK_SUBPASS_EXTERNAL;
|
|
|
|
|
dep[1].srcStageMask = graphicsStages;
|
|
|
|
|
dep[1].dstStageMask = outsideStages;
|
|
|
|
|
dep[1].srcAccessMask = VK_ACCESS_MEMORY_WRITE_BIT;
|
|
|
|
|
dep[1].dstAccessMask = VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT;
|
|
|
|
|
dep[1].dependencyFlags = 0;
|
|
|
|
|
|
|
|
|
|
renderPassCreateInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
|
|
|
|
|
renderPassCreateInfo.pNext = NULL;
|
|
|
|
|
renderPassCreateInfo.flags = 0;
|
|
|
|
@ -6225,8 +6149,8 @@ static VkRenderPass VULKAN_INTERNAL_CreateRenderPass(
|
|
|
|
|
renderPassCreateInfo.attachmentCount = attachmentDescriptionCount;
|
|
|
|
|
renderPassCreateInfo.subpassCount = 1;
|
|
|
|
|
renderPassCreateInfo.pSubpasses = &subpass;
|
|
|
|
|
renderPassCreateInfo.dependencyCount = 2;
|
|
|
|
|
renderPassCreateInfo.pDependencies = dep;
|
|
|
|
|
renderPassCreateInfo.dependencyCount = 0;
|
|
|
|
|
renderPassCreateInfo.pDependencies = NULL;
|
|
|
|
|
|
|
|
|
|
vulkanResult = renderer->vkCreateRenderPass(
|
|
|
|
|
renderer->logicalDevice,
|
|
|
|
@ -6255,7 +6179,6 @@ static VkRenderPass VULKAN_INTERNAL_CreateTransientRenderPass(
|
|
|
|
|
VkAttachmentReference depthStencilAttachmentReference;
|
|
|
|
|
Refresh_ColorAttachmentDescription attachmentDescription;
|
|
|
|
|
VkSubpassDescription subpass;
|
|
|
|
|
VkSubpassDependency dep[2];
|
|
|
|
|
VkRenderPassCreateInfo renderPassCreateInfo;
|
|
|
|
|
VkRenderPass renderPass;
|
|
|
|
|
VkResult result;
|
|
|
|
@ -6266,7 +6189,6 @@ static VkRenderPass VULKAN_INTERNAL_CreateTransientRenderPass(
|
|
|
|
|
uint32_t resolveReferenceCount = 0;
|
|
|
|
|
uint32_t i;
|
|
|
|
|
|
|
|
|
|
/* Note: Render pass compatibility does not care about layout */
|
|
|
|
|
for (i = 0; i < attachmentInfo.colorAttachmentCount; i += 1)
|
|
|
|
|
{
|
|
|
|
|
attachmentDescription = attachmentInfo.colorAttachmentDescriptions[i];
|
|
|
|
@ -6400,37 +6322,6 @@ static VkRenderPass VULKAN_INTERNAL_CreateTransientRenderPass(
|
|
|
|
|
subpass.pResolveAttachments = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const VkPipelineStageFlags graphicsStages = 0
|
|
|
|
|
| VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT
|
|
|
|
|
| VK_PIPELINE_STAGE_VERTEX_INPUT_BIT
|
|
|
|
|
| VK_PIPELINE_STAGE_VERTEX_SHADER_BIT
|
|
|
|
|
| VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
|
|
|
|
|
| VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
|
|
|
|
|
| VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT
|
|
|
|
|
| VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
|
|
|
|
|
;
|
|
|
|
|
const VkPipelineStageFlags outsideStages = 0
|
|
|
|
|
| graphicsStages
|
|
|
|
|
| VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT
|
|
|
|
|
| VK_PIPELINE_STAGE_TRANSFER_BIT
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
dep[0].srcSubpass = VK_SUBPASS_EXTERNAL;
|
|
|
|
|
dep[0].dstSubpass = 0;
|
|
|
|
|
dep[0].srcStageMask = outsideStages;
|
|
|
|
|
dep[0].dstStageMask = graphicsStages;
|
|
|
|
|
dep[0].srcAccessMask = VK_ACCESS_MEMORY_WRITE_BIT;
|
|
|
|
|
dep[0].dstAccessMask = VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT;
|
|
|
|
|
dep[0].dependencyFlags = 0;
|
|
|
|
|
|
|
|
|
|
dep[1].srcSubpass = 0;
|
|
|
|
|
dep[1].dstSubpass = VK_SUBPASS_EXTERNAL;
|
|
|
|
|
dep[1].srcStageMask = graphicsStages;
|
|
|
|
|
dep[1].dstStageMask = outsideStages;
|
|
|
|
|
dep[1].srcAccessMask = VK_ACCESS_MEMORY_WRITE_BIT;
|
|
|
|
|
dep[1].dstAccessMask = VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT;
|
|
|
|
|
dep[1].dependencyFlags = 0;
|
|
|
|
|
|
|
|
|
|
renderPassCreateInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
|
|
|
|
|
renderPassCreateInfo.pNext = NULL;
|
|
|
|
|
renderPassCreateInfo.flags = 0;
|
|
|
|
@ -6438,8 +6329,8 @@ static VkRenderPass VULKAN_INTERNAL_CreateTransientRenderPass(
|
|
|
|
|
renderPassCreateInfo.attachmentCount = attachmentDescriptionCount;
|
|
|
|
|
renderPassCreateInfo.subpassCount = 1;
|
|
|
|
|
renderPassCreateInfo.pSubpasses = &subpass;
|
|
|
|
|
renderPassCreateInfo.dependencyCount = 2;
|
|
|
|
|
renderPassCreateInfo.pDependencies = dep;
|
|
|
|
|
renderPassCreateInfo.dependencyCount = 0;
|
|
|
|
|
renderPassCreateInfo.pDependencies = NULL;
|
|
|
|
|
|
|
|
|
|
result = renderer->vkCreateRenderPass(
|
|
|
|
|
renderer->logicalDevice,
|
|
|
|
@ -7230,8 +7121,7 @@ static Refresh_Buffer* VULKAN_CreateBuffer(
|
|
|
|
|
(VulkanRenderer*) driverData,
|
|
|
|
|
sizeInBytes,
|
|
|
|
|
resourceAccessType,
|
|
|
|
|
vulkanUsageFlags,
|
|
|
|
|
0
|
|
|
|
|
vulkanUsageFlags
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -7313,6 +7203,7 @@ static VulkanTransferBuffer* VULKAN_INTERNAL_AcquireTransferBuffer(
|
|
|
|
|
RESOURCE_ACCESS_TRANSFER_READ_WRITE,
|
|
|
|
|
VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT,
|
|
|
|
|
1,
|
|
|
|
|
0,
|
|
|
|
|
1
|
|
|
|
|
);
|
|
|
|
|
transferBuffer->fromPool = 0;
|
|
|
|
@ -7352,7 +7243,7 @@ static void VULKAN_SetTextureData(
|
|
|
|
|
VulkanTransferBuffer *transferBuffer;
|
|
|
|
|
VkBufferImageCopy imageCopy;
|
|
|
|
|
uint8_t *stagingBufferPointer;
|
|
|
|
|
uint32_t blockSize = VULKAN_INTERNAL_GetTextureBlockSize(vulkanTexture->format);
|
|
|
|
|
uint32_t blockSize = VULKAN_INTERNAL_TextureBlockSize(vulkanTexture->format);
|
|
|
|
|
uint32_t bufferRowLength;
|
|
|
|
|
uint32_t bufferImageHeight;
|
|
|
|
|
|
|
|
|
@ -7880,14 +7771,6 @@ static void VULKAN_SetBufferData(
|
|
|
|
|
vulkanBuffer
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// this janky call will wait for transfer writes to finish!
|
|
|
|
|
VULKAN_INTERNAL_BufferMemoryBarrier(
|
|
|
|
|
renderer,
|
|
|
|
|
vulkanCommandBuffer->commandBuffer,
|
|
|
|
|
RESOURCE_ACCESS_TRANSFER_WRITE,
|
|
|
|
|
vulkanBuffer
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
bufferCopy.srcOffset = transferBuffer->offset;
|
|
|
|
|
bufferCopy.dstOffset = offsetInBytes;
|
|
|
|
|
bufferCopy.size = (VkDeviceSize) dataLength;
|
|
|
|
@ -8557,13 +8440,10 @@ static VkRenderPass VULKAN_INTERNAL_FetchRenderPass(
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < colorAttachmentCount; i += 1)
|
|
|
|
|
{
|
|
|
|
|
texture = ((VulkanTextureContainer*) colorAttachmentInfos[i].texture)->vulkanTexture;
|
|
|
|
|
|
|
|
|
|
hash.colorTargetDescriptions[i].format = texture->format;
|
|
|
|
|
hash.colorTargetDescriptions[i].format = ((VulkanTextureContainer*) colorAttachmentInfos[i].texture)->vulkanTexture->format;
|
|
|
|
|
hash.colorTargetDescriptions[i].clearColor = colorAttachmentInfos[i].clearColor;
|
|
|
|
|
hash.colorTargetDescriptions[i].loadOp = colorAttachmentInfos[i].loadOp;
|
|
|
|
|
hash.colorTargetDescriptions[i].storeOp = colorAttachmentInfos[i].storeOp;
|
|
|
|
|
hash.colorTargetDescriptions[i].finalLayout = VULKAN_INTERNAL_GetRenderPassFinalLayout(texture);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hash.colorAttachmentSampleCount = REFRESH_SAMPLECOUNT_1;
|
|
|
|
@ -8585,18 +8465,14 @@ static VkRenderPass VULKAN_INTERNAL_FetchRenderPass(
|
|
|
|
|
hash.depthStencilTargetDescription.storeOp = REFRESH_STOREOP_DONT_CARE;
|
|
|
|
|
hash.depthStencilTargetDescription.stencilLoadOp = REFRESH_LOADOP_DONT_CARE;
|
|
|
|
|
hash.depthStencilTargetDescription.stencilStoreOp = REFRESH_STOREOP_DONT_CARE;
|
|
|
|
|
hash.depthStencilTargetDescription.finalLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
texture = ((VulkanTextureContainer*) depthStencilAttachmentInfo->texture)->vulkanTexture;
|
|
|
|
|
|
|
|
|
|
hash.depthStencilTargetDescription.format = texture->format;
|
|
|
|
|
hash.depthStencilTargetDescription.format = ((VulkanTextureContainer*) depthStencilAttachmentInfo->texture)->vulkanTexture->format;
|
|
|
|
|
hash.depthStencilTargetDescription.loadOp = depthStencilAttachmentInfo->loadOp;
|
|
|
|
|
hash.depthStencilTargetDescription.storeOp = depthStencilAttachmentInfo->storeOp;
|
|
|
|
|
hash.depthStencilTargetDescription.stencilLoadOp = depthStencilAttachmentInfo->stencilLoadOp;
|
|
|
|
|
hash.depthStencilTargetDescription.stencilStoreOp = depthStencilAttachmentInfo->stencilStoreOp;
|
|
|
|
|
hash.depthStencilTargetDescription.finalLayout = VULKAN_INTERNAL_GetRenderPassFinalLayout(texture);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderPass = RenderPassHashArray_Fetch(
|
|
|
|
@ -9157,11 +9033,35 @@ static void VULKAN_EndRenderPass(
|
|
|
|
|
|
|
|
|
|
if (currentTexture->usageFlags & VK_IMAGE_USAGE_SAMPLED_BIT)
|
|
|
|
|
{
|
|
|
|
|
currentTexture->resourceAccessType = RESOURCE_ACCESS_ANY_SHADER_READ_SAMPLED_IMAGE;
|
|
|
|
|
VULKAN_INTERNAL_ImageMemoryBarrier(
|
|
|
|
|
renderer,
|
|
|
|
|
vulkanCommandBuffer->commandBuffer,
|
|
|
|
|
RESOURCE_ACCESS_ANY_SHADER_READ_SAMPLED_IMAGE,
|
|
|
|
|
currentTexture->aspectFlags,
|
|
|
|
|
0,
|
|
|
|
|
currentTexture->layerCount,
|
|
|
|
|
0,
|
|
|
|
|
currentTexture->levelCount,
|
|
|
|
|
0,
|
|
|
|
|
currentTexture->image,
|
|
|
|
|
¤tTexture->resourceAccessType
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
else if (currentTexture->usageFlags & VK_IMAGE_USAGE_STORAGE_BIT)
|
|
|
|
|
{
|
|
|
|
|
currentTexture->resourceAccessType = RESOURCE_ACCESS_COMPUTE_SHADER_STORAGE_IMAGE_READ_WRITE;
|
|
|
|
|
VULKAN_INTERNAL_ImageMemoryBarrier(
|
|
|
|
|
renderer,
|
|
|
|
|
vulkanCommandBuffer->commandBuffer,
|
|
|
|
|
RESOURCE_ACCESS_COMPUTE_SHADER_STORAGE_IMAGE_READ_WRITE,
|
|
|
|
|
currentTexture->aspectFlags,
|
|
|
|
|
0,
|
|
|
|
|
currentTexture->layerCount,
|
|
|
|
|
0,
|
|
|
|
|
currentTexture->levelCount,
|
|
|
|
|
0,
|
|
|
|
|
currentTexture->image,
|
|
|
|
|
¤tTexture->resourceAccessType
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
vulkanCommandBuffer->renderPassColorTargetCount = 0;
|
|
|
|
@ -9172,7 +9072,19 @@ static void VULKAN_EndRenderPass(
|
|
|
|
|
|
|
|
|
|
if (currentTexture->usageFlags & VK_IMAGE_USAGE_SAMPLED_BIT)
|
|
|
|
|
{
|
|
|
|
|
currentTexture->resourceAccessType = RESOURCE_ACCESS_ANY_SHADER_READ_SAMPLED_IMAGE;
|
|
|
|
|
VULKAN_INTERNAL_ImageMemoryBarrier(
|
|
|
|
|
renderer,
|
|
|
|
|
vulkanCommandBuffer->commandBuffer,
|
|
|
|
|
RESOURCE_ACCESS_ANY_SHADER_READ_SAMPLED_IMAGE,
|
|
|
|
|
currentTexture->aspectFlags,
|
|
|
|
|
0,
|
|
|
|
|
currentTexture->layerCount,
|
|
|
|
|
0,
|
|
|
|
|
currentTexture->levelCount,
|
|
|
|
|
0,
|
|
|
|
|
currentTexture->image,
|
|
|
|
|
¤tTexture->resourceAccessType
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
vulkanCommandBuffer->renderPassDepthTexture = NULL;
|
|
|
|
@ -10685,6 +10597,7 @@ static uint8_t VULKAN_INTERNAL_DefragmentMemory(
|
|
|
|
|
currentRegion->vulkanBuffer->size,
|
|
|
|
|
RESOURCE_ACCESS_NONE,
|
|
|
|
|
currentRegion->vulkanBuffer->usage,
|
|
|
|
|
currentRegion->vulkanBuffer->requireHostVisible,
|
|
|
|
|
currentRegion->vulkanBuffer->preferDeviceLocal,
|
|
|
|
|
0
|
|
|
|
|
);
|
|
|
|
@ -12089,10 +12002,11 @@ static Refresh_Device* VULKAN_CreateDevice(
|
|
|
|
|
|
|
|
|
|
renderer->dummyBuffer = VULKAN_INTERNAL_CreateBuffer(
|
|
|
|
|
renderer,
|
|
|
|
|
1,
|
|
|
|
|
16,
|
|
|
|
|
RESOURCE_ACCESS_GENERAL,
|
|
|
|
|
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
1
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
@ -12209,6 +12123,7 @@ static Refresh_Device* VULKAN_CreateDevice(
|
|
|
|
|
RESOURCE_ACCESS_TRANSFER_READ_WRITE,
|
|
|
|
|
VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT,
|
|
|
|
|
1,
|
|
|
|
|
0,
|
|
|
|
|
1
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|