Merge remote-tracking branch 'origin/master' into vulkan
[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
27 #include "brw_context.h"
28 #include "brw_state.h"
29
30
31 /* Creates a new TES constant buffer reflecting the current TES program's
32 * constants, if needed by the TES program.
33 *
34 * Otherwise, constants go through the CURBEs using the brw_constant_buffer
35 * state atom.
36 */
37 static void
38 brw_upload_tes_pull_constants(struct brw_context *brw)
39 {
40 struct brw_stage_state *stage_state = &brw->tes.base;
41
42 /* BRW_NEW_TESS_PROGRAMS */
43 struct brw_tess_eval_program *dp =
44 (struct brw_tess_eval_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.prog_data->base.base;
51
52 /* _NEW_PROGRAM_CONSTANTS */
53 brw_upload_pull_constants(brw, BRW_NEW_TES_CONSTBUF, &dp->program.Base,
54 stage_state, prog_data);
55 }
56
57 const struct brw_tracked_state brw_tes_pull_constants = {
58 .dirty = {
59 .mesa = _NEW_PROGRAM_CONSTANTS,
60 .brw = BRW_NEW_BATCH |
61 BRW_NEW_TES_PROG_DATA |
62 BRW_NEW_TESS_PROGRAMS,
63 },
64 .emit = brw_upload_tes_pull_constants,
65 };
66
67 static void
68 brw_upload_tes_ubo_surfaces(struct brw_context *brw)
69 {
70 struct gl_context *ctx = &brw->ctx;
71
72 /* _NEW_PROGRAM */
73 struct gl_shader_program *prog =
74 ctx->_Shader->CurrentProgram[MESA_SHADER_TESS_EVAL];
75
76 if (!prog)
77 return;
78
79 /* BRW_NEW_TES_PROG_DATA */
80 struct brw_stage_prog_data *prog_data = &brw->tes.prog_data->base.base;
81
82 brw_upload_ubo_surfaces(brw, prog->_LinkedShaders[MESA_SHADER_TESS_EVAL],
83 &brw->tes.base, prog_data);
84 }
85
86 const struct brw_tracked_state brw_tes_ubo_surfaces = {
87 .dirty = {
88 .mesa = _NEW_PROGRAM,
89 .brw = BRW_NEW_BATCH |
90 BRW_NEW_TES_PROG_DATA |
91 BRW_NEW_UNIFORM_BUFFER,
92 },
93 .emit = brw_upload_tes_ubo_surfaces,
94 };
95
96 static void
97 brw_upload_tes_abo_surfaces(struct brw_context *brw)
98 {
99 struct gl_context *ctx = &brw->ctx;
100 /* _NEW_PROGRAM */
101 struct gl_shader_program *prog =
102 ctx->_Shader->CurrentProgram[MESA_SHADER_TESS_EVAL];
103
104 if (prog) {
105 /* BRW_NEW_TES_PROG_DATA */
106 brw_upload_abo_surfaces(brw, prog->_LinkedShaders[MESA_SHADER_TESS_EVAL],
107 &brw->tes.base, &brw->tes.prog_data->base.base);
108 }
109 }
110
111 const struct brw_tracked_state brw_tes_abo_surfaces = {
112 .dirty = {
113 .mesa = _NEW_PROGRAM,
114 .brw = BRW_NEW_ATOMIC_BUFFER |
115 BRW_NEW_BATCH |
116 BRW_NEW_TES_PROG_DATA,
117 },
118 .emit = brw_upload_tes_abo_surfaces,
119 };
120
121 static void
122 brw_upload_tes_image_surfaces(struct brw_context *brw)
123 {
124 struct gl_context *ctx = &brw->ctx;
125 /* BRW_NEW_TESS_PROGRAMS */
126 struct gl_shader_program *prog =
127 ctx->_Shader->CurrentProgram[MESA_SHADER_TESS_EVAL];
128
129 if (prog) {
130 /* BRW_NEW_TES_PROG_DATA, BRW_NEW_IMAGE_UNITS */
131 brw_upload_image_surfaces(brw, prog->_LinkedShaders[MESA_SHADER_TESS_EVAL],
132 &brw->tes.base, &brw->tes.prog_data->base.base);
133 }
134 }
135
136 const struct brw_tracked_state brw_tes_image_surfaces = {
137 .dirty = {
138 .brw = BRW_NEW_BATCH |
139 BRW_NEW_IMAGE_UNITS |
140 BRW_NEW_TESS_PROGRAMS |
141 BRW_NEW_TES_PROG_DATA,
142 },
143 .emit = brw_upload_tes_image_surfaces,
144 };