1
0
mirror of https://github.com/Yours3lf/rpi-vk-driver.git synced 2025-02-20 17:54:17 +01:00

cubemapping seems to be somewhat working

now just need to modify the test to showcase it well
This commit is contained in:
Unknown 2020-04-14 18:31:58 +01:00
parent 2a171f6095
commit cb60bade91
5 changed files with 23 additions and 8 deletions

View File

@ -214,6 +214,8 @@ typedef struct VkImage_T
uint32_t compositeAlpha;
uint32_t presentMode;
uint32_t clipped;
uint32_t flags;
} _image;
typedef struct VkImageView_T

View File

@ -143,12 +143,13 @@ void createSampler(VkDevice device, VkSampler* nearestTextureSampler, VkSampler*
rpi_vkCreateSampler(device, &sampler, 0, linearTextureSampler);
}
void createRendertarget(VkDevice device, uint32_t baseMip, uint32_t width, uint32_t height, VkImage textureImage, VkImageView* textureView, VkRenderPass* offscreenRenderPass, VkFramebuffer* offscreenFramebuffer)
void createRendertarget(VkDevice device, uint32_t baseLayer, uint32_t baseMip, uint32_t width, uint32_t height, VkImage textureImage, VkImageView* textureView, VkRenderPass* offscreenRenderPass, VkFramebuffer* offscreenFramebuffer)
{
_image* img = textureImage;
VkFormat format = img->format;
printf("\nCopy Create RT\n");
printf("baseLayer %u\n", baseLayer);
printf("baseMip %u\n", baseMip);
printf("width %u\n", width);
printf("height %u\n", height);
@ -169,7 +170,7 @@ void createRendertarget(VkDevice device, uint32_t baseMip, uint32_t width, uint3
view.components.r = VK_COMPONENT_SWIZZLE_R;
view.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
view.subresourceRange.baseMipLevel = baseMip;
view.subresourceRange.baseArrayLayer = 0;
view.subresourceRange.baseArrayLayer = baseLayer;
view.subresourceRange.layerCount = 1;
view.subresourceRange.levelCount = 1;
view.image = textureImage;
@ -899,7 +900,7 @@ VKAPI_ATTR void VKAPI_CALL rpi_vkCmdCopyBufferToImage(
writeDescriptorSet.descriptorCount = 1;
rpi_vkUpdateDescriptorSets(device, 1, &writeDescriptorSet, 0, 0);
createRendertarget(device, pRegions[c].imageSubresource.mipLevel, width, height, img, &textureView, &offscreenRenderPass, &offscreenFramebuffer);
createRendertarget(device, pRegions[c].imageSubresource.baseArrayLayer, pRegions[c].imageSubresource.mipLevel, width, height, img, &textureView, &offscreenRenderPass, &offscreenFramebuffer);
createPipeline(device, 0, 4, 5, device->emulBufferToTextureShaderModule, device->emulBufferDsl, &blitPipelineLayout, offscreenRenderPass, &blitPipeline);
//offscreen rendering
@ -1062,7 +1063,7 @@ VKAPI_ATTR void VKAPI_CALL rpi_vkCmdBlitImage(
writeDescriptorSet.descriptorCount = 1;
rpi_vkUpdateDescriptorSets(device, 1, &writeDescriptorSet, 0, 0);
createRendertarget(device, dstMipLevel, dstWidth, dstHeight, dstImage, &dstTextureView, &offscreenRenderPass, &offscreenFramebuffer);
createRendertarget(device, 0, dstMipLevel, dstWidth, dstHeight, dstImage, &dstTextureView, &offscreenRenderPass, &offscreenFramebuffer);
createPipeline(device, 1, 4, 2, device->emulTextureToTextureShaderModule, device->emulTextureDsl, &blitPipelineLayout, offscreenRenderPass, &blitPipeline);
//offscreen rendering

View File

@ -329,13 +329,17 @@ static uint32_t drawCommon(VkCommandBuffer commandBuffer)
_descriptorImage* di = getMapElement(ds->imageBindingMap, mapping.descriptorBinding);
di += mapping.descriptorArrayElement;
uint32_t cubemapStride = (di->imageView->image->width * di->imageView->image->height * getFormatBpp(di->imageView->interpretedFormat)) >> 3;
fprintf(stderr, "cubemap stride %i\n", cubemapStride);
//TODO handle miplevels according to subresource rage?
uint32_t params[4];
encodeTextureUniform(params,
di->imageView->subresourceRange.levelCount - 1,
getTextureDataType(di->imageView->interpretedFormat),
di->imageView->viewType == VK_IMAGE_VIEW_TYPE_CUBE,
0, //TODO cubemap stride
cubemapStride >> 12, //TODO cubemap stride in multiples of 4KB
di->imageView->image->levelOffsets[0] >> 12, //Image level 0 offset in multiples of 4KB
di->imageView->image->height & 2047,
di->imageView->image->width & 2047,
@ -367,7 +371,8 @@ static uint32_t drawCommon(VkCommandBuffer commandBuffer)
//TODO handle this properly
//TMU0_B requires an extra uniform written
//we need to signal that somehow from API side
if(di->sampler->disableAutoLod)
//if mode is cubemap we don't need an extra uniform, it's included!
if(di->imageView->viewType != VK_IMAGE_VIEW_TYPE_CUBE && di->sampler->disableAutoLod)
{
size += 4;
}

View File

@ -58,11 +58,13 @@ void rpi_vkCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassB
{
writeMSAAimage = fb->attachmentViews[rp->subpasses[0].pColorAttachments[0].attachment].image;
writeMSAAimageOffset = fb->attachmentViews[rp->subpasses[0].pColorAttachments[0].attachment].image->levelOffsets[fb->attachmentViews[rp->subpasses[0].pColorAttachments[0].attachment].subresourceRange.baseMipLevel];
writeMSAAimageOffset += fb->attachmentViews[rp->subpasses[0].pColorAttachments[0].attachment].subresourceRange.baseArrayLayer * fb->attachmentViews[rp->subpasses[0].pColorAttachments[0].attachment].image->size / fb->attachmentViews[rp->subpasses[0].pColorAttachments[0].attachment].image->layers;
}
else
{
writeImage = fb->attachmentViews[rp->subpasses[0].pColorAttachments[0].attachment].image;
writeImageOffset = fb->attachmentViews[rp->subpasses[0].pColorAttachments[0].attachment].image->levelOffsets[fb->attachmentViews[rp->subpasses[0].pColorAttachments[0].attachment].subresourceRange.baseMipLevel];
writeImageOffset += fb->attachmentViews[rp->subpasses[0].pColorAttachments[0].attachment].subresourceRange.baseArrayLayer * fb->attachmentViews[rp->subpasses[0].pColorAttachments[0].attachment].image->size / fb->attachmentViews[rp->subpasses[0].pColorAttachments[0].attachment].image->layers;
}
}
@ -70,6 +72,7 @@ void rpi_vkCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassB
{
readImage = fb->attachmentViews[rp->subpasses[0].pColorAttachments[0].attachment].image;
readImageOffset = fb->attachmentViews[rp->subpasses[0].pColorAttachments[0].attachment].image->levelOffsets[fb->attachmentViews[rp->subpasses[0].pColorAttachments[0].attachment].subresourceRange.baseMipLevel];
readImageOffset += fb->attachmentViews[rp->subpasses[0].pColorAttachments[0].attachment].subresourceRange.baseArrayLayer * fb->attachmentViews[rp->subpasses[0].pColorAttachments[0].attachment].image->size / fb->attachmentViews[rp->subpasses[0].pColorAttachments[0].attachment].image->layers;
if(rp->attachments[rp->subpasses[0].pColorAttachments[0].attachment].samples > 1)
{
@ -83,6 +86,7 @@ void rpi_vkCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassB
{
writeImage = fb->attachmentViews[rp->subpasses[0].pResolveAttachments[0].attachment].image;
writeImageOffset = fb->attachmentViews[rp->subpasses[0].pResolveAttachments[0].attachment].image->levelOffsets[fb->attachmentViews[rp->subpasses[0].pResolveAttachments[0].attachment].subresourceRange.baseMipLevel];
writeImageOffset += fb->attachmentViews[rp->subpasses[0].pColorAttachments[0].attachment].subresourceRange.baseArrayLayer * fb->attachmentViews[rp->subpasses[0].pColorAttachments[0].attachment].image->size / fb->attachmentViews[rp->subpasses[0].pColorAttachments[0].attachment].image->layers;
performResolve = 1;
}
}
@ -96,11 +100,13 @@ void rpi_vkCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassB
{
writeMSAAdepthStencilImage = fb->attachmentViews[rp->subpasses[0].pDepthStencilAttachment->attachment].image;
writeMSAAdepthStencilImageOffset = fb->attachmentViews[rp->subpasses[0].pDepthStencilAttachment->attachment].image->levelOffsets[fb->attachmentViews[rp->subpasses[0].pDepthStencilAttachment->attachment].subresourceRange.baseMipLevel];
writeMSAAdepthStencilImageOffset += fb->attachmentViews[rp->subpasses[0].pDepthStencilAttachment->attachment].subresourceRange.baseArrayLayer * fb->attachmentViews[rp->subpasses[0].pColorAttachments[0].attachment].image->size / fb->attachmentViews[rp->subpasses[0].pDepthStencilAttachment->attachment].image->layers;
}
else
{
writeDepthStencilImage = fb->attachmentViews[rp->subpasses[0].pDepthStencilAttachment->attachment].image;
writeDepthStencilImageOffset = fb->attachmentViews[rp->subpasses[0].pDepthStencilAttachment->attachment].image->levelOffsets[fb->attachmentViews[rp->subpasses[0].pDepthStencilAttachment->attachment].subresourceRange.baseMipLevel];
writeDepthStencilImageOffset += fb->attachmentViews[rp->subpasses[0].pDepthStencilAttachment->attachment].subresourceRange.baseArrayLayer * fb->attachmentViews[rp->subpasses[0].pColorAttachments[0].attachment].image->size / fb->attachmentViews[rp->subpasses[0].pDepthStencilAttachment->attachment].image->layers;
}
}
@ -109,6 +115,7 @@ void rpi_vkCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassB
{
readDepthStencilImage = fb->attachmentViews[rp->subpasses[0].pDepthStencilAttachment->attachment].image;
readDepthStencilImageOffset = fb->attachmentViews[rp->subpasses[0].pDepthStencilAttachment->attachment].image->levelOffsets[fb->attachmentViews[rp->subpasses[0].pDepthStencilAttachment->attachment].subresourceRange.baseMipLevel];
readDepthStencilImageOffset += fb->attachmentViews[rp->subpasses[0].pDepthStencilAttachment->attachment].subresourceRange.baseArrayLayer * fb->attachmentViews[rp->subpasses[0].pColorAttachments[0].attachment].image->size / fb->attachmentViews[rp->subpasses[0].pDepthStencilAttachment->attachment].image->layers;
if(rp->attachments[rp->subpasses[0].pDepthStencilAttachment->attachment].samples > 1)
{

View File

@ -195,7 +195,7 @@ VKAPI_ATTR VkResult VKAPI_CALL rpi_vkCreateImage(
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
//TODO flags?
i->flags = pCreateInfo->flags;
i->type = pCreateInfo->imageType;
i->fb = 0; //needed for modeset
i->width = pCreateInfo->extent.width;
@ -397,7 +397,7 @@ VKAPI_ATTR void VKAPI_CALL rpi_vkGetImageMemoryRequirements(
i->levelOffsets[c] = i->levelOffsets[c - 1] - mipSizes[c];
}
i->size = getBOAlignedSize(((i->paddedWidth * i->paddedHeight * bpp) >> 3) + i->levelOffsets[0], ARM_PAGE_SIZE);
i->size = getBOAlignedSize(((i->paddedWidth * i->paddedHeight * bpp) >> 3) + i->levelOffsets[0], ARM_PAGE_SIZE) * i->layers;
// fprintf(stderr, "i->tiling %u\n", i->tiling);
// fprintf(stderr, "i->levelOffsets[0] %u\n", i->levelOffsets[0]);