1
0
mirror of https://github.com/Yours3lf/rpi-vk-driver.git synced 2025-03-21 12:29:15 +01:00

added index buffering

This commit is contained in:
Unknown 2019-09-23 19:40:36 +01:00
parent 167398b262
commit 37ec0a6e06
5 changed files with 79 additions and 28 deletions

View File

@ -127,6 +127,8 @@ VKAPI_ATTR VkResult VKAPI_CALL vkAllocateCommandBuffers(
pCommandBuffers[c]->graphicsPipeline = 0;
pCommandBuffers[c]->computePipeline = 0;
pCommandBuffers[c]->numDrawCallsSubmitted = 0;
pCommandBuffers[c]->indexBuffer = 0;
pCommandBuffers[c]->indexBufferOffset = 0;
pCommandBuffers[c]->vertexBufferDirty = 1;
pCommandBuffers[c]->indexBufferDirty = 1;
pCommandBuffers[c]->viewportDirty = 1;
@ -330,14 +332,22 @@ VKAPI_ATTR VkResult VKAPI_CALL vkQueueSubmit(
submitCl.clear_color[0] = i->clearColor[0];
submitCl.clear_color[1] = i->clearColor[1];
submitCl.zs_write.hindex = depthStencilImageIdx;
submitCl.zs_write.offset = 0;
submitCl.zs_write.flags = 0;
submitCl.zs_write.bits = VC4_SET_FIELD(VC4_LOADSTORE_TILE_BUFFER_ZS, VC4_LOADSTORE_TILE_BUFFER_BUFFER) |
VC4_SET_FIELD(dsI->tiling, VC4_LOADSTORE_TILE_BUFFER_TILING);
if(dsI)
{
submitCl.zs_write.hindex = depthStencilImageIdx;
submitCl.zs_write.offset = 0;
submitCl.zs_write.flags = 0;
submitCl.zs_write.bits = VC4_SET_FIELD(VC4_LOADSTORE_TILE_BUFFER_ZS, VC4_LOADSTORE_TILE_BUFFER_BUFFER) |
VC4_SET_FIELD(dsI->tiling, VC4_LOADSTORE_TILE_BUFFER_TILING);
submitCl.clear_z = dsI->clearColor[0]; //0...1 -> 0...0xffffff
submitCl.clear_s = dsI->clearColor[1]; //0...0xff
submitCl.clear_z = dsI->clearColor[0]; //0...1 -> 0...0xffffff
submitCl.clear_s = dsI->clearColor[1]; //0...0xff
}
else
{
submitCl.clear_z = 0;
submitCl.clear_s = 0;
}
submitCl.min_x_tile = 0;
submitCl.min_y_tile = 0;

View File

@ -354,6 +354,9 @@ typedef struct VkCommandBuffer_T
uint32_t vertexBufferOffsets[8];
_buffer* vertexBuffers[8];
uint32_t indexBufferOffset;
_buffer* indexBuffer;
} _commandBuffer;
typedef struct VkFence_T

View File

@ -2,10 +2,7 @@
#include "kernel/vc4_packet.h"
/*
* https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#vkCmdDraw
*/
void vkCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance)
static void drawCommon(VkCommandBuffer commandBuffer)
{
assert(commandBuffer);
@ -85,8 +82,8 @@ void vkCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t ins
//Configuration Bits
clFit(commandBuffer, &commandBuffer->binCl, V3D21_CONFIGURATION_BITS_length);
clInsertConfigurationBits(&commandBuffer->binCl,
1, //earlyz updates enable
1, //earlyz enable
cb->graphicsPipeline->depthWriteEnable, //earlyz updates enable
cb->graphicsPipeline->depthTestEnable, //earlyz enable
cb->graphicsPipeline->depthWriteEnable, //z updates enable
cb->graphicsPipeline->depthTestEnable ? getCompareOp(cb->graphicsPipeline->depthCompareOp) : V3D_COMPARE_FUNC_ALWAYS, //depth compare func
0, //coverage read mode
@ -140,10 +137,6 @@ void vkCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t ins
0, //extended shader state record
cb->graphicsPipeline->vertexAttributeDescriptionCount & 0x7); //number of attribute arrays, 0 -> 8
//Vertex Array Primitives (draw call)
clFit(commandBuffer, &commandBuffer->binCl, V3D21_VERTEX_ARRAY_PRIMITIVES_length);
clInsertVertexArrayPrimitives(&commandBuffer->binCl, firstVertex, vertexCount, getPrimitiveMode(cb->graphicsPipeline->topology));
//emit shader record
ControlListAddress fragCode = {
.handle = ((_shaderModule*)(cb->graphicsPipeline->modules[ulog2(VK_SHADER_STAGE_FRAGMENT_BIT)]))->bos[RPI_ASSEMBLY_TYPE_FRAGMENT],
@ -182,7 +175,7 @@ void vkCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t ins
attribSize += getFormatByteSize(cb->graphicsPipeline->vertexAttributeDescriptions[c].format);
}
//TODO number of attribs
//number of attribs
//3 is the number of type of possible shaders
for(int c = 0; c < (3 + attribCount)*4; ++c)
{
@ -238,12 +231,6 @@ void vkCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t ins
}
}
//write uniforms
_pipelineLayout* pl = cb->graphicsPipeline->layout;
@ -402,6 +389,22 @@ void vkCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t ins
}
}
}
}
/*
* https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#vkCmdDraw
*/
void vkCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance)
{
assert(commandBuffer);
drawCommon(commandBuffer);
_commandBuffer* cb = commandBuffer;
//Submit draw call: vertex Array Primitives
clFit(commandBuffer, &commandBuffer->binCl, V3D21_VERTEX_ARRAY_PRIMITIVES_length);
clInsertVertexArrayPrimitives(&commandBuffer->binCl, firstVertex, vertexCount, getPrimitiveMode(cb->graphicsPipeline->topology));
cb->numDrawCallsSubmitted++;
}
@ -414,7 +417,27 @@ VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndexed(
int32_t vertexOffset,
uint32_t firstInstance)
{
//TODO
assert(commandBuffer);
drawCommon(commandBuffer);
_commandBuffer* cb = commandBuffer;
clFit(commandBuffer, &commandBuffer->handlesCl, 4);
uint32_t idx = clGetHandleIndex(&commandBuffer->handlesCl, cb->binCl.currMarker->handlesBuf, cb->binCl.currMarker->handlesSize, cb->indexBuffer);
clInsertGEMRelocations(&commandBuffer->binCl, cb->indexBuffer->boundMem->bo, 0);
//Submit draw call: vertex Array Primitives
clFit(commandBuffer, &commandBuffer->binCl, V3D21_VERTEX_ARRAY_PRIMITIVES_length);
clInsertIndexedPrimitiveList(&commandBuffer->binCl,
0xffff, //TODO max index?
0, //TODO we can pass an offset here
indexCount,
1, //we only support 16 bit indices
getPrimitiveMode(cb->graphicsPipeline->topology));
cb->numDrawCallsSubmitted++;
}
VKAPI_ATTR void VKAPI_CALL vkCmdDrawIndexedIndirect(

View File

@ -65,8 +65,11 @@ void vkCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBegin
clGetHandleIndex(&commandBuffer->handlesCl, commandBuffer->binCl.currMarker->handlesBuf, commandBuffer->binCl.currMarker->handlesSize, i->boundMem->bo);
//insert reloc for depth/stencil image
clFit(commandBuffer, &commandBuffer->handlesCl, 4);
clGetHandleIndex(&commandBuffer->handlesCl, commandBuffer->binCl.currMarker->handlesBuf, commandBuffer->binCl.currMarker->handlesSize, dsI->boundMem->bo);
if(dsI)
{
clFit(commandBuffer, &commandBuffer->handlesCl, 4);
clGetHandleIndex(&commandBuffer->handlesCl, commandBuffer->binCl.currMarker->handlesBuf, commandBuffer->binCl.currMarker->handlesSize, dsI->boundMem->bo);
}
//TODO handle multiple attachments
for(uint32_t c = 0; c < cb->renderpass->numAttachments; ++c)

View File

@ -207,7 +207,19 @@ VKAPI_ATTR void VKAPI_CALL vkCmdBindIndexBuffer(
VkDeviceSize offset,
VkIndexType indexType)
{
//TODO
assert(commandBuffer);
if(indexType == VK_INDEX_TYPE_UINT32)
{
UNSUPPORTED(VK_INDEX_TYPE_UINT32);
}
_commandBuffer* cb = commandBuffer;
cb->indexBuffer = buffer;
cb->indexBufferOffset = offset;
cb->indexBufferDirty = 1;
}
/*