Clear part of an image? (Scissor)

Is there any way to use a scissor to clear part of an image with the vkCmdClearColorImage and vkCmdClearDepthImage commands?

I am handling multiple cameras, and want each camera to have clearing and viewport options so the end user can have one camera that renders to part of the screen. I don’t think I can use the RenderPass clear settings for this because the RenderPass is all tied together with framebuffer creation and other things, which makes the whole thing rather inflexible.

Is there a way to do this?

You cannot clear part of an image without using some form of rendering operation. Whether a render pass clear or just drawing stuff to the image.

OK sure, you could probably use a compute shader to write values directly to the area of the image, but that’s not going to be fast.

Why would you be clearing a “camera” if you’re not about to render to it? Just make the higher level code behave itself.

The framebuffer creation code accepts a renderpass object in part of the creation parameters. The renderpass contains options for clearing the depth and camera images. So now we need a bunch of different renderpass objects and a bunch of different framebuffer objects to handle each combination of settings, and something that should be very simple turns into this cascading explosion of code.

An example application of this feature would be a rear-view mirror situated across the top of the screen. You would not want to clear the whole screen, just the viewport of the second camera.

An example where you don’t want to clear the color buffer would be if you use two cameras with different ranges to render a larger view than would be possible with the limits of the depth buffer. For example, you could have one camera with a range of 0.1-1000, and another camera with a range of 1000-10,000. You would want the depth buffer cleared between those renders, but not the color buffer.

I do think the vkCmdClear…Image() functions should have an additional parameter for a region or a series of regions to clear.

From your requirements it looks like vkCmdClearAttachments is what you’re looking for. I’ve been using this in some of my applications for clearing parts of an image/attachment within a single renderpass and it allows you to specify an arbitrary number of rectangles to clear.

Sure, but you would only be clearing it because you’re about to render to it, right? So it should already be an attachment. And we have a function for that: vkCmdClearAttachments.

The point is that you shouldn’t separate the clearing of the region of the attachment from the intent to render to that attachment. From the high-level perspective of the engine you’re clearly writing, when exposing the ability to render to a sub-region of the current framebuffer, you should allow the user to say that they want to clear that sub-region before rendering to it.

So there’s no need for “bunch of different renderpass objects and a bunch of different framebuffer objects”. You simply connect the operations which are connected.

I was not aware of the vkCmdClearAttachments command. This appears to fit the bill.