fix some sync hazards
parent
425694ede5
commit
ae98ae2345
|
@ -1,4 +1,4 @@
|
||||||
/* Refresh - XNA-inspired 3D Graphics Library with modern capabilities
|
/* Refresh - XNA-inspired 3D Graphics Library with modern capabilities
|
||||||
*
|
*
|
||||||
* Copyright (c) 2020 Evan Hemsley
|
* Copyright (c) 2020 Evan Hemsley
|
||||||
*
|
*
|
||||||
|
@ -560,8 +560,8 @@ static const VulkanResourceAccessInfo AccessMap[RESOURCE_ACCESS_TYPES_COUNT] =
|
||||||
|
|
||||||
/* RESOURCE_ACCESS_ANY_SHADER_READ_SAMPLED_IMAGE */
|
/* RESOURCE_ACCESS_ANY_SHADER_READ_SAMPLED_IMAGE */
|
||||||
{
|
{
|
||||||
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
|
VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
|
||||||
VK_ACCESS_SHADER_READ_BIT,
|
VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
|
||||||
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
|
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -1011,6 +1011,7 @@ typedef struct RenderPassHash
|
||||||
uint32_t colorAttachmentCount;
|
uint32_t colorAttachmentCount;
|
||||||
RenderPassDepthStencilTargetDescription depthStencilTargetDescription;
|
RenderPassDepthStencilTargetDescription depthStencilTargetDescription;
|
||||||
Refresh_SampleCount colorAttachmentSampleCount;
|
Refresh_SampleCount colorAttachmentSampleCount;
|
||||||
|
VkImageLayout finalLayout;
|
||||||
} RenderPassHash;
|
} RenderPassHash;
|
||||||
|
|
||||||
typedef struct RenderPassHashMap
|
typedef struct RenderPassHashMap
|
||||||
|
@ -1042,6 +1043,11 @@ static inline uint8_t RenderPassHash_Compare(
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (a->finalLayout != b->finalLayout)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < a->colorAttachmentCount; i += 1)
|
for (i = 0; i < a->colorAttachmentCount; i += 1)
|
||||||
{
|
{
|
||||||
if (a->colorTargetDescriptions[i].format != b->colorTargetDescriptions[i].format)
|
if (a->colorTargetDescriptions[i].format != b->colorTargetDescriptions[i].format)
|
||||||
|
@ -5942,6 +5948,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,
|
||||||
|
@ -5956,7 +5997,7 @@ static VkRenderPass VULKAN_INTERNAL_CreateRenderPass(
|
||||||
VkAttachmentReference depthStencilAttachmentReference;
|
VkAttachmentReference depthStencilAttachmentReference;
|
||||||
VkRenderPassCreateInfo renderPassCreateInfo;
|
VkRenderPassCreateInfo renderPassCreateInfo;
|
||||||
VkSubpassDescription subpass;
|
VkSubpassDescription subpass;
|
||||||
VkImageLayout finalLayout;
|
VkSubpassDependency dep[2];
|
||||||
VkRenderPass renderPass;
|
VkRenderPass renderPass;
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|
||||||
|
@ -5971,19 +6012,6 @@ static VkRenderPass VULKAN_INTERNAL_CreateRenderPass(
|
||||||
{
|
{
|
||||||
texture = ((VulkanTextureContainer*) colorAttachmentInfos[i].texture)->vulkanTexture;
|
texture = ((VulkanTextureContainer*) colorAttachmentInfos[i].texture)->vulkanTexture;
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (texture->msaaTex != NULL)
|
if (texture->msaaTex != NULL)
|
||||||
{
|
{
|
||||||
msaaTexture = texture->msaaTex;
|
msaaTexture = texture->msaaTex;
|
||||||
|
@ -6022,7 +6050,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 =
|
||||||
finalLayout;
|
VULKAN_INTERNAL_GetRenderPassFinalLayout(texture);
|
||||||
|
|
||||||
resolveReferences[resolveReferenceCount].attachment =
|
resolveReferences[resolveReferenceCount].attachment =
|
||||||
attachmentDescriptionCount;
|
attachmentDescriptionCount;
|
||||||
|
@ -6078,8 +6106,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 =
|
||||||
finalLayout;
|
VULKAN_INTERNAL_GetRenderPassFinalLayout(texture);
|
||||||
|
|
||||||
|
|
||||||
colorAttachmentReferences[colorAttachmentReferenceCount].attachment = attachmentDescriptionCount;
|
colorAttachmentReferences[colorAttachmentReferenceCount].attachment = attachmentDescriptionCount;
|
||||||
colorAttachmentReferences[colorAttachmentReferenceCount].layout =
|
colorAttachmentReferences[colorAttachmentReferenceCount].layout =
|
||||||
|
@ -6107,15 +6134,6 @@ static VkRenderPass VULKAN_INTERNAL_CreateRenderPass(
|
||||||
{
|
{
|
||||||
texture = ((VulkanTextureContainer*) depthStencilAttachmentInfo->texture)->vulkanTexture;
|
texture = ((VulkanTextureContainer*) depthStencilAttachmentInfo->texture)->vulkanTexture;
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
attachmentDescriptions[attachmentDescriptionCount].flags = 0;
|
attachmentDescriptions[attachmentDescriptionCount].flags = 0;
|
||||||
attachmentDescriptions[attachmentDescriptionCount].format = texture->format;
|
attachmentDescriptions[attachmentDescriptionCount].format = texture->format;
|
||||||
attachmentDescriptions[attachmentDescriptionCount].samples = RefreshToVK_SampleCount[
|
attachmentDescriptions[attachmentDescriptionCount].samples = RefreshToVK_SampleCount[
|
||||||
|
@ -6136,7 +6154,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 =
|
||||||
finalLayout;
|
VULKAN_INTERNAL_GetRenderPassFinalLayout(texture);
|
||||||
|
|
||||||
depthStencilAttachmentReference.attachment =
|
depthStencilAttachmentReference.attachment =
|
||||||
attachmentDescriptionCount;
|
attachmentDescriptionCount;
|
||||||
|
@ -6158,6 +6176,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;
|
||||||
|
@ -6165,8 +6214,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,
|
||||||
|
@ -6195,6 +6244,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;
|
||||||
|
@ -6205,7 +6255,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 compare about layout */
|
/* 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];
|
||||||
|
@ -6339,6 +6389,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;
|
||||||
|
@ -6346,8 +6427,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,
|
||||||
|
@ -8492,6 +8573,8 @@ static VkRenderPass VULKAN_INTERNAL_FetchRenderPass(
|
||||||
hash.depthStencilTargetDescription.stencilStoreOp = depthStencilAttachmentInfo->stencilStoreOp;
|
hash.depthStencilTargetDescription.stencilStoreOp = depthStencilAttachmentInfo->stencilStoreOp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hash.finalLayout = VULKAN_INTERNAL_GetRenderPassFinalLayout(texture);
|
||||||
|
|
||||||
renderPass = RenderPassHashArray_Fetch(
|
renderPass = RenderPassHashArray_Fetch(
|
||||||
&renderer->renderPassHashArray,
|
&renderer->renderPassHashArray,
|
||||||
&hash
|
&hash
|
||||||
|
|
Loading…
Reference in New Issue