mojira.dev
MC-310360

`clearColorTexture` and `clearDepthTexture` clear all mipmaps with the Vulkan rendering backend, unlike with the OpenGL one

Vulkan:

private void clearColorTextureUnsynced(final MemoryStack stack, final GpuTexture colorTexture, final Vector4fc clearColor) {
   VkClearColorValue vkClearColor = VulkanUtils.putArgb(VkClearColorValue.calloc(stack), clearColor);
   VkImageSubresourceRange subresourceRange = VkImageSubresourceRange.calloc(stack);
   subresourceRange.baseMipLevel(0);
   subresourceRange.levelCount(colorTexture.getMipLevels());
   subresourceRange.baseArrayLayer(0);
   subresourceRange.layerCount(1);
   subresourceRange.aspectMask(1);
   VK12.vkCmdClearColorImage(this.commandBuffer(), ((VulkanGpuTexture)colorTexture).vkImage(), 1, vkClearColor, subresourceRange);
}

public void clearDepthTextureUnsynced(final MemoryStack stack, final GpuTexture depthTexture, final double clearDepth) {
   VkClearDepthStencilValue vkClearDepth = VkClearDepthStencilValue.calloc(stack).depth((float)clearDepth);
   VkImageSubresourceRange subresourceRange = VkImageSubresourceRange.calloc(stack);
   subresourceRange.baseMipLevel(0);
   subresourceRange.levelCount(depthTexture.getMipLevels());
   subresourceRange.baseArrayLayer(0);
   subresourceRange.layerCount(1);
   subresourceRange.aspectMask(2);
   VK12.vkCmdClearDepthStencilImage(this.commandBuffer(), ((VulkanGpuTexture)depthTexture).vkImage(), 1, vkClearDepth, subresourceRange);
}

OpenGL:

@Override
public void clearColorTexture(final GpuTexture colorTexture, final Vector4fc clearColor) {
   this.device.directStateAccess().bindFrameBufferTextures(this.drawFbo, ((GlTexture)colorTexture).id, 0, 0, 36160);
   GL33C.glClearColor(clearColor.x(), clearColor.y(), clearColor.z(), clearColor.w());
   GlStateManager._disableScissorTest();
   GlStateManager._colorMask(15);
   GlStateManager._clear(16384);
   GlStateManager._glFramebufferTexture2D(36160, 36064, 3553, 0, 0);
   GlStateManager._glBindFramebuffer(36160, 0);
}

@Override
public void clearDepthTexture(final GpuTexture depthTexture, final double clearDepth) {
   this.device.directStateAccess().bindFrameBufferTextures(this.drawFbo, 0, ((GlTexture)depthTexture).id, 0, 36160);
   GL33C.glDrawBuffer(0);
   GL33C.glClearDepth(clearDepth);
   GlStateManager._depthMask(true);
   GlStateManager._disableScissorTest();
   GlStateManager._clear(256);
   GL33C.glDrawBuffer(36064);
   GlStateManager._glFramebufferTexture2D(36160, 36096, 3553, 0, 0);
   GlStateManager._glBindFramebuffer(36160, 0);
}

This makes Vulkan more expensive than OpenGL

subresourceRange.levelCount(1);

should be used

Comments 1

Lolo

RogueLogix

Community Consensus

Platform G

Normal

Rendering

26.3 Snapshot 5

26.3 Snapshot 6

Retrieved