From cdd209d43abbe4f19f1b9f72a8164e900dc22792 Mon Sep 17 00:00:00 2001 From: yours3lf <0.tamas.marton@gmail.com> Date: Sat, 16 May 2020 14:49:09 +0100 Subject: [PATCH] fixed mipmapping --- driver/ControlListUtil.h | 2 +- driver/command.c | 34 +++++++++++++--------------------- driver/common.h | 1 + driver/renderpass.c | 4 ++-- driver/resource.c | 4 ++++ 5 files changed, 21 insertions(+), 24 deletions(-) diff --git a/driver/ControlListUtil.h b/driver/ControlListUtil.h index a9501a5..66733c6 100644 --- a/driver/ControlListUtil.h +++ b/driver/ControlListUtil.h @@ -38,7 +38,7 @@ typedef struct CLMarker uint32_t clearColor[2]; uint32_t clearDepth, clearStencil; uint32_t width, height; //render w/h - uint32_t renderToMip; + uint32_t mipLevel; //pointers that point to where all the other CL data is //plus sizes diff --git a/driver/command.c b/driver/command.c index c7b0b50..4b43dde 100644 --- a/driver/command.c +++ b/driver/command.c @@ -360,11 +360,9 @@ VKAPI_ATTR VkResult VKAPI_CALL rpi_vkQueueSubmit( { uint32_t tiling = writeImage->tiling; - uint32_t isLT = isLTformat(getFormatBpp(writeImage->format), marker->width, marker->height); - - if(writeImage->tiling == VC4_TILING_FORMAT_T && isLT) + if(marker->mipLevel > 0) { - tiling = VC4_TILING_FORMAT_LT; + tiling = writeImage->levelTiling[marker->mipLevel]; } submitCl.color_write.hindex = writeImageIdx; @@ -392,11 +390,9 @@ VKAPI_ATTR VkResult VKAPI_CALL rpi_vkQueueSubmit( { uint32_t tiling = readImage->tiling; - uint32_t isLT = isLTformat(getFormatBpp(readImage->format), marker->width, marker->height); - - if(readImage->tiling == VC4_TILING_FORMAT_T && isLT) + if(marker->mipLevel > 0) { - tiling = VC4_TILING_FORMAT_LT; + tiling = readImage->levelTiling[marker->mipLevel]; } submitCl.color_read.hindex = readImageIdx; @@ -410,11 +406,9 @@ VKAPI_ATTR VkResult VKAPI_CALL rpi_vkQueueSubmit( { uint32_t tiling = writeDepthStencilImage->tiling; - uint32_t isLT = isLTformat(getFormatBpp(writeDepthStencilImage->format), marker->width, marker->height); - - if(writeDepthStencilImage->tiling == VC4_TILING_FORMAT_T && isLT) + if(marker->mipLevel > 0) { - tiling = VC4_TILING_FORMAT_LT; + tiling = writeDepthStencilImage->levelTiling[marker->mipLevel]; } submitCl.zs_write.hindex = writeDepthStencilImageIdx; @@ -436,11 +430,9 @@ VKAPI_ATTR VkResult VKAPI_CALL rpi_vkQueueSubmit( { uint32_t tiling = readDepthStencilImage->tiling; - uint32_t isLT = isLTformat(getFormatBpp(readDepthStencilImage->format), marker->width, marker->height); - - if(readDepthStencilImage->tiling == VC4_TILING_FORMAT_T && isLT) + if(marker->mipLevel > 0) { - tiling = VC4_TILING_FORMAT_LT; + tiling = readDepthStencilImage->levelTiling[marker->mipLevel]; } submitCl.zs_read.hindex = readDepthStencilImageIdx; @@ -498,7 +490,7 @@ VKAPI_ATTR VkResult VKAPI_CALL rpi_vkQueueSubmit( heightInTiles = divRoundUp(height, tileSizeH); //pad width if rendering to miplevel - if(marker->renderToMip) + if(marker->mipLevel > 0) { width = getPow2Pad(width); width = width < 4 ? 4 : width; @@ -542,21 +534,21 @@ VKAPI_ATTR VkResult VKAPI_CALL rpi_vkQueueSubmit( submitCl.shader_rec_count = marker->shaderRecCount; submitCl.uniforms_size = marker->uniformsSize; - /** + /**/ printf("BCL:\n"); clDump(((uint8_t*)marker) + sizeof(CLMarker), marker->size); printf("BO handles: "); for(int d = 0; d < marker->handlesSize / 4; ++d) { - printf("%u ", *((uint32_t*)(marker->handlesBuf)+d)); + printf("%u ", *(((uint32_t*)getCPAptrFromOffset(cmdbuf->handlesCl.CPA, marker->handlesBufOffset))+d)); } printf("\nUniforms: "); for(int d = 0; d < marker->uniformsSize / 4; ++d) { - printf("%i ", *((uint32_t*)(marker->uniformsBuf)+d)); + printf("%i ", *(((uint32_t*)getCPAptrFromOffset(cmdbuf->uniformsCl.CPA, marker->uniformsBufOffset))+d)); } printf("\nShader recs: "); - uint8_t* ptr = marker->shaderRecBuf + (3 + 3) * 4; + uint8_t* ptr = getCPAptrFromOffset(cmdbuf->shaderRecCl.CPA, marker->shaderRecBufOffset + (3 + 3) * 4); for(int d = 0; d < marker->shaderRecCount; ++d) { uint8_t flags = *ptr; diff --git a/driver/common.h b/driver/common.h index 0d99da0..d24f35d 100644 --- a/driver/common.h +++ b/driver/common.h @@ -197,6 +197,7 @@ typedef struct VkImage_T uint32_t width, height, depth; uint32_t miplevels, samples; uint32_t levelOffsets[11]; //max 11 mip levels + uint32_t levelTiling[11]; uint32_t layers; //number of views for multiview/stereo uint32_t size; //overall size including padding and alignment uint32_t stride; //the number of bytes from one row of pixels in memory to the next row of pixels in memory (aka pitch) diff --git a/driver/renderpass.c b/driver/renderpass.c index 133ab24..ee3c566 100644 --- a/driver/renderpass.c +++ b/driver/renderpass.c @@ -248,11 +248,11 @@ void rpi_vkCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassB } //pad render size if we are rendering to a mip level - currMarker->renderToMip = biggestMip > 0; + currMarker->mipLevel = biggestMip; uint32_t width = currMarker->width; - if(currMarker->renderToMip) + if(currMarker->mipLevel > 0) { width = getPow2Pad(width); width = width < 4 ? 4 : width; diff --git a/driver/resource.c b/driver/resource.c index 79d6d1d..d32c3ce 100644 --- a/driver/resource.c +++ b/driver/resource.c @@ -202,6 +202,7 @@ VKAPI_ATTR VkResult VKAPI_CALL rpi_vkCreateImage( i->depth = pCreateInfo->extent.depth; i->miplevels = pCreateInfo->mipLevels; memset(i->levelOffsets, 0, sizeof(uint32_t) * 11); + memset(i->levelTiling, 0, sizeof(uint32_t) * 11); i->samples = pCreateInfo->samples; i->layers = pCreateInfo->arrayLayers; i->size = 0; @@ -311,6 +312,8 @@ VKAPI_ATTR void VKAPI_CALL rpi_vkGetImageMemoryRequirements( for(int c = i->miplevels - 1; c >= 0; c--) { + i->levelTiling[c] = i->tiling; + uint32_t mipW, mipH; if(!c) { @@ -340,6 +343,7 @@ VKAPI_ATTR void VKAPI_CALL rpi_vkGetImageMemoryRequirements( uint32_t isMipLT = isLTformat(bpp, mipW, mipH); if(isMipLT) { + i->levelTiling[c] = VC4_TILING_FORMAT_LT; mipW = roundUp(mipW, utileW); mipH = roundUp(mipH, utileH); }