draw call API revision

submit_rewrite
cosmonaut 2020-12-22 22:56:26 -08:00
parent a174573b02
commit 89f8ef1e9e
4 changed files with 33 additions and 66 deletions

View File

@ -435,7 +435,7 @@ typedef struct REFRESH_StencilOpState
uint32_t reference; uint32_t reference;
} REFRESH_StencilOpState; } REFRESH_StencilOpState;
typedef struct REFRESH_RenderTargetBlendState typedef struct REFRESH_ColorTargetBlendState
{ {
uint8_t blendEnable; uint8_t blendEnable;
REFRESH_BlendFactor srcColorBlendFactor; REFRESH_BlendFactor srcColorBlendFactor;
@ -445,7 +445,7 @@ typedef struct REFRESH_RenderTargetBlendState
REFRESH_BlendFactor dstAlphaBlendFactor; REFRESH_BlendFactor dstAlphaBlendFactor;
REFRESH_BlendOp alphaBlendOp; REFRESH_BlendOp alphaBlendOp;
REFRESH_ColorComponentFlags colorWriteMask; REFRESH_ColorComponentFlags colorWriteMask;
} REFRESH_RenderTargetBlendState; } REFRESH_ColorTargetBlendState;
typedef struct REFRESH_PipelineLayoutCreateInfo typedef struct REFRESH_PipelineLayoutCreateInfo
{ {
@ -542,7 +542,7 @@ typedef struct REFRESH_ColorBlendState
{ {
uint8_t blendOpEnable; uint8_t blendOpEnable;
REFRESH_LogicOp logicOp; REFRESH_LogicOp logicOp;
const REFRESH_RenderTargetBlendState *blendStates; const REFRESH_ColorTargetBlendState *blendStates;
uint32_t blendStateCount; uint32_t blendStateCount;
float blendConstants[4]; float blendConstants[4];
} REFRESH_ColorBlendState; } REFRESH_ColorBlendState;
@ -634,8 +634,6 @@ REFRESHAPI void REFRESH_Clear(
/* Draws data from vertex/index buffers with instancing enabled. /* 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. * baseVertex: The starting offset to read from the vertex buffer.
* minVertexIndex: The lowest index value expected from the index buffer. * minVertexIndex: The lowest index value expected from the index buffer.
* numVertices: The highest offset 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( REFRESHAPI void REFRESH_DrawInstancedPrimitives(
REFRESH_Device *device, REFRESH_Device *device,
REFRESH_GraphicsPipeline *graphicsPipeline,
REFRESH_PrimitiveType primitiveType,
uint32_t baseVertex, uint32_t baseVertex,
uint32_t minVertexIndex, uint32_t minVertexIndex,
uint32_t numVertices, uint32_t numVertices,
@ -661,8 +657,6 @@ REFRESHAPI void REFRESH_DrawInstancedPrimitives(
/* Draws data from vertex/index buffers. /* 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. * baseVertex: The starting offset to read from the vertex buffer.
* minVertexIndex: The lowest index value expected from the index buffer. * minVertexIndex: The lowest index value expected from the index buffer.
* numVertices: The highest offset 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( REFRESHAPI void REFRESH_DrawIndexedPrimitives(
REFRESH_Device *device, REFRESH_Device *device,
REFRESH_GraphicsPipeline *graphicsPipeline,
REFRESH_PrimitiveType primitiveType,
uint32_t baseVertex, uint32_t baseVertex,
uint32_t minVertexIndex, uint32_t minVertexIndex,
uint32_t numVertices, uint32_t numVertices,
@ -686,15 +678,11 @@ REFRESHAPI void REFRESH_DrawIndexedPrimitives(
/* Draws data from vertex buffers. /* 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. * vertexStart: The starting offset to read from the vertex buffer.
* primitiveCount: The number of primitives to draw. * primitiveCount: The number of primitives to draw.
*/ */
REFRESHAPI void REFRESH_DrawPrimitives( REFRESHAPI void REFRESH_DrawPrimitives(
REFRESH_Device *device, REFRESH_Device *device,
REFRESH_GraphicsPipeline *graphicsPipeline,
REFRESH_PrimitiveType primitiveType,
uint32_t vertexStart, uint32_t vertexStart,
uint32_t primitiveCount uint32_t primitiveCount
); );

View File

@ -161,8 +161,6 @@ void REFRESH_Clear(
void REFRESH_DrawIndexedPrimitives( void REFRESH_DrawIndexedPrimitives(
REFRESH_Device *device, REFRESH_Device *device,
REFRESH_GraphicsPipeline *graphicsPipeline,
REFRESH_PrimitiveType primitiveType,
uint32_t baseVertex, uint32_t baseVertex,
uint32_t minVertexIndex, uint32_t minVertexIndex,
uint32_t numVertices, uint32_t numVertices,
@ -174,8 +172,6 @@ void REFRESH_DrawIndexedPrimitives(
NULL_RETURN(device); NULL_RETURN(device);
device->DrawIndexedPrimitives( device->DrawIndexedPrimitives(
device->driverData, device->driverData,
graphicsPipeline,
primitiveType,
baseVertex, baseVertex,
minVertexIndex, minVertexIndex,
numVertices, numVertices,
@ -188,8 +184,6 @@ void REFRESH_DrawIndexedPrimitives(
void REFRESH_DrawInstancedPrimitives( void REFRESH_DrawInstancedPrimitives(
REFRESH_Device *device, REFRESH_Device *device,
REFRESH_GraphicsPipeline *graphicsPipeline,
REFRESH_PrimitiveType primitiveType,
uint32_t baseVertex, uint32_t baseVertex,
uint32_t minVertexIndex, uint32_t minVertexIndex,
uint32_t numVertices, uint32_t numVertices,
@ -202,8 +196,6 @@ void REFRESH_DrawInstancedPrimitives(
NULL_RETURN(device); NULL_RETURN(device);
device->DrawInstancedPrimitives( device->DrawInstancedPrimitives(
device->driverData, device->driverData,
graphicsPipeline,
primitiveType,
baseVertex, baseVertex,
minVertexIndex, minVertexIndex,
numVertices, numVertices,
@ -217,16 +209,12 @@ void REFRESH_DrawInstancedPrimitives(
void REFRESH_DrawPrimitives( void REFRESH_DrawPrimitives(
REFRESH_Device *device, REFRESH_Device *device,
REFRESH_GraphicsPipeline *graphicsPipeline,
REFRESH_PrimitiveType primitiveType,
uint32_t vertexStart, uint32_t vertexStart,
uint32_t primitiveCount uint32_t primitiveCount
) { ) {
NULL_RETURN(device); NULL_RETURN(device);
device->DrawPrimitives( device->DrawPrimitives(
device->driverData, device->driverData,
graphicsPipeline,
primitiveType,
vertexStart, vertexStart,
primitiveCount primitiveCount
); );

View File

@ -179,8 +179,6 @@ struct REFRESH_Device
void (*DrawInstancedPrimitives)( void (*DrawInstancedPrimitives)(
REFRESH_Renderer *driverData, REFRESH_Renderer *driverData,
REFRESH_GraphicsPipeline *graphicsPipeline,
REFRESH_PrimitiveType primitiveType,
uint32_t baseVertex, uint32_t baseVertex,
uint32_t minVertexIndex, uint32_t minVertexIndex,
uint32_t numVertices, uint32_t numVertices,
@ -193,8 +191,6 @@ struct REFRESH_Device
void (*DrawIndexedPrimitives)( void (*DrawIndexedPrimitives)(
REFRESH_Renderer *driverData, REFRESH_Renderer *driverData,
REFRESH_GraphicsPipeline *graphicsPipeline,
REFRESH_PrimitiveType primitiveType,
uint32_t baseVertex, uint32_t baseVertex,
uint32_t minVertexIndex, uint32_t minVertexIndex,
uint32_t numVertices, uint32_t numVertices,
@ -206,8 +202,6 @@ struct REFRESH_Device
void (*DrawPrimitives)( void (*DrawPrimitives)(
REFRESH_Renderer *driverData, REFRESH_Renderer *driverData,
REFRESH_GraphicsPipeline *graphicsPipeline,
REFRESH_PrimitiveType primitiveType,
uint32_t vertexStart, uint32_t vertexStart,
uint32_t primitiveCount uint32_t primitiveCount
); );

View File

@ -629,6 +629,20 @@ typedef struct SwapChainSupportDetails
uint32_t presentModesLength; uint32_t presentModesLength;
} SwapChainSupportDetails; } 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 typedef struct VulkanRenderer
{ {
VkInstance instance; VkInstance instance;
@ -681,6 +695,8 @@ typedef struct VulkanRenderer
VkCommandBuffer currentCommandBuffer; VkCommandBuffer currentCommandBuffer;
uint32_t numActiveCommands; uint32_t numActiveCommands;
VulkanGraphicsPipeline *currentGraphicsPipeline;
/* /*
* TODO: we can get rid of this reference when we * TODO: we can get rid of this reference when we
* come up with a clever descriptor set reuse system * come up with a clever descriptor set reuse system
@ -779,21 +795,6 @@ typedef struct VulkanDepthStencilTarget
VkImageView view; VkImageView view;
} VulkanDepthStencilTarget; } 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 */ /* Forward declarations */
static void VULKAN_INTERNAL_BeginCommandBuffer(VulkanRenderer *renderer); static void VULKAN_INTERNAL_BeginCommandBuffer(VulkanRenderer *renderer);
@ -2249,8 +2250,6 @@ static void VULKAN_Clear(
static void VULKAN_DrawInstancedPrimitives( static void VULKAN_DrawInstancedPrimitives(
REFRESH_Renderer *driverData, REFRESH_Renderer *driverData,
REFRESH_GraphicsPipeline *graphicsPipeline,
REFRESH_PrimitiveType primitiveType,
uint32_t baseVertex, uint32_t baseVertex,
uint32_t minVertexIndex, uint32_t minVertexIndex,
uint32_t numVertices, uint32_t numVertices,
@ -2261,12 +2260,11 @@ static void VULKAN_DrawInstancedPrimitives(
REFRESH_IndexElementSize indexElementSize REFRESH_IndexElementSize indexElementSize
) { ) {
VulkanRenderer *renderer = (VulkanRenderer*) driverData; VulkanRenderer *renderer = (VulkanRenderer*) driverData;
VulkanGraphicsPipeline *pipeline = (VulkanGraphicsPipeline*) graphicsPipeline;
VkDescriptorSet descriptorSets[4]; VkDescriptorSet descriptorSets[4];
uint32_t dynamicOffsets[2]; uint32_t dynamicOffsets[2];
descriptorSets[0] = pipeline->vertexSamplerDescriptorSet; descriptorSets[0] = renderer->currentGraphicsPipeline->vertexSamplerDescriptorSet;
descriptorSets[1] = pipeline->fragmentSamplerDescriptorSet; descriptorSets[1] = renderer->currentGraphicsPipeline->fragmentSamplerDescriptorSet;
descriptorSets[2] = renderer->vertexUBODescriptorSet; descriptorSets[2] = renderer->vertexUBODescriptorSet;
descriptorSets[3] = renderer->fragmentUBODescriptorSet; descriptorSets[3] = renderer->fragmentUBODescriptorSet;
@ -2276,7 +2274,7 @@ static void VULKAN_DrawInstancedPrimitives(
RECORD_CMD(renderer->vkCmdBindDescriptorSets( RECORD_CMD(renderer->vkCmdBindDescriptorSets(
renderer->currentCommandBuffer, renderer->currentCommandBuffer,
VK_PIPELINE_BIND_POINT_GRAPHICS, VK_PIPELINE_BIND_POINT_GRAPHICS,
pipeline->layout, renderer->currentGraphicsPipeline->layout,
0, 0,
4, 4,
descriptorSets, descriptorSets,
@ -2286,7 +2284,10 @@ static void VULKAN_DrawInstancedPrimitives(
RECORD_CMD(renderer->vkCmdDrawIndexed( RECORD_CMD(renderer->vkCmdDrawIndexed(
renderer->currentCommandBuffer, renderer->currentCommandBuffer,
PrimitiveVerts(primitiveType, primitiveCount), PrimitiveVerts(
renderer->currentGraphicsPipeline->primitiveType,
primitiveCount
),
instanceCount, instanceCount,
startIndex, startIndex,
baseVertex, baseVertex,
@ -2296,8 +2297,6 @@ static void VULKAN_DrawInstancedPrimitives(
static void VULKAN_DrawIndexedPrimitives( static void VULKAN_DrawIndexedPrimitives(
REFRESH_Renderer *driverData, REFRESH_Renderer *driverData,
REFRESH_GraphicsPipeline *graphicsPipeline,
REFRESH_PrimitiveType primitiveType,
uint32_t baseVertex, uint32_t baseVertex,
uint32_t minVertexIndex, uint32_t minVertexIndex,
uint32_t numVertices, uint32_t numVertices,
@ -2308,8 +2307,6 @@ static void VULKAN_DrawIndexedPrimitives(
) { ) {
VULKAN_DrawInstancedPrimitives( VULKAN_DrawInstancedPrimitives(
driverData, driverData,
graphicsPipeline,
primitiveType,
baseVertex, baseVertex,
minVertexIndex, minVertexIndex,
numVertices, numVertices,
@ -2323,18 +2320,15 @@ static void VULKAN_DrawIndexedPrimitives(
static void VULKAN_DrawPrimitives( static void VULKAN_DrawPrimitives(
REFRESH_Renderer *driverData, REFRESH_Renderer *driverData,
REFRESH_GraphicsPipeline *graphicsPipeline,
REFRESH_PrimitiveType primitiveType,
uint32_t vertexStart, uint32_t vertexStart,
uint32_t primitiveCount uint32_t primitiveCount
) { ) {
VulkanRenderer *renderer = (VulkanRenderer*) driverData; VulkanRenderer *renderer = (VulkanRenderer*) driverData;
VulkanGraphicsPipeline *pipeline = (VulkanGraphicsPipeline*) graphicsPipeline;
VkDescriptorSet descriptorSets[4]; VkDescriptorSet descriptorSets[4];
uint32_t dynamicOffsets[2]; uint32_t dynamicOffsets[2];
descriptorSets[0] = pipeline->vertexSamplerDescriptorSet; descriptorSets[0] = renderer->currentGraphicsPipeline->vertexSamplerDescriptorSet;
descriptorSets[1] = pipeline->fragmentSamplerDescriptorSet; descriptorSets[1] = renderer->currentGraphicsPipeline->fragmentSamplerDescriptorSet;
descriptorSets[2] = renderer->vertexUBODescriptorSet; descriptorSets[2] = renderer->vertexUBODescriptorSet;
descriptorSets[3] = renderer->fragmentUBODescriptorSet; descriptorSets[3] = renderer->fragmentUBODescriptorSet;
@ -2344,7 +2338,7 @@ static void VULKAN_DrawPrimitives(
RECORD_CMD(renderer->vkCmdBindDescriptorSets( RECORD_CMD(renderer->vkCmdBindDescriptorSets(
renderer->currentCommandBuffer, renderer->currentCommandBuffer,
VK_PIPELINE_BIND_POINT_GRAPHICS, VK_PIPELINE_BIND_POINT_GRAPHICS,
pipeline->layout, renderer->currentGraphicsPipeline->layout,
0, 0,
4, 4,
descriptorSets, descriptorSets,
@ -2355,7 +2349,7 @@ static void VULKAN_DrawPrimitives(
RECORD_CMD(renderer->vkCmdDraw( RECORD_CMD(renderer->vkCmdDraw(
renderer->currentCommandBuffer, renderer->currentCommandBuffer,
PrimitiveVerts( PrimitiveVerts(
primitiveType, renderer->currentGraphicsPipeline->primitiveType,
primitiveCount primitiveCount
), ),
1, 1,
@ -3013,6 +3007,7 @@ static REFRESH_GraphicsPipeline* VULKAN_CreateGraphicsPipeline(
graphicsPipeline->vertexSamplerBindingCount = pipelineCreateInfo->pipelineLayoutCreateInfo.vertexSamplerBindingCount; graphicsPipeline->vertexSamplerBindingCount = pipelineCreateInfo->pipelineLayoutCreateInfo.vertexSamplerBindingCount;
graphicsPipeline->fragmentSamplerBindingCount = pipelineCreateInfo->pipelineLayoutCreateInfo.fragmentSamplerBindingCount; graphicsPipeline->fragmentSamplerBindingCount = pipelineCreateInfo->pipelineLayoutCreateInfo.fragmentSamplerBindingCount;
graphicsPipeline->layout = pipelineLayout; graphicsPipeline->layout = pipelineLayout;
graphicsPipeline->primitiveType = pipelineCreateInfo->topologyState.topology;
/* Pipeline */ /* Pipeline */
@ -4728,6 +4723,8 @@ static void VULKAN_BindGraphicsPipeline(
VK_PIPELINE_BIND_POINT_GRAPHICS, VK_PIPELINE_BIND_POINT_GRAPHICS,
pipeline->pipeline pipeline->pipeline
)); ));
renderer->currentGraphicsPipeline = pipeline;
} }
static void VULKAN_INTERNAL_MarkAsBound( static void VULKAN_INTERNAL_MarkAsBound(