Compare commits

..

No commits in common. "main" and "1.15.3" have entirely different histories.
main ... 1.15.3

3 changed files with 214 additions and 129 deletions

View File

@ -9,7 +9,7 @@ option(BUILD_SHARED_LIBS "Build shared library" ON)
# Version # Version
SET(LIB_MAJOR_VERSION "1") SET(LIB_MAJOR_VERSION "1")
SET(LIB_MINOR_VERSION "15") SET(LIB_MINOR_VERSION "15")
SET(LIB_REVISION "4") SET(LIB_REVISION "3")
SET(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_REVISION}") SET(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_REVISION}")
# Build Type # Build Type

View File

@ -56,7 +56,7 @@ extern "C" {
#define REFRESH_MAJOR_VERSION 1 #define REFRESH_MAJOR_VERSION 1
#define REFRESH_MINOR_VERSION 15 #define REFRESH_MINOR_VERSION 15
#define REFRESH_PATCH_VERSION 4 #define REFRESH_PATCH_VERSION 3
#define REFRESH_COMPILED_VERSION ( \ #define REFRESH_COMPILED_VERSION ( \
(REFRESH_MAJOR_VERSION * 100 * 100) + \ (REFRESH_MAJOR_VERSION * 100 * 100) + \

View File

@ -708,7 +708,6 @@ struct VulkanBuffer
VulkanResourceAccessType resourceAccessType; VulkanResourceAccessType resourceAccessType;
VkBufferUsageFlags usage; VkBufferUsageFlags usage;
uint8_t requireHostVisible;
uint8_t preferDeviceLocal; uint8_t preferDeviceLocal;
SDL_atomic_t referenceCount; /* Tracks command buffer usage */ SDL_atomic_t referenceCount; /* Tracks command buffer usage */
@ -999,6 +998,7 @@ typedef struct RenderPassColorTargetDescription
Refresh_Vec4 clearColor; Refresh_Vec4 clearColor;
Refresh_LoadOp loadOp; Refresh_LoadOp loadOp;
Refresh_StoreOp storeOp; Refresh_StoreOp storeOp;
VkImageLayout finalLayout;
} RenderPassColorTargetDescription; } RenderPassColorTargetDescription;
typedef struct RenderPassDepthStencilTargetDescription typedef struct RenderPassDepthStencilTargetDescription
@ -1008,6 +1008,7 @@ typedef struct RenderPassDepthStencilTargetDescription
Refresh_StoreOp storeOp; Refresh_StoreOp storeOp;
Refresh_LoadOp stencilLoadOp; Refresh_LoadOp stencilLoadOp;
Refresh_StoreOp stencilStoreOp; Refresh_StoreOp stencilStoreOp;
VkImageLayout finalLayout;
} RenderPassDepthStencilTargetDescription; } RenderPassDepthStencilTargetDescription;
typedef struct RenderPassHash typedef struct RenderPassHash
@ -1071,6 +1072,11 @@ static inline uint8_t RenderPassHash_Compare(
{ {
return 0; return 0;
} }
if (a->colorTargetDescriptions[i].finalLayout != b->colorTargetDescriptions[i].finalLayout)
{
return 0;
}
} }
if (a->depthStencilTargetDescription.format != b->depthStencilTargetDescription.format) if (a->depthStencilTargetDescription.format != b->depthStencilTargetDescription.format)
@ -1098,6 +1104,11 @@ static inline uint8_t RenderPassHash_Compare(
return 0; return 0;
} }
if (a->depthStencilTargetDescription.finalLayout != b->depthStencilTargetDescription.finalLayout)
{
return 0;
}
return 1; return 1;
} }
@ -1980,51 +1991,59 @@ static inline uint32_t VULKAN_INTERNAL_BytesPerPixel(VkFormat format)
{ {
switch (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_R32G32B32A32_SFLOAT:
case VK_FORMAT_BC2_UNORM_BLOCK: case VK_FORMAT_BC2_UNORM_BLOCK:
case VK_FORMAT_BC3_UNORM_BLOCK: case VK_FORMAT_BC3_UNORM_BLOCK:
case VK_FORMAT_BC7_UNORM_BLOCK: case VK_FORMAT_BC7_UNORM_BLOCK:
case VK_FORMAT_R16G16B16A16_UINT:
return 16; 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: default:
Refresh_LogError("Texture format not recognized!"); Refresh_LogError("Invalid texture format!");
return 0; return 0;
} }
} }
static inline uint32_t VULKAN_INTERNAL_TextureBlockSize( static inline uint32_t VULKAN_INTERNAL_GetTextureBlockSize(
VkFormat format VkFormat format
) { ) {
switch (format) switch (format)
@ -2039,28 +2058,24 @@ static inline uint32_t VULKAN_INTERNAL_TextureBlockSize(
case VK_FORMAT_R5G6B5_UNORM_PACK16: case VK_FORMAT_R5G6B5_UNORM_PACK16:
case VK_FORMAT_A1R5G5B5_UNORM_PACK16: case VK_FORMAT_A1R5G5B5_UNORM_PACK16:
case VK_FORMAT_B4G4R4A4_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_A2R10G10B10_UNORM_PACK32:
case VK_FORMAT_R16G16_UNORM: case VK_FORMAT_R16G16_UNORM:
case VK_FORMAT_R16G16B16A16_UNORM: case VK_FORMAT_R16G16B16A16_UNORM:
case VK_FORMAT_R8_UNORM: case VK_FORMAT_R8_UNORM:
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_R32_SFLOAT:
case VK_FORMAT_R32G32_SFLOAT: case VK_FORMAT_R32G32_SFLOAT:
case VK_FORMAT_R32G32B32A32_SFLOAT: case VK_FORMAT_R32G32B32A32_SFLOAT:
case VK_FORMAT_R16_SFLOAT:
case VK_FORMAT_R16G16_SFLOAT:
case VK_FORMAT_R16G16B16A16_SFLOAT:
case VK_FORMAT_R8_UINT: case VK_FORMAT_R8_UINT:
case VK_FORMAT_R8G8_UINT: case VK_FORMAT_R8G8_UINT:
case VK_FORMAT_R8G8B8A8_UINT: case VK_FORMAT_R8G8B8A8_UINT:
case VK_FORMAT_R16_UINT: case VK_FORMAT_R16_UINT:
case VK_FORMAT_R16G16_UINT: case VK_FORMAT_R16G16_UINT:
case VK_FORMAT_R16G16B16A16_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; return 1;
default: default:
Refresh_LogError("Unrecognized texture format!"); Refresh_LogError("Unrecognized texture format!");
@ -2073,8 +2088,17 @@ static inline VkDeviceSize VULKAN_INTERNAL_BytesPerImage(
uint32_t height, uint32_t height,
VkFormat format VkFormat format
) { ) {
uint32_t blockSize = VULKAN_INTERNAL_TextureBlockSize(format); uint32_t blocksPerRow = width;
return (width * height * VULKAN_INTERNAL_BytesPerPixel(format)) / (blockSize * blockSize); 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);
} }
static inline Refresh_SampleCount VULKAN_INTERNAL_GetMaxMultiSampleCount( static inline Refresh_SampleCount VULKAN_INTERNAL_GetMaxMultiSampleCount(
@ -2933,7 +2957,7 @@ static uint8_t VULKAN_INTERNAL_BindMemoryForImage(
{ {
memoryTypeIndex = 0; memoryTypeIndex = 0;
requiredMemoryPropertyFlags = 0; requiredMemoryPropertyFlags = 0;
ignoredMemoryPropertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; ignoredMemoryPropertyFlags = VK_MEMORY_HEAP_DEVICE_LOCAL_BIT;
if (isRenderTarget) if (isRenderTarget)
{ {
@ -2979,32 +3003,23 @@ static uint8_t VULKAN_INTERNAL_BindMemoryForBuffer(
VulkanRenderer* renderer, VulkanRenderer* renderer,
VkBuffer buffer, VkBuffer buffer,
VkDeviceSize size, VkDeviceSize size,
uint8_t requireHostVisible,
uint8_t preferDeviceLocal, uint8_t preferDeviceLocal,
uint8_t dedicatedAllocation, uint8_t dedicatedAllocation,
VulkanMemoryUsedRegion** usedRegion VulkanMemoryUsedRegion** usedRegion
) { ) {
uint8_t bindResult = 0; uint8_t bindResult = 0;
uint32_t memoryTypeIndex = 0; uint32_t memoryTypeIndex = 0;
VkMemoryPropertyFlags requiredMemoryPropertyFlags = 0; VkMemoryPropertyFlags requiredMemoryPropertyFlags;
VkMemoryPropertyFlags ignoredMemoryPropertyFlags = 0; VkMemoryPropertyFlags ignoredMemoryPropertyFlags;
VkMemoryRequirements2KHR memoryRequirements = VkMemoryRequirements2KHR memoryRequirements =
{ {
VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2_KHR, VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2_KHR,
NULL NULL
}; };
if (requireHostVisible)
{
requiredMemoryPropertyFlags = requiredMemoryPropertyFlags =
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
}
else
{
ignoredMemoryPropertyFlags =
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
}
if (preferDeviceLocal) if (preferDeviceLocal)
{ {
@ -3043,10 +3058,9 @@ static uint8_t VULKAN_INTERNAL_BindMemoryForBuffer(
} }
/* Bind failed, try again if originally preferred device local */ /* Bind failed, try again if originally preferred device local */
if (bindResult != 1) if (bindResult != 1 && preferDeviceLocal)
{ {
memoryTypeIndex = 0; memoryTypeIndex = 0;
requiredMemoryPropertyFlags = requiredMemoryPropertyFlags =
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
@ -4107,7 +4121,6 @@ static VulkanBuffer* VULKAN_INTERNAL_CreateBuffer(
VkDeviceSize size, VkDeviceSize size,
VulkanResourceAccessType resourceAccessType, VulkanResourceAccessType resourceAccessType,
VkBufferUsageFlags usage, VkBufferUsageFlags usage,
uint8_t requireHostVisible,
uint8_t preferDeviceLocal, uint8_t preferDeviceLocal,
uint8_t dedicatedAllocation uint8_t dedicatedAllocation
) { ) {
@ -4121,7 +4134,6 @@ static VulkanBuffer* VULKAN_INTERNAL_CreateBuffer(
buffer->size = size; buffer->size = size;
buffer->resourceAccessType = resourceAccessType; buffer->resourceAccessType = resourceAccessType;
buffer->usage = usage; buffer->usage = usage;
buffer->requireHostVisible = requireHostVisible;
buffer->preferDeviceLocal = preferDeviceLocal; buffer->preferDeviceLocal = preferDeviceLocal;
bufferCreateInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; bufferCreateInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
@ -4145,7 +4157,6 @@ static VulkanBuffer* VULKAN_INTERNAL_CreateBuffer(
renderer, renderer,
buffer->buffer, buffer->buffer,
buffer->size, buffer->size,
buffer->requireHostVisible,
buffer->preferDeviceLocal, buffer->preferDeviceLocal,
dedicatedAllocation, dedicatedAllocation,
&buffer->usedRegion &buffer->usedRegion
@ -4229,7 +4240,6 @@ static VulkanUniformBufferPool* VULKAN_INTERNAL_CreateUniformBufferPool(
UBO_BUFFER_SIZE, UBO_BUFFER_SIZE,
resourceAccessType, resourceAccessType,
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
1,
0, 0,
1 1
); );
@ -4275,7 +4285,8 @@ static VulkanBufferContainer* VULKAN_INTERNAL_CreateBufferContainer(
VulkanRenderer *renderer, VulkanRenderer *renderer,
uint32_t sizeInBytes, uint32_t sizeInBytes,
VulkanResourceAccessType resourceAccessType, VulkanResourceAccessType resourceAccessType,
VkBufferUsageFlags usageFlags VkBufferUsageFlags usageFlags,
uint8_t dedicated
) { ) {
VulkanBufferContainer* bufferContainer; VulkanBufferContainer* bufferContainer;
VulkanBuffer* buffer; VulkanBuffer* buffer;
@ -4288,9 +4299,8 @@ static VulkanBufferContainer* VULKAN_INTERNAL_CreateBufferContainer(
sizeInBytes, sizeInBytes,
resourceAccessType, resourceAccessType,
usageFlags, usageFlags,
0,
1, 1,
0 dedicated
); );
if (buffer == NULL) if (buffer == NULL)
@ -5949,6 +5959,41 @@ static VulkanRenderTarget* VULKAN_INTERNAL_FetchRenderTarget(
return renderTarget; 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( static VkRenderPass VULKAN_INTERNAL_CreateRenderPass(
VulkanRenderer *renderer, VulkanRenderer *renderer,
VulkanCommandBuffer *commandBuffer, VulkanCommandBuffer *commandBuffer,
@ -5963,6 +6008,7 @@ static VkRenderPass VULKAN_INTERNAL_CreateRenderPass(
VkAttachmentReference depthStencilAttachmentReference; VkAttachmentReference depthStencilAttachmentReference;
VkRenderPassCreateInfo renderPassCreateInfo; VkRenderPassCreateInfo renderPassCreateInfo;
VkSubpassDescription subpass; VkSubpassDescription subpass;
VkSubpassDependency dep[2];
VkRenderPass renderPass; VkRenderPass renderPass;
uint32_t i; uint32_t i;
@ -6015,7 +6061,7 @@ static VkRenderPass VULKAN_INTERNAL_CreateRenderPass(
attachmentDescriptions[attachmentDescriptionCount].initialLayout = attachmentDescriptions[attachmentDescriptionCount].initialLayout =
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
attachmentDescriptions[attachmentDescriptionCount].finalLayout = attachmentDescriptions[attachmentDescriptionCount].finalLayout =
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; VULKAN_INTERNAL_GetRenderPassFinalLayout(texture);
resolveReferences[resolveReferenceCount].attachment = resolveReferences[resolveReferenceCount].attachment =
attachmentDescriptionCount; attachmentDescriptionCount;
@ -6071,8 +6117,7 @@ static VkRenderPass VULKAN_INTERNAL_CreateRenderPass(
attachmentDescriptions[attachmentDescriptionCount].initialLayout = attachmentDescriptions[attachmentDescriptionCount].initialLayout =
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
attachmentDescriptions[attachmentDescriptionCount].finalLayout = attachmentDescriptions[attachmentDescriptionCount].finalLayout =
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; VULKAN_INTERNAL_GetRenderPassFinalLayout(texture);
colorAttachmentReferences[colorAttachmentReferenceCount].attachment = attachmentDescriptionCount; colorAttachmentReferences[colorAttachmentReferenceCount].attachment = attachmentDescriptionCount;
colorAttachmentReferences[colorAttachmentReferenceCount].layout = colorAttachmentReferences[colorAttachmentReferenceCount].layout =
@ -6120,7 +6165,7 @@ static VkRenderPass VULKAN_INTERNAL_CreateRenderPass(
attachmentDescriptions[attachmentDescriptionCount].initialLayout = attachmentDescriptions[attachmentDescriptionCount].initialLayout =
VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
attachmentDescriptions[attachmentDescriptionCount].finalLayout = attachmentDescriptions[attachmentDescriptionCount].finalLayout =
VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; VULKAN_INTERNAL_GetRenderPassFinalLayout(texture);
depthStencilAttachmentReference.attachment = depthStencilAttachmentReference.attachment =
attachmentDescriptionCount; attachmentDescriptionCount;
@ -6142,6 +6187,37 @@ static VkRenderPass VULKAN_INTERNAL_CreateRenderPass(
subpass.pResolveAttachments = NULL; 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.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
renderPassCreateInfo.pNext = NULL; renderPassCreateInfo.pNext = NULL;
renderPassCreateInfo.flags = 0; renderPassCreateInfo.flags = 0;
@ -6149,8 +6225,8 @@ static VkRenderPass VULKAN_INTERNAL_CreateRenderPass(
renderPassCreateInfo.attachmentCount = attachmentDescriptionCount; renderPassCreateInfo.attachmentCount = attachmentDescriptionCount;
renderPassCreateInfo.subpassCount = 1; renderPassCreateInfo.subpassCount = 1;
renderPassCreateInfo.pSubpasses = &subpass; renderPassCreateInfo.pSubpasses = &subpass;
renderPassCreateInfo.dependencyCount = 0; renderPassCreateInfo.dependencyCount = 2;
renderPassCreateInfo.pDependencies = NULL; renderPassCreateInfo.pDependencies = dep;
vulkanResult = renderer->vkCreateRenderPass( vulkanResult = renderer->vkCreateRenderPass(
renderer->logicalDevice, renderer->logicalDevice,
@ -6179,6 +6255,7 @@ static VkRenderPass VULKAN_INTERNAL_CreateTransientRenderPass(
VkAttachmentReference depthStencilAttachmentReference; VkAttachmentReference depthStencilAttachmentReference;
Refresh_ColorAttachmentDescription attachmentDescription; Refresh_ColorAttachmentDescription attachmentDescription;
VkSubpassDescription subpass; VkSubpassDescription subpass;
VkSubpassDependency dep[2];
VkRenderPassCreateInfo renderPassCreateInfo; VkRenderPassCreateInfo renderPassCreateInfo;
VkRenderPass renderPass; VkRenderPass renderPass;
VkResult result; VkResult result;
@ -6189,6 +6266,7 @@ static VkRenderPass VULKAN_INTERNAL_CreateTransientRenderPass(
uint32_t resolveReferenceCount = 0; uint32_t resolveReferenceCount = 0;
uint32_t i; uint32_t i;
/* Note: Render pass compatibility does not care about layout */
for (i = 0; i < attachmentInfo.colorAttachmentCount; i += 1) for (i = 0; i < attachmentInfo.colorAttachmentCount; i += 1)
{ {
attachmentDescription = attachmentInfo.colorAttachmentDescriptions[i]; attachmentDescription = attachmentInfo.colorAttachmentDescriptions[i];
@ -6322,6 +6400,37 @@ static VkRenderPass VULKAN_INTERNAL_CreateTransientRenderPass(
subpass.pResolveAttachments = NULL; 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.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
renderPassCreateInfo.pNext = NULL; renderPassCreateInfo.pNext = NULL;
renderPassCreateInfo.flags = 0; renderPassCreateInfo.flags = 0;
@ -6329,8 +6438,8 @@ static VkRenderPass VULKAN_INTERNAL_CreateTransientRenderPass(
renderPassCreateInfo.attachmentCount = attachmentDescriptionCount; renderPassCreateInfo.attachmentCount = attachmentDescriptionCount;
renderPassCreateInfo.subpassCount = 1; renderPassCreateInfo.subpassCount = 1;
renderPassCreateInfo.pSubpasses = &subpass; renderPassCreateInfo.pSubpasses = &subpass;
renderPassCreateInfo.dependencyCount = 0; renderPassCreateInfo.dependencyCount = 2;
renderPassCreateInfo.pDependencies = NULL; renderPassCreateInfo.pDependencies = dep;
result = renderer->vkCreateRenderPass( result = renderer->vkCreateRenderPass(
renderer->logicalDevice, renderer->logicalDevice,
@ -7121,7 +7230,8 @@ static Refresh_Buffer* VULKAN_CreateBuffer(
(VulkanRenderer*) driverData, (VulkanRenderer*) driverData,
sizeInBytes, sizeInBytes,
resourceAccessType, resourceAccessType,
vulkanUsageFlags vulkanUsageFlags,
0
); );
} }
@ -7203,7 +7313,6 @@ static VulkanTransferBuffer* VULKAN_INTERNAL_AcquireTransferBuffer(
RESOURCE_ACCESS_TRANSFER_READ_WRITE, RESOURCE_ACCESS_TRANSFER_READ_WRITE,
VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT, VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT,
1, 1,
0,
1 1
); );
transferBuffer->fromPool = 0; transferBuffer->fromPool = 0;
@ -7243,7 +7352,7 @@ static void VULKAN_SetTextureData(
VulkanTransferBuffer *transferBuffer; VulkanTransferBuffer *transferBuffer;
VkBufferImageCopy imageCopy; VkBufferImageCopy imageCopy;
uint8_t *stagingBufferPointer; uint8_t *stagingBufferPointer;
uint32_t blockSize = VULKAN_INTERNAL_TextureBlockSize(vulkanTexture->format); uint32_t blockSize = VULKAN_INTERNAL_GetTextureBlockSize(vulkanTexture->format);
uint32_t bufferRowLength; uint32_t bufferRowLength;
uint32_t bufferImageHeight; uint32_t bufferImageHeight;
@ -7771,6 +7880,14 @@ static void VULKAN_SetBufferData(
vulkanBuffer 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.srcOffset = transferBuffer->offset;
bufferCopy.dstOffset = offsetInBytes; bufferCopy.dstOffset = offsetInBytes;
bufferCopy.size = (VkDeviceSize) dataLength; bufferCopy.size = (VkDeviceSize) dataLength;
@ -8440,10 +8557,13 @@ static VkRenderPass VULKAN_INTERNAL_FetchRenderPass(
for (i = 0; i < colorAttachmentCount; i += 1) for (i = 0; i < colorAttachmentCount; i += 1)
{ {
hash.colorTargetDescriptions[i].format = ((VulkanTextureContainer*) colorAttachmentInfos[i].texture)->vulkanTexture->format; texture = ((VulkanTextureContainer*) colorAttachmentInfos[i].texture)->vulkanTexture;
hash.colorTargetDescriptions[i].format = texture->format;
hash.colorTargetDescriptions[i].clearColor = colorAttachmentInfos[i].clearColor; hash.colorTargetDescriptions[i].clearColor = colorAttachmentInfos[i].clearColor;
hash.colorTargetDescriptions[i].loadOp = colorAttachmentInfos[i].loadOp; hash.colorTargetDescriptions[i].loadOp = colorAttachmentInfos[i].loadOp;
hash.colorTargetDescriptions[i].storeOp = colorAttachmentInfos[i].storeOp; hash.colorTargetDescriptions[i].storeOp = colorAttachmentInfos[i].storeOp;
hash.colorTargetDescriptions[i].finalLayout = VULKAN_INTERNAL_GetRenderPassFinalLayout(texture);
} }
hash.colorAttachmentSampleCount = REFRESH_SAMPLECOUNT_1; hash.colorAttachmentSampleCount = REFRESH_SAMPLECOUNT_1;
@ -8465,14 +8585,18 @@ static VkRenderPass VULKAN_INTERNAL_FetchRenderPass(
hash.depthStencilTargetDescription.storeOp = REFRESH_STOREOP_DONT_CARE; hash.depthStencilTargetDescription.storeOp = REFRESH_STOREOP_DONT_CARE;
hash.depthStencilTargetDescription.stencilLoadOp = REFRESH_LOADOP_DONT_CARE; hash.depthStencilTargetDescription.stencilLoadOp = REFRESH_LOADOP_DONT_CARE;
hash.depthStencilTargetDescription.stencilStoreOp = REFRESH_STOREOP_DONT_CARE; hash.depthStencilTargetDescription.stencilStoreOp = REFRESH_STOREOP_DONT_CARE;
hash.depthStencilTargetDescription.finalLayout = VK_IMAGE_LAYOUT_UNDEFINED;
} }
else else
{ {
hash.depthStencilTargetDescription.format = ((VulkanTextureContainer*) depthStencilAttachmentInfo->texture)->vulkanTexture->format; texture = ((VulkanTextureContainer*) depthStencilAttachmentInfo->texture)->vulkanTexture;
hash.depthStencilTargetDescription.format = texture->format;
hash.depthStencilTargetDescription.loadOp = depthStencilAttachmentInfo->loadOp; hash.depthStencilTargetDescription.loadOp = depthStencilAttachmentInfo->loadOp;
hash.depthStencilTargetDescription.storeOp = depthStencilAttachmentInfo->storeOp; hash.depthStencilTargetDescription.storeOp = depthStencilAttachmentInfo->storeOp;
hash.depthStencilTargetDescription.stencilLoadOp = depthStencilAttachmentInfo->stencilLoadOp; hash.depthStencilTargetDescription.stencilLoadOp = depthStencilAttachmentInfo->stencilLoadOp;
hash.depthStencilTargetDescription.stencilStoreOp = depthStencilAttachmentInfo->stencilStoreOp; hash.depthStencilTargetDescription.stencilStoreOp = depthStencilAttachmentInfo->stencilStoreOp;
hash.depthStencilTargetDescription.finalLayout = VULKAN_INTERNAL_GetRenderPassFinalLayout(texture);
} }
renderPass = RenderPassHashArray_Fetch( renderPass = RenderPassHashArray_Fetch(
@ -9033,35 +9157,11 @@ static void VULKAN_EndRenderPass(
if (currentTexture->usageFlags & VK_IMAGE_USAGE_SAMPLED_BIT) if (currentTexture->usageFlags & VK_IMAGE_USAGE_SAMPLED_BIT)
{ {
VULKAN_INTERNAL_ImageMemoryBarrier( currentTexture->resourceAccessType = RESOURCE_ACCESS_ANY_SHADER_READ_SAMPLED_IMAGE;
renderer,
vulkanCommandBuffer->commandBuffer,
RESOURCE_ACCESS_ANY_SHADER_READ_SAMPLED_IMAGE,
currentTexture->aspectFlags,
0,
currentTexture->layerCount,
0,
currentTexture->levelCount,
0,
currentTexture->image,
&currentTexture->resourceAccessType
);
} }
else if (currentTexture->usageFlags & VK_IMAGE_USAGE_STORAGE_BIT) else if (currentTexture->usageFlags & VK_IMAGE_USAGE_STORAGE_BIT)
{ {
VULKAN_INTERNAL_ImageMemoryBarrier( currentTexture->resourceAccessType = RESOURCE_ACCESS_COMPUTE_SHADER_STORAGE_IMAGE_READ_WRITE;
renderer,
vulkanCommandBuffer->commandBuffer,
RESOURCE_ACCESS_COMPUTE_SHADER_STORAGE_IMAGE_READ_WRITE,
currentTexture->aspectFlags,
0,
currentTexture->layerCount,
0,
currentTexture->levelCount,
0,
currentTexture->image,
&currentTexture->resourceAccessType
);
} }
} }
vulkanCommandBuffer->renderPassColorTargetCount = 0; vulkanCommandBuffer->renderPassColorTargetCount = 0;
@ -9072,19 +9172,7 @@ static void VULKAN_EndRenderPass(
if (currentTexture->usageFlags & VK_IMAGE_USAGE_SAMPLED_BIT) if (currentTexture->usageFlags & VK_IMAGE_USAGE_SAMPLED_BIT)
{ {
VULKAN_INTERNAL_ImageMemoryBarrier( currentTexture->resourceAccessType = RESOURCE_ACCESS_ANY_SHADER_READ_SAMPLED_IMAGE;
renderer,
vulkanCommandBuffer->commandBuffer,
RESOURCE_ACCESS_ANY_SHADER_READ_SAMPLED_IMAGE,
currentTexture->aspectFlags,
0,
currentTexture->layerCount,
0,
currentTexture->levelCount,
0,
currentTexture->image,
&currentTexture->resourceAccessType
);
} }
} }
vulkanCommandBuffer->renderPassDepthTexture = NULL; vulkanCommandBuffer->renderPassDepthTexture = NULL;
@ -10597,7 +10685,6 @@ static uint8_t VULKAN_INTERNAL_DefragmentMemory(
currentRegion->vulkanBuffer->size, currentRegion->vulkanBuffer->size,
RESOURCE_ACCESS_NONE, RESOURCE_ACCESS_NONE,
currentRegion->vulkanBuffer->usage, currentRegion->vulkanBuffer->usage,
currentRegion->vulkanBuffer->requireHostVisible,
currentRegion->vulkanBuffer->preferDeviceLocal, currentRegion->vulkanBuffer->preferDeviceLocal,
0 0
); );
@ -12002,11 +12089,10 @@ static Refresh_Device* VULKAN_CreateDevice(
renderer->dummyBuffer = VULKAN_INTERNAL_CreateBuffer( renderer->dummyBuffer = VULKAN_INTERNAL_CreateBuffer(
renderer, renderer,
16, 1,
RESOURCE_ACCESS_GENERAL, RESOURCE_ACCESS_GENERAL,
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
0, 0,
0,
1 1
); );
@ -12123,7 +12209,6 @@ static Refresh_Device* VULKAN_CreateDevice(
RESOURCE_ACCESS_TRANSFER_READ_WRITE, RESOURCE_ACCESS_TRANSFER_READ_WRITE,
VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT, VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT,
1, 1,
0,
1 1
); );