xref: /aosp_15_r20/external/mesa3d/docs/gallium/resources.rst (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1*61046927SAndroid Build Coastguard Worker.. _resource:
2*61046927SAndroid Build Coastguard Worker
3*61046927SAndroid Build Coastguard WorkerResources and derived objects
4*61046927SAndroid Build Coastguard Worker=============================
5*61046927SAndroid Build Coastguard Worker
6*61046927SAndroid Build Coastguard WorkerResources represent objects that hold data: textures and buffers.
7*61046927SAndroid Build Coastguard Worker
8*61046927SAndroid Build Coastguard WorkerThey are mostly modelled after the resources in Direct3D 10/11, but with a
9*61046927SAndroid Build Coastguard Workerdifferent transfer/update mechanism, and more features for OpenGL support.
10*61046927SAndroid Build Coastguard Worker
11*61046927SAndroid Build Coastguard WorkerResources can be used in several ways, and it is required to specify all planned uses through an appropriate set of bind flags.
12*61046927SAndroid Build Coastguard Worker
13*61046927SAndroid Build Coastguard WorkerTODO: write much more on resources
14*61046927SAndroid Build Coastguard Worker
15*61046927SAndroid Build Coastguard WorkerTransfers
16*61046927SAndroid Build Coastguard Worker---------
17*61046927SAndroid Build Coastguard Worker
18*61046927SAndroid Build Coastguard WorkerTransfers are the mechanism used to access resources with the CPU.
19*61046927SAndroid Build Coastguard Worker
20*61046927SAndroid Build Coastguard WorkerOpenGL: OpenGL supports mapping buffers and has inline transfer functions for both buffers and textures
21*61046927SAndroid Build Coastguard Worker
22*61046927SAndroid Build Coastguard WorkerD3D11: D3D11 lacks transfers, but has special resource types that are mappable to the CPU address space
23*61046927SAndroid Build Coastguard Worker
24*61046927SAndroid Build Coastguard WorkerTODO: write much more on transfers
25*61046927SAndroid Build Coastguard Worker
26*61046927SAndroid Build Coastguard WorkerResource targets
27*61046927SAndroid Build Coastguard Worker----------------
28*61046927SAndroid Build Coastguard Worker
29*61046927SAndroid Build Coastguard WorkerResource targets determine the type of a resource.
30*61046927SAndroid Build Coastguard Worker
31*61046927SAndroid Build Coastguard WorkerNote that drivers may not actually have the restrictions listed regarding
32*61046927SAndroid Build Coastguard Workercoordinate normalization and wrap modes, and in fact efficient OpenCL
33*61046927SAndroid Build Coastguard Workersupport will probably require drivers that don't have any of them, which
34*61046927SAndroid Build Coastguard Workerwill probably be advertised with an appropriate cap.
35*61046927SAndroid Build Coastguard Worker
36*61046927SAndroid Build Coastguard WorkerTODO: document all targets. Note that both 3D and cube have restrictions
37*61046927SAndroid Build Coastguard Workerthat depend on the hardware generation.
38*61046927SAndroid Build Coastguard Worker
39*61046927SAndroid Build Coastguard Worker
40*61046927SAndroid Build Coastguard WorkerPIPE_BUFFER
41*61046927SAndroid Build Coastguard Worker^^^^^^^^^^^
42*61046927SAndroid Build Coastguard Worker
43*61046927SAndroid Build Coastguard WorkerBuffer resource: can be used as a vertex, index, constant buffer
44*61046927SAndroid Build Coastguard Worker(appropriate bind flags must be requested).
45*61046927SAndroid Build Coastguard Worker
46*61046927SAndroid Build Coastguard WorkerBuffers do not really have a format, it's just bytes, but they are required
47*61046927SAndroid Build Coastguard Workerto have their type set to a R8 format (without a specific "just byte" format,
48*61046927SAndroid Build Coastguard WorkerR8_UINT would probably make the most sense, but for historic reasons R8_UNORM
49*61046927SAndroid Build Coastguard Workeris OK too). (This is just to make some shared buffer/texture code easier so
50*61046927SAndroid Build Coastguard Workerformat size can be queried.)
51*61046927SAndroid Build Coastguard Workerwidth0 serves as size, most other resource properties don't apply but must be
52*61046927SAndroid Build Coastguard Workerset appropriately (depth0/height0/array_size must be 1, last_level 0).
53*61046927SAndroid Build Coastguard Worker
54*61046927SAndroid Build Coastguard WorkerThey can be bound to stream output if supported.
55*61046927SAndroid Build Coastguard WorkerTODO: what about the restrictions lifted by the several later GL transform feedback extensions? How does one advertise that in Gallium?
56*61046927SAndroid Build Coastguard Worker
57*61046927SAndroid Build Coastguard WorkerThey can be also be bound to a shader stage (for sampling) as usual by
58*61046927SAndroid Build Coastguard Workercreating an appropriate sampler view, if the driver supports PIPE_CAP_TEXTURE_BUFFER_OBJECTS.
59*61046927SAndroid Build Coastguard WorkerThis supports larger width than a 1d texture would
60*61046927SAndroid Build Coastguard Worker(TODO limit currently unspecified, minimum must be at least 65536).
61*61046927SAndroid Build Coastguard WorkerOnly the "direct fetch" sample opcodes are supported (TGSI_OPCODE_TXF,
62*61046927SAndroid Build Coastguard WorkerTGSI_OPCODE_SAMPLE_I) so the sampler state (coord wrapping etc.)
63*61046927SAndroid Build Coastguard Workeris mostly ignored (with SAMPLE_I there's no sampler state at all).
64*61046927SAndroid Build Coastguard Worker
65*61046927SAndroid Build Coastguard WorkerThey can be also be bound to the framebuffer (only as color render target, not
66*61046927SAndroid Build Coastguard Workerdepth buffer, also there cannot be a depth buffer bound at the same time) as usual
67*61046927SAndroid Build Coastguard Workerby creating an appropriate view (this is not usable in OpenGL).
68*61046927SAndroid Build Coastguard WorkerTODO there's no CAP bit currently for this, there's also unspecified size etc. limits
69*61046927SAndroid Build Coastguard WorkerTODO: is there any chance of supporting GL pixel buffer object acceleration with this?
70*61046927SAndroid Build Coastguard Worker
71*61046927SAndroid Build Coastguard Worker
72*61046927SAndroid Build Coastguard WorkerOpenGL: vertex buffers in GL 1.5 or :ext:`GL_ARB_vertex_buffer_object`
73*61046927SAndroid Build Coastguard Worker
74*61046927SAndroid Build Coastguard Worker- Binding to stream out requires GL 3.0 or :ext:`GL_NV_transform_feedback`
75*61046927SAndroid Build Coastguard Worker- Binding as constant buffers requires GL 3.1 or :ext:`GL_ARB_uniform_buffer_object`
76*61046927SAndroid Build Coastguard Worker- Binding to a sampling stage requires GL 3.1 or :ext:`GL_ARB_texture_buffer_object`
77*61046927SAndroid Build Coastguard Worker
78*61046927SAndroid Build Coastguard WorkerD3D11: buffer resources
79*61046927SAndroid Build Coastguard Worker- Binding to a render target requires D3D_FEATURE_LEVEL_10_0
80*61046927SAndroid Build Coastguard Worker
81*61046927SAndroid Build Coastguard WorkerPIPE_TEXTURE_1D / PIPE_TEXTURE_1D_ARRAY
82*61046927SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
83*61046927SAndroid Build Coastguard Worker1D surface accessed with normalized coordinates.
84*61046927SAndroid Build Coastguard Worker1D array textures are supported depending on PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS.
85*61046927SAndroid Build Coastguard Worker
86*61046927SAndroid Build Coastguard Worker- If PIPE_CAP_NPOT_TEXTURES is not supported,
87*61046927SAndroid Build Coastguard Worker      width must be a power of two
88*61046927SAndroid Build Coastguard Worker- height0 must be 1
89*61046927SAndroid Build Coastguard Worker- depth0 must be 1
90*61046927SAndroid Build Coastguard Worker- array_size must be 1 for PIPE_TEXTURE_1D
91*61046927SAndroid Build Coastguard Worker- Mipmaps can be used
92*61046927SAndroid Build Coastguard Worker- Must use normalized coordinates
93*61046927SAndroid Build Coastguard Worker
94*61046927SAndroid Build Coastguard WorkerOpenGL: GL_TEXTURE_1D in GL 1.0
95*61046927SAndroid Build Coastguard Worker
96*61046927SAndroid Build Coastguard Worker- PIPE_CAP_NPOT_TEXTURES is equivalent to GL 2.0 or :ext:`GL_ARB_texture_non_power_of_two`
97*61046927SAndroid Build Coastguard Worker
98*61046927SAndroid Build Coastguard WorkerD3D11: 1D textures in D3D_FEATURE_LEVEL_10_0
99*61046927SAndroid Build Coastguard Worker
100*61046927SAndroid Build Coastguard WorkerPIPE_TEXTURE_RECT
101*61046927SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^
102*61046927SAndroid Build Coastguard Worker2D surface with OpenGL GL_TEXTURE_RECTANGLE semantics.
103*61046927SAndroid Build Coastguard Worker
104*61046927SAndroid Build Coastguard Worker- depth0 must be 1
105*61046927SAndroid Build Coastguard Worker- array_size must be 1
106*61046927SAndroid Build Coastguard Worker- last_level must be 0
107*61046927SAndroid Build Coastguard Worker- Must use unnormalized coordinates
108*61046927SAndroid Build Coastguard Worker- Must use a clamp wrap mode
109*61046927SAndroid Build Coastguard Worker
110*61046927SAndroid Build Coastguard WorkerOpenGL: GL_TEXTURE_RECTANGLE in GL 3.1 or :ext:`GL_ARB_texture_rectangle` or
111*61046927SAndroid Build Coastguard Worker:ext:`GL_NV_texture_rectangle`
112*61046927SAndroid Build Coastguard Worker
113*61046927SAndroid Build Coastguard WorkerOpenCL: can create OpenCL images based on this, that can then be sampled arbitrarily
114*61046927SAndroid Build Coastguard Worker
115*61046927SAndroid Build Coastguard WorkerD3D11: not supported (only PIPE_TEXTURE_2D with normalized coordinates is supported)
116*61046927SAndroid Build Coastguard Worker
117*61046927SAndroid Build Coastguard WorkerPIPE_TEXTURE_2D / PIPE_TEXTURE_2D_ARRAY
118*61046927SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
119*61046927SAndroid Build Coastguard Worker2D surface accessed with normalized coordinates.
120*61046927SAndroid Build Coastguard Worker2D array textures are supported depending on PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS.
121*61046927SAndroid Build Coastguard Worker
122*61046927SAndroid Build Coastguard Worker- If PIPE_CAP_NPOT_TEXTURES is not supported,
123*61046927SAndroid Build Coastguard Worker      width and height must be powers of two
124*61046927SAndroid Build Coastguard Worker- depth0 must be 1
125*61046927SAndroid Build Coastguard Worker- array_size must be 1 for PIPE_TEXTURE_2D
126*61046927SAndroid Build Coastguard Worker- Mipmaps can be used
127*61046927SAndroid Build Coastguard Worker- Must use normalized coordinates
128*61046927SAndroid Build Coastguard Worker- No special restrictions on wrap modes
129*61046927SAndroid Build Coastguard Worker
130*61046927SAndroid Build Coastguard WorkerOpenGL: GL_TEXTURE_2D in GL 1.0
131*61046927SAndroid Build Coastguard Worker
132*61046927SAndroid Build Coastguard Worker- PIPE_CAP_NPOT_TEXTURES is equivalent to GL 2.0 or :ext:`GL_ARB_texture_non_power_of_two`
133*61046927SAndroid Build Coastguard Worker
134*61046927SAndroid Build Coastguard WorkerOpenCL: can create OpenCL images based on this, that can then be sampled arbitrarily
135*61046927SAndroid Build Coastguard Worker
136*61046927SAndroid Build Coastguard WorkerD3D11: 2D textures
137*61046927SAndroid Build Coastguard Worker
138*61046927SAndroid Build Coastguard Worker- PIPE_CAP_NPOT_TEXTURES is equivalent to D3D_FEATURE_LEVEL_9_3
139*61046927SAndroid Build Coastguard Worker
140*61046927SAndroid Build Coastguard WorkerPIPE_TEXTURE_3D
141*61046927SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^
142*61046927SAndroid Build Coastguard Worker
143*61046927SAndroid Build Coastguard Worker3-dimensional array of texels.
144*61046927SAndroid Build Coastguard WorkerMipmap dimensions are reduced in all 3 coordinates.
145*61046927SAndroid Build Coastguard Worker
146*61046927SAndroid Build Coastguard Worker- If PIPE_CAP_NPOT_TEXTURES is not supported,
147*61046927SAndroid Build Coastguard Worker      width, height and depth must be powers of two
148*61046927SAndroid Build Coastguard Worker- array_size must be 1
149*61046927SAndroid Build Coastguard Worker- Must use normalized coordinates
150*61046927SAndroid Build Coastguard Worker
151*61046927SAndroid Build Coastguard WorkerOpenGL: GL_TEXTURE_3D in GL 1.2 or :ext:`GL_EXT_texture3D`
152*61046927SAndroid Build Coastguard Worker
153*61046927SAndroid Build Coastguard Worker- PIPE_CAP_NPOT_TEXTURES is equivalent to GL 2.0 or :ext:`GL_ARB_texture_non_power_of_two`
154*61046927SAndroid Build Coastguard Worker
155*61046927SAndroid Build Coastguard WorkerD3D11: 3D textures
156*61046927SAndroid Build Coastguard Worker
157*61046927SAndroid Build Coastguard Worker- PIPE_CAP_NPOT_TEXTURES is equivalent to D3D_FEATURE_LEVEL_10_0
158*61046927SAndroid Build Coastguard Worker
159*61046927SAndroid Build Coastguard WorkerPIPE_TEXTURE_CUBE / PIPE_TEXTURE_CUBE_ARRAY
160*61046927SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
161*61046927SAndroid Build Coastguard Worker
162*61046927SAndroid Build Coastguard WorkerCube maps consist of 6 2D faces.
163*61046927SAndroid Build Coastguard WorkerThe 6 surfaces form an imaginary cube, and sampling happens by mapping an
164*61046927SAndroid Build Coastguard Workerinput 3-vector to the point of the cube surface in that direction.
165*61046927SAndroid Build Coastguard WorkerCube map arrays are supported depending on PIPE_CAP_CUBE_MAP_ARRAY.
166*61046927SAndroid Build Coastguard Worker
167*61046927SAndroid Build Coastguard WorkerSampling may be optionally seamless if a driver supports it (PIPE_CAP_SEAMLESS_CUBE_MAP),
168*61046927SAndroid Build Coastguard Workerresulting in filtering taking samples from multiple surfaces near to the edge.
169*61046927SAndroid Build Coastguard Worker
170*61046927SAndroid Build Coastguard Worker- Width and height must be equal
171*61046927SAndroid Build Coastguard Worker- depth0 must be 1
172*61046927SAndroid Build Coastguard Worker- array_size must be a multiple of 6
173*61046927SAndroid Build Coastguard Worker- If PIPE_CAP_NPOT_TEXTURES is not supported,
174*61046927SAndroid Build Coastguard Worker      width and height must be powers of two
175*61046927SAndroid Build Coastguard Worker- Must use normalized coordinates
176*61046927SAndroid Build Coastguard Worker
177*61046927SAndroid Build Coastguard WorkerOpenGL: GL_TEXTURE_CUBE_MAP in GL 1.3 or :ext:`GL_EXT_texture_cube_map`
178*61046927SAndroid Build Coastguard Worker
179*61046927SAndroid Build Coastguard Worker- PIPE_CAP_NPOT_TEXTURES is equivalent to GL 2.0 or :ext:`GL_ARB_texture_non_power_of_two`
180*61046927SAndroid Build Coastguard Worker- Seamless cube maps require GL 3.2 or :ext:`GL_ARB_seamless_cube_map` or :ext:`GL_AMD_seamless_cubemap_per_texture`
181*61046927SAndroid Build Coastguard Worker- Cube map arrays require GL 4.0 or :ext:`GL_ARB_texture_cube_map_array`
182*61046927SAndroid Build Coastguard Worker
183*61046927SAndroid Build Coastguard WorkerD3D11: 2D array textures with the D3D11_RESOURCE_MISC_TEXTURECUBE flag
184*61046927SAndroid Build Coastguard Worker
185*61046927SAndroid Build Coastguard Worker- PIPE_CAP_NPOT_TEXTURES is equivalent to D3D_FEATURE_LEVEL_10_0
186*61046927SAndroid Build Coastguard Worker- Cube map arrays require D3D_FEATURE_LEVEL_10_1
187*61046927SAndroid Build Coastguard Worker
188*61046927SAndroid Build Coastguard WorkerSurfaces
189*61046927SAndroid Build Coastguard Worker--------
190*61046927SAndroid Build Coastguard Worker
191*61046927SAndroid Build Coastguard WorkerSurfaces are views of a resource that can be bound as a framebuffer to serve as the render target or depth buffer.
192*61046927SAndroid Build Coastguard Worker
193*61046927SAndroid Build Coastguard WorkerTODO: write much more on surfaces
194*61046927SAndroid Build Coastguard Worker
195*61046927SAndroid Build Coastguard WorkerOpenGL: FBOs are collections of surfaces in GL 3.0 or :ext:`GL_ARB_framebuffer_object`
196*61046927SAndroid Build Coastguard Worker
197*61046927SAndroid Build Coastguard WorkerD3D11: render target views and depth/stencil views
198*61046927SAndroid Build Coastguard Worker
199*61046927SAndroid Build Coastguard WorkerSampler views
200*61046927SAndroid Build Coastguard Worker-------------
201*61046927SAndroid Build Coastguard Worker
202*61046927SAndroid Build Coastguard WorkerSampler views are views of a resource that can be bound to a pipeline stage to be sampled from shaders.
203*61046927SAndroid Build Coastguard Worker
204*61046927SAndroid Build Coastguard WorkerTODO: write much more on sampler views
205*61046927SAndroid Build Coastguard Worker
206*61046927SAndroid Build Coastguard WorkerOpenGL: texture objects are actually sampler view and resource in a single unit
207*61046927SAndroid Build Coastguard Worker
208*61046927SAndroid Build Coastguard WorkerD3D11: shader resource views
209