a6204ced28b255299d9b705f4736a080e03c5e4d
[mesa.git] / src / mesa / drivers / dri / i965 / brw_tes_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 TES constant buffer reflecting the current TES program's
33 * constants, if needed by the TES program.
34 *
35 * Otherwise, constants go through the CURBEs using the brw_constant_buffer
36 * state atom.
37 */
38 static void
39 brw_upload_tes_pull_constants(struct brw_context *brw)
40 {
41 struct brw_stage_state *stage_state = &brw->tes.base;
42
43 /* BRW_NEW_TESS_PROGRAMS */
44 struct brw_program *dp = (struct brw_program *) brw->tess_eval_program;
45
46 if (!dp)
47 return;
48
49 /* BRW_NEW_TES_PROG_DATA */
50 const struct brw_stage_prog_data *prog_data = brw->tes.base.prog_data;
51
52 _mesa_shader_write_subroutine_indices(&brw->ctx, MESA_SHADER_TESS_EVAL);
53 /* _NEW_PROGRAM_CONSTANTS */
54 brw_upload_pull_constants(brw, BRW_NEW_TES_CONSTBUF, &dp->program,
55 stage_state, prog_data);
56 }
57
58 const struct brw_tracked_state brw_tes_pull_constants = {
59 .dirty = {
60 .mesa = _NEW_PROGRAM_CONSTANTS,
61 .brw = BRW_NEW_BATCH |
62 BRW_NEW_TES_PROG_DATA |
63 BRW_NEW_TESS_PROGRAMS,
64 },
65 .emit = brw_upload_tes_pull_constants,
66 };
67
68 static void
69 brw_upload_tes_ubo_surfaces(struct brw_context *brw)
70 {
71 struct gl_context *ctx = &brw->ctx;
72
73 /* _NEW_PROGRAM */
74 struct gl_program *prog =
75 ctx->_Shader->CurrentProgram[MESA_SHADER_TESS_EVAL];
76
77 /* BRW_NEW_TES_PROG_DATA */
78 struct brw_stage_prog_data *prog_data = brw->tes.base.prog_data;
79
80 brw_upload_ubo_surfaces(brw, prog, &brw->tes.base, prog_data);
81 }
82
83 const struct brw_tracked_state brw_tes_ubo_surfaces = {
84 .dirty = {
85 .mesa = _NEW_PROGRAM,
86 .brw = BRW_NEW_BATCH |
87 BRW_NEW_TES_PROG_DATA |
88 BRW_NEW_UNIFORM_BUFFER,
89 },
90 .emit = brw_upload_tes_ubo_surfaces,
91 };
92
93 static void
94 brw_upload_tes_abo_surfaces(struct brw_context *brw)
95 {
96 /* _NEW_PROGRAM */
97 const struct gl_program *tep = brw->tess_eval_program;
98
99 if (tep) {
100 /* BRW_NEW_TES_PROG_DATA */
101 brw_upload_abo_surfaces(brw, tep, &brw->tes.base,
102 brw->tes.base.prog_data);
103 }
104 }
105
106 const struct brw_tracked_state brw_tes_abo_surfaces = {
107 .dirty = {
108 .mesa = _NEW_PROGRAM,
109 .brw = BRW_NEW_ATOMIC_BUFFER |
110 BRW_NEW_BATCH |
111 BRW_NEW_TES_PROG_DATA,
112 },
113 .emit = brw_upload_tes_abo_surfaces,
114 };
115
116 static void
117 brw_upload_tes_image_surfaces(struct brw_context *brw)
118 {
119 /* BRW_NEW_TESS_PROGRAMS */
120 const struct gl_program *tep = brw->tess_eval_program;
121
122 if (tep) {
123 /* BRW_NEW_TES_PROG_DATA, BRW_NEW_IMAGE_UNITS */
124 brw_upload_image_surfaces(brw, tep, &brw->tes.base,
125 brw->tes.base.prog_data);
126 }
127 }
128
129 const struct brw_tracked_state brw_tes_image_surfaces = {
130 .dirty = {
131 .brw = BRW_NEW_BATCH |
132 BRW_NEW_AUX_STATE |
133 BRW_NEW_IMAGE_UNITS |
134 BRW_NEW_TESS_PROGRAMS |
135 BRW_NEW_TES_PROG_DATA,
136 },
137 .emit = brw_upload_tes_image_surfaces,
138 };