Updated gitignore, got basic polygon UI pipeline rendering shapes with offsets/colors
							parent
							
								
									1fa7b38624
								
							
						
					
					
						commit
						e9d3a71a1d
					
				| @ -0,0 +1,21 @@ | ||||
| #ifndef COMMAND_H | ||||
| #define COMMAND_H | ||||
| 
 | ||||
| #include "vulkan/vulkan_core.h" | ||||
| 
 | ||||
| typedef struct QueueStruct { | ||||
|   VkQueue handle; | ||||
|   uint32_t family; | ||||
|   uint32_t index; | ||||
| } Queue; | ||||
| 
 | ||||
| 
 | ||||
| VkCommandBuffer command_begin_single(VkDevice device, VkCommandPool transfer_pool); | ||||
| 
 | ||||
| VkResult command_end_single(VkDevice device, VkCommandBuffer command_buffer, VkCommandPool transfer_pool, Queue transfer_queue); | ||||
| 
 | ||||
| VkResult command_transition_image_layout(VkDevice device, VkCommandPool transfer_pool, Queue transfer_queue, VkImageLayout old_layout, VkImageLayout new_layout, VkImage image, VkAccessFlags src_mask, VkAccessFlags dst_mask, VkPipelineStageFlags source, VkPipelineStageFlags dest, uint32_t source_family, uint32_t dest_family, VkImageAspectFlags aspect_flags); | ||||
| 
 | ||||
| VkResult command_transition_image_layout(VkDevice device, VkCommandPool transfer_pool, Queue transfer_queue, VkImageLayout old_layout, VkImageLayout new_layout, VkImage image, VkAccessFlags src_mask, VkAccessFlags dst_mask, VkPipelineStageFlags source, VkPipelineStageFlags dest, uint32_t source_family, uint32_t dest_family, VkImageAspectFlags aspect_flags); | ||||
| 
 | ||||
| #endif | ||||
| @ -0,0 +1,10 @@ | ||||
| #version 450 | ||||
| 
 | ||||
| layout(location = 0) in vec4 fragColor; | ||||
| 
 | ||||
| layout(location = 0) out vec4 outColor; | ||||
| 
 | ||||
| void main() { | ||||
|     outColor = fragColor; | ||||
| } | ||||
| 
 | ||||
| @ -0,0 +1,19 @@ | ||||
| #version 450 | ||||
| #extension GL_EXT_buffer_reference : require | ||||
| 
 | ||||
| layout(set = 0, binding = 0) uniform UIUniform { | ||||
|   vec2 screen; | ||||
| } scene; | ||||
| 
 | ||||
| layout(location = 0) in vec2 inVertexPosition; | ||||
| layout(location = 1) in vec3 inPolygonPosition; | ||||
| layout(location = 2) in vec2 inPolygonSize; | ||||
| layout(location = 3) in vec4 inColor; | ||||
| 
 | ||||
| layout(location = 0) out vec4 fragColor; | ||||
| 
 | ||||
| void main() { | ||||
|   gl_Position = vec4(vec3(inVertexPosition * inPolygonSize, 0.0) + inPolygonPosition, 1.0); | ||||
|   fragColor = inColor; | ||||
| } | ||||
| 
 | ||||
| @ -0,0 +1,104 @@ | ||||
| #include "command.h" | ||||
| 
 | ||||
| VkCommandBuffer command_begin_single(VkDevice device, VkCommandPool transfer_pool) { | ||||
|   VkCommandBufferAllocateInfo command_info = { | ||||
|     .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, | ||||
|     .level = VK_COMMAND_BUFFER_LEVEL_PRIMARY, | ||||
|     .commandPool = transfer_pool, | ||||
|     .commandBufferCount = 1, | ||||
|   }; | ||||
| 
 | ||||
|   VkCommandBuffer command_buffer; | ||||
|   VkResult result = vkAllocateCommandBuffers(device, &command_info, &command_buffer); | ||||
|   if(result != VK_SUCCESS) { | ||||
|     return VK_NULL_HANDLE; | ||||
|   } | ||||
| 
 | ||||
|   VkCommandBufferBeginInfo begin_info = { | ||||
|     .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, | ||||
|     .flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT, | ||||
|   }; | ||||
| 
 | ||||
|   result = vkBeginCommandBuffer(command_buffer, &begin_info); | ||||
|   if(result != VK_SUCCESS) { | ||||
|     vkFreeCommandBuffers(device, transfer_pool, 1, &command_buffer); | ||||
|     return VK_NULL_HANDLE; | ||||
|   } | ||||
| 
 | ||||
|   return command_buffer; | ||||
| } | ||||
| 
 | ||||
