1*61046927SAndroid Build Coastguard WorkerNIR Texture Instructions 2*61046927SAndroid Build Coastguard Worker======================== 3*61046927SAndroid Build Coastguard Worker 4*61046927SAndroid Build Coastguard WorkerEven though texture instructions *could* be supported as intrinsics, the vast 5*61046927SAndroid Build Coastguard Workernumber of combinations mean that doing so is practically impossible. Instead, 6*61046927SAndroid Build Coastguard WorkerNIR has a dedicated texture instruction. There are several texture operations: 7*61046927SAndroid Build Coastguard Worker 8*61046927SAndroid Build Coastguard Worker.. c:autoenum:: nir_texop 9*61046927SAndroid Build Coastguard Worker :file: src/compiler/nir/nir.h 10*61046927SAndroid Build Coastguard Worker :members: 11*61046927SAndroid Build Coastguard Worker 12*61046927SAndroid Build Coastguard WorkerAs with other instruction types, there is still an array of sources, except 13*61046927SAndroid Build Coastguard Workerthat each source also has a *type* associated with it. There are various 14*61046927SAndroid Build Coastguard Workersource types, each corresponding to a piece of information that the different 15*61046927SAndroid Build Coastguard Workertexture operations require. 16*61046927SAndroid Build Coastguard Worker 17*61046927SAndroid Build Coastguard Worker.. c:autoenum:: nir_tex_src_type 18*61046927SAndroid Build Coastguard Worker :members: 19*61046927SAndroid Build Coastguard Worker 20*61046927SAndroid Build Coastguard WorkerOf particular interest are the texture/sampler deref/index/handle source types. 21*61046927SAndroid Build Coastguard WorkerFirst, note that textures and samplers are specified separately in NIR. While 22*61046927SAndroid Build Coastguard Workernot required for OpenGL, this is required for Vulkan and OpenCL. Some 23*61046927SAndroid Build Coastguard WorkerOpenGL [ES] drivers have to deal with hardware that does not have separate 24*61046927SAndroid Build Coastguard Workersamplers and textures. While not recommended, an OpenGL-only driver may assume 25*61046927SAndroid Build Coastguard Workerthat the texture and sampler derefs will always point to the same resource, if 26*61046927SAndroid Build Coastguard Workerneeded. Note that this pretty well paints your compiler into a corner and 27*61046927SAndroid Build Coastguard Workermakes any future port to Vulkan or OpenCL harder, so such assumptions should 28*61046927SAndroid Build Coastguard Workerreally only be made if targeting OpenGL ES 2.0 era hardware. 29*61046927SAndroid Build Coastguard Worker 30*61046927SAndroid Build Coastguard WorkerAlso, like a lot of other resources, there are multiple ways to represent a 31*61046927SAndroid Build Coastguard Workertexture in NIR. It can be referenced by a variable dereference, an index, or a 32*61046927SAndroid Build Coastguard Workerbindless handle. When using an index or a bindless handle, the texture type 33*61046927SAndroid Build Coastguard Workerinformation is generally not available. To handle this, various information 34*61046927SAndroid Build Coastguard Workerfrom the type is redundantly stored in the :c:struct:`nir_tex_instr` itself. 35*61046927SAndroid Build Coastguard Worker 36*61046927SAndroid Build Coastguard Worker.. c:autostruct:: nir_tex_instr 37*61046927SAndroid Build Coastguard Worker :members: 38*61046927SAndroid Build Coastguard Worker 39*61046927SAndroid Build Coastguard Worker.. c:autostruct:: nir_tex_src 40*61046927SAndroid Build Coastguard Worker :members: 41*61046927SAndroid Build Coastguard Worker 42*61046927SAndroid Build Coastguard WorkerTexture instruction helpers 43*61046927SAndroid Build Coastguard Worker--------------------------- 44*61046927SAndroid Build Coastguard Worker 45*61046927SAndroid Build Coastguard WorkerThere are a number of helper functions for working with NIR texture 46*61046927SAndroid Build Coastguard Workerinstructions. They are documented here in no particular order. 47*61046927SAndroid Build Coastguard Worker 48*61046927SAndroid Build Coastguard Worker.. c:autofunction:: nir_tex_instr_create 49*61046927SAndroid Build Coastguard Worker 50*61046927SAndroid Build Coastguard Worker.. c:autofunction:: nir_tex_instr_need_sampler 51*61046927SAndroid Build Coastguard Worker 52*61046927SAndroid Build Coastguard Worker.. c:autofunction:: nir_tex_instr_result_size 53*61046927SAndroid Build Coastguard Worker 54*61046927SAndroid Build Coastguard Worker.. c:autofunction:: nir_tex_instr_dest_size 55*61046927SAndroid Build Coastguard Worker 56*61046927SAndroid Build Coastguard Worker.. c:autofunction:: nir_tex_instr_is_query 57*61046927SAndroid Build Coastguard Worker 58*61046927SAndroid Build Coastguard Worker.. c:autofunction:: nir_tex_instr_has_implicit_derivative 59*61046927SAndroid Build Coastguard Worker 60*61046927SAndroid Build Coastguard Worker.. c:autofunction:: nir_tex_instr_src_type 61*61046927SAndroid Build Coastguard Worker 62*61046927SAndroid Build Coastguard Worker.. c:autofunction:: nir_tex_instr_src_size 63*61046927SAndroid Build Coastguard Worker 64*61046927SAndroid Build Coastguard Worker.. c:autofunction:: nir_tex_instr_src_index 65*61046927SAndroid Build Coastguard Worker 66*61046927SAndroid Build Coastguard Worker.. c:autofunction:: nir_tex_instr_add_src 67*61046927SAndroid Build Coastguard Worker 68*61046927SAndroid Build Coastguard Worker.. c:autofunction:: nir_tex_instr_remove_src 69*61046927SAndroid Build Coastguard Worker 70*61046927SAndroid Build Coastguard WorkerTexture instruction lowering 71*61046927SAndroid Build Coastguard Worker---------------------------- 72*61046927SAndroid Build Coastguard Worker 73*61046927SAndroid Build Coastguard WorkerBecause most hardware only supports some subset of all possible GLSL/SPIR-V 74*61046927SAndroid Build Coastguard Workertexture operations, NIR provides a quite powerful lowering pass which is able 75*61046927SAndroid Build Coastguard Workerto implement more complex texture operations in terms of simpler ones. 76*61046927SAndroid Build Coastguard Worker 77*61046927SAndroid Build Coastguard Worker.. c:autofunction:: nir_lower_tex 78*61046927SAndroid Build Coastguard Worker 79*61046927SAndroid Build Coastguard Worker.. c:autostruct:: nir_lower_tex_options 80*61046927SAndroid Build Coastguard Worker :members: 81*61046927SAndroid Build Coastguard Worker 82*61046927SAndroid Build Coastguard Worker.. c:autoenum:: nir_lower_tex_packing 83*61046927SAndroid Build Coastguard Worker :members: 84