1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright © 2014-2018 NVIDIA Corporation
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
10bf215546Sopenharmony_ci *
11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next
12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
13bf215546Sopenharmony_ci * Software.
14bf215546Sopenharmony_ci *
15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21bf215546Sopenharmony_ci * IN THE SOFTWARE.
22bf215546Sopenharmony_ci */
23bf215546Sopenharmony_ci
24bf215546Sopenharmony_ci#include <inttypes.h>
25bf215546Sopenharmony_ci#include <stdlib.h>
26bf215546Sopenharmony_ci
27bf215546Sopenharmony_ci#include "util/u_debug.h"
28bf215546Sopenharmony_ci#include "util/u_draw.h"
29bf215546Sopenharmony_ci#include "util/u_inlines.h"
30bf215546Sopenharmony_ci#include "util/u_upload_mgr.h"
31bf215546Sopenharmony_ci
32bf215546Sopenharmony_ci#include "tegra_context.h"
33bf215546Sopenharmony_ci#include "tegra_resource.h"
34bf215546Sopenharmony_ci#include "tegra_screen.h"
35bf215546Sopenharmony_ci
36bf215546Sopenharmony_cistatic void
37bf215546Sopenharmony_citegra_destroy(struct pipe_context *pcontext)
38bf215546Sopenharmony_ci{
39bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
40bf215546Sopenharmony_ci
41bf215546Sopenharmony_ci   if (context->base.stream_uploader)
42bf215546Sopenharmony_ci      u_upload_destroy(context->base.stream_uploader);
43bf215546Sopenharmony_ci
44bf215546Sopenharmony_ci   context->gpu->destroy(context->gpu);
45bf215546Sopenharmony_ci   free(context);
46bf215546Sopenharmony_ci}
47bf215546Sopenharmony_ci
48bf215546Sopenharmony_cistatic void
49bf215546Sopenharmony_citegra_draw_vbo(struct pipe_context *pcontext,
50bf215546Sopenharmony_ci               const struct pipe_draw_info *pinfo,
51bf215546Sopenharmony_ci               unsigned drawid_offset,
52bf215546Sopenharmony_ci               const struct pipe_draw_indirect_info *pindirect,
53bf215546Sopenharmony_ci               const struct pipe_draw_start_count_bias *draws,
54bf215546Sopenharmony_ci               unsigned num_draws)
55bf215546Sopenharmony_ci{
56bf215546Sopenharmony_ci   if (num_draws > 1) {
57bf215546Sopenharmony_ci      util_draw_multi(pcontext, pinfo, drawid_offset, pindirect, draws, num_draws);
58bf215546Sopenharmony_ci      return;
59bf215546Sopenharmony_ci   }
60bf215546Sopenharmony_ci
61bf215546Sopenharmony_ci   if (!pindirect && (!draws[0].count || !pinfo->instance_count))
62bf215546Sopenharmony_ci      return;
63bf215546Sopenharmony_ci
64bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
65bf215546Sopenharmony_ci   struct pipe_draw_indirect_info indirect;
66bf215546Sopenharmony_ci   struct pipe_draw_info info;
67bf215546Sopenharmony_ci
68bf215546Sopenharmony_ci   if (pinfo && ((pindirect && pindirect->buffer) || pinfo->index_size)) {
69bf215546Sopenharmony_ci      memcpy(&info, pinfo, sizeof(info));
70bf215546Sopenharmony_ci
71bf215546Sopenharmony_ci      if (pindirect && pindirect->buffer) {
72bf215546Sopenharmony_ci         memcpy(&indirect, pindirect, sizeof(indirect));
73bf215546Sopenharmony_ci         indirect.buffer = tegra_resource_unwrap(pindirect->buffer);
74bf215546Sopenharmony_ci         indirect.indirect_draw_count = tegra_resource_unwrap(pindirect->indirect_draw_count);
75bf215546Sopenharmony_ci         pindirect = &indirect;
76bf215546Sopenharmony_ci      }
77bf215546Sopenharmony_ci
78bf215546Sopenharmony_ci      if (pinfo->index_size && !pinfo->has_user_indices)
79bf215546Sopenharmony_ci         info.index.resource = tegra_resource_unwrap(info.index.resource);
80bf215546Sopenharmony_ci
81bf215546Sopenharmony_ci      pinfo = &info;
82bf215546Sopenharmony_ci   }
83bf215546Sopenharmony_ci
84bf215546Sopenharmony_ci   context->gpu->draw_vbo(context->gpu, pinfo, drawid_offset, pindirect, draws, num_draws);
85bf215546Sopenharmony_ci}
86bf215546Sopenharmony_ci
87bf215546Sopenharmony_cistatic void
88bf215546Sopenharmony_citegra_render_condition(struct pipe_context *pcontext,
89bf215546Sopenharmony_ci                       struct pipe_query *query,
90bf215546Sopenharmony_ci                       bool condition,
91bf215546Sopenharmony_ci                       unsigned int mode)
92bf215546Sopenharmony_ci{
93bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
94bf215546Sopenharmony_ci
95bf215546Sopenharmony_ci   context->gpu->render_condition(context->gpu, query, condition, mode);
96bf215546Sopenharmony_ci}
97bf215546Sopenharmony_ci
98bf215546Sopenharmony_cistatic struct pipe_query *
99bf215546Sopenharmony_citegra_create_query(struct pipe_context *pcontext, unsigned int query_type,
100bf215546Sopenharmony_ci                   unsigned int index)
101bf215546Sopenharmony_ci{
102bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
103bf215546Sopenharmony_ci
104bf215546Sopenharmony_ci   return context->gpu->create_query(context->gpu, query_type, index);
105bf215546Sopenharmony_ci}
106bf215546Sopenharmony_ci
107bf215546Sopenharmony_cistatic struct pipe_query *
108bf215546Sopenharmony_citegra_create_batch_query(struct pipe_context *pcontext,
109bf215546Sopenharmony_ci                         unsigned int num_queries,
110bf215546Sopenharmony_ci                         unsigned int *queries)
111bf215546Sopenharmony_ci{
112bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
113bf215546Sopenharmony_ci
114bf215546Sopenharmony_ci   return context->gpu->create_batch_query(context->gpu, num_queries,
115bf215546Sopenharmony_ci                                           queries);
116bf215546Sopenharmony_ci}
117bf215546Sopenharmony_ci
118bf215546Sopenharmony_cistatic void
119bf215546Sopenharmony_citegra_destroy_query(struct pipe_context *pcontext, struct pipe_query *query)
120bf215546Sopenharmony_ci{
121bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
122bf215546Sopenharmony_ci
123bf215546Sopenharmony_ci   context->gpu->destroy_query(context->gpu, query);
124bf215546Sopenharmony_ci}
125bf215546Sopenharmony_ci
126bf215546Sopenharmony_cistatic bool
127bf215546Sopenharmony_citegra_begin_query(struct pipe_context *pcontext, struct pipe_query *query)
128bf215546Sopenharmony_ci{
129bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
130bf215546Sopenharmony_ci
131bf215546Sopenharmony_ci   return context->gpu->begin_query(context->gpu, query);
132bf215546Sopenharmony_ci}
133bf215546Sopenharmony_ci
134bf215546Sopenharmony_cistatic bool
135bf215546Sopenharmony_citegra_end_query(struct pipe_context *pcontext, struct pipe_query *query)
136bf215546Sopenharmony_ci{
137bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
138bf215546Sopenharmony_ci
139bf215546Sopenharmony_ci   return context->gpu->end_query(context->gpu, query);
140bf215546Sopenharmony_ci}
141bf215546Sopenharmony_ci
142bf215546Sopenharmony_cistatic bool
143bf215546Sopenharmony_citegra_get_query_result(struct pipe_context *pcontext,
144bf215546Sopenharmony_ci                       struct pipe_query *query,
145bf215546Sopenharmony_ci                       bool wait,
146bf215546Sopenharmony_ci                       union pipe_query_result *result)
147bf215546Sopenharmony_ci{
148bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
149bf215546Sopenharmony_ci
150bf215546Sopenharmony_ci   return context->gpu->get_query_result(context->gpu, query, wait,
151bf215546Sopenharmony_ci                     result);
152bf215546Sopenharmony_ci}
153bf215546Sopenharmony_ci
154bf215546Sopenharmony_cistatic void
155bf215546Sopenharmony_citegra_get_query_result_resource(struct pipe_context *pcontext,
156bf215546Sopenharmony_ci                                struct pipe_query *query,
157bf215546Sopenharmony_ci                                enum pipe_query_flags flags,
158bf215546Sopenharmony_ci                                enum pipe_query_value_type result_type,
159bf215546Sopenharmony_ci                                int index,
160bf215546Sopenharmony_ci                                struct pipe_resource *resource,
161bf215546Sopenharmony_ci                                unsigned int offset)
162bf215546Sopenharmony_ci{
163bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
164bf215546Sopenharmony_ci
165bf215546Sopenharmony_ci   context->gpu->get_query_result_resource(context->gpu, query, flags,
166bf215546Sopenharmony_ci                                           result_type, index, resource,
167bf215546Sopenharmony_ci                                           offset);
168bf215546Sopenharmony_ci}
169bf215546Sopenharmony_ci
170bf215546Sopenharmony_cistatic void
171bf215546Sopenharmony_citegra_set_active_query_state(struct pipe_context *pcontext, bool enable)
172bf215546Sopenharmony_ci{
173bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
174bf215546Sopenharmony_ci
175bf215546Sopenharmony_ci   context->gpu->set_active_query_state(context->gpu, enable);
176bf215546Sopenharmony_ci}
177bf215546Sopenharmony_ci
178bf215546Sopenharmony_cistatic void *
179bf215546Sopenharmony_citegra_create_blend_state(struct pipe_context *pcontext,
180bf215546Sopenharmony_ci                         const struct pipe_blend_state *cso)
181bf215546Sopenharmony_ci{
182bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
183bf215546Sopenharmony_ci
184bf215546Sopenharmony_ci   return context->gpu->create_blend_state(context->gpu, cso);
185bf215546Sopenharmony_ci}
186bf215546Sopenharmony_ci
187bf215546Sopenharmony_cistatic void
188bf215546Sopenharmony_citegra_bind_blend_state(struct pipe_context *pcontext, void *so)
189bf215546Sopenharmony_ci{
190bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
191bf215546Sopenharmony_ci
192bf215546Sopenharmony_ci   context->gpu->bind_blend_state(context->gpu, so);
193bf215546Sopenharmony_ci}
194bf215546Sopenharmony_ci
195bf215546Sopenharmony_cistatic void
196bf215546Sopenharmony_citegra_delete_blend_state(struct pipe_context *pcontext, void *so)
197bf215546Sopenharmony_ci{
198bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
199bf215546Sopenharmony_ci
200bf215546Sopenharmony_ci   context->gpu->delete_blend_state(context->gpu, so);
201bf215546Sopenharmony_ci}
202bf215546Sopenharmony_ci
203bf215546Sopenharmony_cistatic void *
204bf215546Sopenharmony_citegra_create_sampler_state(struct pipe_context *pcontext,
205bf215546Sopenharmony_ci                           const struct pipe_sampler_state *cso)
206bf215546Sopenharmony_ci{
207bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
208bf215546Sopenharmony_ci
209bf215546Sopenharmony_ci   return context->gpu->create_sampler_state(context->gpu, cso);
210bf215546Sopenharmony_ci}
211bf215546Sopenharmony_ci
212bf215546Sopenharmony_cistatic void
213bf215546Sopenharmony_citegra_bind_sampler_states(struct pipe_context *pcontext, unsigned shader,
214bf215546Sopenharmony_ci                          unsigned start_slot, unsigned num_samplers,
215bf215546Sopenharmony_ci                          void **samplers)
216bf215546Sopenharmony_ci{
217bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
218bf215546Sopenharmony_ci
219bf215546Sopenharmony_ci   context->gpu->bind_sampler_states(context->gpu, shader, start_slot,
220bf215546Sopenharmony_ci                                     num_samplers, samplers);
221bf215546Sopenharmony_ci}
222bf215546Sopenharmony_ci
223bf215546Sopenharmony_cistatic void
224bf215546Sopenharmony_citegra_delete_sampler_state(struct pipe_context *pcontext, void *so)
225bf215546Sopenharmony_ci{
226bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
227bf215546Sopenharmony_ci
228bf215546Sopenharmony_ci   context->gpu->delete_sampler_state(context->gpu, so);
229bf215546Sopenharmony_ci}
230bf215546Sopenharmony_ci
231bf215546Sopenharmony_cistatic void *
232bf215546Sopenharmony_citegra_create_rasterizer_state(struct pipe_context *pcontext,
233bf215546Sopenharmony_ci                              const struct pipe_rasterizer_state *cso)
234bf215546Sopenharmony_ci{
235bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
236bf215546Sopenharmony_ci
237bf215546Sopenharmony_ci   return context->gpu->create_rasterizer_state(context->gpu, cso);
238bf215546Sopenharmony_ci}
239bf215546Sopenharmony_ci
240bf215546Sopenharmony_cistatic void
241bf215546Sopenharmony_citegra_bind_rasterizer_state(struct pipe_context *pcontext, void *so)
242bf215546Sopenharmony_ci{
243bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
244bf215546Sopenharmony_ci
245bf215546Sopenharmony_ci   context->gpu->bind_rasterizer_state(context->gpu, so);
246bf215546Sopenharmony_ci}
247bf215546Sopenharmony_ci
248bf215546Sopenharmony_cistatic void
249bf215546Sopenharmony_citegra_delete_rasterizer_state(struct pipe_context *pcontext, void *so)
250bf215546Sopenharmony_ci{
251bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
252bf215546Sopenharmony_ci
253bf215546Sopenharmony_ci   context->gpu->delete_rasterizer_state(context->gpu, so);
254bf215546Sopenharmony_ci}
255bf215546Sopenharmony_ci
256bf215546Sopenharmony_cistatic void *
257bf215546Sopenharmony_citegra_create_depth_stencil_alpha_state(struct pipe_context *pcontext,
258bf215546Sopenharmony_ci                                       const struct pipe_depth_stencil_alpha_state *cso)
259bf215546Sopenharmony_ci{
260bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
261bf215546Sopenharmony_ci
262bf215546Sopenharmony_ci   return context->gpu->create_depth_stencil_alpha_state(context->gpu, cso);
263bf215546Sopenharmony_ci}
264bf215546Sopenharmony_ci
265bf215546Sopenharmony_cistatic void
266bf215546Sopenharmony_citegra_bind_depth_stencil_alpha_state(struct pipe_context *pcontext, void *so)
267bf215546Sopenharmony_ci{
268bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
269bf215546Sopenharmony_ci
270bf215546Sopenharmony_ci   context->gpu->bind_depth_stencil_alpha_state(context->gpu, so);
271bf215546Sopenharmony_ci}
272bf215546Sopenharmony_ci
273bf215546Sopenharmony_cistatic void
274bf215546Sopenharmony_citegra_delete_depth_stencil_alpha_state(struct pipe_context *pcontext, void *so)
275bf215546Sopenharmony_ci{
276bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
277bf215546Sopenharmony_ci
278bf215546Sopenharmony_ci   context->gpu->delete_depth_stencil_alpha_state(context->gpu, so);
279bf215546Sopenharmony_ci}
280bf215546Sopenharmony_ci
281bf215546Sopenharmony_cistatic void *
282bf215546Sopenharmony_citegra_create_fs_state(struct pipe_context *pcontext,
283bf215546Sopenharmony_ci                      const struct pipe_shader_state *cso)
284bf215546Sopenharmony_ci{
285bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
286bf215546Sopenharmony_ci
287bf215546Sopenharmony_ci   return context->gpu->create_fs_state(context->gpu, cso);
288bf215546Sopenharmony_ci}
289bf215546Sopenharmony_ci
290bf215546Sopenharmony_cistatic void
291bf215546Sopenharmony_citegra_bind_fs_state(struct pipe_context *pcontext, void *so)
292bf215546Sopenharmony_ci{
293bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
294bf215546Sopenharmony_ci
295bf215546Sopenharmony_ci   context->gpu->bind_fs_state(context->gpu, so);
296bf215546Sopenharmony_ci}
297bf215546Sopenharmony_ci
298bf215546Sopenharmony_cistatic void
299bf215546Sopenharmony_citegra_delete_fs_state(struct pipe_context *pcontext, void *so)
300bf215546Sopenharmony_ci{
301bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
302bf215546Sopenharmony_ci
303bf215546Sopenharmony_ci   context->gpu->delete_fs_state(context->gpu, so);
304bf215546Sopenharmony_ci}
305bf215546Sopenharmony_ci
306bf215546Sopenharmony_cistatic void *
307bf215546Sopenharmony_citegra_create_vs_state(struct pipe_context *pcontext,
308bf215546Sopenharmony_ci                      const struct pipe_shader_state *cso)
309bf215546Sopenharmony_ci{
310bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
311bf215546Sopenharmony_ci
312bf215546Sopenharmony_ci   return context->gpu->create_vs_state(context->gpu, cso);
313bf215546Sopenharmony_ci}
314bf215546Sopenharmony_ci
315bf215546Sopenharmony_cistatic void
316bf215546Sopenharmony_citegra_bind_vs_state(struct pipe_context *pcontext, void *so)
317bf215546Sopenharmony_ci{
318bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
319bf215546Sopenharmony_ci
320bf215546Sopenharmony_ci   context->gpu->bind_vs_state(context->gpu, so);
321bf215546Sopenharmony_ci}
322bf215546Sopenharmony_ci
323bf215546Sopenharmony_cistatic void
324bf215546Sopenharmony_citegra_delete_vs_state(struct pipe_context *pcontext, void *so)
325bf215546Sopenharmony_ci{
326bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
327bf215546Sopenharmony_ci
328bf215546Sopenharmony_ci   context->gpu->delete_vs_state(context->gpu, so);
329bf215546Sopenharmony_ci}
330bf215546Sopenharmony_ci
331bf215546Sopenharmony_cistatic void *
332bf215546Sopenharmony_citegra_create_gs_state(struct pipe_context *pcontext,
333bf215546Sopenharmony_ci                      const struct pipe_shader_state *cso)
334bf215546Sopenharmony_ci{
335bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
336bf215546Sopenharmony_ci
337bf215546Sopenharmony_ci   return context->gpu->create_gs_state(context->gpu, cso);
338bf215546Sopenharmony_ci}
339bf215546Sopenharmony_ci
340bf215546Sopenharmony_cistatic void
341bf215546Sopenharmony_citegra_bind_gs_state(struct pipe_context *pcontext, void *so)
342bf215546Sopenharmony_ci{
343bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
344bf215546Sopenharmony_ci
345bf215546Sopenharmony_ci   context->gpu->bind_gs_state(context->gpu, so);
346bf215546Sopenharmony_ci}
347bf215546Sopenharmony_ci
348bf215546Sopenharmony_cistatic void
349bf215546Sopenharmony_citegra_delete_gs_state(struct pipe_context *pcontext, void *so)
350bf215546Sopenharmony_ci{
351bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
352bf215546Sopenharmony_ci
353bf215546Sopenharmony_ci   context->gpu->delete_gs_state(context->gpu, so);
354bf215546Sopenharmony_ci}
355bf215546Sopenharmony_ci
356bf215546Sopenharmony_cistatic void *
357bf215546Sopenharmony_citegra_create_tcs_state(struct pipe_context *pcontext,
358bf215546Sopenharmony_ci                       const struct pipe_shader_state *cso)
359bf215546Sopenharmony_ci{
360bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
361bf215546Sopenharmony_ci
362bf215546Sopenharmony_ci   return context->gpu->create_tcs_state(context->gpu, cso);
363bf215546Sopenharmony_ci}
364bf215546Sopenharmony_ci
365bf215546Sopenharmony_cistatic void
366bf215546Sopenharmony_citegra_bind_tcs_state(struct pipe_context *pcontext, void *so)
367bf215546Sopenharmony_ci{
368bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
369bf215546Sopenharmony_ci
370bf215546Sopenharmony_ci   context->gpu->bind_tcs_state(context->gpu, so);
371bf215546Sopenharmony_ci}
372bf215546Sopenharmony_ci
373bf215546Sopenharmony_cistatic void
374bf215546Sopenharmony_citegra_delete_tcs_state(struct pipe_context *pcontext, void *so)
375bf215546Sopenharmony_ci{
376bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
377bf215546Sopenharmony_ci
378bf215546Sopenharmony_ci   context->gpu->delete_tcs_state(context->gpu, so);
379bf215546Sopenharmony_ci}
380bf215546Sopenharmony_ci
381bf215546Sopenharmony_cistatic void *
382bf215546Sopenharmony_citegra_create_tes_state(struct pipe_context *pcontext,
383bf215546Sopenharmony_ci                       const struct pipe_shader_state *cso)
384bf215546Sopenharmony_ci{
385bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
386bf215546Sopenharmony_ci
387bf215546Sopenharmony_ci   return context->gpu->create_tes_state(context->gpu, cso);
388bf215546Sopenharmony_ci}
389bf215546Sopenharmony_ci
390bf215546Sopenharmony_cistatic void
391bf215546Sopenharmony_citegra_bind_tes_state(struct pipe_context *pcontext, void *so)
392bf215546Sopenharmony_ci{
393bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
394bf215546Sopenharmony_ci
395bf215546Sopenharmony_ci   context->gpu->bind_tes_state(context->gpu, so);
396bf215546Sopenharmony_ci}
397bf215546Sopenharmony_ci
398bf215546Sopenharmony_cistatic void
399bf215546Sopenharmony_citegra_delete_tes_state(struct pipe_context *pcontext, void *so)
400bf215546Sopenharmony_ci{
401bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
402bf215546Sopenharmony_ci
403bf215546Sopenharmony_ci   context->gpu->delete_tes_state(context->gpu, so);
404bf215546Sopenharmony_ci}
405bf215546Sopenharmony_ci
406bf215546Sopenharmony_cistatic void *
407bf215546Sopenharmony_citegra_create_vertex_elements_state(struct pipe_context *pcontext,
408bf215546Sopenharmony_ci                                   unsigned num_elements,
409bf215546Sopenharmony_ci                                   const struct pipe_vertex_element *elements)
410bf215546Sopenharmony_ci{
411bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
412bf215546Sopenharmony_ci
413bf215546Sopenharmony_ci   return context->gpu->create_vertex_elements_state(context->gpu,
414bf215546Sopenharmony_ci                                                     num_elements,
415bf215546Sopenharmony_ci                                                     elements);
416bf215546Sopenharmony_ci}
417bf215546Sopenharmony_ci
418bf215546Sopenharmony_cistatic void
419bf215546Sopenharmony_citegra_bind_vertex_elements_state(struct pipe_context *pcontext, void *so)
420bf215546Sopenharmony_ci{
421bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
422bf215546Sopenharmony_ci
423bf215546Sopenharmony_ci   context->gpu->bind_vertex_elements_state(context->gpu, so);
424bf215546Sopenharmony_ci}
425bf215546Sopenharmony_ci
426bf215546Sopenharmony_cistatic void
427bf215546Sopenharmony_citegra_delete_vertex_elements_state(struct pipe_context *pcontext, void *so)
428bf215546Sopenharmony_ci{
429bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
430bf215546Sopenharmony_ci
431bf215546Sopenharmony_ci   context->gpu->delete_vertex_elements_state(context->gpu, so);
432bf215546Sopenharmony_ci}
433bf215546Sopenharmony_ci
434bf215546Sopenharmony_cistatic void
435bf215546Sopenharmony_citegra_set_blend_color(struct pipe_context *pcontext,
436bf215546Sopenharmony_ci                      const struct pipe_blend_color *color)
437bf215546Sopenharmony_ci{
438bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
439bf215546Sopenharmony_ci
440bf215546Sopenharmony_ci   context->gpu->set_blend_color(context->gpu, color);
441bf215546Sopenharmony_ci}
442bf215546Sopenharmony_ci
443bf215546Sopenharmony_cistatic void
444bf215546Sopenharmony_citegra_set_stencil_ref(struct pipe_context *pcontext,
445bf215546Sopenharmony_ci                      const struct pipe_stencil_ref ref)
446bf215546Sopenharmony_ci{
447bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
448bf215546Sopenharmony_ci
449bf215546Sopenharmony_ci   context->gpu->set_stencil_ref(context->gpu, ref);
450bf215546Sopenharmony_ci}
451bf215546Sopenharmony_ci
452bf215546Sopenharmony_cistatic void
453bf215546Sopenharmony_citegra_set_sample_mask(struct pipe_context *pcontext, unsigned int mask)
454bf215546Sopenharmony_ci{
455bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
456bf215546Sopenharmony_ci
457bf215546Sopenharmony_ci   context->gpu->set_sample_mask(context->gpu, mask);
458bf215546Sopenharmony_ci}
459bf215546Sopenharmony_ci
460bf215546Sopenharmony_cistatic void
461bf215546Sopenharmony_citegra_set_min_samples(struct pipe_context *pcontext, unsigned int samples)
462bf215546Sopenharmony_ci{
463bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
464bf215546Sopenharmony_ci
465bf215546Sopenharmony_ci   context->gpu->set_min_samples(context->gpu, samples);
466bf215546Sopenharmony_ci}
467bf215546Sopenharmony_ci
468bf215546Sopenharmony_cistatic void
469bf215546Sopenharmony_citegra_set_clip_state(struct pipe_context *pcontext,
470bf215546Sopenharmony_ci                     const struct pipe_clip_state *state)
471bf215546Sopenharmony_ci{
472bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
473bf215546Sopenharmony_ci
474bf215546Sopenharmony_ci   context->gpu->set_clip_state(context->gpu, state);
475bf215546Sopenharmony_ci}
476bf215546Sopenharmony_ci
477bf215546Sopenharmony_cistatic void
478bf215546Sopenharmony_citegra_set_constant_buffer(struct pipe_context *pcontext, unsigned int shader,
479bf215546Sopenharmony_ci                          unsigned int index, bool take_ownership,
480bf215546Sopenharmony_ci                          const struct pipe_constant_buffer *buf)
481bf215546Sopenharmony_ci{
482bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
483bf215546Sopenharmony_ci   struct pipe_constant_buffer buffer;
484bf215546Sopenharmony_ci
485bf215546Sopenharmony_ci   if (buf && buf->buffer) {
486bf215546Sopenharmony_ci      memcpy(&buffer, buf, sizeof(buffer));
487bf215546Sopenharmony_ci      buffer.buffer = tegra_resource_unwrap(buffer.buffer);
488bf215546Sopenharmony_ci      buf = &buffer;
489bf215546Sopenharmony_ci   }
490bf215546Sopenharmony_ci
491bf215546Sopenharmony_ci   context->gpu->set_constant_buffer(context->gpu, shader, index, take_ownership, buf);
492bf215546Sopenharmony_ci}
493bf215546Sopenharmony_ci
494bf215546Sopenharmony_cistatic void
495bf215546Sopenharmony_citegra_set_framebuffer_state(struct pipe_context *pcontext,
496bf215546Sopenharmony_ci                            const struct pipe_framebuffer_state *fb)
497bf215546Sopenharmony_ci{
498bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
499bf215546Sopenharmony_ci   struct pipe_framebuffer_state state;
500bf215546Sopenharmony_ci   unsigned i;
501bf215546Sopenharmony_ci
502bf215546Sopenharmony_ci   if (fb) {
503bf215546Sopenharmony_ci      memcpy(&state, fb, sizeof(state));
504bf215546Sopenharmony_ci
505bf215546Sopenharmony_ci      for (i = 0; i < fb->nr_cbufs; i++)
506bf215546Sopenharmony_ci         state.cbufs[i] = tegra_surface_unwrap(fb->cbufs[i]);
507bf215546Sopenharmony_ci
508bf215546Sopenharmony_ci      while (i < PIPE_MAX_COLOR_BUFS)
509bf215546Sopenharmony_ci         state.cbufs[i++] = NULL;
510bf215546Sopenharmony_ci
511bf215546Sopenharmony_ci      state.zsbuf = tegra_surface_unwrap(fb->zsbuf);
512bf215546Sopenharmony_ci
513bf215546Sopenharmony_ci      fb = &state;
514bf215546Sopenharmony_ci   }
515bf215546Sopenharmony_ci
516bf215546Sopenharmony_ci   context->gpu->set_framebuffer_state(context->gpu, fb);
517bf215546Sopenharmony_ci}
518bf215546Sopenharmony_ci
519bf215546Sopenharmony_cistatic void
520bf215546Sopenharmony_citegra_set_polygon_stipple(struct pipe_context *pcontext,
521bf215546Sopenharmony_ci                          const struct pipe_poly_stipple *stipple)
522bf215546Sopenharmony_ci{
523bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
524bf215546Sopenharmony_ci
525bf215546Sopenharmony_ci   context->gpu->set_polygon_stipple(context->gpu, stipple);
526bf215546Sopenharmony_ci}
527bf215546Sopenharmony_ci
528bf215546Sopenharmony_cistatic void
529bf215546Sopenharmony_citegra_set_scissor_states(struct pipe_context *pcontext, unsigned start_slot,
530bf215546Sopenharmony_ci                         unsigned num_scissors,
531bf215546Sopenharmony_ci                         const struct pipe_scissor_state *scissors)
532bf215546Sopenharmony_ci{
533bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
534bf215546Sopenharmony_ci
535bf215546Sopenharmony_ci   context->gpu->set_scissor_states(context->gpu, start_slot, num_scissors,
536bf215546Sopenharmony_ci                                    scissors);
537bf215546Sopenharmony_ci}
538bf215546Sopenharmony_ci
539bf215546Sopenharmony_cistatic void
540bf215546Sopenharmony_citegra_set_window_rectangles(struct pipe_context *pcontext, bool include,
541bf215546Sopenharmony_ci                            unsigned int num_rectangles,
542bf215546Sopenharmony_ci                            const struct pipe_scissor_state *rectangles)
543bf215546Sopenharmony_ci{
544bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
545bf215546Sopenharmony_ci
546bf215546Sopenharmony_ci   context->gpu->set_window_rectangles(context->gpu, include, num_rectangles,
547bf215546Sopenharmony_ci                                       rectangles);
548bf215546Sopenharmony_ci}
549bf215546Sopenharmony_ci
550bf215546Sopenharmony_cistatic void
551bf215546Sopenharmony_citegra_set_viewport_states(struct pipe_context *pcontext, unsigned start_slot,
552bf215546Sopenharmony_ci                          unsigned num_viewports,
553bf215546Sopenharmony_ci                          const struct pipe_viewport_state *viewports)
554bf215546Sopenharmony_ci{
555bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
556bf215546Sopenharmony_ci
557bf215546Sopenharmony_ci   context->gpu->set_viewport_states(context->gpu, start_slot, num_viewports,
558bf215546Sopenharmony_ci                                     viewports);
559bf215546Sopenharmony_ci}
560bf215546Sopenharmony_ci
561bf215546Sopenharmony_cistatic void
562bf215546Sopenharmony_citegra_set_sampler_views(struct pipe_context *pcontext, unsigned shader,
563bf215546Sopenharmony_ci                        unsigned start_slot, unsigned num_views,
564bf215546Sopenharmony_ci                        unsigned unbind_num_trailing_slots,
565bf215546Sopenharmony_ci                        bool take_ownership,
566bf215546Sopenharmony_ci                        struct pipe_sampler_view **pviews)
567bf215546Sopenharmony_ci{
568bf215546Sopenharmony_ci   struct pipe_sampler_view *views[PIPE_MAX_SHADER_SAMPLER_VIEWS];
569bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
570bf215546Sopenharmony_ci   struct tegra_sampler_view *view;
571bf215546Sopenharmony_ci   unsigned i;
572bf215546Sopenharmony_ci
573bf215546Sopenharmony_ci   for (i = 0; i < num_views; i++) {
574bf215546Sopenharmony_ci      /* adjust private reference count */
575bf215546Sopenharmony_ci      view = to_tegra_sampler_view(pviews[i]);
576bf215546Sopenharmony_ci      if (view) {
577bf215546Sopenharmony_ci         view->refcount--;
578bf215546Sopenharmony_ci         if (!view->refcount) {
579bf215546Sopenharmony_ci            view->refcount = 100000000;
580bf215546Sopenharmony_ci            p_atomic_add(&view->gpu->reference.count, view->refcount);
581bf215546Sopenharmony_ci         }
582bf215546Sopenharmony_ci      }
583bf215546Sopenharmony_ci
584bf215546Sopenharmony_ci      views[i] = tegra_sampler_view_unwrap(pviews[i]);
585bf215546Sopenharmony_ci   }
586bf215546Sopenharmony_ci
587bf215546Sopenharmony_ci   context->gpu->set_sampler_views(context->gpu, shader, start_slot,
588bf215546Sopenharmony_ci                                   num_views, unbind_num_trailing_slots,
589bf215546Sopenharmony_ci                                   take_ownership, views);
590bf215546Sopenharmony_ci}
591bf215546Sopenharmony_ci
592bf215546Sopenharmony_cistatic void
593bf215546Sopenharmony_citegra_set_tess_state(struct pipe_context *pcontext,
594bf215546Sopenharmony_ci                     const float default_outer_level[4],
595bf215546Sopenharmony_ci                     const float default_inner_level[2])
596bf215546Sopenharmony_ci{
597bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
598bf215546Sopenharmony_ci
599bf215546Sopenharmony_ci   context->gpu->set_tess_state(context->gpu, default_outer_level,
600bf215546Sopenharmony_ci                                default_inner_level);
601bf215546Sopenharmony_ci}
602bf215546Sopenharmony_ci
603bf215546Sopenharmony_cistatic void
604bf215546Sopenharmony_citegra_set_debug_callback(struct pipe_context *pcontext,
605bf215546Sopenharmony_ci                         const struct util_debug_callback *callback)
606bf215546Sopenharmony_ci{
607bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
608bf215546Sopenharmony_ci
609bf215546Sopenharmony_ci   context->gpu->set_debug_callback(context->gpu, callback);
610bf215546Sopenharmony_ci}
611bf215546Sopenharmony_ci
612bf215546Sopenharmony_cistatic void
613bf215546Sopenharmony_citegra_set_shader_buffers(struct pipe_context *pcontext, unsigned int shader,
614bf215546Sopenharmony_ci                         unsigned start, unsigned count,
615bf215546Sopenharmony_ci                         const struct pipe_shader_buffer *buffers,
616bf215546Sopenharmony_ci                         unsigned writable_bitmask)
617bf215546Sopenharmony_ci{
618bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
619bf215546Sopenharmony_ci
620bf215546Sopenharmony_ci   context->gpu->set_shader_buffers(context->gpu, shader, start, count,
621bf215546Sopenharmony_ci                                    buffers, writable_bitmask);
622bf215546Sopenharmony_ci}
623bf215546Sopenharmony_ci
624bf215546Sopenharmony_cistatic void
625bf215546Sopenharmony_citegra_set_shader_images(struct pipe_context *pcontext, unsigned int shader,
626bf215546Sopenharmony_ci                        unsigned start, unsigned count,
627bf215546Sopenharmony_ci                        unsigned unbind_num_trailing_slots,
628bf215546Sopenharmony_ci                        const struct pipe_image_view *images)
629bf215546Sopenharmony_ci{
630bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
631bf215546Sopenharmony_ci
632bf215546Sopenharmony_ci   context->gpu->set_shader_images(context->gpu, shader, start, count,
633bf215546Sopenharmony_ci                                   unbind_num_trailing_slots, images);
634bf215546Sopenharmony_ci}
635bf215546Sopenharmony_ci
636bf215546Sopenharmony_cistatic void
637bf215546Sopenharmony_citegra_set_vertex_buffers(struct pipe_context *pcontext, unsigned start_slot,
638bf215546Sopenharmony_ci                         unsigned num_buffers, unsigned unbind_num_trailing_slots,
639bf215546Sopenharmony_ci                         bool take_ownership,
640bf215546Sopenharmony_ci                         const struct pipe_vertex_buffer *buffers)
641bf215546Sopenharmony_ci{
642bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
643bf215546Sopenharmony_ci   struct pipe_vertex_buffer buf[PIPE_MAX_SHADER_INPUTS];
644bf215546Sopenharmony_ci   unsigned i;
645bf215546Sopenharmony_ci
646bf215546Sopenharmony_ci   if (num_buffers && buffers) {
647bf215546Sopenharmony_ci      memcpy(buf, buffers, num_buffers * sizeof(struct pipe_vertex_buffer));
648bf215546Sopenharmony_ci
649bf215546Sopenharmony_ci      for (i = 0; i < num_buffers; i++) {
650bf215546Sopenharmony_ci         if (!buf[i].is_user_buffer)
651bf215546Sopenharmony_ci            buf[i].buffer.resource = tegra_resource_unwrap(buf[i].buffer.resource);
652bf215546Sopenharmony_ci      }
653bf215546Sopenharmony_ci
654bf215546Sopenharmony_ci      buffers = buf;
655bf215546Sopenharmony_ci   }
656bf215546Sopenharmony_ci
657bf215546Sopenharmony_ci   context->gpu->set_vertex_buffers(context->gpu, start_slot, num_buffers,
658bf215546Sopenharmony_ci                                    unbind_num_trailing_slots,
659bf215546Sopenharmony_ci                                    take_ownership, buffers);
660bf215546Sopenharmony_ci}
661bf215546Sopenharmony_ci
662bf215546Sopenharmony_cistatic struct pipe_stream_output_target *
663bf215546Sopenharmony_citegra_create_stream_output_target(struct pipe_context *pcontext,
664bf215546Sopenharmony_ci                                  struct pipe_resource *presource,
665bf215546Sopenharmony_ci                                  unsigned buffer_offset,
666bf215546Sopenharmony_ci                                  unsigned buffer_size)
667bf215546Sopenharmony_ci{
668bf215546Sopenharmony_ci   struct tegra_resource *resource = to_tegra_resource(presource);
669bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
670bf215546Sopenharmony_ci
671bf215546Sopenharmony_ci   return context->gpu->create_stream_output_target(context->gpu,
672bf215546Sopenharmony_ci                                                    resource->gpu,
673bf215546Sopenharmony_ci                                                    buffer_offset,
674bf215546Sopenharmony_ci                                                    buffer_size);
675bf215546Sopenharmony_ci}
676bf215546Sopenharmony_ci
677bf215546Sopenharmony_cistatic void
678bf215546Sopenharmony_citegra_stream_output_target_destroy(struct pipe_context *pcontext,
679bf215546Sopenharmony_ci                                   struct pipe_stream_output_target *target)
680bf215546Sopenharmony_ci{
681bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
682bf215546Sopenharmony_ci
683bf215546Sopenharmony_ci   context->gpu->stream_output_target_destroy(context->gpu, target);
684bf215546Sopenharmony_ci}
685bf215546Sopenharmony_ci
686bf215546Sopenharmony_cistatic void
687bf215546Sopenharmony_citegra_set_stream_output_targets(struct pipe_context *pcontext,
688bf215546Sopenharmony_ci                                unsigned num_targets,
689bf215546Sopenharmony_ci                                struct pipe_stream_output_target **targets,
690bf215546Sopenharmony_ci                                const unsigned *offsets)
691bf215546Sopenharmony_ci{
692bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
693bf215546Sopenharmony_ci
694bf215546Sopenharmony_ci   context->gpu->set_stream_output_targets(context->gpu, num_targets,
695bf215546Sopenharmony_ci                                           targets, offsets);
696bf215546Sopenharmony_ci}
697bf215546Sopenharmony_ci
698bf215546Sopenharmony_cistatic void
699bf215546Sopenharmony_citegra_resource_copy_region(struct pipe_context *pcontext,
700bf215546Sopenharmony_ci                           struct pipe_resource *pdst,
701bf215546Sopenharmony_ci                           unsigned int dst_level,
702bf215546Sopenharmony_ci                           unsigned int dstx,
703bf215546Sopenharmony_ci                           unsigned int dsty,
704bf215546Sopenharmony_ci                           unsigned int dstz,
705bf215546Sopenharmony_ci                           struct pipe_resource *psrc,
706bf215546Sopenharmony_ci                           unsigned int src_level,
707bf215546Sopenharmony_ci                           const struct pipe_box *src_box)
708bf215546Sopenharmony_ci{
709bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
710bf215546Sopenharmony_ci   struct tegra_resource *dst = to_tegra_resource(pdst);
711bf215546Sopenharmony_ci   struct tegra_resource *src = to_tegra_resource(psrc);
712bf215546Sopenharmony_ci
713bf215546Sopenharmony_ci   context->gpu->resource_copy_region(context->gpu, dst->gpu, dst_level, dstx,
714bf215546Sopenharmony_ci                                      dsty, dstz, src->gpu, src_level,
715bf215546Sopenharmony_ci                                      src_box);
716bf215546Sopenharmony_ci}
717bf215546Sopenharmony_ci
718bf215546Sopenharmony_cistatic void
719bf215546Sopenharmony_citegra_blit(struct pipe_context *pcontext, const struct pipe_blit_info *pinfo)
720bf215546Sopenharmony_ci{
721bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
722bf215546Sopenharmony_ci   struct pipe_blit_info info;
723bf215546Sopenharmony_ci
724bf215546Sopenharmony_ci   if (pinfo) {
725bf215546Sopenharmony_ci      memcpy(&info, pinfo, sizeof(info));
726bf215546Sopenharmony_ci      info.dst.resource = tegra_resource_unwrap(info.dst.resource);
727bf215546Sopenharmony_ci      info.src.resource = tegra_resource_unwrap(info.src.resource);
728bf215546Sopenharmony_ci      pinfo = &info;
729bf215546Sopenharmony_ci   }
730bf215546Sopenharmony_ci
731bf215546Sopenharmony_ci   context->gpu->blit(context->gpu, pinfo);
732bf215546Sopenharmony_ci}
733bf215546Sopenharmony_ci
734bf215546Sopenharmony_cistatic void
735bf215546Sopenharmony_citegra_clear(struct pipe_context *pcontext, unsigned buffers, const struct pipe_scissor_state *scissor_state,
736bf215546Sopenharmony_ci            const union pipe_color_union *color, double depth,
737bf215546Sopenharmony_ci            unsigned stencil)
738bf215546Sopenharmony_ci{
739bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
740bf215546Sopenharmony_ci
741bf215546Sopenharmony_ci   context->gpu->clear(context->gpu, buffers, NULL, color, depth, stencil);
742bf215546Sopenharmony_ci}
743bf215546Sopenharmony_ci
744bf215546Sopenharmony_cistatic void
745bf215546Sopenharmony_citegra_clear_render_target(struct pipe_context *pcontext,
746bf215546Sopenharmony_ci                          struct pipe_surface *pdst,
747bf215546Sopenharmony_ci                          const union pipe_color_union *color,
748bf215546Sopenharmony_ci                          unsigned int dstx,
749bf215546Sopenharmony_ci                          unsigned int dsty,
750bf215546Sopenharmony_ci                          unsigned int width,
751bf215546Sopenharmony_ci                          unsigned int height,
752bf215546Sopenharmony_ci                          bool render_condition)
753bf215546Sopenharmony_ci{
754bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
755bf215546Sopenharmony_ci   struct tegra_surface *dst = to_tegra_surface(pdst);
756bf215546Sopenharmony_ci
757bf215546Sopenharmony_ci   context->gpu->clear_render_target(context->gpu, dst->gpu, color, dstx,
758bf215546Sopenharmony_ci                                     dsty, width, height, render_condition);
759bf215546Sopenharmony_ci}
760bf215546Sopenharmony_ci
761bf215546Sopenharmony_cistatic void
762bf215546Sopenharmony_citegra_clear_depth_stencil(struct pipe_context *pcontext,
763bf215546Sopenharmony_ci                          struct pipe_surface *pdst,
764bf215546Sopenharmony_ci                          unsigned int flags,
765bf215546Sopenharmony_ci                          double depth,
766bf215546Sopenharmony_ci                          unsigned int stencil,
767bf215546Sopenharmony_ci                          unsigned int dstx,
768bf215546Sopenharmony_ci                          unsigned int dsty,
769bf215546Sopenharmony_ci                          unsigned int width,
770bf215546Sopenharmony_ci                          unsigned int height,
771bf215546Sopenharmony_ci                          bool render_condition)
772bf215546Sopenharmony_ci{
773bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
774bf215546Sopenharmony_ci   struct tegra_surface *dst = to_tegra_surface(pdst);
775bf215546Sopenharmony_ci
776bf215546Sopenharmony_ci   context->gpu->clear_depth_stencil(context->gpu, dst->gpu, flags, depth,
777bf215546Sopenharmony_ci                                     stencil, dstx, dsty, width, height,
778bf215546Sopenharmony_ci                                     render_condition);
779bf215546Sopenharmony_ci}
780bf215546Sopenharmony_ci
781bf215546Sopenharmony_cistatic void
782bf215546Sopenharmony_citegra_clear_texture(struct pipe_context *pcontext,
783bf215546Sopenharmony_ci                    struct pipe_resource *presource,
784bf215546Sopenharmony_ci                    unsigned int level,
785bf215546Sopenharmony_ci                    const struct pipe_box *box,
786bf215546Sopenharmony_ci                    const void *data)
787bf215546Sopenharmony_ci{
788bf215546Sopenharmony_ci   struct tegra_resource *resource = to_tegra_resource(presource);
789bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
790bf215546Sopenharmony_ci
791bf215546Sopenharmony_ci   context->gpu->clear_texture(context->gpu, resource->gpu, level, box, data);
792bf215546Sopenharmony_ci}
793bf215546Sopenharmony_ci
794bf215546Sopenharmony_cistatic void
795bf215546Sopenharmony_citegra_clear_buffer(struct pipe_context *pcontext,
796bf215546Sopenharmony_ci                   struct pipe_resource *presource,
797bf215546Sopenharmony_ci                   unsigned int offset,
798bf215546Sopenharmony_ci                   unsigned int size,
799bf215546Sopenharmony_ci                   const void *value,
800bf215546Sopenharmony_ci                   int value_size)
801bf215546Sopenharmony_ci{
802bf215546Sopenharmony_ci   struct tegra_resource *resource = to_tegra_resource(presource);
803bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
804bf215546Sopenharmony_ci
805bf215546Sopenharmony_ci   context->gpu->clear_buffer(context->gpu, resource->gpu, offset, size,
806bf215546Sopenharmony_ci                              value, value_size);
807bf215546Sopenharmony_ci}
808bf215546Sopenharmony_ci
809bf215546Sopenharmony_cistatic void
810bf215546Sopenharmony_citegra_flush(struct pipe_context *pcontext, struct pipe_fence_handle **fence,
811bf215546Sopenharmony_ci            unsigned flags)
812bf215546Sopenharmony_ci{
813bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
814bf215546Sopenharmony_ci
815bf215546Sopenharmony_ci   context->gpu->flush(context->gpu, fence, flags);
816bf215546Sopenharmony_ci}
817bf215546Sopenharmony_ci
818bf215546Sopenharmony_cistatic void
819bf215546Sopenharmony_citegra_create_fence_fd(struct pipe_context *pcontext,
820bf215546Sopenharmony_ci                      struct pipe_fence_handle **fence,
821bf215546Sopenharmony_ci                      int fd, enum pipe_fd_type type)
822bf215546Sopenharmony_ci{
823bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
824bf215546Sopenharmony_ci
825bf215546Sopenharmony_ci   assert(type == PIPE_FD_TYPE_NATIVE_SYNC);
826bf215546Sopenharmony_ci   context->gpu->create_fence_fd(context->gpu, fence, fd, type);
827bf215546Sopenharmony_ci}
828bf215546Sopenharmony_ci
829bf215546Sopenharmony_cistatic void
830bf215546Sopenharmony_citegra_fence_server_sync(struct pipe_context *pcontext,
831bf215546Sopenharmony_ci                        struct pipe_fence_handle *fence)
832bf215546Sopenharmony_ci{
833bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
834bf215546Sopenharmony_ci
835bf215546Sopenharmony_ci   context->gpu->fence_server_sync(context->gpu, fence);
836bf215546Sopenharmony_ci}
837bf215546Sopenharmony_ci
838bf215546Sopenharmony_cistatic struct pipe_sampler_view *
839bf215546Sopenharmony_citegra_create_sampler_view(struct pipe_context *pcontext,
840bf215546Sopenharmony_ci                          struct pipe_resource *presource,
841bf215546Sopenharmony_ci                          const struct pipe_sampler_view *template)
842bf215546Sopenharmony_ci{
843bf215546Sopenharmony_ci   struct tegra_resource *resource = to_tegra_resource(presource);
844bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
845bf215546Sopenharmony_ci   struct tegra_sampler_view *view;
846bf215546Sopenharmony_ci
847bf215546Sopenharmony_ci   view = calloc(1, sizeof(*view));
848bf215546Sopenharmony_ci   if (!view)
849bf215546Sopenharmony_ci      return NULL;
850bf215546Sopenharmony_ci
851bf215546Sopenharmony_ci   view->base = *template;
852bf215546Sopenharmony_ci   view->base.context = pcontext;
853bf215546Sopenharmony_ci   /* overwrite to prevent reference from being released */
854bf215546Sopenharmony_ci   view->base.texture = NULL;
855bf215546Sopenharmony_ci   pipe_reference_init(&view->base.reference, 1);
856bf215546Sopenharmony_ci   pipe_resource_reference(&view->base.texture, presource);
857bf215546Sopenharmony_ci
858bf215546Sopenharmony_ci   view->gpu = context->gpu->create_sampler_view(context->gpu, resource->gpu,
859bf215546Sopenharmony_ci                                                 template);
860bf215546Sopenharmony_ci
861bf215546Sopenharmony_ci   /* use private reference count */
862bf215546Sopenharmony_ci   view->gpu->reference.count += 100000000;
863bf215546Sopenharmony_ci   view->refcount = 100000000;
864bf215546Sopenharmony_ci
865bf215546Sopenharmony_ci   return &view->base;
866bf215546Sopenharmony_ci}
867bf215546Sopenharmony_ci
868bf215546Sopenharmony_cistatic void
869bf215546Sopenharmony_citegra_sampler_view_destroy(struct pipe_context *pcontext,
870bf215546Sopenharmony_ci                           struct pipe_sampler_view *pview)
871bf215546Sopenharmony_ci{
872bf215546Sopenharmony_ci   struct tegra_sampler_view *view = to_tegra_sampler_view(pview);
873bf215546Sopenharmony_ci
874bf215546Sopenharmony_ci   pipe_resource_reference(&view->base.texture, NULL);
875bf215546Sopenharmony_ci   /* adjust private reference count */
876bf215546Sopenharmony_ci   p_atomic_add(&view->gpu->reference.count, -view->refcount);
877bf215546Sopenharmony_ci   pipe_sampler_view_reference(&view->gpu, NULL);
878bf215546Sopenharmony_ci   free(view);
879bf215546Sopenharmony_ci}
880bf215546Sopenharmony_ci
881bf215546Sopenharmony_cistatic struct pipe_surface *
882bf215546Sopenharmony_citegra_create_surface(struct pipe_context *pcontext,
883bf215546Sopenharmony_ci                     struct pipe_resource *presource,
884bf215546Sopenharmony_ci                     const struct pipe_surface *template)
885bf215546Sopenharmony_ci{
886bf215546Sopenharmony_ci   struct tegra_resource *resource = to_tegra_resource(presource);
887bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
888bf215546Sopenharmony_ci   struct tegra_surface *surface;
889bf215546Sopenharmony_ci
890bf215546Sopenharmony_ci   surface = calloc(1, sizeof(*surface));
891bf215546Sopenharmony_ci   if (!surface)
892bf215546Sopenharmony_ci      return NULL;
893bf215546Sopenharmony_ci
894bf215546Sopenharmony_ci   surface->gpu = context->gpu->create_surface(context->gpu, resource->gpu,
895bf215546Sopenharmony_ci                                               template);
896bf215546Sopenharmony_ci   if (!surface->gpu) {
897bf215546Sopenharmony_ci      free(surface);
898bf215546Sopenharmony_ci      return NULL;
899bf215546Sopenharmony_ci   }
900bf215546Sopenharmony_ci
901bf215546Sopenharmony_ci   memcpy(&surface->base, surface->gpu, sizeof(*surface->gpu));
902bf215546Sopenharmony_ci   /* overwrite to prevent reference from being released */
903bf215546Sopenharmony_ci   surface->base.texture = NULL;
904bf215546Sopenharmony_ci
905bf215546Sopenharmony_ci   pipe_reference_init(&surface->base.reference, 1);
906bf215546Sopenharmony_ci   pipe_resource_reference(&surface->base.texture, presource);
907bf215546Sopenharmony_ci   surface->base.context = &context->base;
908bf215546Sopenharmony_ci
909bf215546Sopenharmony_ci   return &surface->base;
910bf215546Sopenharmony_ci}
911bf215546Sopenharmony_ci
912bf215546Sopenharmony_cistatic void
913bf215546Sopenharmony_citegra_surface_destroy(struct pipe_context *pcontext,
914bf215546Sopenharmony_ci                      struct pipe_surface *psurface)
915bf215546Sopenharmony_ci{
916bf215546Sopenharmony_ci   struct tegra_surface *surface = to_tegra_surface(psurface);
917bf215546Sopenharmony_ci
918bf215546Sopenharmony_ci   pipe_resource_reference(&surface->base.texture, NULL);
919bf215546Sopenharmony_ci   pipe_surface_reference(&surface->gpu, NULL);
920bf215546Sopenharmony_ci   free(surface);
921bf215546Sopenharmony_ci}
922bf215546Sopenharmony_ci
923bf215546Sopenharmony_cistatic void *
924bf215546Sopenharmony_citegra_transfer_map(struct pipe_context *pcontext,
925bf215546Sopenharmony_ci                   struct pipe_resource *presource,
926bf215546Sopenharmony_ci                   unsigned level, unsigned usage,
927bf215546Sopenharmony_ci                   const struct pipe_box *box,
928bf215546Sopenharmony_ci                   struct pipe_transfer **ptransfer)
929bf215546Sopenharmony_ci{
930bf215546Sopenharmony_ci   struct tegra_resource *resource = to_tegra_resource(presource);
931bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
932bf215546Sopenharmony_ci   struct tegra_transfer *transfer;
933bf215546Sopenharmony_ci
934bf215546Sopenharmony_ci   transfer = calloc(1, sizeof(*transfer));
935bf215546Sopenharmony_ci   if (!transfer)
936bf215546Sopenharmony_ci      return NULL;
937bf215546Sopenharmony_ci
938bf215546Sopenharmony_ci   if (presource->target == PIPE_BUFFER) {
939bf215546Sopenharmony_ci      transfer->map = context->gpu->buffer_map(context->gpu, resource->gpu,
940bf215546Sopenharmony_ci                                                 level, usage, box,
941bf215546Sopenharmony_ci                                                 &transfer->gpu);
942bf215546Sopenharmony_ci   } else {
943bf215546Sopenharmony_ci      transfer->map = context->gpu->texture_map(context->gpu, resource->gpu,
944bf215546Sopenharmony_ci                                                 level, usage, box,
945bf215546Sopenharmony_ci                                                 &transfer->gpu);
946bf215546Sopenharmony_ci   }
947bf215546Sopenharmony_ci   memcpy(&transfer->base, transfer->gpu, sizeof(*transfer->gpu));
948bf215546Sopenharmony_ci   transfer->base.resource = NULL;
949bf215546Sopenharmony_ci   pipe_resource_reference(&transfer->base.resource, presource);
950bf215546Sopenharmony_ci
951bf215546Sopenharmony_ci   *ptransfer = &transfer->base;
952bf215546Sopenharmony_ci
953bf215546Sopenharmony_ci   return transfer->map;
954bf215546Sopenharmony_ci}
955bf215546Sopenharmony_ci
956bf215546Sopenharmony_cistatic void
957bf215546Sopenharmony_citegra_transfer_flush_region(struct pipe_context *pcontext,
958bf215546Sopenharmony_ci                            struct pipe_transfer *ptransfer,
959bf215546Sopenharmony_ci                            const struct pipe_box *box)
960bf215546Sopenharmony_ci{
961bf215546Sopenharmony_ci   struct tegra_transfer *transfer = to_tegra_transfer(ptransfer);
962bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
963bf215546Sopenharmony_ci
964bf215546Sopenharmony_ci   context->gpu->transfer_flush_region(context->gpu, transfer->gpu, box);
965bf215546Sopenharmony_ci}
966bf215546Sopenharmony_ci
967bf215546Sopenharmony_cistatic void
968bf215546Sopenharmony_citegra_transfer_unmap(struct pipe_context *pcontext,
969bf215546Sopenharmony_ci                     struct pipe_transfer *ptransfer)
970bf215546Sopenharmony_ci{
971bf215546Sopenharmony_ci   struct tegra_transfer *transfer = to_tegra_transfer(ptransfer);
972bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
973bf215546Sopenharmony_ci
974bf215546Sopenharmony_ci   if (ptransfer->resource->target == PIPE_BUFFER)
975bf215546Sopenharmony_ci      context->gpu->buffer_unmap(context->gpu, transfer->gpu);
976bf215546Sopenharmony_ci   else
977bf215546Sopenharmony_ci      context->gpu->texture_unmap(context->gpu, transfer->gpu);
978bf215546Sopenharmony_ci   pipe_resource_reference(&transfer->base.resource, NULL);
979bf215546Sopenharmony_ci   free(transfer);
980bf215546Sopenharmony_ci}
981bf215546Sopenharmony_ci
982bf215546Sopenharmony_cistatic void
983bf215546Sopenharmony_citegra_buffer_subdata(struct pipe_context *pcontext,
984bf215546Sopenharmony_ci                     struct pipe_resource *presource,
985bf215546Sopenharmony_ci                     unsigned usage, unsigned offset,
986bf215546Sopenharmony_ci                     unsigned size, const void *data)
987bf215546Sopenharmony_ci{
988bf215546Sopenharmony_ci   struct tegra_resource *resource = to_tegra_resource(presource);
989bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
990bf215546Sopenharmony_ci
991bf215546Sopenharmony_ci   context->gpu->buffer_subdata(context->gpu, resource->gpu, usage, offset,
992bf215546Sopenharmony_ci                                size, data);
993bf215546Sopenharmony_ci}
994bf215546Sopenharmony_ci
995bf215546Sopenharmony_cistatic void
996bf215546Sopenharmony_citegra_texture_subdata(struct pipe_context *pcontext,
997bf215546Sopenharmony_ci                      struct pipe_resource *presource,
998bf215546Sopenharmony_ci                      unsigned level,
999bf215546Sopenharmony_ci                      unsigned usage,
1000bf215546Sopenharmony_ci                      const struct pipe_box *box,
1001bf215546Sopenharmony_ci                      const void *data,
1002bf215546Sopenharmony_ci                      unsigned stride,
1003bf215546Sopenharmony_ci                      unsigned layer_stride)
1004bf215546Sopenharmony_ci{
1005bf215546Sopenharmony_ci   struct tegra_resource *resource = to_tegra_resource(presource);
1006bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
1007bf215546Sopenharmony_ci
1008bf215546Sopenharmony_ci   context->gpu->texture_subdata(context->gpu, resource->gpu, level, usage,
1009bf215546Sopenharmony_ci                                 box, data, stride, layer_stride);
1010bf215546Sopenharmony_ci}
1011bf215546Sopenharmony_ci
1012bf215546Sopenharmony_cistatic void
1013bf215546Sopenharmony_citegra_texture_barrier(struct pipe_context *pcontext, unsigned int flags)
1014bf215546Sopenharmony_ci{
1015bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
1016bf215546Sopenharmony_ci
1017bf215546Sopenharmony_ci   context->gpu->texture_barrier(context->gpu, flags);
1018bf215546Sopenharmony_ci}
1019bf215546Sopenharmony_ci
1020bf215546Sopenharmony_cistatic void
1021bf215546Sopenharmony_citegra_memory_barrier(struct pipe_context *pcontext, unsigned int flags)
1022bf215546Sopenharmony_ci{
1023bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
1024bf215546Sopenharmony_ci
1025bf215546Sopenharmony_ci   if (!(flags & ~PIPE_BARRIER_UPDATE))
1026bf215546Sopenharmony_ci      return;
1027bf215546Sopenharmony_ci
1028bf215546Sopenharmony_ci   context->gpu->memory_barrier(context->gpu, flags);
1029bf215546Sopenharmony_ci}
1030bf215546Sopenharmony_ci
1031bf215546Sopenharmony_cistatic struct pipe_video_codec *
1032bf215546Sopenharmony_citegra_create_video_codec(struct pipe_context *pcontext,
1033bf215546Sopenharmony_ci                         const struct pipe_video_codec *template)
1034bf215546Sopenharmony_ci{
1035bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
1036bf215546Sopenharmony_ci
1037bf215546Sopenharmony_ci   return context->gpu->create_video_codec(context->gpu, template);
1038bf215546Sopenharmony_ci}
1039bf215546Sopenharmony_ci
1040bf215546Sopenharmony_cistatic struct pipe_video_buffer *
1041bf215546Sopenharmony_citegra_create_video_buffer(struct pipe_context *pcontext,
1042bf215546Sopenharmony_ci                          const struct pipe_video_buffer *template)
1043bf215546Sopenharmony_ci{
1044bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
1045bf215546Sopenharmony_ci
1046bf215546Sopenharmony_ci   return context->gpu->create_video_buffer(context->gpu, template);
1047bf215546Sopenharmony_ci}
1048bf215546Sopenharmony_ci
1049bf215546Sopenharmony_cistatic void *
1050bf215546Sopenharmony_citegra_create_compute_state(struct pipe_context *pcontext,
1051bf215546Sopenharmony_ci                           const struct pipe_compute_state *template)
1052bf215546Sopenharmony_ci{
1053bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
1054bf215546Sopenharmony_ci
1055bf215546Sopenharmony_ci   return context->gpu->create_compute_state(context->gpu, template);
1056bf215546Sopenharmony_ci}
1057bf215546Sopenharmony_ci
1058bf215546Sopenharmony_cistatic void
1059bf215546Sopenharmony_citegra_bind_compute_state(struct pipe_context *pcontext, void *so)
1060bf215546Sopenharmony_ci{
1061bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
1062bf215546Sopenharmony_ci
1063bf215546Sopenharmony_ci   context->gpu->bind_compute_state(context->gpu, so);
1064bf215546Sopenharmony_ci}
1065bf215546Sopenharmony_ci
1066bf215546Sopenharmony_cistatic void
1067bf215546Sopenharmony_citegra_delete_compute_state(struct pipe_context *pcontext, void *so)
1068bf215546Sopenharmony_ci{
1069bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
1070bf215546Sopenharmony_ci
1071bf215546Sopenharmony_ci   context->gpu->delete_compute_state(context->gpu, so);
1072bf215546Sopenharmony_ci}
1073bf215546Sopenharmony_ci
1074bf215546Sopenharmony_cistatic void
1075bf215546Sopenharmony_citegra_set_compute_resources(struct pipe_context *pcontext,
1076bf215546Sopenharmony_ci                            unsigned int start, unsigned int count,
1077bf215546Sopenharmony_ci                            struct pipe_surface **resources)
1078bf215546Sopenharmony_ci{
1079bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
1080bf215546Sopenharmony_ci
1081bf215546Sopenharmony_ci   /* XXX unwrap resources */
1082bf215546Sopenharmony_ci
1083bf215546Sopenharmony_ci   context->gpu->set_compute_resources(context->gpu, start, count, resources);
1084bf215546Sopenharmony_ci}
1085bf215546Sopenharmony_ci
1086bf215546Sopenharmony_cistatic void
1087bf215546Sopenharmony_citegra_set_global_binding(struct pipe_context *pcontext, unsigned int first,
1088bf215546Sopenharmony_ci                         unsigned int count, struct pipe_resource **resources,
1089bf215546Sopenharmony_ci                         uint32_t **handles)
1090bf215546Sopenharmony_ci{
1091bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
1092bf215546Sopenharmony_ci
1093bf215546Sopenharmony_ci   /* XXX unwrap resources */
1094bf215546Sopenharmony_ci
1095bf215546Sopenharmony_ci   context->gpu->set_global_binding(context->gpu, first, count, resources,
1096bf215546Sopenharmony_ci                                    handles);
1097bf215546Sopenharmony_ci}
1098bf215546Sopenharmony_ci
1099bf215546Sopenharmony_cistatic void
1100bf215546Sopenharmony_citegra_launch_grid(struct pipe_context *pcontext,
1101bf215546Sopenharmony_ci                  const struct pipe_grid_info *info)
1102bf215546Sopenharmony_ci{
1103bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
1104bf215546Sopenharmony_ci
1105bf215546Sopenharmony_ci   /* XXX unwrap info->indirect? */
1106bf215546Sopenharmony_ci
1107bf215546Sopenharmony_ci   context->gpu->launch_grid(context->gpu, info);
1108bf215546Sopenharmony_ci}
1109bf215546Sopenharmony_ci
1110bf215546Sopenharmony_cistatic void
1111bf215546Sopenharmony_citegra_get_sample_position(struct pipe_context *pcontext, unsigned int count,
1112bf215546Sopenharmony_ci                          unsigned int index, float *value)
1113bf215546Sopenharmony_ci{
1114bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
1115bf215546Sopenharmony_ci
1116bf215546Sopenharmony_ci   context->gpu->get_sample_position(context->gpu, count, index, value);
1117bf215546Sopenharmony_ci}
1118bf215546Sopenharmony_ci
1119bf215546Sopenharmony_cistatic uint64_t
1120bf215546Sopenharmony_citegra_get_timestamp(struct pipe_context *pcontext)
1121bf215546Sopenharmony_ci{
1122bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
1123bf215546Sopenharmony_ci
1124bf215546Sopenharmony_ci   return context->gpu->get_timestamp(context->gpu);
1125bf215546Sopenharmony_ci}
1126bf215546Sopenharmony_ci
1127bf215546Sopenharmony_cistatic void
1128bf215546Sopenharmony_citegra_flush_resource(struct pipe_context *pcontext,
1129bf215546Sopenharmony_ci                     struct pipe_resource *presource)
1130bf215546Sopenharmony_ci{
1131bf215546Sopenharmony_ci   struct tegra_resource *resource = to_tegra_resource(presource);
1132bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
1133bf215546Sopenharmony_ci
1134bf215546Sopenharmony_ci   context->gpu->flush_resource(context->gpu, resource->gpu);
1135bf215546Sopenharmony_ci}
1136bf215546Sopenharmony_ci
1137bf215546Sopenharmony_cistatic void
1138bf215546Sopenharmony_citegra_invalidate_resource(struct pipe_context *pcontext,
1139bf215546Sopenharmony_ci                          struct pipe_resource *presource)
1140bf215546Sopenharmony_ci{
1141bf215546Sopenharmony_ci   struct tegra_resource *resource = to_tegra_resource(presource);
1142bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
1143bf215546Sopenharmony_ci
1144bf215546Sopenharmony_ci   context->gpu->invalidate_resource(context->gpu, resource->gpu);
1145bf215546Sopenharmony_ci}
1146bf215546Sopenharmony_ci
1147bf215546Sopenharmony_cistatic enum pipe_reset_status
1148bf215546Sopenharmony_citegra_get_device_reset_status(struct pipe_context *pcontext)
1149bf215546Sopenharmony_ci{
1150bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
1151bf215546Sopenharmony_ci
1152bf215546Sopenharmony_ci   return context->gpu->get_device_reset_status(context->gpu);
1153bf215546Sopenharmony_ci}
1154bf215546Sopenharmony_ci
1155bf215546Sopenharmony_cistatic void
1156bf215546Sopenharmony_citegra_set_device_reset_callback(struct pipe_context *pcontext,
1157bf215546Sopenharmony_ci                                const struct pipe_device_reset_callback *cb)
1158bf215546Sopenharmony_ci{
1159bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
1160bf215546Sopenharmony_ci
1161bf215546Sopenharmony_ci   context->gpu->set_device_reset_callback(context->gpu, cb);
1162bf215546Sopenharmony_ci}
1163bf215546Sopenharmony_ci
1164bf215546Sopenharmony_cistatic void
1165bf215546Sopenharmony_citegra_dump_debug_state(struct pipe_context *pcontext, FILE *stream,
1166bf215546Sopenharmony_ci                       unsigned int flags)
1167bf215546Sopenharmony_ci{
1168bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
1169bf215546Sopenharmony_ci
1170bf215546Sopenharmony_ci   context->gpu->dump_debug_state(context->gpu, stream, flags);
1171bf215546Sopenharmony_ci}
1172bf215546Sopenharmony_ci
1173bf215546Sopenharmony_cistatic void
1174bf215546Sopenharmony_citegra_emit_string_marker(struct pipe_context *pcontext, const char *string,
1175bf215546Sopenharmony_ci                         int length)
1176bf215546Sopenharmony_ci{
1177bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
1178bf215546Sopenharmony_ci
1179bf215546Sopenharmony_ci   context->gpu->emit_string_marker(context->gpu, string, length);
1180bf215546Sopenharmony_ci}
1181bf215546Sopenharmony_ci
1182bf215546Sopenharmony_cistatic bool
1183bf215546Sopenharmony_citegra_generate_mipmap(struct pipe_context *pcontext,
1184bf215546Sopenharmony_ci                      struct pipe_resource *presource,
1185bf215546Sopenharmony_ci                      enum pipe_format format,
1186bf215546Sopenharmony_ci                      unsigned int base_level,
1187bf215546Sopenharmony_ci                      unsigned int last_level,
1188bf215546Sopenharmony_ci                      unsigned int first_layer,
1189bf215546Sopenharmony_ci                      unsigned int last_layer)
1190bf215546Sopenharmony_ci{
1191bf215546Sopenharmony_ci   struct tegra_resource *resource = to_tegra_resource(presource);
1192bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
1193bf215546Sopenharmony_ci
1194bf215546Sopenharmony_ci   return context->gpu->generate_mipmap(context->gpu, resource->gpu, format,
1195bf215546Sopenharmony_ci                                        base_level, last_level, first_layer,
1196bf215546Sopenharmony_ci                                        last_layer);
1197bf215546Sopenharmony_ci}
1198bf215546Sopenharmony_ci
1199bf215546Sopenharmony_cistatic uint64_t
1200bf215546Sopenharmony_citegra_create_texture_handle(struct pipe_context *pcontext,
1201bf215546Sopenharmony_ci                            struct pipe_sampler_view *view,
1202bf215546Sopenharmony_ci                            const struct pipe_sampler_state *state)
1203bf215546Sopenharmony_ci{
1204bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
1205bf215546Sopenharmony_ci
1206bf215546Sopenharmony_ci   return context->gpu->create_texture_handle(context->gpu, view, state);
1207bf215546Sopenharmony_ci}
1208bf215546Sopenharmony_ci
1209bf215546Sopenharmony_cistatic void tegra_delete_texture_handle(struct pipe_context *pcontext,
1210bf215546Sopenharmony_ci                                        uint64_t handle)
1211bf215546Sopenharmony_ci{
1212bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
1213bf215546Sopenharmony_ci
1214bf215546Sopenharmony_ci   context->gpu->delete_texture_handle(context->gpu, handle);
1215bf215546Sopenharmony_ci}
1216bf215546Sopenharmony_ci
1217bf215546Sopenharmony_cistatic void tegra_make_texture_handle_resident(struct pipe_context *pcontext,
1218bf215546Sopenharmony_ci                                               uint64_t handle, bool resident)
1219bf215546Sopenharmony_ci{
1220bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
1221bf215546Sopenharmony_ci
1222bf215546Sopenharmony_ci   context->gpu->make_texture_handle_resident(context->gpu, handle, resident);
1223bf215546Sopenharmony_ci}
1224bf215546Sopenharmony_ci
1225bf215546Sopenharmony_cistatic uint64_t tegra_create_image_handle(struct pipe_context *pcontext,
1226bf215546Sopenharmony_ci                                          const struct pipe_image_view *image)
1227bf215546Sopenharmony_ci{
1228bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
1229bf215546Sopenharmony_ci
1230bf215546Sopenharmony_ci   return context->gpu->create_image_handle(context->gpu, image);
1231bf215546Sopenharmony_ci}
1232bf215546Sopenharmony_ci
1233bf215546Sopenharmony_cistatic void tegra_delete_image_handle(struct pipe_context *pcontext,
1234bf215546Sopenharmony_ci                                      uint64_t handle)
1235bf215546Sopenharmony_ci{
1236bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
1237bf215546Sopenharmony_ci
1238bf215546Sopenharmony_ci   context->gpu->delete_image_handle(context->gpu, handle);
1239bf215546Sopenharmony_ci}
1240bf215546Sopenharmony_ci
1241bf215546Sopenharmony_cistatic void tegra_make_image_handle_resident(struct pipe_context *pcontext,
1242bf215546Sopenharmony_ci                                             uint64_t handle, unsigned access,
1243bf215546Sopenharmony_ci                                             bool resident)
1244bf215546Sopenharmony_ci{
1245bf215546Sopenharmony_ci   struct tegra_context *context = to_tegra_context(pcontext);
1246bf215546Sopenharmony_ci
1247bf215546Sopenharmony_ci   context->gpu->make_image_handle_resident(context->gpu, handle, access,
1248bf215546Sopenharmony_ci                                            resident);
1249bf215546Sopenharmony_ci}
1250bf215546Sopenharmony_ci
1251bf215546Sopenharmony_cistruct pipe_context *
1252bf215546Sopenharmony_citegra_screen_context_create(struct pipe_screen *pscreen, void *priv,
1253bf215546Sopenharmony_ci                            unsigned int flags)
1254bf215546Sopenharmony_ci{
1255bf215546Sopenharmony_ci   struct tegra_screen *screen = to_tegra_screen(pscreen);
1256bf215546Sopenharmony_ci   struct tegra_context *context;
1257bf215546Sopenharmony_ci
1258bf215546Sopenharmony_ci   context = calloc(1, sizeof(*context));
1259bf215546Sopenharmony_ci   if (!context)
1260bf215546Sopenharmony_ci      return NULL;
1261bf215546Sopenharmony_ci
1262bf215546Sopenharmony_ci   context->gpu = screen->gpu->context_create(screen->gpu, priv, flags);
1263bf215546Sopenharmony_ci   if (!context->gpu) {
1264bf215546Sopenharmony_ci      debug_error("failed to create GPU context\n");
1265bf215546Sopenharmony_ci      goto free;
1266bf215546Sopenharmony_ci   }
1267bf215546Sopenharmony_ci
1268bf215546Sopenharmony_ci   context->base.screen = &screen->base;
1269bf215546Sopenharmony_ci   context->base.priv = priv;
1270bf215546Sopenharmony_ci
1271bf215546Sopenharmony_ci   /*
1272bf215546Sopenharmony_ci    * Create custom stream and const uploaders. Note that technically nouveau
1273bf215546Sopenharmony_ci    * already creates uploaders that could be reused, but that would make the
1274bf215546Sopenharmony_ci    * resource unwrapping rather complicate. The reason for that is that both
1275bf215546Sopenharmony_ci    * uploaders create resources based on the context that they were created
1276bf215546Sopenharmony_ci    * from, which means that nouveau's uploader will use the nouveau context
1277bf215546Sopenharmony_ci    * which means that those resources must not be unwrapped. So before each
1278bf215546Sopenharmony_ci    * resource is unwrapped, the code would need to check that it does not
1279bf215546Sopenharmony_ci    * correspond to the uploaders' buffers.
1280bf215546Sopenharmony_ci    *
1281bf215546Sopenharmony_ci    * However, duplicating the uploaders here sounds worse than it is. The
1282bf215546Sopenharmony_ci    * default implementation that nouveau uses allocates buffers lazily, and
1283bf215546Sopenharmony_ci    * since it is never used, no buffers will every be allocated and the only
1284bf215546Sopenharmony_ci    * memory wasted is that occupied by the nouveau uploader itself.
1285bf215546Sopenharmony_ci    */
1286bf215546Sopenharmony_ci   context->base.stream_uploader = u_upload_create_default(&context->base);
1287bf215546Sopenharmony_ci   if (!context->base.stream_uploader)
1288bf215546Sopenharmony_ci      goto destroy;
1289bf215546Sopenharmony_ci
1290bf215546Sopenharmony_ci   context->base.const_uploader = context->base.stream_uploader;
1291bf215546Sopenharmony_ci
1292bf215546Sopenharmony_ci   context->base.destroy = tegra_destroy;
1293bf215546Sopenharmony_ci
1294bf215546Sopenharmony_ci   context->base.draw_vbo = tegra_draw_vbo;
1295bf215546Sopenharmony_ci
1296bf215546Sopenharmony_ci   context->base.render_condition = tegra_render_condition;
1297bf215546Sopenharmony_ci
1298bf215546Sopenharmony_ci   context->base.create_query = tegra_create_query;
1299bf215546Sopenharmony_ci   context->base.create_batch_query = tegra_create_batch_query;
1300bf215546Sopenharmony_ci   context->base.destroy_query = tegra_destroy_query;
1301bf215546Sopenharmony_ci   context->base.begin_query = tegra_begin_query;
1302bf215546Sopenharmony_ci   context->base.end_query = tegra_end_query;
1303bf215546Sopenharmony_ci   context->base.get_query_result = tegra_get_query_result;
1304bf215546Sopenharmony_ci   context->base.get_query_result_resource = tegra_get_query_result_resource;
1305bf215546Sopenharmony_ci   context->base.set_active_query_state = tegra_set_active_query_state;
1306bf215546Sopenharmony_ci
1307bf215546Sopenharmony_ci   context->base.create_blend_state = tegra_create_blend_state;
1308bf215546Sopenharmony_ci   context->base.bind_blend_state = tegra_bind_blend_state;
1309bf215546Sopenharmony_ci   context->base.delete_blend_state = tegra_delete_blend_state;
1310bf215546Sopenharmony_ci
1311bf215546Sopenharmony_ci   context->base.create_sampler_state = tegra_create_sampler_state;
1312bf215546Sopenharmony_ci   context->base.bind_sampler_states = tegra_bind_sampler_states;
1313bf215546Sopenharmony_ci   context->base.delete_sampler_state = tegra_delete_sampler_state;
1314bf215546Sopenharmony_ci
1315bf215546Sopenharmony_ci   context->base.create_rasterizer_state = tegra_create_rasterizer_state;
1316bf215546Sopenharmony_ci   context->base.bind_rasterizer_state = tegra_bind_rasterizer_state;
1317bf215546Sopenharmony_ci   context->base.delete_rasterizer_state = tegra_delete_rasterizer_state;
1318bf215546Sopenharmony_ci
1319bf215546Sopenharmony_ci   context->base.create_depth_stencil_alpha_state = tegra_create_depth_stencil_alpha_state;
1320bf215546Sopenharmony_ci   context->base.bind_depth_stencil_alpha_state = tegra_bind_depth_stencil_alpha_state;
1321bf215546Sopenharmony_ci   context->base.delete_depth_stencil_alpha_state = tegra_delete_depth_stencil_alpha_state;
1322bf215546Sopenharmony_ci
1323bf215546Sopenharmony_ci   context->base.create_fs_state = tegra_create_fs_state;
1324bf215546Sopenharmony_ci   context->base.bind_fs_state = tegra_bind_fs_state;
1325bf215546Sopenharmony_ci   context->base.delete_fs_state = tegra_delete_fs_state;
1326bf215546Sopenharmony_ci
1327bf215546Sopenharmony_ci   context->base.create_vs_state = tegra_create_vs_state;
1328bf215546Sopenharmony_ci   context->base.bind_vs_state = tegra_bind_vs_state;
1329bf215546Sopenharmony_ci   context->base.delete_vs_state = tegra_delete_vs_state;
1330bf215546Sopenharmony_ci
1331bf215546Sopenharmony_ci   context->base.create_gs_state = tegra_create_gs_state;
1332bf215546Sopenharmony_ci   context->base.bind_gs_state = tegra_bind_gs_state;
1333bf215546Sopenharmony_ci   context->base.delete_gs_state = tegra_delete_gs_state;
1334bf215546Sopenharmony_ci
1335bf215546Sopenharmony_ci   context->base.create_tcs_state = tegra_create_tcs_state;
1336bf215546Sopenharmony_ci   context->base.bind_tcs_state = tegra_bind_tcs_state;
1337bf215546Sopenharmony_ci   context->base.delete_tcs_state = tegra_delete_tcs_state;
1338bf215546Sopenharmony_ci
1339bf215546Sopenharmony_ci   context->base.create_tes_state = tegra_create_tes_state;
1340bf215546Sopenharmony_ci   context->base.bind_tes_state = tegra_bind_tes_state;
1341bf215546Sopenharmony_ci   context->base.delete_tes_state = tegra_delete_tes_state;
1342bf215546Sopenharmony_ci
1343bf215546Sopenharmony_ci   context->base.create_vertex_elements_state = tegra_create_vertex_elements_state;
1344bf215546Sopenharmony_ci   context->base.bind_vertex_elements_state = tegra_bind_vertex_elements_state;
1345bf215546Sopenharmony_ci   context->base.delete_vertex_elements_state = tegra_delete_vertex_elements_state;
1346bf215546Sopenharmony_ci
1347bf215546Sopenharmony_ci   context->base.set_blend_color = tegra_set_blend_color;
1348bf215546Sopenharmony_ci   context->base.set_stencil_ref = tegra_set_stencil_ref;
1349bf215546Sopenharmony_ci   context->base.set_sample_mask = tegra_set_sample_mask;
1350bf215546Sopenharmony_ci   context->base.set_min_samples = tegra_set_min_samples;
1351bf215546Sopenharmony_ci   context->base.set_clip_state = tegra_set_clip_state;
1352bf215546Sopenharmony_ci
1353bf215546Sopenharmony_ci   context->base.set_constant_buffer = tegra_set_constant_buffer;
1354bf215546Sopenharmony_ci   context->base.set_framebuffer_state = tegra_set_framebuffer_state;
1355bf215546Sopenharmony_ci   context->base.set_polygon_stipple = tegra_set_polygon_stipple;
1356bf215546Sopenharmony_ci   context->base.set_scissor_states = tegra_set_scissor_states;
1357bf215546Sopenharmony_ci   context->base.set_window_rectangles = tegra_set_window_rectangles;
1358bf215546Sopenharmony_ci   context->base.set_viewport_states = tegra_set_viewport_states;
1359bf215546Sopenharmony_ci   context->base.set_sampler_views = tegra_set_sampler_views;
1360bf215546Sopenharmony_ci   context->base.set_tess_state = tegra_set_tess_state;
1361bf215546Sopenharmony_ci
1362bf215546Sopenharmony_ci   context->base.set_debug_callback = tegra_set_debug_callback;
1363bf215546Sopenharmony_ci
1364bf215546Sopenharmony_ci   context->base.set_shader_buffers = tegra_set_shader_buffers;
1365bf215546Sopenharmony_ci   context->base.set_shader_images = tegra_set_shader_images;
1366bf215546Sopenharmony_ci   context->base.set_vertex_buffers = tegra_set_vertex_buffers;
1367bf215546Sopenharmony_ci
1368bf215546Sopenharmony_ci   context->base.create_stream_output_target = tegra_create_stream_output_target;
1369bf215546Sopenharmony_ci   context->base.stream_output_target_destroy = tegra_stream_output_target_destroy;
1370bf215546Sopenharmony_ci   context->base.set_stream_output_targets = tegra_set_stream_output_targets;
1371bf215546Sopenharmony_ci
1372bf215546Sopenharmony_ci   context->base.resource_copy_region = tegra_resource_copy_region;
1373bf215546Sopenharmony_ci   context->base.blit = tegra_blit;
1374bf215546Sopenharmony_ci   context->base.clear = tegra_clear;
1375bf215546Sopenharmony_ci   context->base.clear_render_target = tegra_clear_render_target;
1376bf215546Sopenharmony_ci   context->base.clear_depth_stencil = tegra_clear_depth_stencil;
1377bf215546Sopenharmony_ci   context->base.clear_texture = tegra_clear_texture;
1378bf215546Sopenharmony_ci   context->base.clear_buffer = tegra_clear_buffer;
1379bf215546Sopenharmony_ci   context->base.flush = tegra_flush;
1380bf215546Sopenharmony_ci
1381bf215546Sopenharmony_ci   context->base.create_fence_fd = tegra_create_fence_fd;
1382bf215546Sopenharmony_ci   context->base.fence_server_sync = tegra_fence_server_sync;
1383bf215546Sopenharmony_ci
1384bf215546Sopenharmony_ci   context->base.create_sampler_view = tegra_create_sampler_view;
1385bf215546Sopenharmony_ci   context->base.sampler_view_destroy = tegra_sampler_view_destroy;
1386bf215546Sopenharmony_ci
1387bf215546Sopenharmony_ci   context->base.create_surface = tegra_create_surface;
1388bf215546Sopenharmony_ci   context->base.surface_destroy = tegra_surface_destroy;
1389bf215546Sopenharmony_ci
1390bf215546Sopenharmony_ci   context->base.buffer_map = tegra_transfer_map;
1391bf215546Sopenharmony_ci   context->base.texture_map = tegra_transfer_map;
1392bf215546Sopenharmony_ci   context->base.transfer_flush_region = tegra_transfer_flush_region;
1393bf215546Sopenharmony_ci   context->base.buffer_unmap = tegra_transfer_unmap;
1394bf215546Sopenharmony_ci   context->base.texture_unmap = tegra_transfer_unmap;
1395bf215546Sopenharmony_ci   context->base.buffer_subdata = tegra_buffer_subdata;
1396bf215546Sopenharmony_ci   context->base.texture_subdata = tegra_texture_subdata;
1397bf215546Sopenharmony_ci
1398bf215546Sopenharmony_ci   context->base.texture_barrier = tegra_texture_barrier;
1399bf215546Sopenharmony_ci   context->base.memory_barrier = tegra_memory_barrier;
1400bf215546Sopenharmony_ci
1401bf215546Sopenharmony_ci   context->base.create_video_codec = tegra_create_video_codec;
1402bf215546Sopenharmony_ci   context->base.create_video_buffer = tegra_create_video_buffer;
1403bf215546Sopenharmony_ci
1404bf215546Sopenharmony_ci   context->base.create_compute_state = tegra_create_compute_state;
1405bf215546Sopenharmony_ci   context->base.bind_compute_state = tegra_bind_compute_state;
1406bf215546Sopenharmony_ci   context->base.delete_compute_state = tegra_delete_compute_state;
1407bf215546Sopenharmony_ci   context->base.set_compute_resources = tegra_set_compute_resources;
1408bf215546Sopenharmony_ci   context->base.set_global_binding = tegra_set_global_binding;
1409bf215546Sopenharmony_ci   context->base.launch_grid = tegra_launch_grid;
1410bf215546Sopenharmony_ci   context->base.get_sample_position = tegra_get_sample_position;
1411bf215546Sopenharmony_ci   context->base.get_timestamp = tegra_get_timestamp;
1412bf215546Sopenharmony_ci
1413bf215546Sopenharmony_ci   context->base.flush_resource = tegra_flush_resource;
1414bf215546Sopenharmony_ci   context->base.invalidate_resource = tegra_invalidate_resource;
1415bf215546Sopenharmony_ci
1416bf215546Sopenharmony_ci   context->base.get_device_reset_status = tegra_get_device_reset_status;
1417bf215546Sopenharmony_ci   context->base.set_device_reset_callback = tegra_set_device_reset_callback;
1418bf215546Sopenharmony_ci   context->base.dump_debug_state = tegra_dump_debug_state;
1419bf215546Sopenharmony_ci   context->base.emit_string_marker = tegra_emit_string_marker;
1420bf215546Sopenharmony_ci
1421bf215546Sopenharmony_ci   context->base.generate_mipmap = tegra_generate_mipmap;
1422bf215546Sopenharmony_ci
1423bf215546Sopenharmony_ci   context->base.create_texture_handle = tegra_create_texture_handle;
1424bf215546Sopenharmony_ci   context->base.delete_texture_handle = tegra_delete_texture_handle;
1425bf215546Sopenharmony_ci   context->base.make_texture_handle_resident = tegra_make_texture_handle_resident;
1426bf215546Sopenharmony_ci   context->base.create_image_handle = tegra_create_image_handle;
1427bf215546Sopenharmony_ci   context->base.delete_image_handle = tegra_delete_image_handle;
1428bf215546Sopenharmony_ci   context->base.make_image_handle_resident = tegra_make_image_handle_resident;
1429bf215546Sopenharmony_ci
1430bf215546Sopenharmony_ci   return &context->base;
1431bf215546Sopenharmony_ci
1432bf215546Sopenharmony_cidestroy:
1433bf215546Sopenharmony_ci   context->gpu->destroy(context->gpu);
1434bf215546Sopenharmony_cifree:
1435bf215546Sopenharmony_ci   free(context);
1436bf215546Sopenharmony_ci   return NULL;
1437bf215546Sopenharmony_ci}
1438