Compare commits

..

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

3 changed files with 217 additions and 132 deletions

View File

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

View File

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

View File

@ -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 16777216 /* 16MB */
#define UBO_SECTION_SIZE 4096 /* 4KB */
#define UBO_BUFFER_SIZE 16000000 /* 16MB */
#define UBO_SECTION_SIZE 4000 /* 4KB */
#define DESCRIPTOR_POOL_STARTING_SIZE 128
#define DEFRAG_TIME 200
#define WINDOW_DATA "Refresh_VulkanWindowData"
@ -708,7 +708,6 @@ struct VulkanBuffer
VulkanResourceAccessType resourceAccessType;
VkBufferUsageFlags usage;
uint8_t requireHostVisible;
uint8_t preferDeviceLocal;
SDL_atomic_t referenceCount; /* Tracks command buffer usage */
@ -999,6 +998,7 @@ typedef struct RenderPassColorTargetDescription
Refresh_Vec4 clearColor;
Refresh_LoadOp loadOp;
Refresh_StoreOp storeOp;
VkImageLayout finalLayout;
} RenderPassColorTargetDescription;
typedef struct RenderPassDepthStencilTargetDescription
@ -1008,6 +1008,7 @@ typedef struct RenderPassDepthStencilTargetDescription
Refresh_StoreOp storeOp;
Refresh_LoadOp stencilLoadOp;
Refresh_StoreOp stencilStoreOp;
VkImageLayout finalLayout;
} RenderPassDepthStencilTargetDescription;
typedef struct RenderPassHash
@ -1071,6 +1072,11 @@ 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)
@ -1098,6 +1104,11 @@ static inline uint8_t RenderPassHash_Compare(
return 0;
}
if (a->depthStencilTargetDescription.finalLayout != b->depthStencilTargetDescription.finalLayout)
{
return 0;
}
return 1;
}
@ -1980,51 +1991,59 @@ 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("Texture format not recognized!");
Refresh_LogError("Invalid texture format!");
return 0;
}
}
static inline uint32_t VULKAN_INTERNAL_TextureBlockSize(
static inline uint32_t VULKAN_INTERNAL_GetTextureBlockSize(
VkFormat format
) {
switch (format)
@ -2039,28 +2058,24 @@ static inline uint32_t VULKAN_INTERNAL_TextureBlockSize(
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_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_R16_SFLOAT:
case VK_FORMAT_R16G16_SFLOAT:
case VK_FORMAT_R16G16B16A16_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!");
@ -2073,8 +2088,17 @@ static inline VkDeviceSize VULKAN_INTERNAL_BytesPerImage(
uint32_t height,
VkFormat format
) {
uint32_t blockSize = VULKAN_INTERNAL_TextureBlockSize(format);
return (width * height * VULKAN_INTERNAL_BytesPerPixel(format)) / (blockSize * blockSize);
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);
}
static inline Refresh_SampleCount VULKAN_INTERNAL_GetMaxMultiSampleCount(
@ -2933,7 +2957,7 @@ static uint8_t VULKAN_INTERNAL_BindMemoryForImage(
{
memoryTypeIndex = 0;
requiredMemoryPropertyFlags = 0;
ignoredMemoryPropertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
ignoredMemoryPropertyFlags = VK_MEMORY_HEAP_DEVICE_LOCAL_BIT;
if (isRenderTarget)
{
@ -2979,32 +3003,23 @@ 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 = 0;
VkMemoryPropertyFlags ignoredMemoryPropertyFlags = 0;
VkMemoryPropertyFlags requiredMemoryPropertyFlags;
VkMemoryPropertyFlags ignoredMemoryPropertyFlags;
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;
}
requiredMemoryPropertyFlags =
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
if (preferDeviceLocal)
{
@ -3043,10 +3058,9 @@ static uint8_t VULKAN_INTERNAL_BindMemoryForBuffer(
}
/* Bind failed, try again if originally preferred device local */
if (bindResult != 1)
if (bindResult != 1 && preferDeviceLocal)
{
memoryTypeIndex = 0;
requiredMemoryPropertyFlags =
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
@ -4107,7 +4121,6 @@ static VulkanBuffer* VULKAN_INTERNAL_CreateBuffer(
VkDeviceSize size,
VulkanResourceAccessType resourceAccessType,
VkBufferUsageFlags usage,
uint8_t requireHostVisible,
uint8_t preferDeviceLocal,
uint8_t dedicatedAllocation
) {
@ -4121,7 +4134,6 @@ 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;
@ -4145,7 +4157,6 @@ static VulkanBuffer* VULKAN_INTERNAL_CreateBuffer(
renderer,
buffer->buffer,
buffer->size,
buffer->requireHostVisible,
buffer->preferDeviceLocal,
dedicatedAllocation,
&buffer->usedRegion
@ -4229,7 +4240,6 @@ static VulkanUniformBufferPool* VULKAN_INTERNAL_CreateUniformBufferPool(
UBO_BUFFER_SIZE,
resourceAccessType,
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
1,
0,
1
);
@ -4275,7 +4285,8 @@ static VulkanBufferContainer* VULKAN_INTERNAL_CreateBufferContainer(
VulkanRenderer *renderer,
uint32_t sizeInBytes,
VulkanResourceAccessType resourceAccessType,
VkBufferUsageFlags usageFlags
VkBufferUsageFlags usageFlags,
uint8_t dedicated
) {
VulkanBufferContainer* bufferContainer;
VulkanBuffer* buffer;
@ -4288,9 +4299,8 @@ static VulkanBufferContainer* VULKAN_INTERNAL_CreateBufferContainer(
sizeInBytes,
resourceAccessType,
usageFlags,
0,
1,
0
dedicated
);
if (buffer == NULL)
@ -4335,7 +4345,7 @@ static uint8_t VULKAN_INTERNAL_CreateUniformBuffer(
uniformBuffer->poolOffset = bufferPool->nextAvailableOffset;
uniformBuffer->offset = 0;
bufferPool->nextAvailableOffset += VULKAN_INTERNAL_NextHighestAlignment(UBO_SECTION_SIZE, renderer->minUBOAlignment);
bufferPool->nextAvailableOffset += UBO_SECTION_SIZE;
if (bufferPool->nextAvailableOffset >= UBO_BUFFER_SIZE)
{
@ -5949,6 +5959,41 @@ 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,
@ -5963,6 +6008,7 @@ static VkRenderPass VULKAN_INTERNAL_CreateRenderPass(
VkAttachmentReference depthStencilAttachmentReference;
VkRenderPassCreateInfo renderPassCreateInfo;
VkSubpassDescription subpass;
VkSubpassDependency dep[2];
VkRenderPass renderPass;
uint32_t i;
@ -6015,7 +6061,7 @@ static VkRenderPass VULKAN_INTERNAL_CreateRenderPass(
attachmentDescriptions[attachmentDescriptionCount].initialLayout =
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
attachmentDescriptions[attachmentDescriptionCount].finalLayout =
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
VULKAN_INTERNAL_GetRenderPassFinalLayout(texture);
resolveReferences[resolveReferenceCount].attachment =
attachmentDescriptionCount;
@ -6071,8 +6117,7 @@ static VkRenderPass VULKAN_INTERNAL_CreateRenderPass(
attachmentDescriptions[attachmentDescriptionCount].initialLayout =
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
attachmentDescriptions[attachmentDescriptionCount].finalLayout =
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
VULKAN_INTERNAL_GetRenderPassFinalLayout(texture);
colorAttachmentReferences[colorAttachmentReferenceCount].attachment = attachmentDescriptionCount;
colorAttachmentReferences[colorAttachmentReferenceCount].layout =
@ -6120,7 +6165,7 @@ static VkRenderPass VULKAN_INTERNAL_CreateRenderPass(
attachmentDescriptions[attachmentDescriptionCount].initialLayout =
VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
attachmentDescriptions[attachmentDescriptionCount].finalLayout =
VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
VULKAN_INTERNAL_GetRenderPassFinalLayout(texture);
depthStencilAttachmentReference.attachment =
attachmentDescriptionCount;
@ -6142,6 +6187,37 @@ 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;
@ -6149,8 +6225,8 @@ static VkRenderPass VULKAN_INTERNAL_CreateRenderPass(
renderPassCreateInfo.attachmentCount = attachmentDescriptionCount;
renderPassCreateInfo.subpassCount = 1;
renderPassCreateInfo.pSubpasses = &subpass;
renderPassCreateInfo.dependencyCount = 0;
renderPassCreateInfo.pDependencies = NULL;
renderPassCreateInfo.dependencyCount = 2;
renderPassCreateInfo.pDependencies = dep;
vulkanResult = renderer->vkCreateRenderPass(
renderer->logicalDevice,
@ -6179,6 +6255,7 @@ static VkRenderPass VULKAN_INTERNAL_CreateTransientRenderPass(
VkAttachmentReference depthStencilAttachmentReference;
Refresh_ColorAttachmentDescription attachmentDescription;
VkSubpassDescription subpass;
VkSubpassDependency dep[2];
VkRenderPassCreateInfo renderPassCreateInfo;
VkRenderPass renderPass;
VkResult result;
@ -6189,6 +6266,7 @@ 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];
@ -6322,6 +6400,37 @@ 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;
@ -6329,8 +6438,8 @@ static VkRenderPass VULKAN_INTERNAL_CreateTransientRenderPass(
renderPassCreateInfo.attachmentCount = attachmentDescriptionCount;
renderPassCreateInfo.subpassCount = 1;
renderPassCreateInfo.pSubpasses = &subpass;
renderPassCreateInfo.dependencyCount = 0;
renderPassCreateInfo.pDependencies = NULL;
renderPassCreateInfo.dependencyCount = 2;
renderPassCreateInfo.pDependencies = dep;
result = renderer->vkCreateRenderPass(
renderer->logicalDevice,
@ -7121,7 +7230,8 @@ static Refresh_Buffer* VULKAN_CreateBuffer(
(VulkanRenderer*) driverData,
sizeInBytes,
resourceAccessType,
vulkanUsageFlags
vulkanUsageFlags,
0
);
}
@ -7203,7 +7313,6 @@ 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;
@ -7243,7 +7352,7 @@ static void VULKAN_SetTextureData(
VulkanTransferBuffer *transferBuffer;
VkBufferImageCopy imageCopy;
uint8_t *stagingBufferPointer;
uint32_t blockSize = VULKAN_INTERNAL_TextureBlockSize(vulkanTexture->format);
uint32_t blockSize = VULKAN_INTERNAL_GetTextureBlockSize(vulkanTexture->format);
uint32_t bufferRowLength;
uint32_t bufferImageHeight;
@ -7771,6 +7880,14 @@ 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;
@ -8440,10 +8557,13 @@ static VkRenderPass VULKAN_INTERNAL_FetchRenderPass(
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].loadOp = colorAttachmentInfos[i].loadOp;
hash.colorTargetDescriptions[i].storeOp = colorAttachmentInfos[i].storeOp;
hash.colorTargetDescriptions[i].finalLayout = VULKAN_INTERNAL_GetRenderPassFinalLayout(texture);
}
hash.colorAttachmentSampleCount = REFRESH_SAMPLECOUNT_1;
@ -8465,14 +8585,18 @@ 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
{
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.storeOp = depthStencilAttachmentInfo->storeOp;
hash.depthStencilTargetDescription.stencilLoadOp = depthStencilAttachmentInfo->stencilLoadOp;
hash.depthStencilTargetDescription.stencilStoreOp = depthStencilAttachmentInfo->stencilStoreOp;
hash.depthStencilTargetDescription.finalLayout = VULKAN_INTERNAL_GetRenderPassFinalLayout(texture);
}
renderPass = RenderPassHashArray_Fetch(
@ -9033,35 +9157,11 @@ static void VULKAN_EndRenderPass(
if (currentTexture->usageFlags & VK_IMAGE_USAGE_SAMPLED_BIT)
{
VULKAN_INTERNAL_ImageMemoryBarrier(
renderer,
vulkanCommandBuffer->commandBuffer,
RESOURCE_ACCESS_ANY_SHADER_READ_SAMPLED_IMAGE,
currentTexture->aspectFlags,
0,
currentTexture->layerCount,
0,
currentTexture->levelCount,
0,
currentTexture->image,
&currentTexture->resourceAccessType
);
currentTexture->resourceAccessType = RESOURCE_ACCESS_ANY_SHADER_READ_SAMPLED_IMAGE;
}
else if (currentTexture->usageFlags & VK_IMAGE_USAGE_STORAGE_BIT)
{
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,
&currentTexture->resourceAccessType
);
currentTexture->resourceAccessType = RESOURCE_ACCESS_COMPUTE_SHADER_STORAGE_IMAGE_READ_WRITE;
}
}
vulkanCommandBuffer->renderPassColorTargetCount = 0;
@ -9072,19 +9172,7 @@ static void VULKAN_EndRenderPass(
if (currentTexture->usageFlags & VK_IMAGE_USAGE_SAMPLED_BIT)
{
VULKAN_INTERNAL_ImageMemoryBarrier(
renderer,
vulkanCommandBuffer->commandBuffer,
RESOURCE_ACCESS_ANY_SHADER_READ_SAMPLED_IMAGE,
currentTexture->aspectFlags,
0,
currentTexture->layerCount,
0,
currentTexture->levelCount,
0,
currentTexture->image,
&currentTexture->resourceAccessType
);
currentTexture->resourceAccessType = RESOURCE_ACCESS_ANY_SHADER_READ_SAMPLED_IMAGE;
}
}
vulkanCommandBuffer->renderPassDepthTexture = NULL;
@ -10597,7 +10685,6 @@ static uint8_t VULKAN_INTERNAL_DefragmentMemory(
currentRegion->vulkanBuffer->size,
RESOURCE_ACCESS_NONE,
currentRegion->vulkanBuffer->usage,
currentRegion->vulkanBuffer->requireHostVisible,
currentRegion->vulkanBuffer->preferDeviceLocal,
0
);
@ -12002,11 +12089,10 @@ static Refresh_Device* VULKAN_CreateDevice(
renderer->dummyBuffer = VULKAN_INTERNAL_CreateBuffer(
renderer,
16,
1,
RESOURCE_ACCESS_GENERAL,
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
0,
0,
1
);
@ -12123,7 +12209,6 @@ 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
);