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;
} 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
);

View File

@ -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
);

View File

@ -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
);

View File

@ -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(