Search

A technology, a device or an article

GPU hasn’t responded yet: why does the occlusion query take time?

An occlusion result exists after command recording. Availability, age and a correct bounding shape determine when it can justify culling.

A red sphere partly hidden by cardboard walls in a miniature theatre
ITNWS AI-generated conceptual illustration. The theatre screen evokes an occlusion test; this is not an image from a game benchmark.ITNWS · image_gen · Original ITNWS AI-generated conceptual editorial illustration

A scene contains a courtyard behind a high wall. The CPU has already reached the point of deciding whether to send the courtyard’s detailed geometry for the next frame, and the GPU is still busy with commands that will allow you to determine whether even the edge of the courtyard is visible. For the application, the question is simple: “draw?” The answer depends on the work ahead in the execution queue. If you immediately request it back, the processor may stall waiting. If you continue without it, you will have to make a decision with incomplete knowledge. This begins a useful conversation about occlusion queries: from the moment when the result is needed, and the moment when it exists.

The courtyard and wall are hypothetical. We didn’t run the game, measure frame rates, or compare video cards. They help to look at the Vulkan interface, where an occlusion query tracks samples that pass the provided fragment tests for the covered drawing commands. This is not a query of the final rendered image and not the ability of the GPU to look ahead at the future result. The basis of the response is created by executing graphical commands. Documentation Vulkan Queries reviewed October 31, 2026; subsequent conclusions about application decisions are an analysis of this contract.

The app can draw a simplified bounding shape instead of an expensive yard and see if its samples pass the depth test against a pre-prepared wall. But the shape and pipeline states themselves become part of the issue. If the shell does not cover all possible geometry, its disappearance does not prove the disappearance of the courtyard. If a test accidentally records depth or color, observation can change what it was only intended to examine. Therefore, saving begins with the right substitute question: cheap enough to ask, and careful enough not to throw away what is visible.

The answer does not exist yet

The CPU writes the start and end of the request to the command buffer. Between them are drawing commands whose passing samples must be counted. However, writing commands is not the same as executing them. Even sending a buffer to the queue does not mean that the GPU has already passed the corresponding place. The logical completion of a request in the source program and the readiness of the result in time are different events. An interface error occurs when a developer treats a familiar begin/end pair as a synchronous call to a regular function with a return value already computed. The graphics queue does not make such a promise.

When reading via vkGetQueryPoolResults, you can request a wait using VK_QUERY_RESULT_WAIT_BIT. Then the application consciously agrees to wait for the desired state. Without this flag, VK_NOT_READY is possible if some of the requested results are not yet available. Function reference separately describes readiness, data format, and synchronization conditions. An unavailable response must not be encoded as zero visibility. Zero already claims that suitable samples failed; inaccessibility means that complete evidence is not yet available. Substitution can remove an object precisely when the system was simply working asynchronously.

The WITH_AVAILABILITY flag allows you to obtain an availability indicator along with the data, but does not make the calculation instantaneous. It adds information about the state of the response. The application still needs to know which buffer locations contain the value and the availability flag, the result width, and the stride between records. An incorrectly read adjacent element is capable of looking like a plausible visibility result. Here the binary interface is no less important than the graphical design: a convincing screen does not prove that the program used exactly the result that it intended to read.

The possibility of partial results also requires caution. A positive intermediate counter already indicates that some samples have passed. A zero intermediate value does not prove definitive absence: the rest of the work may not have been completed yet. And availability is reported by a separate property – the completeness of the corresponding request. For an object exclusion algorithm, such asymmetry is significant. Erring on the side of unnecessary drawing usually costs work; false culling changes the image. This is an engineering reasoning about the chosen task, and not a universal rule for the admissibility of all partial reading options.

If the CPU polls for readiness in a tight loop, it doesn’t necessarily help the GPU finish faster. It may merely spend time repeating the question while the dependency remains the same. Waiting can reduce the useful overlap between the two processors. Therefore, the number of queries and individual read speed say little about the overall benefit. You need to understand what the application would have done during this period and what work actually disappeared due to the response. Without this, "throwing away the invisible" may be a more expensive way to produce the same frame.

Yesterday’s knowledge in today’s scene

A common solution is to use an earlier result while the GPU prepares a new one. Then the application is freed from immediate dependence, but acquires a dependency on the age of the data. In our yard, the camera could move over the edge of the wall. The old zero correctly described the previous angle and is no longer a sufficient reason to remove the new visible part. Visibility depends on camera, objects, depth and test conditions. It is not enough to associate the result only with the name of the object: it also has a history of the conditions in which the question was asked.

Therefore, the algorithm may temporarily draw an object under uncertainty, expand the shell being tested, or reset confidence after significant movement. The specific policy depends on the margin of error and the structure of the scene. The historical result is useful as a prediction when the consistency of conditions is preserved; it does not become a guarantee of a future image. It is important not to pass off such temporal heuristics as an exact property of the hardware request. The query itself could work perfectly correctly while the application incorrectly carried its response to the next frame.

