Skip to content

RI::cmdResolve, resolveTo

What it does

A resolve turns a multisampled texture view into a single-sampled one, combining each pixel's samples into a single value. RI provides two ways to record a resolve:

  • At the end of a rendering section: set resolveTo (a single-sampled TextureView) and resolveMode on a ColorAttachment or the DepthAttachment passed to cmdBeginRendering. cmdEndRendering then performs the resolve.
  • As a standalone command: call RI::cmdResolve(cmd, src, dst, mode) outside any rendering section.

The ResolveMode enum selects how the samples of a pixel are combined: eAverage, eMin, eMax, or eSampleZero.

  • Color resolves only support eAverage, and only for non-integer formats.
  • Depth and stencil resolves use the modes the GPU reports in device.limits.depthResolveModes and device.limits.stencilResolveModes. Each bitmask contains RI::resolveModeBit(mode) for every supported mode. A format with both depth and stencil resolves both aspects with the same mode, so RI::resolveModeBit(mode) must be present in both masks. eMin and eMax are the portable depth modes on desktop GPUs; D3D12 does not support eSampleZero. RI does not emulate missing modes: if you need an unsupported mode, resolve in your own shader instead.

Signature

// <RI/RI.hpp>, namespace RI
void cmdResolve(CommandList &cmd, const TextureView &src, const TextureView &dst, ResolveMode mode);

From the header: Resolves a multisampled view into a single-sampled one (P52, P76), outside rendering sections. Counts as Stage::eRenderTarget (color) or Stage::eDepthStencil (depth) for barriers.

// <RI/RI.hpp>, namespace RI
enum class ResolveMode : uint8 { eAverage, eMin, eMax, eSampleZero };

From the header: MSAA resolve (P52, P76): how the samples of a pixel become one value. Color resolves average; depth and stencil take the modes the device reports in DeviceLimits::depthResolveModes / stencilResolveModes. No emulation.

Value Meaning
eAverage
eMin
eMax
eSampleZero
// <RI/RI.hpp>, namespace RI
constexpr uint32 resolveModeBit(ResolveMode mode);

From the header: The bit of mode in DeviceLimits::depthResolveModes and stencilResolveModes.

How RI does it

  • Vulkan: cmdBeginRendering binds each resolveTo target as a dynamic rendering resolve attachment (resolveImageView and resolveMode on VkRenderingAttachmentInfo), and cmdEndRendering transitions it back to its resting layout. cmdResolve records an empty rendering section that loads the source and resolves it, because vkCmdResolveImage only averages color. Supported depth and stencil modes are read from VkPhysicalDeviceDepthStencilResolveProperties.
  • D3D12: RI records ResolveSubresourceRegion for each layer and plane, either after the rendering section in cmdEndRendering or directly in cmdResolve. Before and after the resolve, RI transitions the views into D3D12_BARRIER_LAYOUT_RESOLVE_SOURCE and D3D12_BARRIER_LAYOUT_RESOLVE_DEST and back to their resting layouts. Depth and stencil resolves require programmable sample positions tier 2 (which provides eAverage, eMin, and eMax for depth, and eMin and eMax for stencil).

Rules and errors

  • The source view must be multisampled and the destination view single-sampled, with the same dimensions, layer count, and format. The destination texture must have TextureUsage::eRenderTarget (color) or TextureUsage::eDepthStencil (depth).
  • In validation builds, violating the view requirements, resolving an integer color format, using a color mode other than eAverage, using a depth or stencil mode the GPU does not support, or calling cmdResolve inside a rendering section reports a programmer error.
  • For barriers, resolves count as Stage::eRenderTarget (color) or Stage::eDepthStencil (depth) writes; their results are visible after the layout switch back to rest that RI records, like attachment writes.
  • A destination placed over memory that another resource previously used must be discarded with cmdDiscard before the resolve. Validation builds report a missing discard at cmdResolve, or at cmdBeginRendering for a resolveTo target.