fix more transfer bugs
This commit is contained in:
parent
e495eaf31b
commit
0c5521153f
55
vulkan.d
55
vulkan.d
@ -217,9 +217,11 @@ enum ImageLayout : VkImageLayout
|
||||
Undefined = VK_IMAGE_LAYOUT_UNDEFINED,
|
||||
General = VK_IMAGE_LAYOUT_GENERAL,
|
||||
ColorAttach = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
|
||||
DepthAttach = VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL,
|
||||
ReadOnly = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
|
||||
TransferDst = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
||||
TransferSrc = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
|
||||
PresentSrc = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
|
||||
}
|
||||
|
||||
alias IL = ImageLayout;
|
||||
@ -565,6 +567,12 @@ struct Vulkan
|
||||
return this.present_images[this.image_index];
|
||||
}
|
||||
|
||||
@property Descriptor*
|
||||
present_image_ptr()
|
||||
{
|
||||
return this.present_images.ptr + this.image_index;
|
||||
}
|
||||
|
||||
Arena*
|
||||
FrameArena()
|
||||
{
|
||||
@ -804,6 +812,8 @@ BeginFrame()
|
||||
flags: VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT,
|
||||
};
|
||||
|
||||
g_vk.present_image_ptr.image.layout = IL.Undefined;
|
||||
|
||||
result = vkBeginCommandBuffer(g_vk.cmd, &cmd_info);
|
||||
VkCheckA("BeginFrame failure: vkBeginCommandBuffer error", result);
|
||||
}
|
||||
@ -818,11 +828,10 @@ SetClearColors(f32[4] color_clear, f32[4] depth_clear)
|
||||
void
|
||||
BeginRendering()
|
||||
{
|
||||
Transition(g_vk.cmd, &g_vk.draw_image, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
|
||||
Transition(g_vk.cmd, &g_vk.depth_image, VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL);
|
||||
Transition(g_vk.cmd, &g_vk.draw_image, IL.ColorAttach);
|
||||
Transition(g_vk.cmd, &g_vk.depth_image, IL.DepthAttach);
|
||||
|
||||
VkImage image = g_vk.present_image.image.image;
|
||||
Transition(g_vk.cmd, image, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
|
||||
Transition(g_vk.cmd, g_vk.present_image_ptr, IL.TransferDst);
|
||||
|
||||
VkClearValue[2] clear_color = [
|
||||
{ color: { float32: g_vk.color_clear } },
|
||||
@ -865,7 +874,7 @@ GetAspect()
|
||||
void
|
||||
PrepComputeDrawImage()
|
||||
{
|
||||
Transition(g_vk.cmd, &g_vk.draw_image, VK_IMAGE_LAYOUT_GENERAL);
|
||||
Transition(g_vk.cmd, &g_vk.draw_image, IL.General);
|
||||
}
|
||||
|
||||
void
|
||||
@ -887,7 +896,7 @@ SubmitAndPresent()
|
||||
VkSemaphore acquire_sem = g_vk.acquire_sem;
|
||||
VkSemaphore submit_sem = g_vk.submit_sem;
|
||||
|
||||
Transition(g_vk.cmd, &g_vk.draw_image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
|
||||
Transition(g_vk.cmd, &g_vk.draw_image, IL.TransferSrc);
|
||||
|
||||
VkExtent2D extent = {
|
||||
width: g_vk.swapchain_extent.width,
|
||||
@ -895,9 +904,9 @@ SubmitAndPresent()
|
||||
};
|
||||
|
||||
// TODO: Find out how to copy from same dimension images (pretty sure its not blitting)
|
||||
Copy(g_vk.cmd, &g_vk.draw_image, image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, extent, extent);
|
||||
Copy(g_vk.cmd, &g_vk.draw_image, image, IL.TransferDst, extent, extent);
|
||||
|
||||
Transition(g_vk.cmd, image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR);
|
||||
Transition(g_vk.cmd, image, IL.TransferDst, IL.PresentSrc);
|
||||
|
||||
VkResult result = vkEndCommandBuffer(g_vk.cmd);
|
||||
VkCheckA("FinishFrame failure: vkEndCommandBuffer error", result);
|
||||
@ -1186,16 +1195,16 @@ CreateImageView(Descriptor* desc, u8[] data)
|
||||
&pc
|
||||
);
|
||||
|
||||
Transition(g_vk.comp_cmd, &conv_view, VK_IMAGE_LAYOUT_GENERAL);
|
||||
Transition(g_vk.comp_cmd, &conv_view, IL.General);
|
||||
|
||||
Dispatch(g_vk.comp_cmd);
|
||||
|
||||
Transition(g_vk.comp_cmd, desc, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
|
||||
Transition(g_vk.comp_cmd, desc, IL.TransferDst);
|
||||
|
||||
VkExtent2D extent = { width: desc.image.w, height: desc.image.h };
|
||||
Copy(g_vk.comp_cmd, &conv_view, desc, extent, extent);
|
||||
|
||||
Transition(g_vk.comp_cmd, desc, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
|
||||
Transition(g_vk.comp_cmd, desc, IL.ReadOnly);
|
||||
|
||||
FinishComputePass();
|
||||
|
||||
@ -1390,7 +1399,7 @@ Transfer(bool image, T)(Descriptor* desc, T data) if(isArray!(T) || isPointer!(T
|
||||
|
||||
static if(isArray!(T))
|
||||
{
|
||||
u64 data_length = cast(u64)(data.length * T[0].sizeof);
|
||||
u64 data_length = cast(u64)(data.length * (*data.init.ptr).sizeof);
|
||||
}
|
||||
else static if(isPointer!(T))
|
||||
{
|
||||
@ -1409,11 +1418,11 @@ Transfer(bool image, T)(Descriptor* desc, T data) if(isArray!(T) || isPointer!(T
|
||||
{
|
||||
auto fn = function(Descriptor* desc, VkBufferImageCopy copy)
|
||||
{
|
||||
Transition(g_vk.imm_cmd, desc, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
|
||||
Transition(g_vk.imm_cmd, desc, IL.TransferDst);
|
||||
|
||||
vkCmdCopyBufferToImage(g_vk.imm_cmd, g_vk.transfer_buf.buffer, desc.image.image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ©);
|
||||
|
||||
Transition(g_vk.imm_cmd, desc, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
|
||||
Transition(g_vk.imm_cmd, desc, IL.ReadOnly);
|
||||
};
|
||||
|
||||
VkBufferImageCopy copy = {
|
||||
@ -1461,13 +1470,13 @@ Copy(VkCommandBuffer cmd, Descriptor* src, Descriptor* dst, VkExtent2D src_ext,
|
||||
}
|
||||
|
||||
void
|
||||
Copy(VkCommandBuffer cmd, Descriptor* src, VkImage dst, VkImageLayout dst_layout, VkExtent2D src_ext, VkExtent2D dst_ext)
|
||||
Copy(VkCommandBuffer cmd, Descriptor* src, VkImage dst, ImageLayout dst_layout, VkExtent2D src_ext, VkExtent2D dst_ext)
|
||||
{
|
||||
Copy(cmd, src.image.image, dst, src.image.layout, dst_layout, src_ext, dst_ext);
|
||||
}
|
||||
|
||||
void
|
||||
Copy(VkCommandBuffer cmd, VkImage src, VkImage dst, VkImageLayout src_layout, VkImageLayout dst_layout, VkExtent2D src_ext, VkExtent2D dst_ext)
|
||||
Copy(VkCommandBuffer cmd, VkImage src, VkImage dst, ImageLayout src_layout, ImageLayout dst_layout, VkExtent2D src_ext, VkExtent2D dst_ext)
|
||||
{
|
||||
VkImageBlit blit = {
|
||||
srcOffsets: [
|
||||
@ -1653,7 +1662,7 @@ ResetScissor(VkCommandBuffer cmd = cast(VkCommandBuffer)VK_NULL_HANDLE)
|
||||
cmd = cmd == VK_NULL_HANDLE ? g_vk.cmd : cmd;
|
||||
|
||||
VkRect2D scissor = {
|
||||
offset: { x: 0, y: 0 },
|
||||
offset: { x: 0, y: 0 },
|
||||
extent: { width: g_vk.swapchain_extent.width, height: g_vk.swapchain_extent.height },
|
||||
};
|
||||
|
||||
@ -1661,14 +1670,15 @@ ResetScissor(VkCommandBuffer cmd = cast(VkCommandBuffer)VK_NULL_HANDLE)
|
||||
}
|
||||
|
||||
void
|
||||
Transition(VkCommandBuffer cmd, Descriptor* desc, VkImageLayout new_layout)
|
||||
Transition(VkCommandBuffer cmd, Descriptor* desc, ImageLayout new_layout)
|
||||
{
|
||||
ImageDescCheck(desc);
|
||||
Transition(cmd, desc.image.image, desc.image.layout, new_layout);
|
||||
desc.image.layout = new_layout;
|
||||
}
|
||||
|
||||
void
|
||||
Transition(VkCommandBuffer cmd, VkImage image, VkImageLayout current_layout, VkImageLayout new_layout)
|
||||
Transition(VkCommandBuffer cmd, VkImage image, ImageLayout current_layout, ImageLayout new_layout)
|
||||
{
|
||||
VkImageMemoryBarrier2 barrier = {
|
||||
sType: VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER_2,
|
||||
@ -1680,7 +1690,7 @@ Transition(VkCommandBuffer cmd, VkImage image, VkImageLayout current_layout, VkI
|
||||
newLayout: new_layout,
|
||||
image: image,
|
||||
subresourceRange: {
|
||||
aspectMask: new_layout == VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL ? VK_IMAGE_ASPECT_DEPTH_BIT : VK_IMAGE_ASPECT_COLOR_BIT,
|
||||
aspectMask: new_layout == IL.DepthAttach ? VK_IMAGE_ASPECT_DEPTH_BIT : VK_IMAGE_ASPECT_COLOR_BIT,
|
||||
baseMipLevel: 0,
|
||||
levelCount: VK_REMAINING_MIP_LEVELS,
|
||||
baseArrayLayer: 0,
|
||||
@ -1977,14 +1987,14 @@ ClearColor(T)(T color)
|
||||
void
|
||||
ClearDepth(f32[4] color = [0.0, 0.0, 0.0, 0.0])
|
||||
{
|
||||
Transition(g_vk.cmd, &g_vk.depth_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
|
||||
Transition(g_vk.cmd, &g_vk.depth_image, IL.TransferDst);
|
||||
ClearColor(&g_vk.depth_image, color);
|
||||
}
|
||||
|
||||
void
|
||||
ClearColor(f32[4] color)
|
||||
{
|
||||
Transition(g_vk.cmd, &g_vk.draw_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
|
||||
Transition(g_vk.cmd, &g_vk.draw_image, IL.TransferDst);
|
||||
ClearColor(&g_vk.draw_image, color);
|
||||
}
|
||||
|
||||
@ -3340,3 +3350,4 @@ version(VULKAN_RENDERER_TEST) unittest
|
||||
Init(handles, 10*1000*1000, 10*1000*1000);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user