Coral chalk outlines of overlapping dark shapes with a displaced faint outline
ITNWS AI-generated conceptual illustration. The displaced trace evokes visibility knowledge becoming stale after motion; it encodes no measurements. — ITNWS · image_gen · Original ITNWS AI-generated conceptual editorial illustration

Even a stationary camera does not ensure the eternal truth of the answer. A wall could disappear, a door could open, or the geometry could change. The animation of the courtyard is able to go beyond the previous shell. A transparent material does not necessarily follow the same overlap logic as an opaque material. All this belongs to the scene model, which the hardware counter does not know. The developer chooses which changes invalidate previous knowledge. The cheaper this decision, the more attractive the approach; the more difficult it is to maintain the correct shell and history, the more work the promised savings eat up.

One large check for a group of objects changes the granularity of knowledge. A non-zero result for the shell of an entire block does not mean that every yard in it is visible. A zero result of a correctly constructed enclosing form under suitable conditions may allow the entire group to be rejected. This asymmetry makes the hierarchy attractive, but not free: additional tests require their own drawing commands and require management of the results. The optimal separation depends on the scene. The number of tree nodes without their execution price does not allow you to promise a speedup to a specific video card or engine.

Reusing the query pool adds another timing trap. As long as the recorded reset command is not executed by the GPU, the old request may remain marked as available. The CPU reads readiness and obtains the old value, although its new command record already provides for a completely different question. The Vulkan manual explicitly warns of this possibility. Having WAIT_BIT is not a spell against an old generation of data. It is necessary to prove that the reset for the intended use actually took place, and to associate what was read with the correct operation, and not just with the correct index.

Separate sets of queries for concurrently processed frames help express the lifetime of the data. But the number of sets should not be prescribed ritually. It is determined by when the application stops reading the previous result and when it is free to start a new write to the corresponding slot. One successful demonstration with a small queue is not enough to prove it with a different depth of execution. Synchronization with a fence or other provided mechanism establishes the fact of execution. The name "frame number such and such" remains a convention of the program until it associates it with the actual history of the GPU.

What exactly is calculated

For a simple culling decision, the difference between zero and non-zero results is sufficient. Without VK_QUERY_CONTROL_PRECISE_BIT, an implementation has the freedom to report a non-zero value instead of the exact number of samples passed. Therefore, it is impossible to turn such a result into a “percentage of object visibility”. Even the exact counter refers to samples of the corresponding commands and tests. It does not measure the area of the usable image in human terms, the number of triangles visible, or the percentage of time actually saved. Each of these statements would require a different definition and additional data.

Precise mode requires support for occlusionQueryPrecise, described in VkPhysicalDeviceFeatures, and the corresponding feature enablement. But the word precise also does not promise the same sample count for all implementations and configurations. The specification indicates the reasons for the differences. To exclude geometry, it is primarily important how a valid zero is interpreted by the selected test. Demanding a larger number of digits or an accurate count for the sake of a beautiful dashboard can be pointless if the solution only uses the fact of passing at least one sample.

The order of drawing changes the meaning of observation. If the wall is not yet in the correct depth buffer, the courtyard shell may pass the test, although it will be covered by later commands in the final image. This is not a lie from the counter: it responded according to the state during execution. Waiting for it to be ready does not correct an incorrectly asked graphical question. Synchronization tells when the result is finished; the setting of the scene determines what it meant. Both parts are needed. Getting a response in a timely manner is not enough if the basis of the question was not consistent with the decision the application was about to make in the first place.

The width of the integer result and overflow handling are important if the program is actually going to parse a count rather than a boolean attribute. Similarly, copying results to the GPU buffer requires synchronizing subsequent access to them. This material does not automatically suggest that an occlusion query be considered a conditional drawing mechanism: the retrieval of data and the command that uses it to manipulate it have separate interfaces. The engine can leave the decision to the GPU or return it to the CPU, but this does not change the time it takes to produce the response, its validity period, and the correct data area.

The practical cost of a request consists of additional drawing, slot management, possible waiting, and remaining work after the decision. If an expensive courtyard is almost always visible, an inspection may not remove much. If a large fixed wall is hiding a lot of complex geometry, asking the right question early can be helpful. These are hypothetical workload properties, not measured editorial results. Choosing a method based on one technology name means leaving out exactly the scene for which it was added. You should check the finished image and the time it was received.

A decision is still needed at the edge of the wall. The current request will be completed later, the previous one is already starting to get old. A well-organized GPU workload makes that gap explicit: which response belongs to which scene and what the application does while the answer is unavailable. The query helps when its answer removes enough work and arrives before the decision is needed. If everything else must stop to obtain it, the cost of the answer becomes part of the visibility of the yard – although there is not a single field for it in the counter itself.

Sources & documentation

  1. Vulkan queries specification ↗
  2. Vulkan vkGetQueryPoolResults reference ↗
  3. Vulkan VkPhysicalDeviceFeatures ↗