From 81d097bb6709fe68ab83f2d66ed8863ca2a69422 Mon Sep 17 00:00:00 2001 From: yours3lf <0.tamas.marton@gmail.com> Date: Fri, 22 May 2020 17:39:56 +0100 Subject: [PATCH] fixed bincl dump, depth bias, z scale offset, restoring old vp --- driver/command.c | 6 +++++- driver/draw.c | 21 +++++++++++++++++++-- driver/stateChange.c | 3 +++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/driver/command.c b/driver/command.c index 2d648d4..9ee13e6 100644 --- a/driver/command.c +++ b/driver/command.c @@ -540,7 +540,11 @@ VKAPI_ATTR VkResult VKAPI_CALL RPIFUNC(vkQueueSubmit)( /** printf("BCL:\n"); - clDump(((uint8_t*)marker) + sizeof(CLMarker), marker->size); + uint8_t* mem = malloc(marker->size); + memcpy(mem, marker+1, marker->size); + clDump(mem, marker->size); + free(mem); + printf("BO handles: "); for(int d = 0; d < marker->handlesSize / 4; ++d) { diff --git a/driver/draw.c b/driver/draw.c index 13b6f33..f08eafe 100644 --- a/driver/draw.c +++ b/driver/draw.c @@ -104,13 +104,30 @@ static uint32_t drawCommon(VkCommandBuffer commandBuffer, int32_t vertexOffset) //TODO Depth Offset clFit(commandBuffer, &commandBuffer->binCl, V3D21_DEPTH_OFFSET_length); - clInsertDepthOffset(&commandBuffer->binCl, cb->graphicsPipeline->depthBiasConstantFactor, cb->graphicsPipeline->depthBiasSlopeFactor); + + float depthBiasConstant = cb->graphicsPipeline->depthBiasConstantFactor; + float depthBiasSlope = cb->graphicsPipeline->depthBiasSlopeFactor; + + for(uint32_t c = 0; c < cb->graphicsPipeline->dynamicStateCount; ++c) + { + if(cb->graphicsPipeline->dynamicStates[c] == VK_DYNAMIC_STATE_DEPTH_BIAS) + { + depthBiasConstant = cb->depthBiasConstantFactor; + depthBiasSlope = cb->depthBiasSlopeFactor; + break; + } + } + + clInsertDepthOffset(&commandBuffer->binCl, depthBiasConstant, depthBiasSlope); //Vulkan conventions, we expect the resulting NDC space Z axis to be in range [0...1] close->far //cb->graphicsPipeline->minDepthBounds; //Clipper Z Scale and Offset clFit(commandBuffer, &commandBuffer->binCl, V3D21_CLIPPER_Z_SCALE_AND_OFFSET_length); - clInsertClipperZScaleOffset(&commandBuffer->binCl, 0.0f, 1.0f); + //offset, scale + float scale = vp.maxDepth - vp.minDepth; + float offset = vp.minDepth; + clInsertClipperZScaleOffset(&commandBuffer->binCl, offset, scale); cb->vertexBufferDirty = 0; cb->depthBoundsDirty = 0; diff --git a/driver/stateChange.c b/driver/stateChange.c index 977495d..4098e96 100644 --- a/driver/stateChange.c +++ b/driver/stateChange.c @@ -620,8 +620,10 @@ VKAPI_ATTR void VKAPI_CALL RPIFUNC(vkCmdClearAttachments)( _buffer* oldVertexBuffers[8]; char oldPushConstantBufferVertex[256]; char oldPushConstantBufferPixel[256]; + VkViewport oldViewport; //save the state that we'll modify + oldViewport = cmdBuf->viewport; oldPipeline = cmdBuf->graphicsPipeline; memcpy(oldVertexBufferOffsets, cmdBuf->vertexBufferOffsets, sizeof(oldVertexBufferOffsets)); memcpy(oldVertexBuffers, cmdBuf->vertexBuffers, sizeof(oldVertexBuffers)); @@ -722,6 +724,7 @@ VKAPI_ATTR void VKAPI_CALL RPIFUNC(vkCmdClearAttachments)( } //restore state + cmdBuf->viewport = oldViewport; cmdBuf->graphicsPipeline = oldPipeline; memcpy(cmdBuf->vertexBufferOffsets, oldVertexBufferOffsets, sizeof(oldVertexBufferOffsets)); memcpy(cmdBuf->vertexBuffers, oldVertexBuffers, sizeof(oldVertexBuffers));