Skip to content

Commit

Permalink
Fix QueueSubmit
Browse files Browse the repository at this point in the history
  • Loading branch information
FaberSanZ committed Nov 28, 2021
1 parent f835c29 commit 695f20d
Show file tree
Hide file tree
Showing 13 changed files with 112 additions and 112 deletions.
2 changes: 1 addition & 1 deletion Src/Samples/Samples/ComputeTexture/ComputeTexture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public override void Initialize()
AdapterConfig = new()
{
SwapChain = true,
VulkanDebug = true
Debug = true
};


Expand Down
2 changes: 1 addition & 1 deletion Src/Samples/Samples/DiffuseLighting/DiffuseLighting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public override void Initialize()
AdapterConfig = new()
{
SwapChain = true,
VulkanDebug = false,
Debug = false,
Fullscreen = false,
};

Expand Down
2 changes: 1 addition & 1 deletion Src/Samples/Samples/LoadGLTF/LoadGLTFExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public override void Initialize()
AdapterConfig = new()
{
SwapChain = true,
VulkanDebug = false,
Debug = false,
Fullscreen = false,
};

Expand Down
2 changes: 1 addition & 1 deletion Src/Samples/Samples/LoadTexture/LoadTextureExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public override void Initialize()
AdapterConfig = new()
{
SwapChain = true,
VulkanDebug = false,
Debug = false,
Fullscreen = false,
};

Expand Down
2 changes: 1 addition & 1 deletion Src/Samples/Samples/PushConstant/PushConstantExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public override void Initialize()
AdapterConfig = new()
{
SwapChain = true,
VulkanDebug = false,
Debug = false,
Fullscreen = false,
//ForceExclusiveTransferQueue = true
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public override void Initialize()
AdapterConfig = new()
{
SwapChain = true,
VulkanDebug = false,
Debug = false,
Fullscreen = false,
};

Expand Down
2 changes: 1 addition & 1 deletion Src/Samples/Samples/Triangle/TriangleExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public override void Initialize()
AdapterConfig = new()
{
SwapChain = true,
VulkanDebug = true,
Debug = true,
};


Expand Down
2 changes: 1 addition & 1 deletion Src/Vultaik/Buffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ internal void Recreate()
sType = VkStructureType.MemoryAllocateInfo,
pNext = null,
allocationSize = memReqs.size,
memoryTypeIndex = NativeDevice.GetMemoryTypeIndex(memReqs.memoryTypeBits, memoryProperties),
memoryTypeIndex = NativeDevice.get_memory_type(memReqs.memoryTypeBits, memoryProperties),
};


Expand Down
10 changes: 5 additions & 5 deletions Src/Vultaik/CommandBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ public CommandBuffer(Device graphicsDevice, CommandBufferType type) : base(graph

Recreate();

//WaitFence = new(NativeDevice, true);
WaitFence = new(NativeDevice, true);
}

public CommandBufferType Type { get; set; }
//public Fence WaitFence { get; set; }
public Fence WaitFence { get; set; }

public void Recreate()
{
Expand Down Expand Up @@ -70,8 +70,8 @@ public void Begin()
{
BeginRenderPassContinue();

//WaitFence.Wait();
//WaitFence.Reset();
WaitFence.Wait();
WaitFence.Reset();
}


Expand Down Expand Up @@ -585,7 +585,7 @@ public void Free()

public void Dispose()
{
//WaitFence.Dispose();
WaitFence.Dispose();
vkDestroyCommandPool(NativeDevice.handle, cmd_command_pool, null);
}

Expand Down
2 changes: 1 addition & 1 deletion Src/Vultaik/Compute/ComputePipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public void CreatePipeline()
sType = VkStructureType.PipelineShaderStageCreateInfo,
pNext = null,
stage = VkShaderStageFlags.Compute,
module = NativeDevice.LoadSpir_V_Shader(shader.Data),
module = NativeDevice.load_spirv_shader(shader.Data),
pName = Interop.String.ToPointer(shader.EntryPoint),
};

