2 * Mesa 3-D graphics library
4 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
29 #include "main/mtypes.h"
32 * \name Flags for meta operations
35 * These flags are passed to _mesa_meta_begin().
37 #define MESA_META_ALL ~0x0
38 #define MESA_META_ALPHA_TEST 0x1
39 #define MESA_META_BLEND 0x2 /**< includes logicop */
40 #define MESA_META_COLOR_MASK 0x4
41 #define MESA_META_DEPTH_TEST 0x8
42 #define MESA_META_FOG 0x10
43 #define MESA_META_PIXEL_STORE 0x20
44 #define MESA_META_PIXEL_TRANSFER 0x40
45 #define MESA_META_RASTERIZATION 0x80
46 #define MESA_META_SCISSOR 0x100
47 #define MESA_META_SHADER 0x200
48 #define MESA_META_STENCIL_TEST 0x400
49 #define MESA_META_TRANSFORM 0x800 /**< modelview/projection matrix state */
50 #define MESA_META_TEXTURE 0x1000
51 #define MESA_META_VERTEX 0x2000
52 #define MESA_META_VIEWPORT 0x4000
53 #define MESA_META_CLAMP_FRAGMENT_COLOR 0x8000
54 #define MESA_META_CLAMP_VERTEX_COLOR 0x10000
55 #define MESA_META_CONDITIONAL_RENDER 0x20000
56 #define MESA_META_CLIP 0x40000
57 #define MESA_META_SELECT_FEEDBACK 0x80000
58 #define MESA_META_MULTISAMPLE 0x100000
59 #define MESA_META_FRAMEBUFFER_SRGB 0x200000
60 #define MESA_META_OCCLUSION_QUERY 0x400000
61 #define MESA_META_DRAW_BUFFERS 0x800000
62 #define MESA_META_DITHER 0x1000000
66 * State which we may save/restore across meta ops.
67 * XXX this may be incomplete...
71 GLbitfield SavedState
; /**< bitmask of MESA_META_* flags */
73 /* Always saved/restored with meta. */
76 /** MESA_META_CLEAR (and others?) */
77 struct gl_query_object
*CurrentOcclusionObject
;
79 /** MESA_META_ALPHA_TEST */
80 GLboolean AlphaEnabled
;
84 /** MESA_META_BLEND */
85 GLbitfield BlendEnabled
;
86 GLboolean ColorLogicOpEnabled
;
88 /** MESA_META_DITHER */
91 /** MESA_META_COLOR_MASK */
92 GLubyte ColorMask
[MAX_DRAW_BUFFERS
][4];
94 /** MESA_META_DEPTH_TEST */
95 struct gl_depthbuffer_attrib Depth
;
100 /** MESA_META_PIXEL_STORE */
101 struct gl_pixelstore_attrib Pack
, Unpack
;
103 /** MESA_META_PIXEL_TRANSFER */
104 GLfloat RedBias
, RedScale
;
105 GLfloat GreenBias
, GreenScale
;
106 GLfloat BlueBias
, BlueScale
;
107 GLfloat AlphaBias
, AlphaScale
;
108 GLfloat DepthBias
, DepthScale
;
109 GLboolean MapColorFlag
;
111 /** MESA_META_RASTERIZATION */
112 GLenum FrontPolygonMode
, BackPolygonMode
;
113 GLboolean PolygonOffset
;
114 GLboolean PolygonSmooth
;
115 GLboolean PolygonStipple
;
116 GLboolean PolygonCull
;
118 /** MESA_META_SCISSOR */
119 struct gl_scissor_attrib Scissor
;
121 /** MESA_META_SHADER */
122 GLboolean VertexProgramEnabled
;
123 struct gl_vertex_program
*VertexProgram
;
124 GLboolean FragmentProgramEnabled
;
125 struct gl_fragment_program
*FragmentProgram
;
126 GLboolean ATIFragmentShaderEnabled
;
127 struct gl_shader_program
*Shader
[MESA_SHADER_STAGES
];
128 struct gl_shader_program
*ActiveShader
;
129 struct gl_pipeline_object
*Pipeline
;
131 /** MESA_META_STENCIL_TEST */
132 struct gl_stencil_attrib Stencil
;
134 /** MESA_META_TRANSFORM */
136 GLfloat ModelviewMatrix
[16];
137 GLfloat ProjectionMatrix
[16];
138 GLfloat TextureMatrix
[16];
140 /** MESA_META_CLIP */
141 GLbitfield ClipPlanesEnabled
;
143 /** MESA_META_TEXTURE */
145 GLuint ClientActiveUnit
;
146 /** for unit[0] only */
147 struct gl_texture_object
*CurrentTexture
[NUM_TEXTURE_TARGETS
];
148 /** mask of TEXTURE_2D_BIT, etc */
149 GLbitfield TexEnabled
[MAX_TEXTURE_UNITS
];
150 GLbitfield TexGenEnabled
[MAX_TEXTURE_UNITS
];
151 GLuint EnvMode
; /* unit[0] only */
153 /** MESA_META_VERTEX */
154 struct gl_vertex_array_object
*VAO
;
155 struct gl_buffer_object
*ArrayBufferObj
;
157 /** MESA_META_VIEWPORT */
158 GLfloat ViewportX
, ViewportY
, ViewportW
, ViewportH
;
159 GLclampd DepthNear
, DepthFar
;
161 /** MESA_META_CLAMP_FRAGMENT_COLOR */
162 GLenum ClampFragmentColor
;
164 /** MESA_META_CLAMP_VERTEX_COLOR */
165 GLenum ClampVertexColor
;
167 /** MESA_META_CONDITIONAL_RENDER */
168 struct gl_query_object
*CondRenderQuery
;
169 GLenum CondRenderMode
;
171 /** MESA_META_SELECT_FEEDBACK */
173 struct gl_selection Select
;
174 struct gl_feedback Feedback
;
176 /** MESA_META_MULTISAMPLE */
177 struct gl_multisample_attrib Multisample
;
179 /** MESA_META_FRAMEBUFFER_SRGB */
180 GLboolean sRGBEnabled
;
182 /** Miscellaneous (always disabled) */
184 GLboolean RasterDiscard
;
185 GLboolean TransformFeedbackNeedsResume
;
187 GLuint DrawBufferName
, ReadBufferName
, RenderbufferName
;
189 /** MESA_META_DRAW_BUFFERS */
190 GLenum ColorDrawBuffers
[MAX_DRAW_BUFFERS
];
194 * Temporary texture used for glBlitFramebuffer, glDrawPixels, etc.
195 * This is currently shared by all the meta ops. But we could create a
196 * separate one for each of glDrawPixel, glBlitFramebuffer, glCopyPixels, etc.
201 GLenum Target
; /**< GL_TEXTURE_2D or GL_TEXTURE_RECTANGLE */
202 GLsizei MinSize
; /**< Min texture size to allocate */
203 GLsizei MaxSize
; /**< Max possible texture size */
204 GLboolean NPOT
; /**< Non-power of two size OK? */
205 GLsizei Width
, Height
; /**< Current texture size */
207 GLfloat Sright
, Ttop
; /**< right, top texcoords */
211 * State for GLSL texture sampler which is used to generate fragment
212 * shader in _mesa_meta_generate_mipmap().
217 const char *texcoords
;
222 * Table of all sampler types and shaders for accessing them.
224 struct blit_shader_table
{
225 struct blit_shader sampler_1d
;
226 struct blit_shader sampler_2d
;
227 struct blit_shader sampler_3d
;
228 struct blit_shader sampler_rect
;
229 struct blit_shader sampler_cubemap
;
230 struct blit_shader sampler_1d_array
;
231 struct blit_shader sampler_2d_array
;
232 struct blit_shader sampler_cubemap_array
;
236 * Indices in the blit_state->msaa_shaders[] array
238 * Note that setup_glsl_msaa_blit_shader() assumes that the _INT enums are five
239 * more than the corresponding non-_INT versions and _UINT are five beyond that.
241 enum blit_msaa_shader
{
242 BLIT_1X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE
,
243 BLIT_2X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE
,
244 BLIT_4X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE
,
245 BLIT_8X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE
,
246 BLIT_16X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE
,
247 BLIT_1X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE_INT
,
248 BLIT_2X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE_INT
,
249 BLIT_4X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE_INT
,
250 BLIT_8X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE_INT
,
251 BLIT_16X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE_INT
,
252 BLIT_1X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE_UINT
,
253 BLIT_2X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE_UINT
,
254 BLIT_4X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE_UINT
,
255 BLIT_8X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE_UINT
,
256 BLIT_16X_MSAA_SHADER_2D_MULTISAMPLE_RESOLVE_UINT
,
257 BLIT_MSAA_SHADER_2D_MULTISAMPLE_COPY
,
258 BLIT_MSAA_SHADER_2D_MULTISAMPLE_COPY_INT
,
259 BLIT_MSAA_SHADER_2D_MULTISAMPLE_COPY_UINT
,
260 BLIT_MSAA_SHADER_2D_MULTISAMPLE_DEPTH_RESOLVE
,
261 BLIT_MSAA_SHADER_2D_MULTISAMPLE_DEPTH_COPY
,
262 BLIT_1X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE
,
263 BLIT_2X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE
,
264 BLIT_4X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE
,
265 BLIT_8X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE
,
266 BLIT_16X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE
,
267 BLIT_1X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE_INT
,
268 BLIT_2X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE_INT
,
269 BLIT_4X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE_INT
,
270 BLIT_8X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE_INT
,
271 BLIT_16X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE_INT
,
272 BLIT_1X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE_UINT
,
273 BLIT_2X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE_UINT
,
274 BLIT_4X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE_UINT
,
275 BLIT_8X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE_UINT
,
276 BLIT_16X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_RESOLVE_UINT
,
277 BLIT_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_COPY
,
278 BLIT_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_COPY_INT
,
279 BLIT_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_COPY_UINT
,
280 BLIT_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_DEPTH_RESOLVE
,
281 BLIT_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_DEPTH_COPY
,
282 BLIT_2X_MSAA_SHADER_2D_MULTISAMPLE_SCALED_RESOLVE
,
283 BLIT_4X_MSAA_SHADER_2D_MULTISAMPLE_SCALED_RESOLVE
,
284 BLIT_8X_MSAA_SHADER_2D_MULTISAMPLE_SCALED_RESOLVE
,
285 BLIT_2X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_SCALED_RESOLVE
,
286 BLIT_4X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_SCALED_RESOLVE
,
287 BLIT_8X_MSAA_SHADER_2D_MULTISAMPLE_ARRAY_SCALED_RESOLVE
,
288 BLIT_MSAA_SHADER_COUNT
,
292 * State for glBlitFramebufer()
298 struct blit_shader_table shaders
;
299 GLuint msaa_shaders
[BLIT_MSAA_SHADER_COUNT
];
300 struct temp_texture depthTex
;
301 bool no_ctsi_fallback
;
304 struct fb_tex_blit_state
306 GLint baseLevelSave
, maxLevelSave
;
307 GLuint sampler
, samplerSave
, stencilSamplingSave
;
313 * State for glClear()
323 GLuint IntegerShaderProg
;
324 GLint IntegerColorLocation
;
325 GLint IntegerLayerLocation
;
330 * State for glCopyPixels()
340 * State for glDrawPixels()
347 GLuint StencilFP
; /**< Fragment program for drawing stencil images */
348 GLuint DepthFP
; /**< Fragment program for drawing depth images */
353 * State for glBitmap()
359 struct temp_texture Tex
; /**< separate texture from other meta ops */
363 * State for _mesa_meta_generate_mipmap()
365 struct gen_mipmap_state
372 struct blit_shader_table shaders
;
376 * One of the FBO states for decompress_state. There will be one for each
377 * required renderbuffer format.
379 struct decompress_fbo_state
386 * State for texture decompression
388 struct decompress_state
391 struct decompress_fbo_state byteFBO
, floatFBO
;
394 struct blit_shader_table shaders
;
398 * State for glDrawTex()
406 #define MAX_META_OPS_DEPTH 8
408 * All per-context meta state.
412 /** Stack of state saved during meta-ops */
413 struct save_state Save
[MAX_META_OPS_DEPTH
];
414 /** Save stack depth */
415 GLuint SaveStackDepth
;
417 struct temp_texture TempTex
;
419 struct blit_state Blit
; /**< For _mesa_meta_BlitFramebuffer() */
420 struct clear_state Clear
; /**< For _mesa_meta_Clear() */
421 struct copypix_state CopyPix
; /**< For _mesa_meta_CopyPixels() */
422 struct drawpix_state DrawPix
; /**< For _mesa_meta_DrawPixels() */
423 struct bitmap_state Bitmap
; /**< For _mesa_meta_Bitmap() */
424 struct gen_mipmap_state Mipmap
; /**< For _mesa_meta_GenerateMipmap() */
425 struct decompress_state Decompress
; /**< For texture decompression */
426 struct drawtex_state DrawTex
; /**< For _mesa_meta_DrawTex() */
430 GLfloat x
, y
, z
, tex
[4];
435 _mesa_meta_init(struct gl_context
*ctx
);
438 _mesa_meta_free(struct gl_context
*ctx
);
441 _mesa_meta_begin(struct gl_context
*ctx
, GLbitfield state
);
444 _mesa_meta_end(struct gl_context
*ctx
);
447 _mesa_meta_in_progress(struct gl_context
*ctx
);
450 _mesa_meta_fb_tex_blit_begin(const struct gl_context
*ctx
,
451 struct fb_tex_blit_state
*blit
);
454 _mesa_meta_fb_tex_blit_end(struct gl_context
*ctx
, GLenum target
,
455 struct fb_tex_blit_state
*blit
);
458 _mesa_meta_bind_rb_as_tex_image(struct gl_context
*ctx
,
459 struct gl_renderbuffer
*rb
,
461 struct gl_texture_object
**texObj
,
465 _mesa_meta_setup_sampler(struct gl_context
*ctx
,
466 const struct gl_texture_object
*texObj
,
467 GLenum target
, GLenum filter
, GLuint srcLevel
);
470 _mesa_meta_BlitFramebuffer(struct gl_context
*ctx
,
471 GLint srcX0
, GLint srcY0
, GLint srcX1
, GLint srcY1
,
472 GLint dstX0
, GLint dstY0
, GLint dstX1
, GLint dstY1
,
473 GLbitfield mask
, GLenum filter
);
476 _mesa_meta_and_swrast_BlitFramebuffer(struct gl_context
*ctx
,
477 GLint srcX0
, GLint srcY0
,
478 GLint srcX1
, GLint srcY1
,
479 GLint dstX0
, GLint dstY0
,
480 GLint dstX1
, GLint dstY1
,
481 GLbitfield mask
, GLenum filter
);
484 _mesa_meta_CopyImageSubData_uncompressed(struct gl_context
*ctx
,
485 struct gl_texture_image
*src_tex_image
,
486 int src_x
, int src_y
, int src_z
,
487 struct gl_texture_image
*dst_tex_image
,
488 int dst_x
, int dst_y
, int dst_z
,
489 int src_width
, int src_height
);
492 _mesa_meta_Clear(struct gl_context
*ctx
, GLbitfield buffers
);
495 _mesa_meta_glsl_Clear(struct gl_context
*ctx
, GLbitfield buffers
);
498 _mesa_meta_CopyPixels(struct gl_context
*ctx
, GLint srcx
, GLint srcy
,
499 GLsizei width
, GLsizei height
,
500 GLint dstx
, GLint dsty
, GLenum type
);
503 _mesa_meta_DrawPixels(struct gl_context
*ctx
,
504 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
505 GLenum format
, GLenum type
,
506 const struct gl_pixelstore_attrib
*unpack
,
507 const GLvoid
*pixels
);
510 _mesa_meta_Bitmap(struct gl_context
*ctx
,
511 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
512 const struct gl_pixelstore_attrib
*unpack
,
513 const GLubyte
*bitmap
);
516 _mesa_meta_GenerateMipmap(struct gl_context
*ctx
, GLenum target
,
517 struct gl_texture_object
*texObj
);
520 _mesa_meta_CopyTexSubImage(struct gl_context
*ctx
, GLuint dims
,
521 struct gl_texture_image
*texImage
,
522 GLint xoffset
, GLint yoffset
, GLint slice
,
523 struct gl_renderbuffer
*rb
,
525 GLsizei width
, GLsizei height
);
528 _mesa_meta_ClearTexSubImage(struct gl_context
*ctx
,
529 struct gl_texture_image
*texImage
,
530 GLint xoffset
, GLint yoffset
, GLint zoffset
,
531 GLsizei width
, GLsizei height
, GLsizei depth
,
532 const GLvoid
*clearValue
);
535 _mesa_meta_GetTexImage(struct gl_context
*ctx
,
536 GLenum format
, GLenum type
, GLvoid
*pixels
,
537 struct gl_texture_image
*texImage
);
540 _mesa_meta_DrawTex(struct gl_context
*ctx
, GLfloat x
, GLfloat y
, GLfloat z
,
541 GLfloat width
, GLfloat height
);
543 /* meta-internal functions */
545 _mesa_meta_drawbuffers_from_bitfield(GLbitfield bits
);
548 _mesa_meta_compile_shader_with_debug(struct gl_context
*ctx
, GLenum target
,
549 const GLcharARB
*source
);
553 _mesa_meta_link_program_with_debug(struct gl_context
*ctx
, GLuint program
);
556 _mesa_meta_compile_and_link_program(struct gl_context
*ctx
,
557 const char *vs_source
,
558 const char *fs_source
,
563 _mesa_meta_alloc_texture(struct temp_texture
*tex
,
564 GLsizei width
, GLsizei height
, GLenum intFormat
);
567 _mesa_meta_setup_texture_coords(GLenum faceTarget
,
577 struct temp_texture
*
578 _mesa_meta_get_temp_texture(struct gl_context
*ctx
);
580 struct temp_texture
*
581 _mesa_meta_get_temp_depth_texture(struct gl_context
*ctx
);
584 _mesa_meta_setup_vertex_objects(GLuint
*VAO
, GLuint
*VBO
,
585 bool use_generic_attributes
,
586 unsigned vertex_size
, unsigned texcoord_size
,
587 unsigned color_size
);
590 _mesa_meta_setup_ff_tnl_for_blit(GLuint
*VAO
, GLuint
*VBO
,
591 unsigned texcoord_size
);
594 _mesa_meta_setup_drawpix_texture(struct gl_context
*ctx
,
595 struct temp_texture
*tex
,
597 GLsizei width
, GLsizei height
,
598 GLenum format
, GLenum type
,
599 const GLvoid
*pixels
);
602 _mesa_meta_setup_copypix_texture(struct gl_context
*ctx
,
603 struct temp_texture
*tex
,
604 GLint srcX
, GLint srcY
,
605 GLsizei width
, GLsizei height
,
610 _mesa_meta_setup_blit_shader(struct gl_context
*ctx
,
612 struct blit_shader_table
*table
);
615 _mesa_meta_glsl_blit_cleanup(struct blit_state
*blit
);
618 _mesa_meta_blit_shader_table_cleanup(struct blit_shader_table
*table
);
621 _mesa_meta_glsl_generate_mipmap_cleanup(struct gen_mipmap_state
*mipmap
);
624 _mesa_meta_bind_fbo_image(GLenum target
, GLenum attachment
,
625 struct gl_texture_image
*texImage
, GLuint layer
);