17ec681f3SmrgNIR Texture Instructions 27ec681f3Smrg======================== 37ec681f3Smrg 47ec681f3SmrgEven though texture instructions *could* be supported as intrinsics, the vast 57ec681f3Smrgnumber of combinations mean that doing so is practically impossible. Instead, 67ec681f3SmrgNIR has a dedicated texture instruction. There are several texture operations: 77ec681f3Smrg 87ec681f3Smrg.. doxygenenum:: nir_texop 97ec681f3Smrg 107ec681f3SmrgAs with other instruction types, there is still an array of sources, except 117ec681f3Smrgthat each source also has a *type* associated with it. There are various 127ec681f3Smrgsource types, each corresponding to a piece of information that the different 137ec681f3Smrgtexture operations require. 147ec681f3Smrg 157ec681f3Smrg.. doxygenenum:: nir_tex_src_type 167ec681f3Smrg 177ec681f3SmrgOf particular interest are the texture/sampler deref/index/handle source types. 187ec681f3SmrgFirst, note that textures and samplers are specified separately in NIR. While 197ec681f3Smrgnot required for OpenGL, this is required for Vulkan and OpenCL. Some 207ec681f3SmrgOpenGL [ES] drivers have to deal with hardware that does not have separate 217ec681f3Smrgsamplers and textures. While not recommended, an OpenGL-only driver may assume 227ec681f3Smrgthat the texture and sampler derefs will always point to the same resource, if 237ec681f3Smrgneeded. Note that this pretty well paints your compiler into a corner and 247ec681f3Smrgmakes any future port to Vulkan or OpenCL harder, so such assumptions should 257ec681f3Smrgreally only be made if targeting OpenGL ES 2.0 era hardware. 267ec681f3Smrg 277ec681f3SmrgAlso, like a lot of other resources, there are multiple ways to represent a 287ec681f3Smrgtexture in NIR. It can be referenced by a variable dereference, an index, or a 297ec681f3Smrgbindless handle. When using an index or a bindless handle, the texture type 307ec681f3Smrginformation is generally not available. To handle this, various information 317ec681f3Smrgfrom the type is redundantly stored in the :cpp:struct:`nir_tex_instr` itself. 327ec681f3Smrg 337ec681f3Smrg.. doxygenstruct:: nir_tex_instr 347ec681f3Smrg :members: 357ec681f3Smrg 367ec681f3Smrg.. doxygenstruct:: nir_tex_src 377ec681f3Smrg :members: 387ec681f3Smrg 397ec681f3SmrgTexture instruction helpers 407ec681f3Smrg--------------------------- 417ec681f3Smrg 427ec681f3SmrgThere are a number of helper functions for working with NIR texture 437ec681f3Smrginstructions. They are documented here in no particular order. 447ec681f3Smrg 457ec681f3Smrg.. doxygenfunction:: nir_tex_instr_create 467ec681f3Smrg.. doxygenfunction:: nir_tex_instr_need_sampler 477ec681f3Smrg.. doxygenfunction:: nir_tex_instr_result_size 487ec681f3Smrg.. doxygenfunction:: nir_tex_instr_dest_size 497ec681f3Smrg.. doxygenfunction:: nir_tex_instr_is_query 507ec681f3Smrg.. doxygenfunction:: nir_tex_instr_has_implicit_derivative 517ec681f3Smrg.. doxygenfunction:: nir_tex_instr_src_type 527ec681f3Smrg.. doxygenfunction:: nir_tex_instr_src_size 537ec681f3Smrg.. doxygenfunction:: nir_tex_instr_src_index 547ec681f3Smrg.. doxygenfunction:: nir_tex_instr_add_src 557ec681f3Smrg.. doxygenfunction:: nir_tex_instr_remove_src 567ec681f3Smrg 577ec681f3SmrgTexture instruction lowering 587ec681f3Smrg---------------------------- 597ec681f3Smrg 607ec681f3SmrgBecause most hardware only supports some subset of all possible GLSL/SPIR-V 617ec681f3Smrgtexture operations, NIR provides a quite powerful lowering pass which is able 627ec681f3Smrgto implement more complex texture operations in terms of simpler ones. 637ec681f3Smrg 647ec681f3Smrg.. doxygenfunction:: nir_lower_tex 657ec681f3Smrg.. doxygenstruct:: nir_lower_tex_options 667ec681f3Smrg :members: 677ec681f3Smrg.. doxygenenum:: nir_lower_tex_packing 68