diff --git a/include/Refresh.h b/include/Refresh.h index b5d9238..62875bd 100644 --- a/include/Refresh.h +++ b/include/Refresh.h @@ -435,7 +435,7 @@ typedef struct REFRESH_StencilOpState uint32_t reference; } REFRESH_StencilOpState; -typedef struct REFRESH_RenderTargetBlendState +typedef struct REFRESH_ColorTargetBlendState { uint8_t blendEnable; REFRESH_BlendFactor srcColorBlendFactor; @@ -445,7 +445,7 @@ typedef struct REFRESH_RenderTargetBlendState REFRESH_BlendFactor dstAlphaBlendFactor; REFRESH_BlendOp alphaBlendOp; REFRESH_ColorComponentFlags colorWriteMask; -} REFRESH_RenderTargetBlendState; +} REFRESH_ColorTargetBlendState; typedef struct REFRESH_PipelineLayoutCreateInfo { @@ -542,7 +542,7 @@ typedef struct REFRESH_ColorBlendState { uint8_t blendOpEnable; REFRESH_LogicOp logicOp; - const REFRESH_RenderTargetBlendState *blendStates; + const REFRESH_ColorTargetBlendState *blendStates; uint32_t blendStateCount; float blendConstants[4]; } REFRESH_ColorBlendState; @@ -634,8 +634,6 @@ REFRESHAPI void REFRESH_Clear( /* Draws data from vertex/index buffers with instancing enabled. * - * graphicsPipeline: The graphics pipeline through which to draw. - * primitiveType: The primitive topology of the vertex data. * baseVertex: The starting offset to read from the vertex buffer. * minVertexIndex: The lowest index value expected from the index buffer. * numVertices: The highest offset expected from the index buffer. @@ -647,8 +645,6 @@ REFRESHAPI void REFRESH_Clear( */ REFRESHAPI void REFRESH_DrawInstancedPrimitives( REFRESH_Device *device, - REFRESH_GraphicsPipeline *graphicsPipeline, - REFRESH_PrimitiveType primitiveType, uint32_t baseVertex, uint32_t minVertexIndex, uint32_t numVertices, @@ -661,8 +657,6 @@ REFRESHAPI void REFRESH_DrawInstancedPrimitives( /* Draws data from vertex/index buffers. * - * graphicsPipeline: The graphics pipeline through which to draw. - * primitiveType: The primitive topology of the vertex data. * baseVertex: The starting offset to read from the vertex buffer. * minVertexIndex: The lowest index value expected from the index buffer. * numVertices: The highest offset expected from the index buffer. @@ -673,8 +667,6 @@ REFRESHAPI void REFRESH_DrawInstancedPrimitives( */ REFRESHAPI void REFRESH_DrawIndexedPrimitives( REFRESH_Device *device, - REFRESH_GraphicsPipeline *graphicsPipeline, - REFRESH_PrimitiveType primitiveType, uint32_t baseVertex, uint32_t minVertexIndex, uint32_t numVertices, @@ -686,15 +678,11 @@ REFRESHAPI void REFRESH_DrawIndexedPrimitives( /* Draws data from vertex buffers. * - * graphicsPipeline: The graphics pipeline through which to draw. - * primitiveType: The primitive topology of the vertex data. * vertexStart: The starting offset to read from the vertex buffer. * primitiveCount: The number of primitives to draw. */ REFRESHAPI void REFRESH_DrawPrimitives( REFRESH_Device *device, - REFRESH_GraphicsPipeline *graphicsPipeline, - REFRESH_PrimitiveType primitiveType, uint32_t vertexStart, uint32_t primitiveCount ); diff --git a/src/Refresh.c b/src/Refresh.c index 7e4ccde..02bb0c9 100644 --- a/src/Refresh.c +++ b/src/Refresh.c @@ -161,8 +161,6 @@ void REFRESH_Clear( void REFRESH_DrawIndexedPrimitives( REFRESH_Device *device, - REFRESH_GraphicsPipeline *graphicsPipeline, - REFRESH_PrimitiveType primitiveType, uint32_t baseVertex, uint32_t minVertexIndex, uint32_t numVertices, @@ -174,8 +172,6 @@ void REFRESH_DrawIndexedPrimitives( NULL_RETURN(device); device->DrawIndexedPrimitives( device->driverData, - graphicsPipeline, - primitiveType, baseVertex, minVertexIndex, numVertices, @@ -188,8 +184,6 @@ void REFRESH_DrawIndexedPrimitives( void REFRESH_DrawInstancedPrimitives( REFRESH_Device *device, - REFRESH_GraphicsPipeline *graphicsPipeline, - REFRESH_PrimitiveType primitiveType, uint32_t baseVertex, uint32_t minVertexIndex, uint32_t numVertices, @@ -202,8 +196,6 @@ void REFRESH_DrawInstancedPrimitives( NULL_RETURN(device); device->DrawInstancedPrimitives( device->driverData, - graphicsPipeline, - primitiveType, baseVertex, minVertexIndex, numVertices, @@ -217,16 +209,12 @@ void REFRESH_DrawInstancedPrimitives( void REFRESH_DrawPrimitives( REFRESH_Device *device, - REFRESH_GraphicsPipeline *graphicsPipeline, - REFRESH_PrimitiveType primitiveType, uint32_t vertexStart, uint32_t primitiveCount ) { NULL_RETURN(device); device->DrawPrimitives( device->driverData, - graphicsPipeline, - primitiveType, vertexStart, primitiveCount ); diff --git a/src/Refresh_Driver.h b/src/Refresh_Driver.h index 2db64f6..76eab05 100644 --- a/src/Refresh_Driver.h +++ b/src/Refresh_Driver.h @@ -179,8 +179,6 @@ struct REFRESH_Device void (*DrawInstancedPrimitives)( REFRESH_Renderer *driverData, - REFRESH_GraphicsPipeline *graphicsPipeline, - REFRESH_PrimitiveType primitiveType, uint32_t baseVertex, uint32_t minVertexIndex, uint32_t numVertices, @@ -193,8 +191,6 @@ struct REFRESH_Device void (*DrawIndexedPrimitives)( REFRESH_Renderer *driverData, - REFRESH_GraphicsPipeline *graphicsPipeline, - REFRESH_PrimitiveType primitiveType, uint32_t baseVertex, uint32_t minVertexIndex, uint32_t numVertices, @@ -206,8 +202,6 @@ struct REFRESH_Device void (*DrawPrimitives)( REFRESH_Renderer *driverData, - REFRESH_GraphicsPipeline *graphicsPipeline, - REFRESH_PrimitiveType primitiveType, uint32_t vertexStart, uint32_t primitiveCount ); diff --git a/src/Refresh_Driver_Vulkan.c b/src/Refresh_Driver_Vulkan.c index b536904..98597a2 100644 --- a/src/Refresh_Driver_Vulkan.c +++ b/src/Refresh_Driver_Vulkan.c @@ -629,6 +629,20 @@ typedef struct SwapChainSupportDetails uint32_t presentModesLength; } SwapChainSupportDetails; +typedef struct VulkanGraphicsPipeline +{ + VkPipeline pipeline; + VkPipelineLayout layout; + REFRESH_PrimitiveType primitiveType; + VkDescriptorPool descriptorPool; + VkDescriptorSetLayout vertexSamplerLayout; + uint32_t vertexSamplerBindingCount; + VkDescriptorSetLayout fragmentSamplerLayout; + uint32_t fragmentSamplerBindingCount; + VkDescriptorSet vertexSamplerDescriptorSet; /* updated by SetVertexSamplers */ + VkDescriptorSet fragmentSamplerDescriptorSet; /* updated by SetFragmentSamplers */ +} VulkanGraphicsPipeline; + typedef struct VulkanRenderer { VkInstance instance; @@ -681,6 +695,8 @@ typedef struct VulkanRenderer VkCommandBuffer currentCommandBuffer; uint32_t numActiveCommands; + VulkanGraphicsPipeline *currentGraphicsPipeline; + /* * TODO: we can get rid of this reference when we * come up with a clever descriptor set reuse system @@ -779,21 +795,6 @@ typedef struct VulkanDepthStencilTarget VkImageView view; } VulkanDepthStencilTarget; -/* Pipeline */ - -typedef struct VulkanGraphicsPipeline -{ - VkPipeline pipeline; - VkPipelineLayout layout; - VkDescriptorPool descriptorPool; - VkDescriptorSetLayout vertexSamplerLayout; - uint32_t vertexSamplerBindingCount; - VkDescriptorSetLayout fragmentSamplerLayout; - uint32_t fragmentSamplerBindingCount; - VkDescriptorSet vertexSamplerDescriptorSet; /* updated by SetVertexSamplers */ - VkDescriptorSet fragmentSamplerDescriptorSet; /* updated by SetFragmentSamplers */ -} VulkanGraphicsPipeline; - /* Forward declarations */ static void VULKAN_INTERNAL_BeginCommandBuffer(VulkanRenderer *renderer); @@ -2249,8 +2250,6 @@ static void VULKAN_Clear( static void VULKAN_DrawInstancedPrimitives( REFRESH_Renderer *driverData, - REFRESH_GraphicsPipeline *graphicsPipeline, - REFRESH_PrimitiveType primitiveType, uint32_t baseVertex, uint32_t minVertexIndex, uint32_t numVertices, @@ -2261,12 +2260,11 @@ static void VULKAN_DrawInstancedPrimitives( REFRESH_IndexElementSize indexElementSize ) { VulkanRenderer *renderer = (VulkanRenderer*) driverData; - VulkanGraphicsPipeline *pipeline = (VulkanGraphicsPipeline*) graphicsPipeline; VkDescriptorSet descriptorSets[4]; uint32_t dynamicOffsets[2]; - descriptorSets[0] = pipeline->vertexSamplerDescriptorSet; - descriptorSets[1] = pipeline->fragmentSamplerDescriptorSet; + descriptorSets[0] = renderer->currentGraphicsPipeline->vertexSamplerDescriptorSet; + descriptorSets[1] = renderer->currentGraphicsPipeline->fragmentSamplerDescriptorSet; descriptorSets[2] = renderer->vertexUBODescriptorSet; descriptorSets[3] = renderer->fragmentUBODescriptorSet; @@ -2276,7 +2274,7 @@ static void VULKAN_DrawInstancedPrimitives( RECORD_CMD(renderer->vkCmdBindDescriptorSets( renderer->currentCommandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, - pipeline->layout, + renderer->currentGraphicsPipeline->layout, 0, 4, descriptorSets, @@ -2286,7 +2284,10 @@ static void VULKAN_DrawInstancedPrimitives( RECORD_CMD(renderer->vkCmdDrawIndexed( renderer->currentCommandBuffer, - PrimitiveVerts(primitiveType, primitiveCount), + PrimitiveVerts( + renderer->currentGraphicsPipeline->primitiveType, + primitiveCount + ), instanceCount, startIndex, baseVertex, @@ -2296,8 +2297,6 @@ static void VULKAN_DrawInstancedPrimitives( static void VULKAN_DrawIndexedPrimitives( REFRESH_Renderer *driverData, - REFRESH_GraphicsPipeline *graphicsPipeline, - REFRESH_PrimitiveType primitiveType, uint32_t baseVertex, uint32_t minVertexIndex, uint32_t numVertices, @@ -2308,8 +2307,6 @@ static void VULKAN_DrawIndexedPrimitives( ) { VULKAN_DrawInstancedPrimitives( driverData, - graphicsPipeline, - primitiveType, baseVertex, minVertexIndex, numVertices, @@ -2323,18 +2320,15 @@ static void VULKAN_DrawIndexedPrimitives( static void VULKAN_DrawPrimitives( REFRESH_Renderer *driverData, - REFRESH_GraphicsPipeline *graphicsPipeline, - REFRESH_PrimitiveType primitiveType, uint32_t vertexStart, uint32_t primitiveCount ) { VulkanRenderer *renderer = (VulkanRenderer*) driverData; - VulkanGraphicsPipeline *pipeline = (VulkanGraphicsPipeline*) graphicsPipeline; VkDescriptorSet descriptorSets[4]; uint32_t dynamicOffsets[2]; - descriptorSets[0] = pipeline->vertexSamplerDescriptorSet; - descriptorSets[1] = pipeline->fragmentSamplerDescriptorSet; + descriptorSets[0] = renderer->currentGraphicsPipeline->vertexSamplerDescriptorSet; + descriptorSets[1] = renderer->currentGraphicsPipeline->fragmentSamplerDescriptorSet; descriptorSets[2] = renderer->vertexUBODescriptorSet; descriptorSets[3] = renderer->fragmentUBODescriptorSet; @@ -2344,7 +2338,7 @@ static void VULKAN_DrawPrimitives( RECORD_CMD(renderer->vkCmdBindDescriptorSets( renderer->currentCommandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, - pipeline->layout, + renderer->currentGraphicsPipeline->layout, 0, 4, descriptorSets, @@ -2355,7 +2349,7 @@ static void VULKAN_DrawPrimitives( RECORD_CMD(renderer->vkCmdDraw( renderer->currentCommandBuffer, PrimitiveVerts( - primitiveType, + renderer->currentGraphicsPipeline->primitiveType, primitiveCount ), 1, @@ -3013,6 +3007,7 @@ static REFRESH_GraphicsPipeline* VULKAN_CreateGraphicsPipeline( graphicsPipeline->vertexSamplerBindingCount = pipelineCreateInfo->pipelineLayoutCreateInfo.vertexSamplerBindingCount; graphicsPipeline->fragmentSamplerBindingCount = pipelineCreateInfo->pipelineLayoutCreateInfo.fragmentSamplerBindingCount; graphicsPipeline->layout = pipelineLayout; + graphicsPipeline->primitiveType = pipelineCreateInfo->topologyState.topology; /* Pipeline */ @@ -4728,6 +4723,8 @@ static void VULKAN_BindGraphicsPipeline( VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline->pipeline )); + + renderer->currentGraphicsPipeline = pipeline; } static void VULKAN_INTERNAL_MarkAsBound(