1
votes

I'm using sparse textures with OpenGL 4.4 on Win8.1 latest NV driver as of the date of writing. Everything seems to work fine with regular copied into the committed regions. However when I try to do shader imageLoad/imageStore operations on a sparse texture (with mixed commited/uncommited regions) the texture gets messed up all over the place (values look chaotic or like random mem content).

The extension specs (https://www.opengl.org/registry/specs/ARB/sparse_texture.txt) state that all shader and client side read to uncomitted regions are undefined and write are discarded. However I cannot find any explicit mentions of imageLoad imageStore anywhere. It does mention FBO attachments though (which I want to avoid since I'm using compute shaders).

What's the proper behavior for sparse texture with regards to image load/store?

1

1 Answers

1
votes

"Writes to such regions are ignored. The GL may attempt to write to uncommitted regions but the effect of doing so will be benign."

Evidently the definition of "benign" is up for debate unless you are discussing imageLoad (...). Attempting to store something will not produce random garbage, but reading is very clearly undefined:

"Reads from such regions produce undefined data, but otherwise have no adverse effect."


I would like to take this opportunity to point out, however, that GL_ARB_sparse_texture is functionally incomplete. Many of these things that are undefined in that extension are properly handled given a pair of supplemental extensions.

Think of this like Direct3D 11.2's tiled resources - there are multiple tiers of support depending on hardware capabilities. The ARB extension you are working with here is the minimally functional tier and the more advanced tier is implemented through the following two extensions:

  1. GL_ARB_sparse_texture2
  2. GL_ARB_sparse_texture_clamp

The scenarios you are discussing have well-defined behavior if you read up on Extension #1.

Overview

This extension builds on the ARB_sparse_texture extension, providing the following new functionality:

  • New built-in GLSL texture lookup and image load functions are provided that return information on whether the texels accessed for the texture lookup accessed uncommitted texture memory.

  • New built-in GLSL texture lookup functions are provided that specify a minimum level of detail to use for lookups where the level of detail is computed automatically. This allows shaders to avoid accessing unpopulated portions of high-resolution levels of detail when it knows that the memory accessed is unpopulated, either from a priori knowledge or from feedback provided by the return value of previously executed "sparse" texture lookup functions.

  • Reads of uncommitted texture memory will act as though such memory were filled with zeroes; previously, the values returned by reads were undefined.

Extension #2 is probably of no interest to you since you are dealing with compute shaders.