update API to allow batchable shader params

pull/8/head
cosmonaut 2020-12-28 19:32:49 -08:00
parent da9b255dec
commit 2548833525
4 changed files with 87 additions and 43 deletions

View File

@ -650,6 +650,8 @@ REFRESHAPI void REFRESH_Clear(
* instanceCount: The number of instances that will be drawn.
* indices: The index buffer to bind for this draw call.
* indexElementSize: The size of the index type for this index buffer.
* vertexParamOffset: The offset of the vertex shader param data.
* fragmentParamOffset: The offset of the fragment shader param data.
*/
REFRESHAPI void REFRESH_DrawInstancedPrimitives(
REFRESH_Device *device,
@ -660,7 +662,9 @@ REFRESHAPI void REFRESH_DrawInstancedPrimitives(
uint32_t primitiveCount,
uint32_t instanceCount,
REFRESH_Buffer *indices,
REFRESH_IndexElementSize indexElementSize
REFRESH_IndexElementSize indexElementSize,
uint32_t vertexParamOffset,
uint32_t fragmentParamOffset
);
/* Draws data from vertex/index buffers.
@ -672,6 +676,8 @@ REFRESHAPI void REFRESH_DrawInstancedPrimitives(
* primitiveCount: The number of primitives to draw.
* indices: The index buffer to bind for this draw call.
* indexElementSize: The size of the index type for this index buffer.
* vertexParamOffset: The offset of the vertex shader param data.
* fragmentParamOffset: The offset of the fragment shader param data.
*/
REFRESHAPI void REFRESH_DrawIndexedPrimitives(
REFRESH_Device *device,
@ -681,18 +687,24 @@ REFRESHAPI void REFRESH_DrawIndexedPrimitives(
uint32_t startIndex,
uint32_t primitiveCount,
REFRESH_Buffer *indices,
REFRESH_IndexElementSize indexElementSize
REFRESH_IndexElementSize indexElementSize,
uint32_t vertexParamOffset,
uint32_t fragmentParamOffset
);
/* Draws data from vertex buffers.
*
* vertexStart: The starting offset to read from the vertex buffer.
* primitiveCount: The number of primitives to draw.
* vertexParamOffset: The offset of the vertex shader param data.
* fragmentParamOffset: The offset of the fragment shader param data.
*/
REFRESHAPI void REFRESH_DrawPrimitives(
REFRESH_Device *device,
uint32_t vertexStart,
uint32_t primitiveCount
uint32_t primitiveCount,
uint32_t vertexParamOffset,
uint32_t fragmentParamOffset
);
/* State Creation */
@ -973,31 +985,33 @@ REFRESHAPI void REFRESH_SetIndexBufferData(
uint32_t dataLength
);
/* Pushes vertex shader params for subsequent draw calls.
/* Pushes vertex shader params to the device.
* Returns a starting offset value to be used with draw calls.
*
* NOTE:
* A pipeline must be bound.
* Will use the block size of the currently bound vertex shader.
*
* data: The client data to write into the buffer.
* elementCount: The number of elements from the client buffer to write.
* paramBlockCount: The number of param-sized blocks from the client buffer to write.
*/
REFRESHAPI void REFRESH_PushVertexShaderParams(
REFRESHAPI uint32_t REFRESH_PushVertexShaderParams(
REFRESH_Device *device,
void *data,
uint32_t elementCount
uint32_t paramBlockCount
);
/* Pushes fragment shader params for subsequent draw calls.
/* Pushes fragment shader params to the device.
* Returns a starting offset value to be used with draw calls.
*
* NOTE:
* A pipeline must be bound.
* Will use the block size of the currently bound fragment shader.
*
* data: The client data to write into the buffer.
* elementCount: The number of elements from the client buffer to write.
* paramBlockCount: The number of param-sized blocks from the client buffer to write.
*/
REFRESHAPI void REFRESH_PushFragmentShaderParams(
REFRESHAPI uint32_t REFRESH_PushFragmentShaderParams(
REFRESH_Device *device,
void *data,
uint32_t elementCount

View File

@ -167,7 +167,9 @@ void REFRESH_DrawIndexedPrimitives(
uint32_t startIndex,
uint32_t primitiveCount,
REFRESH_Buffer *indices,
REFRESH_IndexElementSize indexElementSize
REFRESH_IndexElementSize indexElementSize,
uint32_t vertexParamOffset,
uint32_t fragmentParamOffset
) {
NULL_RETURN(device);
device->DrawIndexedPrimitives(
@ -178,7 +180,9 @@ void REFRESH_DrawIndexedPrimitives(
startIndex,
primitiveCount,
indices,
indexElementSize
indexElementSize,
vertexParamOffset,
fragmentParamOffset
);
}
@ -191,7 +195,9 @@ void REFRESH_DrawInstancedPrimitives(
uint32_t primitiveCount,
uint32_t instanceCount,
REFRESH_Buffer *indices,
REFRESH_IndexElementSize indexElementSize
REFRESH_IndexElementSize indexElementSize,
uint32_t vertexParamOffset,
uint32_t fragmentParamOffset
) {
NULL_RETURN(device);
device->DrawInstancedPrimitives(
@ -203,20 +209,26 @@ void REFRESH_DrawInstancedPrimitives(
primitiveCount,
instanceCount,
indices,
indexElementSize
indexElementSize,
vertexParamOffset,
fragmentParamOffset
);
}
void REFRESH_DrawPrimitives(
REFRESH_Device *device,
uint32_t vertexStart,
uint32_t primitiveCount
uint32_t primitiveCount,
uint32_t vertexParamOffset,
uint32_t fragmentParamOffset
) {
NULL_RETURN(device);
device->DrawPrimitives(
device->driverData,
vertexStart,
primitiveCount
primitiveCount,
vertexParamOffset,
fragmentParamOffset
);
}
@ -526,26 +538,26 @@ void REFRESH_SetIndexBufferData(
);
}
void REFRESH_PushVertexShaderParams(
uint32_t REFRESH_PushVertexShaderParams(
REFRESH_Device *device,
void *data,
uint32_t elementCount
) {
NULL_RETURN(device);
device->PushVertexShaderParams(
if (device == NULL) { return 0; }
return device->PushVertexShaderParams(
device->driverData,
data,
elementCount
);
}
void REFRESH_PushFragmentShaderParams(
uint32_t REFRESH_PushFragmentShaderParams(
REFRESH_Device *device,
void *data,
uint32_t elementCount
) {
NULL_RETURN(device);
device->PushFragmentShaderParams(
if (device == NULL) { return 0; }
return device->PushFragmentShaderParams(
device->driverData,
data,
elementCount

View File

@ -186,7 +186,9 @@ struct REFRESH_Device
uint32_t primitiveCount,
uint32_t instanceCount,
REFRESH_Buffer *indices,
REFRESH_IndexElementSize indexElementSize
REFRESH_IndexElementSize indexElementSize,
uint32_t vertexParamOffset,
uint32_t fragmentParamOffset
);
void (*DrawIndexedPrimitives)(
@ -197,13 +199,17 @@ struct REFRESH_Device
uint32_t startIndex,
uint32_t primitiveCount,
REFRESH_Buffer *indices,
REFRESH_IndexElementSize indexElementSize
REFRESH_IndexElementSize indexElementSize,
uint32_t vertexParamOffset,
uint32_t fragmentParamOffset
);
void (*DrawPrimitives)(
REFRESH_Renderer *driverData,
uint32_t vertexStart,
uint32_t primitiveCount
uint32_t primitiveCount,
uint32_t vertexParamOffset,
uint32_t fragmentParamOffset
);
/* State Creation */
@ -354,13 +360,13 @@ struct REFRESH_Device
uint32_t dataLength
);
void(*PushVertexShaderParams)(
uint32_t(*PushVertexShaderParams)(
REFRESH_Renderer *driverData,
void *data,
uint32_t elementCount
);
void(*PushFragmentShaderParams)(
uint32_t(*PushFragmentShaderParams)(
REFRESH_Renderer *driverData,
void *data,
uint32_t elementCount

View File

@ -3192,7 +3192,9 @@ static void VULKAN_DrawInstancedPrimitives(
uint32_t primitiveCount,
uint32_t instanceCount,
REFRESH_Buffer *indices,
REFRESH_IndexElementSize indexElementSize
REFRESH_IndexElementSize indexElementSize,
uint32_t vertexParamOffset,
uint32_t fragmentParamOffset
) {
VulkanRenderer *renderer = (VulkanRenderer*) driverData;
VkDescriptorSet descriptorSets[4];
@ -3203,8 +3205,8 @@ static void VULKAN_DrawInstancedPrimitives(
descriptorSets[2] = renderer->currentGraphicsPipeline->vertexUBODescriptorSet;
descriptorSets[3] = renderer->currentGraphicsPipeline->fragmentUBODescriptorSet;
dynamicOffsets[0] = renderer->vertexUBOOffset;
dynamicOffsets[1] = renderer->fragmentUBOOffset;
dynamicOffsets[0] = vertexParamOffset;
dynamicOffsets[1] = fragmentParamOffset;
RECORD_CMD(renderer->vkCmdBindDescriptorSets(
renderer->currentCommandBuffer,
@ -3238,7 +3240,9 @@ static void VULKAN_DrawIndexedPrimitives(
uint32_t startIndex,
uint32_t primitiveCount,
REFRESH_Buffer *indices,
REFRESH_IndexElementSize indexElementSize
REFRESH_IndexElementSize indexElementSize,
uint32_t vertexParamOffset,
uint32_t fragmentParamOffset
) {
VULKAN_DrawInstancedPrimitives(
driverData,
@ -3249,14 +3253,18 @@ static void VULKAN_DrawIndexedPrimitives(
primitiveCount,
1,
indices,
indexElementSize
indexElementSize,
vertexParamOffset,
fragmentParamOffset
);
}
static void VULKAN_DrawPrimitives(
REFRESH_Renderer *driverData,
uint32_t vertexStart,
uint32_t primitiveCount
uint32_t primitiveCount,
uint32_t vertexUniformBufferOffset,
uint32_t fragmentUniformBufferOffset
) {
VulkanRenderer *renderer = (VulkanRenderer*) driverData;
VkDescriptorSet descriptorSets[4];
@ -3267,8 +3275,8 @@ static void VULKAN_DrawPrimitives(
descriptorSets[2] = renderer->currentGraphicsPipeline->vertexUBODescriptorSet;
descriptorSets[3] = renderer->currentGraphicsPipeline->fragmentUBODescriptorSet;
dynamicOffsets[0] = renderer->vertexUBOOffset;
dynamicOffsets[1] = renderer->fragmentUBOOffset;
dynamicOffsets[0] = vertexUniformBufferOffset;
dynamicOffsets[1] = fragmentUniformBufferOffset;
RECORD_CMD(renderer->vkCmdBindDescriptorSets(
renderer->currentCommandBuffer,
@ -5663,7 +5671,7 @@ static void VULKAN_SetIndexBufferData(
);
}
static void VULKAN_PushVertexShaderParams(
static uint32_t VULKAN_PushVertexShaderParams(
REFRESH_Renderer *driverData,
void *data,
uint32_t elementCount
@ -5679,7 +5687,7 @@ static void VULKAN_PushVertexShaderParams(
UBO_BUFFER_SIZE * (renderer->frameIndex + 1)
) {
REFRESH_LogError("Vertex UBO overflow!");
return;
return 0;
}
VULKAN_INTERNAL_SetBufferData(
@ -5689,9 +5697,11 @@ static void VULKAN_PushVertexShaderParams(
data,
elementCount * renderer->currentGraphicsPipeline->vertexUBOBlockSize
);
return renderer->vertexUBOOffset;
}
static void VULKAN_PushFragmentShaderParams(
static uint32_t VULKAN_PushFragmentShaderParams(
REFRESH_Renderer *driverData,
void *data,
uint32_t elementCount
@ -5707,7 +5717,7 @@ static void VULKAN_PushFragmentShaderParams(
UBO_BUFFER_SIZE * (renderer->frameIndex + 1)
) {
REFRESH_LogError("Fragment UBO overflow!");
return;
return 0;
}
VULKAN_INTERNAL_SetBufferData(
@ -5717,6 +5727,8 @@ static void VULKAN_PushFragmentShaderParams(
data,
elementCount * renderer->currentGraphicsPipeline->fragmentUBOBlockSize
);
return renderer->fragmentUBOOffset;
}
static inline uint8_t SamplerDescriptorSetDataEqual(