| VkResult command_end_single(VkDevice device, VkCommandBuffer command_buffer, VkCommandPool transfer_pool, Queue transfer_queue) { | ||||
|   VkResult result = vkEndCommandBuffer(command_buffer); | ||||
|   if(result != VK_SUCCESS) { | ||||
|     vkFreeCommandBuffers(device, transfer_pool, 1, &command_buffer); | ||||
|     return result; | ||||
|   } | ||||
| 
 | ||||
|   VkSubmitInfo submit_info = { | ||||
|     .sType = VK_STRUCTURE_TYPE_SUBMIT_INFO, | ||||
|     .commandBufferCount = 1, | ||||
|     .pCommandBuffers = &command_buffer, | ||||
|   }; | ||||
| 
 | ||||
|   result = vkQueueSubmit(transfer_queue.handle, 1, &submit_info, 0); | ||||
|   if(result != VK_SUCCESS) { | ||||
|     vkFreeCommandBuffers(device, transfer_pool, 1, &command_buffer); | ||||
|     return result; | ||||
|   } | ||||
| 
 | ||||
|   result = vkQueueWaitIdle(transfer_queue.handle); | ||||
|   vkFreeCommandBuffers(device, transfer_pool, 1, &command_buffer); | ||||
|   return result; | ||||
| } | ||||
| 
 | ||||
| VkResult command_transition_image_layout(VkDevice device, VkCommandPool transfer_pool, Queue transfer_queue, VkImageLayout old_layout, VkImageLayout new_layout, VkImage image, VkAccessFlags src_mask, VkAccessFlags dst_mask, VkPipelineStageFlags source, VkPipelineStageFlags dest, uint32_t source_family, uint32_t dest_family, VkImageAspectFlags aspect_flags) { | ||||
|   VkCommandBuffer command_buffer = command_begin_single(device, transfer_pool); | ||||
| 
 | ||||
|   VkImageMemoryBarrier barrier = { | ||||
|     .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, | ||||
|     .oldLayout = old_layout, | ||||
|     .newLayout = new_layout, | ||||
|     .srcQueueFamilyIndex = source_family, | ||||
|     .dstQueueFamilyIndex = dest_family, | ||||
|     .image = image, | ||||
|     .subresourceRange = { | ||||
|       .aspectMask = aspect_flags, | ||||
|       .levelCount = 1, | ||||
|       .layerCount = 1, | ||||
|       .baseMipLevel = 0, | ||||
|       .baseArrayLayer = 0, | ||||
|     }, | ||||
|     .srcAccessMask = src_mask, | ||||
|     .dstAccessMask = dst_mask, | ||||
|   }; | ||||
|   vkCmdPipelineBarrier(command_buffer, source, dest, 0, 0, 0, 0, 0, 1, &barrier); | ||||
| 
 | ||||
|   return command_end_single(device, command_buffer, transfer_pool, transfer_queue); | ||||
| } | ||||
| 
 | ||||
| VkResult command_copy_buffer_to_image(VkDevice device, VkCommandPool transfer_pool, Queue transfer_queue, VkExtent3D image_size, VkBuffer source, VkImage dest) { | ||||
|   VkCommandBuffer command_buffer = command_begin_single(device, transfer_pool); | ||||
| 
 | ||||
|   VkBufferImageCopy region = { | ||||
|     .bufferOffset = 0, | ||||
|     .bufferRowLength = 0, | ||||
|     .bufferImageHeight = 0, | ||||
|     .imageSubresource = { | ||||
|       .baseArrayLayer = 0, | ||||
|       .layerCount = 1, | ||||
|       .mipLevel = 0, | ||||
|       .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT, | ||||
|     }, | ||||
|     .imageOffset = { | ||||
|       .x = 0, | ||||
|       .y = 0, | ||||
|       .z = 0, | ||||
|     }, | ||||
|     .imageExtent = image_size, | ||||
|   }; | ||||
| 
 | ||||
|   vkCmdCopyBufferToImage(command_buffer, source, dest, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ®ion); | ||||
| 
 | ||||
|   return command_end_single(device, command_buffer, transfer_pool, transfer_queue); | ||||
| } | ||||
		Loading…
	
		Reference in New Issue