Expand Down
182 changes: 91 additions & 91 deletions Src/Vultaik/Device.cs
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ internal void CreateCommandQueues()



internal VkShaderModule LoadSpir_V_Shader(Span<byte> bytes)
internal VkShaderModule load_spirv_shader(Span<byte> bytes)
{

fixed (byte* ptr = bytes)
Expand All @@ -546,7 +546,7 @@ internal VkShaderModule LoadSpir_V_Shader(Span<byte> bytes)
}


internal uint GetMemoryTypeIndex(uint typeBits, VkMemoryPropertyFlags properties)
internal uint get_memory_type(uint typeBits, VkMemoryPropertyFlags properties)
{
// Iterate over all memory types available for the Device used in this example
for (uint i = 0; i < _memoryProperties.memoryTypeCount; i++)
Expand Down Expand Up @@ -753,127 +753,127 @@ public VkQueue get_queue_type_cmd(CommandBuffer cmd)
return VkQueue.Null;
}

public void SubmitTransfer(CommandBuffer commandBuffer, Fence? fence = null)
{
VkQueue queue = get_queue_type_cmd(commandBuffer);
VkCommandBuffer cmd = commandBuffer.handle;
//public void SubmitTransfer(CommandBuffer commandBuffer, Fence? fence = null)
//{
// VkQueue queue = get_queue_type_cmd(commandBuffer);
// VkCommandBuffer cmd = commandBuffer.handle;


VkSubmitInfo submit_info = new()
{
sType = VkStructureType.SubmitInfo,
commandBufferCount = 1,
pCommandBuffers = &cmd,
};
// VkSubmitInfo submit_info = new()
// {
// sType = VkStructureType.SubmitInfo,
// commandBufferCount = 1,
// pCommandBuffers = &cmd,
// };

vkQueueSubmit(queue, 1, &submit_info, VkFence.Null);
}
// vkQueueSubmit(queue, 1, &submit_info, VkFence.Null);
//}


public void Submit(CommandBuffer commandBuffer, Fence? fence = null)
{
VkQueue queue = get_queue_type_cmd(commandBuffer);
VkCommandBuffer cmd = commandBuffer.handle;
VkSemaphore signal_semaphore = render_finished_semaphore;
VkSemaphore wait_semaphore = image_available_semaphore;
//public void Submit(CommandBuffer commandBuffer, Fence? fence = null)
//{
// VkQueue queue = get_queue_type_cmd(commandBuffer);
// VkCommandBuffer cmd = commandBuffer.handle;
// VkSemaphore signal_semaphore = render_finished_semaphore;
// VkSemaphore wait_semaphore = image_available_semaphore;


VkSubmitInfo submit_info = new()
{
sType = VkStructureType.SubmitInfo,
commandBufferCount = 1,
pCommandBuffers = &cmd,
};
// VkSubmitInfo submit_info = new()
// {
// sType = VkStructureType.SubmitInfo,
// commandBufferCount = 1,
// pCommandBuffers = &cmd,
// };


submit_info.waitSemaphoreCount = 1;
submit_info.pWaitSemaphores = &wait_semaphore;
// submit_info.waitSemaphoreCount = 1;
// submit_info.pWaitSemaphores = &wait_semaphore;

submit_info.signalSemaphoreCount = 1;
submit_info.pSignalSemaphores = &signal_semaphore;
// submit_info.signalSemaphoreCount = 1;
// submit_info.pSignalSemaphores = &signal_semaphore;

vkQueueSubmit(queue, 1, &submit_info, VkFence.Null);
}
// vkQueueSubmit(queue, 1, &submit_info, VkFence.Null);
//}



