1 /*
2 Copyright (C) Intel Corp. 2006. All Rights Reserved.
3 Intel funded Tungsten Graphics to
4 develop this 3D driver.
5
6 Permission is hereby granted, free of charge, to any person obtaining
7 a copy of this software and associated documentation files (the
8 "Software"), to deal in the Software without restriction, including
9 without limitation the rights to use, copy, modify, merge, publish,
10 distribute, sublicense, and/or sell copies of the Software, and to
11 permit persons to whom the Software is furnished to do so, subject to
12 the following conditions:
13
14 The above copyright notice and this permission notice (including the
15 next paragraph) shall be included in all copies or substantial
16 portions of the Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
22 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
26 **********************************************************************/
27 /*
28 * Authors:
29 * Keith Whitwell <keithw@vmware.com>
30 */
31
32 #include "main/mtypes.h"
33 #include "program/prog_parameter.h"
34 #include "main/shaderapi.h"
35
36 #include "brw_context.h"
37 #include "brw_state.h"
38 #include "intel_buffer_objects.h"
39
40
41 /* Creates a new VS constant buffer reflecting the current VS program's
42 * constants, if needed by the VS program.
43 *
44 * Otherwise, constants go through the CURBEs using the brw_constant_buffer
45 * state atom.
46 */
47 static void
brw_upload_vs_pull_constants(struct brw_context * brw)48 brw_upload_vs_pull_constants(struct brw_context *brw)
49 {
50 struct brw_stage_state *stage_state = &brw->vs.base;
51
52 /* BRW_NEW_VERTEX_PROGRAM */
53 struct brw_program *vp =
54 (struct brw_program *) brw->programs[MESA_SHADER_VERTEX];
55
56 /* BRW_NEW_VS_PROG_DATA */
57 const struct brw_stage_prog_data *prog_data = brw->vs.base.prog_data;
58
59 _mesa_shader_write_subroutine_indices(&brw->ctx, MESA_SHADER_VERTEX);
60 /* _NEW_PROGRAM_CONSTANTS */
61 brw_upload_pull_constants(brw, BRW_NEW_VS_CONSTBUF, &vp->program,
62 stage_state, prog_data);
63 }
64
65 const struct brw_tracked_state brw_vs_pull_constants = {
66 .dirty = {
67 .mesa = _NEW_PROGRAM_CONSTANTS,
68 .brw = BRW_NEW_BATCH |
69 BRW_NEW_VERTEX_PROGRAM |
70 BRW_NEW_VS_PROG_DATA,
71 },
72 .emit = brw_upload_vs_pull_constants,
73 };
74
75 static void
brw_upload_vs_ubo_surfaces(struct brw_context * brw)76 brw_upload_vs_ubo_surfaces(struct brw_context *brw)
77 {
78 struct gl_context *ctx = &brw->ctx;
79 /* _NEW_PROGRAM */
80 struct gl_program *prog = ctx->_Shader->CurrentProgram[MESA_SHADER_VERTEX];
81
82 /* BRW_NEW_VS_PROG_DATA */
83 brw_upload_ubo_surfaces(brw, prog, &brw->vs.base, brw->vs.base.prog_data);
84 }
85
86 const struct brw_tracked_state brw_vs_ubo_surfaces = {
87 .dirty = {
88 .mesa = _NEW_PROGRAM,
89 .brw = BRW_NEW_BATCH |
90 BRW_NEW_UNIFORM_BUFFER |
91 BRW_NEW_VS_PROG_DATA,
92 },
93 .emit = brw_upload_vs_ubo_surfaces,
94 };
95
96 static void
brw_upload_vs_image_surfaces(struct brw_context * brw)97 brw_upload_vs_image_surfaces(struct brw_context *brw)
98 {
99 /* BRW_NEW_VERTEX_PROGRAM */
100 const struct gl_program *vp = brw->programs[MESA_SHADER_VERTEX];
101
102 if (vp) {
103 /* BRW_NEW_VS_PROG_DATA, BRW_NEW_IMAGE_UNITS, _NEW_TEXTURE */
104 brw_upload_image_surfaces(brw, vp, &brw->vs.base,
105 brw->vs.base.prog_data);
106 }
107 }
108
109 const struct brw_tracked_state brw_vs_image_surfaces = {
110 .dirty = {
111 .mesa = _NEW_TEXTURE,
112 .brw = BRW_NEW_BATCH |
113 BRW_NEW_AUX_STATE |
114 BRW_NEW_IMAGE_UNITS |
115 BRW_NEW_VERTEX_PROGRAM |
116 BRW_NEW_VS_PROG_DATA,
117 },
118 .emit = brw_upload_vs_image_surfaces,
119 };
120