i965: "Fix" aux offsets
[mesa.git] / src / mesa / drivers / dri / i965 / brw_tcs_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
21 * DEALINGS 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 TCS constant buffer reflecting the current TCS program's
33 * constants, if needed by the TCS program.
34 *
35 * Otherwise, constants go through the CURBEs using the brw_constant_buffer
36 * state atom.
37 */
38 static void
39 brw_upload_tcs_pull_constants(struct brw_context *brw)
40 {
41 struct brw_stage_state *stage_state = &brw->tcs.base;
42
43 /* BRW_NEW_TESS_PROGRAMS */
44 struct brw_program *tcp = (struct brw_program *) brw->tess_ctrl_program;
45
46 if (!tcp)
47 return;
48
49 /* BRW_NEW_TCS_PROG_DATA */
50 const struct brw_stage_prog_data *prog_data = brw->tcs.base.prog_data;
51
52 _mesa_shader_write_subroutine_indices(&brw->ctx, MESA_SHADER_TESS_CTRL);
53 /* _NEW_PROGRAM_CONSTANTS */
54 brw_upload_pull_constants(brw, BRW_NEW_TCS_CONSTBUF, &tcp->program,
55 stage_state, prog_data);
56 }
57
58 const struct brw_tracked_state brw_tcs_pull_constants = {
59 .dirty = {
60 .mesa = _NEW_PROGRAM_CONSTANTS,
61 .brw = BRW_NEW_BATCH |
62 BRW_NEW_BLORP |
63 BRW_NEW_TCS_PROG_DATA |
64 BRW_NEW_TESS_PROGRAMS,
65 },
66 .emit = brw_upload_tcs_pull_constants,
67 };
68
69 static void
70 brw_upload_tcs_ubo_surfaces(struct brw_context *brw)
71 {
72 struct gl_context *ctx = &brw->ctx;
73
74 /* _NEW_PROGRAM */
75 struct gl_shader_program *prog =
76 ctx->_Shader->CurrentProgram[MESA_SHADER_TESS_CTRL];
77
78 if (!prog)
79 return;
80
81 /* BRW_NEW_TCS_PROG_DATA */
82 struct brw_stage_prog_data *prog_data = brw->tcs.base.prog_data;
83
84 brw_upload_ubo_surfaces(brw, prog->_LinkedShaders[MESA_SHADER_TESS_CTRL],
85 &brw->tcs.base, prog_data);
86 }
87
88 const struct brw_tracked_state brw_tcs_ubo_surfaces = {
89 .dirty = {
90 .mesa = _NEW_PROGRAM,
91 .brw = BRW_NEW_BATCH |
92 BRW_NEW_BLORP |
93 BRW_NEW_TCS_PROG_DATA |
94 BRW_NEW_UNIFORM_BUFFER,
95 },
96 .emit = brw_upload_tcs_ubo_surfaces,
97 };
98
99 static void
100 brw_upload_tcs_abo_surfaces(struct brw_context *brw)
101 {
102 struct gl_context *ctx = &brw->ctx;
103 /* _NEW_PROGRAM */
104 struct gl_shader_program *prog =
105 ctx->_Shader->CurrentProgram[MESA_SHADER_TESS_CTRL];
106
107 if (prog) {
108 /* BRW_NEW_TCS_PROG_DATA */
109 brw_upload_abo_surfaces(brw, prog->_LinkedShaders[MESA_SHADER_TESS_CTRL],
110 &brw->tcs.base, brw->tcs.base.prog_data);
111 }
112 }
113
114 const struct brw_tracked_state brw_tcs_abo_surfaces = {
115 .dirty = {
116 .mesa = _NEW_PROGRAM,
117 .brw = BRW_NEW_ATOMIC_BUFFER |
118 BRW_NEW_BATCH |
119 BRW_NEW_BLORP |
120 BRW_NEW_TCS_PROG_DATA,
121 },
122 .emit = brw_upload_tcs_abo_surfaces,
123 };
124
125 static void
126 brw_upload_tcs_image_surfaces(struct brw_context *brw)
127 {
128 struct gl_context *ctx = &brw->ctx;
129 /* BRW_NEW_TESS_PROGRAMS */
130 struct gl_shader_program *prog =
131 ctx->_Shader->CurrentProgram[MESA_SHADER_TESS_CTRL];
132
133 if (prog) {
134 /* BRW_NEW_TCS_PROG_DATA, BRW_NEW_IMAGE_UNITS */
135 brw_upload_image_surfaces(brw, prog->_LinkedShaders[MESA_SHADER_TESS_CTRL],
136 &brw->tcs.base, brw->tcs.base.prog_data);
137 }
138 }
139
140 const struct brw_tracked_state brw_tcs_image_surfaces = {
141 .dirty = {
142 .brw = BRW_NEW_BATCH |
143 BRW_NEW_BLORP |
144 BRW_NEW_TCS_PROG_DATA |
145 BRW_NEW_IMAGE_UNITS |
146 BRW_NEW_TESS_PROGRAMS,
147 },
148 .emit = brw_upload_tcs_image_surfaces,
149 };