1
0
mirror of https://github.com/Yours3lf/rpi-vk-driver.git synced 2025-01-19 11:52:16 +01:00

started adding support for secondary cmdbufs, but crashing still

This commit is contained in:
yours3lf 2020-06-11 21:37:50 +01:00
parent 9a8c4ecb7b
commit 2a6438bd43
8 changed files with 219 additions and 154 deletions

View File

@ -201,15 +201,17 @@ void consecutivePoolFree(ConsecutivePoolAllocator* pa, void* p, uint32_t numBloc
pa->numFreeBlocks += numBlocks;
}
uint32_t consecutivePoolReAllocate(ConsecutivePoolAllocator* pa, void* currentMem, uint32_t currNumBlocks)
uint32_t consecutivePoolReAllocate(ConsecutivePoolAllocator* pa, void* currentMem, uint32_t currNumBlocks, uint32_t newNumBlocks)
{
assert(pa);
assert(pa->buf);
assert(currentMem);
assert(currNumBlocks);
//TODO hack
if(newNumBlocks - currNumBlocks < 2)
{
uint32_t* nextCandidate = (char*)currentMem + pa->blockSize * currNumBlocks;
uint32_t* prevPtr = 0;
for(uint32_t* listPtr = pa->nextFreeBlock; listPtr; listPtr = *listPtr)
{
@ -233,17 +235,18 @@ uint32_t consecutivePoolReAllocate(ConsecutivePoolAllocator* pa, void* currentMe
prevPtr = listPtr;
}
}
{
//try to allocate one more block
uint32_t newMemOffset = consecutivePoolAllocate(pa, currNumBlocks + 1);
uint32_t newMemOffset = consecutivePoolAllocate(pa, newNumBlocks);
if(newMemOffset == -1)
{
return -1;
}
pa->numFreeBlocks -= 1;
pa->numFreeBlocks -= newNumBlocks - currNumBlocks;
//copy over old content
memcpy(pa->buf + newMemOffset, currentMem, currNumBlocks * pa->blockSize);

View File

@ -21,7 +21,7 @@ ConsecutivePoolAllocator createConsecutivePoolAllocator(void* b, unsigned bs, un
void destroyConsecutivePoolAllocator(ConsecutivePoolAllocator* pa);
uint32_t consecutivePoolAllocate(ConsecutivePoolAllocator* pa, uint32_t numBlocks);
void consecutivePoolFree(ConsecutivePoolAllocator* pa, void* p, uint32_t numBlocks);
uint32_t consecutivePoolReAllocate(ConsecutivePoolAllocator* pa, void* currentMem, uint32_t currNumBlocks);
uint32_t consecutivePoolReAllocate(ConsecutivePoolAllocator* pa, void* currentMem, uint32_t currNumBlocks, uint32_t newNumBlocks);
void CPAdebugPrint(ConsecutivePoolAllocator* pa);
void* getCPAptrFromOffset(ConsecutivePoolAllocator* pa, uint32_t offset);

View File

@ -19,7 +19,8 @@ uint32_t clHasEnoughSpace(ControlList* cl, uint32_t size)
assert(cl);
assert(cl->CPA);
uint32_t currSize = cl->nextFreeByteOffset - cl->offset;
if(currSize + size < cl->numBlocks * cl->blockSize - 4)
if((currSize + size) <= (cl->numBlocks * cl->blockSize))
{
return 1; //fits!
}

View File

@ -120,6 +120,8 @@ VKAPI_ATTR VkResult VKAPI_CALL RPIFUNC(vkAllocateCommandBuffers)(
pCommandBuffers[c]->dev = device;
pCommandBuffers[c]->level = pAllocateInfo[c].level;
pCommandBuffers[c]->shaderRecCount = 0;
pCommandBuffers[c]->usageFlags = 0;
pCommandBuffers[c]->state = CMDBUF_STATE_INITIAL;
@ -212,16 +214,12 @@ VKAPI_ATTR VkResult VKAPI_CALL RPIFUNC(vkBeginCommandBuffer)(
assert(commandBuffer);
assert(pBeginInfo);
//TODO secondary command buffers
//TODO VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
//specifies that a secondary command buffer is considered to be entirely inside a render pass. If this is a primary command buffer, then this bit is ignored
//TODO VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT
//specifies that a command buffer can be resubmitted to a queue while it is in the pending state, and recorded into multiple primary command buffers
//TODO inheritance info
//When a command buffer begins recording, all state in that command buffer is undefined
commandBuffer->usageFlags = pBeginInfo->flags;
@ -233,6 +231,16 @@ VKAPI_ATTR VkResult VKAPI_CALL RPIFUNC(vkBeginCommandBuffer)(
RPIFUNC(vkResetCommandBuffer)(commandBuffer, 0);
}
if(pBeginInfo->pInheritanceInfo && commandBuffer->level == VK_COMMAND_BUFFER_LEVEL_SECONDARY)
{
VkRenderPassBeginInfo rpbi = {0};
rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
rpbi.framebuffer = pBeginInfo->pInheritanceInfo->framebuffer;
rpbi.renderPass = pBeginInfo->pInheritanceInfo->renderPass;
//TODO query stuff
RPIFUNC(vkCmdBeginRenderPass)(commandBuffer, &rpbi, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
}
PROFILEEND(RPIFUNC(vkBeginCommandBuffer));
return VK_SUCCESS;
}
@ -930,7 +938,42 @@ VKAPI_ATTR void VKAPI_CALL RPIFUNC(vkCmdExecuteCommands)(
const VkCommandBuffer* pCommandBuffers)
{
PROFILESTART(RPIFUNC(vkCmdExecuteCommands));
//TODO
assert(commandBuffer);
assert(commandBufferCount > 0);
assert(pCommandBuffers);
//just copy bincl etc. over until there's a better solution
_commandBuffer* primary = commandBuffer;
for(uint32_t c = 0; c < commandBufferCount; ++c)
{
_commandBuffer* secondary = pCommandBuffers[c];
CLMarker* secondaryMarker = getCPAptrFromOffset(secondary->binCl.CPA, secondary->binCl.currMarkerOffset);
if(!secondaryMarker->size)
{
clCloseCurrentMarker(&secondary->binCl, &secondary->handlesCl, &secondary->shaderRecCl, secondary->shaderRecCount, &secondary->uniformsCl);
}
clFit(&primary->binCl, secondaryMarker->size);
clInsertData(&primary->binCl, secondaryMarker->size, ((uint8_t*)secondaryMarker) + sizeof(CLMarker));
((CLMarker*)getCPAptrFromOffset(primary->binCl.CPA, primary->binCl.currMarkerOffset))->numDrawCallsSubmitted += secondaryMarker->numDrawCallsSubmitted;
//TODO handles/handle indices might be grabled up like this...
clFit(&primary->handlesCl, secondaryMarker->handlesSize);
clInsertData(&primary->handlesCl, secondaryMarker->handlesSize, getCPAptrFromOffset(secondary->handlesCl.CPA, secondaryMarker->handlesBufOffset));
clFit(&primary->uniformsCl, secondaryMarker->uniformsSize);
clInsertData(&primary->uniformsCl, secondaryMarker->uniformsSize, getCPAptrFromOffset(secondary->uniformsCl.CPA, secondaryMarker->uniformsBufOffset));
clFit(&primary->shaderRecCl, secondaryMarker->shaderRecSize);
clInsertData(&primary->shaderRecCl, secondaryMarker->shaderRecSize, getCPAptrFromOffset(secondary->shaderRecCl.CPA, secondaryMarker->shaderRecBufOffset));
primary->shaderRecCount += secondary->shaderRecCount;
}
PROFILEEND(RPIFUNC(vkCmdExecuteCommands));
}

View File

@ -537,9 +537,10 @@ void clFit(ControlList* cl, uint32_t commandSize)
{
uint32_t currSize = cl->nextFreeByteOffset - cl->offset;
uint32_t currMarkerOffset = cl->currMarkerOffset - cl->offset;
cl->offset = consecutivePoolReAllocate(cl->CPA, getCPAptrFromOffset(cl->CPA, cl->offset), cl->numBlocks); assert(cl->offset != ~0u);
uint32_t newNumBlocks = ((currSize + commandSize) / (((ConsecutivePoolAllocator*)cl->CPA)->blockSize)) + 1;
cl->offset = consecutivePoolReAllocate(cl->CPA, getCPAptrFromOffset(cl->CPA, cl->offset), cl->numBlocks, newNumBlocks); assert(cl->offset != ~0u);
cl->nextFreeByteOffset = cl->offset + currSize;
cl->numBlocks++;
cl->numBlocks = newNumBlocks;
cl->currMarkerOffset = cl->currMarkerOffset == ~0u ? ~0u : cl->offset + currMarkerOffset;
if(cl->currMarkerOffset != ~0u)
{

View File

@ -359,6 +359,8 @@ typedef struct VkCommandBuffer_T
_device* dev; //device from which it was created
VkCommandBufferLevel level;
//Recorded commands include commands to bind pipelines and descriptor sets to the command buffer, commands to modify dynamic state, commands to draw (for graphics rendering),
//commands to dispatch (for compute), commands to execute secondary command buffers (for primary command buffers only), commands to copy buffers and images, and other commands

View File

@ -150,6 +150,8 @@ void RPIFUNC(vkCmdBeginRenderPass)(VkCommandBuffer commandBuffer, const VkRender
currMarker->readMSAAimage = readMSAAimage;
currMarker->readMSAAdepthStencilImage = readMSAAdepthStencilImage;
if(commandBuffer->level == VK_COMMAND_BUFFER_LEVEL_PRIMARY)
{
if(rp->subpasses[0].colorAttachmentCount > 0)
{
if(rp->subpasses[0].pColorAttachments)
@ -194,9 +196,14 @@ void RPIFUNC(vkCmdBeginRenderPass)(VkCommandBuffer commandBuffer, const VkRender
}
currMarker->flags = flags;
}
//insert relocs
//only add image stuff if we're in a primary level
//secondary level can't begin a renderpass
//but still will need a marker
if(commandBuffer->level == VK_COMMAND_BUFFER_LEVEL_PRIMARY)
{
if(writeImage)
{
clFit(&commandBuffer->handlesCl, 4);
@ -232,7 +239,10 @@ void RPIFUNC(vkCmdBeginRenderPass)(VkCommandBuffer commandBuffer, const VkRender
clFit(&commandBuffer->handlesCl, 4);
clGetHandleIndex(&commandBuffer->handlesCl, ((CLMarker*)getCPAptrFromOffset(cb->binCl.CPA, cb->binCl.currMarkerOffset))->handlesBufOffset + cb->handlesCl.offset, ((CLMarker*)getCPAptrFromOffset(cb->binCl.CPA, cb->binCl.currMarkerOffset))->handlesSize, writeMSAAdepthStencilImage->boundMem->bo);
}
}
if(commandBuffer->level == VK_COMMAND_BUFFER_LEVEL_PRIMARY)
{
uint32_t bpp = 0;
((CLMarker*)getCPAptrFromOffset(cb->binCl.CPA, cb->binCl.currMarkerOffset))->width = fb->width;
@ -264,6 +274,7 @@ void RPIFUNC(vkCmdBeginRenderPass)(VkCommandBuffer commandBuffer, const VkRender
width = width < 4 ? 4 : width;
}
clFit(&commandBuffer->binCl, V3D21_TILE_BINNING_MODE_CONFIGURATION_length);
clInsertTileBinningModeConfiguration(&commandBuffer->binCl,
0, //double buffer in non ms mode
@ -283,6 +294,7 @@ void RPIFUNC(vkCmdBeginRenderPass)(VkCommandBuffer commandBuffer, const VkRender
//command list.
clFit(&commandBuffer->binCl, V3D21_START_TILE_BINNING_length);
clInsertStartTileBinning(&commandBuffer->binCl);
}
((CLMarker*)getCPAptrFromOffset(cb->binCl.CPA, cb->binCl.currMarkerOffset))->perfmonID = cb->perfmonID;
@ -306,6 +318,8 @@ void RPIFUNC(vkCmdEndRenderPass)(VkCommandBuffer commandBuffer)
//Ending a render pass instance performs any multisample resolve operations on the final subpass
if(commandBuffer->level == VK_COMMAND_BUFFER_LEVEL_PRIMARY)
{
//Increment the semaphore indicating that binning is done and
//unblocking the render thread. Note that this doesn't act
//until the FLUSH completes.
@ -315,6 +329,7 @@ void RPIFUNC(vkCmdEndRenderPass)(VkCommandBuffer commandBuffer)
clInsertIncrementSemaphore(&cb->binCl);
clFit(&cb->binCl, V3D21_FLUSH_length);
clInsertFlush(&cb->binCl);
}
cb->currRenderPass = 0;

View File

@ -1333,8 +1333,8 @@ void CreateVertexBuffer()
float w = 2.0;
float h = 2.0;
float stepH = 6.0*h/1080.0;
float stepW = 8.0*w/1920.0;
float stepH = 90*6.0*h/1080.0;
float stepW = 90*8.0*w/1920.0;
vertices.reserve(3 * 2 * 960 * 540);