diff --git a/driver/ControlListUtil.c b/driver/ControlListUtil.c index 446a00a..039370d 100644 --- a/driver/ControlListUtil.c +++ b/driver/ControlListUtil.c @@ -39,7 +39,7 @@ void clInit(ControlList* cl, void* buffer) cl->currMarker = 0; } -void clInsertNewCLMarker(ControlList* cl, ControlList* handlesCL, ControlList* shaderRecCL, uint32_t shaderRecCount, ControlList* uniformsCL, void* imagePtr) +void clInsertNewCLMarker(ControlList* cl, ControlList* handlesCL, ControlList* shaderRecCL, uint32_t shaderRecCount, ControlList* uniformsCL, void* imagePtr, void* depthStencilImagePtr) { //to be inserted when you'd insert tile binning mode config assert(cl); @@ -52,6 +52,7 @@ void clInsertNewCLMarker(ControlList* cl, ControlList* handlesCL, ControlList* s marker.nextMarker = 0; marker.size = 0; marker.image = imagePtr; + marker.depthStencilImage = depthStencilImagePtr; marker.handlesSize = 0; marker.shaderRecSize = 0; marker.uniformsSize = 0; diff --git a/driver/ControlListUtil.h b/driver/ControlListUtil.h index d49670d..22330da 100644 --- a/driver/ControlListUtil.h +++ b/driver/ControlListUtil.h @@ -18,6 +18,7 @@ typedef struct CLMarker struct CLMarker* nextMarker; uint32_t size; //in bytes void* image; //_image* to render to + void* depthStencilImage; //_image* to render depth/stencil to uint32_t flags; //used to store clear flag etc. //pointers that point to where all the other CL data is @@ -57,7 +58,7 @@ uint32_t divRoundUp(uint32_t n, uint32_t d); uint32_t moveBits(uint32_t d, uint32_t bits, uint32_t offset); uint32_t clHasEnoughSpace(ControlList* cl, uint32_t size); void clInit(ControlList* cl, void* buffer); -void clInsertNewCLMarker(ControlList* cl, ControlList* handlesCL, ControlList* shaderRecCL, uint32_t shaderRecCount, ControlList* uniformsCL, void* imagePtr); +void clInsertNewCLMarker(ControlList* cl, ControlList* handlesCL, ControlList* shaderRecCL, uint32_t shaderRecCount, ControlList* uniformsCL, void* imagePtr, void* depthStencilImagePtr); void clCloseCurrentMarker(ControlList* cl, ControlList* handlesCL, ControlList* shaderRecCL, uint32_t shaderRecCount, ControlList* uniformsCL); void clInsertData(ControlList* cl, uint32_t size, uint8_t* data); void clInsertUniformConstant(ControlList* cl, uint32_t data); diff --git a/driver/command.c b/driver/command.c index ae5456a..ae61976 100644 --- a/driver/command.c +++ b/driver/command.c @@ -309,12 +309,15 @@ VKAPI_ATTR VkResult VKAPI_CALL vkQueueSubmit( }; _image* i = marker->image; + _image* dsI = marker->depthStencilImage; //This should not result in an insertion! uint32_t imageIdx = clGetHandleIndex(&cmdbuf->handlesCl, marker->handlesBuf, marker->handlesSize, i->boundMem->bo); + uint32_t depthStencilImageIdx = dsI ? clGetHandleIndex(&cmdbuf->handlesCl, marker->handlesBuf, marker->handlesSize, dsI->boundMem->bo) : 0; - //TODO - //depth/stencil/msaa + //TODO msaa, read fields + + //TODO handle don't care store bit //fill out submit cl fields submitCl.color_write.hindex = imageIdx; @@ -327,6 +330,15 @@ 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); + + submitCl.clear_z = dsI->clearColor[0]; //0...1 -> 0...0xffffff + submitCl.clear_s = dsI->clearColor[1]; //0...0xff + submitCl.min_x_tile = 0; submitCl.min_y_tile = 0; @@ -352,8 +364,6 @@ VKAPI_ATTR VkResult VKAPI_CALL vkQueueSubmit( submitCl.width = i->width; submitCl.height = i->height; submitCl.flags |= marker->flags; - submitCl.clear_z = 0; //TODO probably 0...0xffffff - submitCl.clear_s = 0; //TODO probably 0...0xff submitCl.bo_handles = marker->handlesBuf; submitCl.bin_cl = ((uint8_t*)marker) + sizeof(CLMarker); @@ -387,7 +397,7 @@ VKAPI_ATTR VkResult VKAPI_CALL vkQueueSubmit( printf("%u ", *((uint32_t*)(marker->uniformsBuf)+d)); } printf("\nShader recs: "); - uint8_t* ptr = marker->shaderRecBuf + (3 + 2) * 4; + uint8_t* ptr = marker->shaderRecBuf + (3 + 1) * 4; for(int d = 0; d < marker->shaderRecCount; ++d) { uint8_t flags = *ptr; diff --git a/driver/renderpass.c b/driver/renderpass.c index e63a72f..9a01eed 100644 --- a/driver/renderpass.c +++ b/driver/renderpass.c @@ -22,32 +22,60 @@ void vkCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBegin { if(cb->renderpass->attachments[c].loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR) { - cb->fbo->attachmentViews[c].image->clearColor[0] = cb->fbo->attachmentViews[c].image->clearColor[1] = packVec4IntoABGR8(pRenderPassBegin->pClearValues->color.float32); + if(!isDepthStencilFormat(cb->renderpass->attachments[c].format)) + { + cb->fbo->attachmentViews[c].image->clearColor[0] = cb->fbo->attachmentViews[c].image->clearColor[1] = packVec4IntoABGR8(pRenderPassBegin->pClearValues[c].color.float32); + } + else + { + //for combined depth/stencil images clearColor 0 is depth and 1 is stencil + cb->fbo->attachmentViews[c].image->clearColor[0] = (uint32_t)(pRenderPassBegin->pClearValues[c].depthStencil.depth * 0xffffff) & 0xffffff; + } } - else if(isDepthStencilFormat(cb->renderpass->attachments[c].format) && cb->renderpass->attachments[c].stencilLoadOp == VK_ATTACHMENT_LOAD_OP_CLEAR) + + if(isDepthStencilFormat(cb->renderpass->attachments[c].format) && cb->renderpass->attachments[c].stencilLoadOp == VK_ATTACHMENT_LOAD_OP_CLEAR) { - //TODO how to pack depth/stencil clear values??? - //cb->fbo->attachmentViews[c].image->needToClear = 1; - //cb->fbo->attachmentViews[c].image->clearColor = packVec4IntoABGR8(pRenderPassBegin->pClearValues->depthStencil.depth); + cb->fbo->attachmentViews[c].image->clearColor[1] = pRenderPassBegin->pClearValues[c].depthStencil.stencil & 0xff; } } cb->currentSubpass = 0; //TODO handle multiple attachments - _image* i = cb->fbo->attachmentViews[0].image; + _image* i = 0; + _image* dsI = 0; + + for(uint32_t c = 0; c < cb->fbo->numAttachmentViews; ++c) + { + if(!isDepthStencilFormat(cb->fbo->attachmentViews[c].image->format)) + { + i = cb->fbo->attachmentViews[c].image; + } + else + { + dsI = cb->fbo->attachmentViews[c].image; + } + } clFit(commandBuffer, &commandBuffer->binCl, sizeof(CLMarker)); - clInsertNewCLMarker(&commandBuffer->binCl, &cb->handlesCl, &cb->shaderRecCl, cb->shaderRecCount, &cb->uniformsCl, i); + clInsertNewCLMarker(&commandBuffer->binCl, &cb->handlesCl, &cb->shaderRecCl, cb->shaderRecCount, &cb->uniformsCl, i, dsI); //insert reloc for render target clFit(commandBuffer, &commandBuffer->handlesCl, 4); 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); + //TODO handle multiple attachments - if(cb->renderpass->attachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR) + for(uint32_t c = 0; c < cb->renderpass->numAttachments; ++c) { - cb->binCl.currMarker->flags |= VC4_SUBMIT_CL_USE_CLEAR_COLOR; + if(cb->renderpass->attachments[c].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR) + { + //TODO separate clear for color / depth / stencil? + cb->binCl.currMarker->flags |= VC4_SUBMIT_CL_USE_CLEAR_COLOR; + } } clFit(commandBuffer, &commandBuffer->binCl, V3D21_TILE_BINNING_MODE_CONFIGURATION_length); diff --git a/driver/stateChange.c b/driver/stateChange.c index 4e0141e..9283e1c 100644 --- a/driver/stateChange.c +++ b/driver/stateChange.c @@ -96,7 +96,7 @@ VKAPI_ATTR void VKAPI_CALL vkCmdClearColorImage( { //Simplest case: just submit a job to clear the image clFit(commandBuffer, &commandBuffer->binCl, sizeof(CLMarker)); - clInsertNewCLMarker(&commandBuffer->binCl, &commandBuffer->handlesCl, &commandBuffer->shaderRecCl, commandBuffer->shaderRecCount, &commandBuffer->uniformsCl, i); + clInsertNewCLMarker(&commandBuffer->binCl, &commandBuffer->handlesCl, &commandBuffer->shaderRecCl, commandBuffer->shaderRecCount, &commandBuffer->uniformsCl, i, 0); //insert reloc for render target clFit(commandBuffer, &commandBuffer->handlesCl, 4); diff --git a/test/depthTest/depthTest.cpp b/test/depthTest/depthTest.cpp index b09eacb..837dcb0 100644 --- a/test/depthTest/depthTest.cpp +++ b/test/depthTest/depthTest.cpp @@ -766,10 +766,6 @@ void recordCommandBuffers() vkCmdBindPipeline(presentCommandBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); - //vkCmdSetViewport(presentCommandBuffers[i], 0, 1, &viewport); - - //vkCmdSetScissor(presentCommandBuffers[i], 0, 1, &scissor); - float Wcoeff = 1.0f; //1.0f / Wc = 2.0 - Wcoeff float viewportScaleX = (float)(swapChainExtent.width) * 0.5f * 16.0f; float viewportScaleY = -1.0f * (float)(swapChainExtent.height) * 0.5f * 16.0f; @@ -785,14 +781,16 @@ void recordCommandBuffers() vkCmdPushConstants(presentCommandBuffers[i], pipelineLayout, VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(pushConstants), &pushConstants); - uint32_t fragColor = 0xffa14ccc; + //even thought yellow is rendered last, if depth buffering works we expect purple to be on top + + uint32_t fragColor = 0xffa14ccc; //purple vkCmdPushConstants(presentCommandBuffers[i], pipelineLayout, VK_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(fragColor), &fragColor); VkDeviceSize offsets = 0; vkCmdBindVertexBuffers(presentCommandBuffers[i], 0, 1, &vertexBuffer1, &offsets ); vkCmdDraw(presentCommandBuffers[i], 3, 1, 0, 0); - fragColor = 0xffafcd02; + fragColor = 0xffafcd02; //yellow vkCmdPushConstants(presentCommandBuffers[i], pipelineLayout, VK_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(fragColor), &fragColor); vkCmdBindVertexBuffers(presentCommandBuffers[i], 0, 1, &vertexBuffer2, &offsets ); @@ -1089,6 +1087,9 @@ void CreateShaders() /**/ //display a color char fs_asm_code[] = + "sig_none ; nop = nop(r0, r0) ; nop = nop(r0, r0) ;" + "sig_none ; nop = nop(r0, r0) ; nop = nop(r0, r0) ;" + "sig_none ; tlb_z = or.always(b, b, nop, rb15) ; nop = nop(r0, r0) ;" "sig_none ; tlb_color_all = or.always(a, a, uni, nop) ; nop = nop(r0, r0) ;" "sig_end ; nop = nop(r0, r0) ; nop = nop(r0, r0) ;" "sig_none ; nop = nop(r0, r0) ; nop = nop(r0, r0) ;"