Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/gallium/drivers/i915/i915_context.c
4570 views
1
/**************************************************************************
2
*
3
* Copyright 2003 VMware, Inc.
4
* All Rights Reserved.
5
*
6
* Permission is hereby granted, free of charge, to any person obtaining a
7
* 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, sub license, 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 portions
16
* of the Software.
17
*
18
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21
* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
*
26
**************************************************************************/
27
28
#include "i915_context.h"
29
#include "i915_batch.h"
30
#include "i915_query.h"
31
#include "i915_resource.h"
32
#include "i915_screen.h"
33
#include "i915_state.h"
34
#include "i915_surface.h"
35
36
#include "draw/draw_context.h"
37
#include "pipe/p_defines.h"
38
#include "pipe/p_screen.h"
39
#include "util/u_draw.h"
40
#include "util/u_inlines.h"
41
#include "util/u_memory.h"
42
#include "util/u_prim.h"
43
#include "util/u_upload_mgr.h"
44
45
DEBUG_GET_ONCE_BOOL_OPTION(i915_no_vbuf, "I915_NO_VBUF", false)
46
47
/*
48
* Draw functions
49
*/
50
51
static void
52
i915_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info,
53
unsigned drawid_offset,
54
const struct pipe_draw_indirect_info *indirect,
55
const struct pipe_draw_start_count_bias *draws,
56
unsigned num_draws)
57
{
58
if (num_draws > 1) {
59
util_draw_multi(pipe, info, drawid_offset, indirect, draws, num_draws);
60
return;
61
}
62
63
struct i915_context *i915 = i915_context(pipe);
64
struct draw_context *draw = i915->draw;
65
const void *mapped_indices = NULL;
66
unsigned i;
67
68
if (!u_trim_pipe_prim(info->mode, (unsigned *)&draws[0].count))
69
return;
70
71
/*
72
* Ack vs contants here, helps ipers a lot.
73
*/
74
i915->dirty &= ~I915_NEW_VS_CONSTANTS;
75
76
if (i915->dirty)
77
i915_update_derived(i915);
78
79
/*
80
* Map vertex buffers
81
*/
82
for (i = 0; i < i915->nr_vertex_buffers; i++) {
83
const void *buf = i915->vertex_buffers[i].is_user_buffer
84
? i915->vertex_buffers[i].buffer.user
85
: NULL;
86
if (!buf) {
87
if (!i915->vertex_buffers[i].buffer.resource)
88
continue;
89
buf = i915_buffer(i915->vertex_buffers[i].buffer.resource)->data;
90
}
91
draw_set_mapped_vertex_buffer(draw, i, buf, ~0);
92
}
93
94
/*
95
* Map index buffer, if present
96
*/
97
if (info->index_size) {
98
mapped_indices = info->has_user_indices ? info->index.user : NULL;
99
if (!mapped_indices)
100
mapped_indices = i915_buffer(info->index.resource)->data;
101
draw_set_indexes(draw, (ubyte *)mapped_indices, info->index_size, ~0);
102
}
103
104
if (i915->constants[PIPE_SHADER_VERTEX])
105
draw_set_mapped_constant_buffer(
106
draw, PIPE_SHADER_VERTEX, 0,
107
i915_buffer(i915->constants[PIPE_SHADER_VERTEX])->data,
108
(i915->current.num_user_constants[PIPE_SHADER_VERTEX] * 4 *
109
sizeof(float)));
110
else
111
draw_set_mapped_constant_buffer(draw, PIPE_SHADER_VERTEX, 0, NULL, 0);
112
113
/*
114
* Do the drawing
115
*/
116
draw_vbo(i915->draw, info, drawid_offset, NULL, draws, num_draws);
117
118
/*
119
* unmap vertex/index buffers
120
*/
121
for (i = 0; i < i915->nr_vertex_buffers; i++) {
122
draw_set_mapped_vertex_buffer(i915->draw, i, NULL, 0);
123
}
124
if (mapped_indices)
125
draw_set_indexes(draw, NULL, 0, 0);
126
127
/*
128
* Instead of flushing on every state change, we flush once here
129
* when we fire the vbo.
130
*/
131
draw_flush(i915->draw);
132
}
133
134
/*
135
* Generic context functions
136
*/
137
138
static void
139
i915_destroy(struct pipe_context *pipe)
140
{
141
struct i915_context *i915 = i915_context(pipe);
142
int i;
143
144
if (i915->blitter)
145
util_blitter_destroy(i915->blitter);
146
147
draw_destroy(i915->draw);
148
149
if (i915->base.stream_uploader)
150
u_upload_destroy(i915->base.stream_uploader);
151
152
if (i915->batch)
153
i915->iws->batchbuffer_destroy(i915->batch);
154
155
/* unbind framebuffer */
156
for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) {
157
pipe_surface_reference(&i915->framebuffer.cbufs[i], NULL);
158
}
159
pipe_surface_reference(&i915->framebuffer.zsbuf, NULL);
160
161
/* unbind constant buffers */
162
for (i = 0; i < PIPE_SHADER_TYPES; i++) {
163
pipe_resource_reference(&i915->constants[i], NULL);
164
}
165
166
FREE(i915);
167
}
168
169
struct pipe_context *
170
i915_create_context(struct pipe_screen *screen, void *priv, unsigned flags)
171
{
172
struct i915_context *i915;
173
174
i915 = CALLOC_STRUCT(i915_context);
175
if (!i915)
176
return NULL;
177
178
i915->iws = i915_screen(screen)->iws;
179
i915->base.screen = screen;
180
i915->base.priv = priv;
181
i915->base.stream_uploader = u_upload_create_default(&i915->base);
182
i915->base.const_uploader = i915->base.stream_uploader;
183
184
i915->base.destroy = i915_destroy;
185
186
if (i915_screen(screen)->debug.use_blitter)
187
i915->base.clear = i915_clear_blitter;
188
else
189
i915->base.clear = i915_clear_render;
190
191
i915->base.draw_vbo = i915_draw_vbo;
192
193
/* init this before draw */
194
slab_create(&i915->transfer_pool, sizeof(struct pipe_transfer), 16);
195
slab_create(&i915->texture_transfer_pool, sizeof(struct i915_transfer), 16);
196
197
/* Batch stream debugging is a bit hacked up at the moment:
198
*/
199
i915->batch = i915->iws->batchbuffer_create(i915->iws);
200
201
/*
202
* Create drawing context and plug our rendering stage into it.
203
*/
204
i915->draw = draw_create(&i915->base);
205
assert(i915->draw);
206
if (!debug_get_option_i915_no_vbuf()) {
207
draw_set_rasterize_stage(i915->draw, i915_draw_vbuf_stage(i915));
208
} else {
209
draw_set_rasterize_stage(i915->draw, i915_draw_render_stage(i915));
210
}
211
212
i915_init_surface_functions(i915);
213
i915_init_state_functions(i915);
214
i915_init_flush_functions(i915);
215
i915_init_resource_functions(i915);
216
i915_init_query_functions(i915);
217
218
/* Create blitter. */
219
i915->blitter = util_blitter_create(&i915->base);
220
assert(i915->blitter);
221
222
/* must be done before installing Draw stages */
223
i915->no_log_program_errors = true;
224
util_blitter_cache_all_shaders(i915->blitter);
225
i915->no_log_program_errors = false;
226
227
draw_install_aaline_stage(i915->draw, &i915->base);
228
draw_install_aapoint_stage(i915->draw, &i915->base);
229
draw_enable_point_sprites(i915->draw, true);
230
231
i915->dirty = ~0;
232
i915->hardware_dirty = ~0;
233
i915->immediate_dirty = ~0;
234
i915->dynamic_dirty = ~0;
235
i915->static_dirty = ~0;
236
i915->flush_dirty = 0;
237
238
i915->current.fixup_swizzle = ~0;
239
240
return &i915->base;
241
}
242
243