Repository navigation
Description
Motivation
Tile-based deferred renderers (TBDR) are popular in mobile devices. These types of renderers split up the framebuffer into tiles, and for each tile, run the fragment shading stage for all triangles that touch that tile. The benefit is that a tile can fit inside on-chip memory, meaning that all pixel operations operate on the on-chip memory as a cache. This cache only has to be transferred to/from main memory once per tile, rather than all pixel operations operating directly on main memory. This is beneficial because the ratio of memory bandwidth to computational facilities is different on mobile devices than desktop devices.
Consider an application that has two distinct fragment shaders which need to communicate on a per-pixel basis (i.e. the rendering of a particular pixel relies on the previously shaded value of that same pixel). This kind of architecture is common; the deferred shading technique uses a first pass to populate a buffer with geometry information, and a second pass to compute lighting for each pixel's geometry computed in the previous pass. The most natural way to encode such an architecture would be two use two render passes, one for each fragment shader / destination texture pair. However, between these two render passes, the rendered data must be flushed out to main memory and then read back in again for the second shader. This data transfer is costly on TBDRs, and unnecessary, because the data is simply round-tripping through main memory.
If this data never had to touch main memory, there would be a performance benefit. However, there's a memory benefit, too: if no data ever ends up actually hitting main memory for a resource, that resource doesn't actually need any memory backing it. We can simply avoid allocating a backing store for that resource in device memory. This can be significant, as a large & fat g-buffer can be tens or even hundreds of megabytes.
I made a benchmark ChipMemorySpeed.zip to try to measure the performance effects. It compares the speed of three realizations of the above architecture:
- Direct Resource Writes: Two passes: The first pass's fragment shader explicitly writes into a texture (as in, the shader itself executes a
write()call) and the second one reads it - Render Targets: Two passes: The first pass renders into a texture as a render target, and the second one reads it
- Imageblocks: One pass: The first fragment shader writes into Metal Imageblock storage which lives on-chip, and the second fragment shader reads from it. This avoids the round-trip through main memory.
The test times how fast every pixel on a 4k * 4k texture gets filled with the above data flows on an iPhone XS. I found that, for a thin intermediate buffer (1 byte per pixel), there was no difference between the Render Targets and Imageblocks approaches. However, for a fatter intermediate buffer (16 bytes per pixel), here are the results:
The results show that keeping data on-chip can result in a 40% performance improvement. Most g-buffers are fatter than 16 bytes per pixel, so we can expect the performance improvements can be even greater with real-world renderers.
These results match intuition. Render targets get access to specialized hardware to dump an entire Imageblock to memory, so it is expected to be faster than directly writing pixel-by-pixel into the destination image. Imageblock data doesn't even have to go to main memory at all, so it is expected to be faster than either of the other two options.
D3D12
D3D12 recently added support for render passes in Windows 10 build 1809. The docs list two main benefits:
- Being able to specify load and store operations, which can avoid render target loads and stores
- Being able to make two distinct render passes behave as if they were a single render pass, even if they are in different command lists. (The two command lists don't have to both call
OMSetRenderTargets()anymore.)
The first item is something we already have in WebGPU (GPULoadOp and GPUStoreOp). I'm not sure that the second item is really relevant to this investigation. I couldn't find any other controls for on-chip memory.
Vulkan
Vulkan has the concept of "subpasses" within a single render pass. Each subpass can render to a different render target, but all the render targets within a render pass must have the same dimensions. A fragment shader inside one of the subpasses is allowed to read from its pixel's location from a previously-executed subpass by using a special function in the shader: subpassLoad(). This function doesn't take an (x, y) location, because it's only allowed to read from its own pixel's location.
At the time the render pass is created, the author has to specify a plan for how many subpasses there will be, which passes have a dependency on which other passes, and which render targets each pass will write to and read from. Given this information, a TBDR can decide how best to use the limited memory available on the chip. For example, if all the render targets fit on-chip, the implementation is free to keep them there, but if they don't all fit, the implementation can choose the best time within the computation graph to "spill" to device memory. The implementation is free to spill as often or as rarely as it wants, and is even free to cause subpassLoad() to read from memory rather than reading from on-chip memory. This means the implementation is essentially performing a register allocation analysis over the render pass, just like how a compiler would do.
Aside: Making the Vulkan runtime perform register selection is surprisingly un-Vulkan-y. I would have expected them to just expose every last detail of the hardware and force applications to figure out how best to use it.
It's also possible to get the memory benefits by specifying VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT at resource creation time. Because it's not guaranteed when the implementation will or will not spill to memory, this flag isn't a guarantee; sometimes it will result in a real allocation and sometimes it won't.
Subpasses exist on all devices, not just TBDR devices. Presumably this is because the details of how they are executed is abstracted away from the machine itself.
Metal
Metal gives application authors fine-grained control over exactly how to use on-chip memory. It exposes this memory with imageblocks. Imageblocks are only available on some iOS and tvOS hardware. A particular fragment shader invocation may only access the imageblock data associated with that particular fragment location.
Imageblocks come in two flavors: implicit and explicit imageblocks. Metal application developers were already using implicit imageblocks without knowing it; when you output to multiple render targets (MRT) and annotate the outputs with [[color(0)]], those fields live in an imageblock.
Explicit imageblocks work by annotating an input and output struct with [[imageblock_data]]. This indicates that the memory backing those fields will live on the chip. This data isn't associated with any render target or any resource - it just lives on-chip. The imageblock lives for the lifetime of the render pass. If two fragment shaders within the same render pass both include structs marked as [[imageblock_data]], then there's a process which matches the fields from one to the other. The format of an imageblock can change throughout the render pass - different structs annotated with [[imageblock_data]] can be present as both an input and an output of a fragment shader, and the different structs are allowed to have different fields. This way, the author is in complete control over what on-chip memory gets used for during every draw call and whether or not to spill to main memory at any particular time.
A render pass has to know how much imageblock memory will be consumed by any fragment shader. Luckily, when compiling the shader, the pipeline state object includes a getter for how much memory that particular pipeline requires, which can be supplied into the render pass. Apple publishes tables of exactly how much on-chip memory is available for each device that supports imageblocks. Currently, this is 32KB for every device that supports it.
Explicit imageblocks don't require any backing resource, so they get memory savings. Implicit imageblocks support the memory savings by specifying MTLResourceOptions.storageModeMemoryless at resource creation time. This isn't a hint; it means the resource will actually not have any payload memory. If you use one of these, you're not allowed to load or store to it.
OpenGL ES (just for fun)
EXT_shader_pixel_local_storage works almost exactly like Metal's imageblocks.