//public void Submit(CommandBuffer commandBuffer, Fence? fence = null)
//{
// VkPipelineStageFlags wait_stages = VkPipelineStageFlags.ColorAttachmentOutput;
// VkSemaphore signal_semaphore = render_finished_semaphore;
// VkSemaphore wait_semaphore = image_available_semaphore;
// VkQueue queue = get_queue_type_cmd(commandBuffer);
// CommandBufferType cmd_type = commandBuffer.Type;
// VkCommandBuffer cmd = commandBuffer.handle;
// var force_exclusive_transfer_queue = false;
// VkFence sync_fence = VkFence.Null;
// bool use_semaphore = true;
public void Submit(CommandBuffer commandBuffer, Fence? fence = null)
{
VkPipelineStageFlags wait_stages = VkPipelineStageFlags.ColorAttachmentOutput;
VkSemaphore signal_semaphore = render_finished_semaphore;
VkSemaphore wait_semaphore = image_available_semaphore;
VkQueue queue = get_queue_type_cmd(commandBuffer);
CommandBufferType cmd_type = commandBuffer.Type;
VkCommandBuffer cmd = commandBuffer.handle;
var force_exclusive_transfer_queue = false;
VkFence sync_fence = VkFence.Null;
bool use_semaphore = true;

// if (queue == transfer_queue && cmd_type == CommandBufferType.AsyncTransfer)
// {
// wait_stages &= ~VkPipelineStageFlags.ColorAttachmentOutput;
if (queue == transfer_queue && cmd_type == CommandBufferType.AsyncTransfer)
{
wait_stages &= ~VkPipelineStageFlags.ColorAttachmentOutput;

// if (force_exclusive_transfer_queue)
// wait_stages |= VkPipelineStageFlags.Transfer;
if (force_exclusive_transfer_queue)
wait_stages |= VkPipelineStageFlags.Transfer;

// use_semaphore = false;
// }
use_semaphore = false;
}


// if (queue == graphics_queue && cmd_type == CommandBufferType.AsyncTransfer)
// {
// wait_stages &= ~VkPipelineStageFlags.ColorAttachmentOutput;
if (queue == graphics_queue && cmd_type == CommandBufferType.AsyncTransfer)
{
wait_stages &= ~VkPipelineStageFlags.ColorAttachmentOutput;

// if(force_exclusive_transfer_queue)
// wait_stages |= VkPipelineStageFlags.Transfer;
if (force_exclusive_transfer_queue)
wait_stages |= VkPipelineStageFlags.Transfer;

// use_semaphore = false;
// }
use_semaphore = false;
}


// if (queue == graphics_queue && cmd_type == CommandBufferType.AsyncCompute)
// {
// wait_stages &= ~VkPipelineStageFlags.ColorAttachmentOutput;
// wait_stages |= VkPipelineStageFlags.ComputeShader;
if (queue == graphics_queue && cmd_type == CommandBufferType.AsyncCompute)
{
wait_stages &= ~VkPipelineStageFlags.ColorAttachmentOutput;
wait_stages |= VkPipelineStageFlags.ComputeShader;

// use_semaphore = false;
// }
use_semaphore = false;
}

// if (queue == compute_queue && cmd_type == CommandBufferType.AsyncCompute)
// {
// wait_stages &= ~VkPipelineStageFlags.ColorAttachmentOutput;
// wait_stages |= VkPipelineStageFlags.ComputeShader;
if (queue == compute_queue && cmd_type == CommandBufferType.AsyncCompute)
{
wait_stages &= ~VkPipelineStageFlags.ColorAttachmentOutput;
wait_stages |= VkPipelineStageFlags.ComputeShader;

// use_semaphore = false;
// }
use_semaphore = false;
}

// VkSubmitInfo submit_info = new()
// {
// sType = VkStructureType.SubmitInfo,
// pWaitDstStageMask = &wait_stages,
// pNext = null,
// commandBufferCount = 1,
// pCommandBuffers = &cmd,
// };
VkSubmitInfo submit_info = new()
{
sType = VkStructureType.SubmitInfo,
pWaitDstStageMask = &wait_stages,
pNext = null,
commandBufferCount = 1,
pCommandBuffers = &cmd,
};

// if (use_semaphore)
// {
// submit_info.waitSemaphoreCount = 1;
// submit_info.pWaitSemaphores = &wait_semaphore;
if (use_semaphore)
{
submit_info.waitSemaphoreCount = 1;
submit_info.pWaitSemaphores = &wait_semaphore;

// submit_info.signalSemaphoreCount = 1;
// submit_info.pSignalSemaphores = &signal_semaphore;
// }
submit_info.signalSemaphoreCount = 1;
submit_info.pSignalSemaphores = &signal_semaphore;
}


// //if (fence is not null)
// // sync_fence = fence.handle;
// //else
// // sync_fence = commandBuffer.WaitFence.handle;
if (fence is not null)
sync_fence = fence.handle;
else
sync_fence = commandBuffer.WaitFence.handle;

// //if (sync_fence != VkFence.Null && queue != VkQueue.Null)
// vkQueueSubmit(queue, 1, &submit_info, sync_fence);
//}
if (sync_fence != VkFence.Null && queue != VkQueue.Null)
vkQueueSubmit(queue, 1, &submit_info, sync_fence);
}

