Merge branch '7.8'
[mesa.git] / src / gallium / drivers / i965 / brw_wm_constant_buffer.c
1 /* XXX: Constant buffers disabled
2 */
3
4
5 /**
6 * Create the constant buffer surface. Vertex/fragment shader constants will be
7 * read from this buffer with Data Port Read instructions/messages.
8 */
9 enum pipe_error
10 brw_create_constant_surface( struct brw_context *brw,
11 struct brw_surface_key *key,
12 struct brw_winsys_buffer **bo_out )
13 {
14 const GLint w = key->width - 1;
15 struct brw_winsys_buffer *bo;
16 struct brw_winsys_reloc reloc[1];
17 enum pipe_error ret;
18
19 /* Emit relocation to surface contents */
20 make_reloc(&reloc[0],
21 BRW_USAGE_SAMPLER,
22 0,
23 offsetof(struct brw_surface_state, ss1),
24 key->bo);
25
26
27 memset(&surf, 0, sizeof(surf));
28
29 surf.ss0.mipmap_layout_mode = BRW_SURFACE_MIPMAPLAYOUT_BELOW;
30 surf.ss0.surface_type = BRW_SURFACE_BUFFER;
31 surf.ss0.surface_format = BRW_SURFACEFORMAT_R32G32B32A32_FLOAT;
32
33 surf.ss1.base_addr = 0; /* reloc */
34
35 surf.ss2.width = w & 0x7f; /* bits 6:0 of size or width */
36 surf.ss2.height = (w >> 7) & 0x1fff; /* bits 19:7 of size or width */
37 surf.ss3.depth = (w >> 20) & 0x7f; /* bits 26:20 of size or width */
38 surf.ss3.pitch = (key->pitch * key->cpp) - 1; /* ignored?? */
39 brw_set_surface_tiling(&surf, key->tiling); /* tiling now allowed */
40
41 ret = brw_upload_cache(&brw->surface_cache, BRW_SS_SURFACE,
42 key, sizeof(*key),
43 reloc, Elements(reloc),
44 &surf, sizeof(surf),
45 NULL, NULL,
46 &bo_out);
47 if (ret)
48 return ret;
49
50 return PIPE_OK;
51 }
52
53
54
55 /**
56 * Update the surface state for a WM constant buffer.
57 * The constant buffer will be (re)allocated here if needed.
58 */
59 static enum pipe_error
60 brw_update_wm_constant_surface( struct brw_context *brw,
61 GLuint surf)
62 {
63 struct brw_surface_key key;
64 struct brw_fragment_shader *fp = brw->curr.fragment_shader;
65 struct pipe_resource *cbuf = brw->curr.fragment_constants;
66 int pitch = cbuf->size / (4 * sizeof(float));
67 enum pipe_error ret;
68
69 /* If we're in this state update atom, we need to update WM constants, so
70 * free the old buffer and create a new one for the new contents.
71 */
72 ret = brw_wm_update_constant_buffer(brw, &fp->const_buffer);
73 if (ret)
74 return ret;
75
76 /* If there's no constant buffer, then no surface BO is needed to point at
77 * it.
78 */
79 if (cbuf == NULL) {
80 bo_reference(&brw->wm.surf_bo[surf], NULL);
81 return PIPE_OK;
82 }
83
84 memset(&key, 0, sizeof(key));
85
86 key.ss0.mipmap_layout_mode = BRW_SURFACE_MIPMAPLAYOUT_BELOW;
87 key.ss0.surface_type = BRW_SURFACE_BUFFER;
88 key.ss0.surface_format = BRW_SURFACEFORMAT_R32G32B32A32_FLOAT;
89
90 key.bo = brw_buffer(cbuf)->bo;
91
92 key.ss2.width = (pitch-1) & 0x7f; /* bits 6:0 of size or width */
93 key.ss2.height = ((pitch-1) >> 7) & 0x1fff; /* bits 19:7 of size or width */
94 key.ss3.depth = ((pitch-1) >> 20) & 0x7f; /* bits 26:20 of size or width */
95 key.ss3.pitch = (pitch * 4 * sizeof(float)) - 1; /* ignored?? */
96 brw_set_surface_tiling(&surf, key->tiling); /* tiling now allowed */
97
98
99 /*
100 printf("%s:\n", __FUNCTION__);
101 printf(" width %d height %d depth %d cpp %d pitch %d\n",
102 key.width, key.height, key.depth, key.cpp, key.pitch);
103 */
104
105 if (brw_search_cache(&brw->surface_cache,
106 BRW_SS_SURFACE,
107 &key, sizeof(key),
108 &key.bo, 1,
109 NULL,
110 &brw->wm.surf_bo[surf]))
111 return PIPE_OK;
112
113 ret = brw_create_constant_surface(brw, &key, &brw->wm.surf_bo[surf]);
114 if (ret)
115 return ret;
116
117 brw->state.dirty.brw |= BRW_NEW_WM_SURFACES;
118 return PIPE_OK;
119 }
120
121 /**
122 * Updates surface / buffer for fragment shader constant buffer, if
123 * one is required.
124 *
125 * This consumes the state updates for the constant buffer, and produces
126 * BRW_NEW_WM_SURFACES to get picked up by brw_prepare_wm_surfaces for
127 * inclusion in the binding table.
128 */
129 static enum pipe_error prepare_wm_constant_surface(struct brw_context *brw )
130 {
131 struct brw_fragment_program *fp =
132 (struct brw_fragment_program *) brw->fragment_program;
133 GLuint surf = SURF_INDEX_FRAG_CONST_BUFFER;
134
135 ret = brw_wm_update_constant_buffer(brw,
136 &fp->const_buffer);
137 if (ret)
138 return ret;
139
140 /* If there's no constant buffer, then no surface BO is needed to point at
141 * it.
142 */
143 if (fp->const_buffer == 0) {
144 if (brw->wm.surf_bo[surf] != NULL) {
145 bo_reference(&brw->wm.surf_bo[surf], NULL);
146 brw->state.dirty.brw |= BRW_NEW_WM_SURFACES;
147 }
148 return PIPE_OK;
149 }
150
151 ret = brw_update_wm_constant_surface(ctx, surf);
152 if (ret)
153 return ret;
154
155 return PIPE_OK
156 }
157
158 const struct brw_tracked_state brw_wm_constant_surface = {
159 .dirty = {
160 .mesa = (_NEW_PROGRAM_CONSTANTS),
161 .brw = (BRW_NEW_FRAGMENT_PROGRAM),
162 .cache = 0
163 },
164 .prepare = prepare_wm_constant_surface,
165 };