Activity
litherum commentedon Sep 15, 2019
See also: #393
kvark commentedon Sep 19, 2019
That awkward moment when Metal is more Vulkan than Vulkan?
Seriously though, Vulkan is full of compromises. Having large opaque structs that hide actual low-level bits and knobs is not inconsistent with the API - look at the pipeline objects.
kvark commentedon Sep 19, 2019
Interestingly, ARM results of benchmarking Vulkan Sub-passes from 2017 roughly matches your numbers: they got 30% better FPS and 80% reduction in bandwidth.
devshgraphicsprogramming commentedon Oct 28, 2019
That would be most probably mostly attributable to hardware color compression.
Seriously?
magcius commentedon Oct 28, 2019
Er, until multi-viewport came along (which is still very optional on Vulkan), yes, all render targets needed to have the same dimensions.
devshgraphicsprogramming commentedon Oct 28, 2019
Funny because they could be different size (the VkImages) in OpenGL since like 3.3 or something like that.
Or do you mean that the viewport has to be the same size?
litherum commentedon Oct 28, 2019
Discussed in the October 28th 2019 call https://docs.google.com/document/d/1vjEeT_CO2zlHZ2K5SiNMdROVDk6ag8skSgN-ZEO4evg/edit
litherum commentedon Feb 10, 2020
Turns out my analysis of Vulkan wasn't quite complete. I was right that GLSL has
subpassLoad(), but it turns out SPIR-V is more expressive than that. In SPIR-V, you can declare an image with dimensionSubpassData(as opposed to dimension2Dor3Dor whatever). Then, you can doOpImageReadto read from any position (!!) in the image. You can't write or sample from this image (or do anything else, AFAICT) because the image can't be aSampledImage; it can only be a raw image.Metal's Imageblocks only let you access the current block. You can't access arbitrary coordinates like you can in SPIR-V.
Kangz commentedon Feb 10, 2020
That's further constrained by the Vulkan execution environment for SPIR-V:
The intent in Vulkan was to allow filter size between subpasses but some hardware can't do it, so for input attachments require sampling at the exact current pixel location.
litherum commentedon Feb 10, 2020
Ugh having to cross-reference two separate specifications is so error-prone
litherum commentedon Feb 10, 2020
Why is SPIR-V more expressive, then? Which API supports both 1) subpasses and 2) reading from anythwere other then the current fragment location?
kvark commentedon Feb 10, 2020
Worth noting that Vulkan drivers appreciate if you specify the subpass dependency to be framebuffer-local (see https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#synchronization-framebuffer-regions), meaning that you can only read the same position as you are at (and the same sample if the input has exactly equal number of samples). So reading from any position has a cost.
litherum commentedon Feb 17, 2020
I just wrote a little sample Vulkan program that tests out
SubpassInputs. The values read from VulkanSubpassInputs are post-blending (meaning: the effects of blending are visible in the read data).I believe this is the opposite of the behavior of
[[color(n)]]in Metal, but I'll make a test app soon to make sure.devshgraphicsprogramming commentedon Feb 17, 2020
just a little heads up, vulkan subpass input can only be a floating point type (no idea what the prevision is XD)
12 remaining items
litherum commentedon Mar 23, 2020
@jdashg made a good comment about coming up with some measurements for rasterizer order groups on DX12 non-tiling GPUs to see how they compare to multiple render passes. The next step is for me to do that.
litherum commentedon Mar 23, 2020
Discussed on the 2020-03-23 call
Usability improvements for tree in standalone (gpuweb#435)
magcius commentedon Oct 29, 2025
Some updates to this for other platforms:
D3D12
D3D12 now has extended its render passes with "preserve local" modes; for each RTV/DSV, you specify begin/end flags that specify whether it will be used as rendering, SRV, or UAV. (I'm unclear exactly how to access the previous value in the buffer in PRESERVE_LOCAL_RENDER mode; while DXC has SubpassInput/SubpassLoad, it seems that's only for the SPIR-V backend); however, it is possible to render to an RT, then use this to access the previous value as an SRV, preserving contents in tile memory. In SRV and UAV mode, it also has a nifty AdditionalWidth/AdditionalHeight feature that lets future shaders access a border of pixels around the current fragment.
Vulkan
VK_KHR_dynamic_rendering_local_read is the replacement for Vulkan's subpasses in the new dynamic rendering system; it works by letting you do a special pipeline barrier inside the render pass. Shaders must still use
subpassInput/subpassLoadand friends. I can't find anything that lets you rebind the attachment as a SRV/UAV, nor any equivalent for the AdditionalWidth/AdditionalHeight feature.Kangz commentedon Jan 14, 2026
Closing in favor of new up to date investigations in the future for on-chip memory.
hoshinolina commentedon Jun 10, 2026
Is there a follow-up issue for this?
devshgraphicsprogramming commentedon Jun 10, 2026
no but Qualcomm landed an interesting new extension introducing a tile memory heap of about 4MB that lets you carve out a bit of on-chip memory for a regular VkBuffer or vkImage and not just have the framebuffer use all of it.
hoshinolina commentedon Jun 10, 2026
A qualcomm-specific extension seems... not that useful compared to something more general like subpasses. It's kind of sad that this was closed 7 years later with no resolution.