internal VkMemoryType memory_prop_ext(VkPhysicalDeviceMemoryProperties memory, uint index)
{
Expand Down
2 changes: 1 addition & 1 deletion Src/Vultaik/Graphics/GraphicsPipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ private void CreateGraphicsPipeline(GraphicsPipelineDescription description)
sType = VkStructureType.PipelineShaderStageCreateInfo,
pNext = null,
stage = (VkShaderStageFlags)shaders[i].Stage,
module = NativeDevice.LoadSpir_V_Shader(shaders[i].Data),
module = NativeDevice.load_spirv_shader(shaders[i].Data),
pName = Interop.String.ToPointer(shaders[i].EntryPoint),
};
}
Expand Down
12 changes: 6 additions & 6 deletions Src/Vultaik/Image.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ internal void create_image(int w, int h)

VkMemoryPropertyFlags memoryProperties = VkMemoryPropertyFlags.DeviceLocal;

uint imageHeapIndex = NativeDevice.GetMemoryTypeIndex(imageMemReq.memoryTypeBits, memoryProperties);
uint imageHeapIndex = NativeDevice.get_memory_type(imageMemReq.memoryTypeBits, memoryProperties);
Console.WriteLine(imageMemReq.size);
VkMemoryAllocateInfo allocInfo = new VkMemoryAllocateInfo
{
Expand Down Expand Up @@ -328,7 +328,7 @@ internal void create_image()

VkMemoryPropertyFlags memoryProperties = VkMemoryPropertyFlags.DeviceLocal;

uint imageHeapIndex = NativeDevice.GetMemoryTypeIndex(imageMemReq.memoryTypeBits, memoryProperties);
uint imageHeapIndex = NativeDevice.get_memory_type(imageMemReq.memoryTypeBits, memoryProperties);

VkMemoryAllocateInfo allocInfo = new VkMemoryAllocateInfo
{
Expand Down Expand Up @@ -432,17 +432,17 @@ public void SetData(byte[] data)
cmd.End();


//Fence fence = new Fence(NativeDevice);
Fence fence = new Fence(NativeDevice);

NativeDevice.SubmitTransfer(cmd, null);
NativeDevice.Submit(cmd, fence);

//fence.Wait();
fence.Wait();

//if (fence.IsSignaled)


// Cleanup staging resources.
//fence.Dispose();
fence.Dispose();
vkFreeMemory(NativeDevice.handle, buffer_memory, null);
vkDestroyBuffer(NativeDevice.handle, buffer.handle, null);

Expand Down

0 comments on commit 695f20d

Please sign in to comment.