• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1NIR Texture Instructions
2========================
3
4Even though texture instructions *could* be supported as intrinsics, the vast
5number of combinations mean that doing so is practically impossible. Instead,
6NIR has a dedicated texture instruction.  There are several texture operations:
7
8.. doxygenenum:: nir_texop
9
10As with other instruction types, there is still an array of sources, except
11that each source also has a *type* associated with it.  There are various
12source types, each corresponding to a piece of information that the different
13texture operations require.
14
15.. doxygenenum:: nir_tex_src_type
16
17Of particular interest are the texture/sampler deref/index/handle source types.
18First, note that textures and samplers are specified separately in NIR.  While
19not required for OpenGL, this is required for Vulkan and OpenCL.  Some
20OpenGL [ES] drivers have to deal with hardware that does not have separate
21samplers and textures.  While not recommended, an OpenGL-only driver may assume
22that the texture and sampler derefs will always point to the same resource, if
23needed.  Note that this pretty well paints your compiler into a corner and
24makes any future port to Vulkan or OpenCL harder, so such assumptions should
25really only be made if targeting OpenGL ES 2.0 era hardware.
26
27Also, like a lot of other resources, there are multiple ways to represent a
28texture in NIR. It can be referenced by a variable dereference, an index, or a
29bindless handle. When using an index or a bindless handle, the texture type
30information is generally not available.  To handle this, various information
31from the type is redundantly stored in the :cpp:struct:`nir_tex_instr` itself.
32
33.. doxygenstruct:: nir_tex_instr
34   :members:
35
36.. doxygenstruct:: nir_tex_src
37   :members:
38
39Texture instruction helpers
40---------------------------
41
42There are a number of helper functions for working with NIR texture
43instructions.  They are documented here in no particular order.
44
45.. doxygenfunction:: nir_tex_instr_create
46.. doxygenfunction:: nir_tex_instr_need_sampler
47.. doxygenfunction:: nir_tex_instr_result_size
48.. doxygenfunction:: nir_tex_instr_dest_size
49.. doxygenfunction:: nir_tex_instr_is_query
50.. doxygenfunction:: nir_tex_instr_has_implicit_derivative
51.. doxygenfunction:: nir_tex_instr_src_type
52.. doxygenfunction:: nir_tex_instr_src_size
53.. doxygenfunction:: nir_tex_instr_src_index
54.. doxygenfunction:: nir_tex_instr_add_src
55.. doxygenfunction:: nir_tex_instr_remove_src
56
57Texture instruction lowering
58----------------------------
59
60Because most hardware only supports some subset of all possible GLSL/SPIR-V
61texture operations, NIR provides a quite powerful lowering pass which is able
62to implement more complex texture operations in terms of simpler ones.
63
64.. doxygenfunction:: nir_lower_tex
65.. doxygenstruct:: nir_lower_tex_options
66   :members:
67.. doxygenenum:: nir_lower_tex_packing
68