i965: Enable EGL_KHR_gl_texture_3D_image
[mesa.git] / src / mesa / drivers / dri / i965 / brw_gs_surface_state.c
1 /*
2 * Copyright © 2013 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #include "main/mtypes.h"
25 #include "program/prog_parameter.h"
26 #include "main/shaderapi.h"
27
28 #include "brw_context.h"
29 #include "brw_state.h"
30
31
32 /* Creates a new GS constant buffer reflecting the current GS program's
33 * constants, if needed by the GS program.
34 *
35 * Otherwise, constants go through the CURBEs using the brw_constant_buffer
36 * state atom.
37 */
38 static void
39 brw_upload_gs_pull_constants(struct brw_context *brw)
40 {
41 struct brw_stage_state *stage_state = &brw->gs.base;
42
43 /* BRW_NEW_GEOMETRY_PROGRAM */
44 struct brw_geometry_program *gp =
45 (struct brw_geometry_program *) brw->geometry_program;
46
47 if (!gp)
48 return;
49
50 /* BRW_NEW_GS_PROG_DATA */
51 const struct brw_vue_prog_data *prog_data = &brw->gs.prog_data->base;
52
53 _mesa_shader_write_subroutine_indices(&brw->ctx, MESA_SHADER_GEOMETRY);
54 /* _NEW_PROGRAM_CONSTANTS */
55 brw_upload_pull_constants(brw, BRW_NEW_GS_CONSTBUF, &gp->program.Base,
56 stage_state, &prog_data->base);
57 }
58
59 const struct brw_tracked_state brw_gs_pull_constants = {
60 .dirty = {
61 .mesa = _NEW_PROGRAM_CONSTANTS,
62 .brw = BRW_NEW_BATCH |
63 BRW_NEW_BLORP |
64 BRW_NEW_GEOMETRY_PROGRAM |
65 BRW_NEW_GS_PROG_DATA,
66 },
67 .emit = brw_upload_gs_pull_constants,
68 };
69
70 static void
71 brw_upload_gs_ubo_surfaces(struct brw_context *brw)
72 {
73 struct gl_context *ctx = &brw->ctx;
74
75 /* _NEW_PROGRAM */
76 struct gl_shader_program *prog =
77 ctx->_Shader->CurrentProgram[MESA_SHADER_GEOMETRY];
78
79 if (!prog)
80 return;
81
82 /* BRW_NEW_GS_PROG_DATA */
83 struct brw_vue_prog_data *prog_data = &brw->gs.prog_data->base;
84
85 brw_upload_ubo_surfaces(brw, prog->_LinkedShaders[MESA_SHADER_GEOMETRY],
86 &brw->gs.base, &prog_data->base);
87 }
88
89 const struct brw_tracked_state brw_gs_ubo_surfaces = {
90 .dirty = {
91 .mesa = _NEW_PROGRAM,
92 .brw = BRW_NEW_BATCH |
93 BRW_NEW_BLORP |
94 BRW_NEW_GS_PROG_DATA |
95 BRW_NEW_UNIFORM_BUFFER,
96 },
97 .emit = brw_upload_gs_ubo_surfaces,
98 };
99
100 static void
101 brw_upload_gs_abo_surfaces(struct brw_context *brw)
102 {
103 struct gl_context *ctx = &brw->ctx;
104 /* _NEW_PROGRAM */
105 struct gl_shader_program *prog =
106 ctx->_Shader->CurrentProgram[MESA_SHADER_GEOMETRY];
107
108 if (prog) {
109 /* BRW_NEW_GS_PROG_DATA */
110 brw_upload_abo_surfaces(brw, prog->_LinkedShaders[MESA_SHADER_GEOMETRY],
111 &brw->gs.base, &brw->gs.prog_data->base.base);
112 }
113 }
114
115 const struct brw_tracked_state brw_gs_abo_surfaces = {
116 .dirty = {
117 .mesa = _NEW_PROGRAM,
118 .brw = BRW_NEW_ATOMIC_BUFFER |
119 BRW_NEW_BATCH |
120 BRW_NEW_BLORP |
121 BRW_NEW_GS_PROG_DATA,
122 },
123 .emit = brw_upload_gs_abo_surfaces,
124 };
125
126 static void
127 brw_upload_gs_image_surfaces(struct brw_context *brw)
128 {
129 struct gl_context *ctx = &brw->ctx;
130 /* BRW_NEW_GEOMETRY_PROGRAM */
131 struct gl_shader_program *prog =
132 ctx->_Shader->CurrentProgram[MESA_SHADER_GEOMETRY];
133
134 if (prog) {
135 /* BRW_NEW_GS_PROG_DATA, BRW_NEW_IMAGE_UNITS, _NEW_TEXTURE */
136 brw_upload_image_surfaces(brw, prog->_LinkedShaders[MESA_SHADER_GEOMETRY],
137 &brw->gs.base, &brw->gs.prog_data->base.base);
138 }
139 }
140
141 const struct brw_tracked_state brw_gs_image_surfaces = {
142 .dirty = {
143 .mesa = _NEW_TEXTURE,
144 .brw = BRW_NEW_BATCH |
145 BRW_NEW_BLORP |
146 BRW_NEW_GEOMETRY_PROGRAM |
147 BRW_NEW_GS_PROG_DATA |
148 BRW_NEW_IMAGE_UNITS,
149 },
150 .emit = brw_upload_gs_image_surfaces,
151 };