Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/gallium/drivers/freedreno/a2xx/fd2_context.c
4574 views
1
/*
2
* Copyright (C) 2013 Rob Clark <[email protected]>
3
*
4
* Permission is hereby granted, free of charge, to any person obtaining a
5
* copy of this software and associated documentation files (the "Software"),
6
* to deal in the Software without restriction, including without limitation
7
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
* and/or sell copies of the Software, and to permit persons to whom the
9
* Software is furnished to do so, subject to the following conditions:
10
*
11
* The above copyright notice and this permission notice (including the next
12
* paragraph) shall be included in all copies or substantial portions of the
13
* Software.
14
*
15
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
* SOFTWARE.
22
*
23
* Authors:
24
* Rob Clark <[email protected]>
25
*/
26
27
#include "fd2_context.h"
28
#include "fd2_blend.h"
29
#include "fd2_draw.h"
30
#include "fd2_emit.h"
31
#include "fd2_gmem.h"
32
#include "fd2_program.h"
33
#include "fd2_query.h"
34
#include "fd2_rasterizer.h"
35
#include "fd2_texture.h"
36
#include "fd2_zsa.h"
37
38
static void
39
fd2_context_destroy(struct pipe_context *pctx) in_dt
40
{
41
fd_context_destroy(pctx);
42
free(pctx);
43
}
44
45
static struct pipe_resource *
46
create_solid_vertexbuf(struct pipe_context *pctx)
47
{
48
/* clang-format off */
49
static const float init_shader_const[] = {
50
/* for clear/gmem2mem/mem2gmem (vertices): */
51
-1.000000, +1.000000, +1.000000,
52
+1.000000, +1.000000, +1.000000,
53
-1.000000, -1.000000, +1.000000,
54
/* for mem2gmem: (tex coords) */
55
+0.000000, +0.000000,
56
+1.000000, +0.000000,
57
+0.000000, +1.000000,
58
/* SCREEN_SCISSOR_BR value (must be at 60 byte offset in page) */
59
0.0,
60
/* zero indices dummy draw workaround (3 16-bit zeros) */
61
0.0, 0.0,
62
};
63
/* clang-format on */
64
65
struct pipe_resource *prsc =
66
pipe_buffer_create(pctx->screen, PIPE_BIND_CUSTOM, PIPE_USAGE_IMMUTABLE,
67
sizeof(init_shader_const));
68
pipe_buffer_write(pctx, prsc, 0, sizeof(init_shader_const),
69
init_shader_const);
70
return prsc;
71
}
72
73
/* clang-format off */
74
static const uint8_t a22x_primtypes[PIPE_PRIM_MAX] = {
75
[PIPE_PRIM_POINTS] = DI_PT_POINTLIST_PSIZE,
76
[PIPE_PRIM_LINES] = DI_PT_LINELIST,
77
[PIPE_PRIM_LINE_STRIP] = DI_PT_LINESTRIP,
78
[PIPE_PRIM_LINE_LOOP] = DI_PT_LINELOOP,
79
[PIPE_PRIM_TRIANGLES] = DI_PT_TRILIST,
80
[PIPE_PRIM_TRIANGLE_STRIP] = DI_PT_TRISTRIP,
81
[PIPE_PRIM_TRIANGLE_FAN] = DI_PT_TRIFAN,
82
};
83
84
static const uint8_t a20x_primtypes[PIPE_PRIM_MAX] = {
85
[PIPE_PRIM_POINTS] = DI_PT_POINTLIST_PSIZE,
86
[PIPE_PRIM_LINES] = DI_PT_LINELIST,
87
[PIPE_PRIM_LINE_STRIP] = DI_PT_LINESTRIP,
88
[PIPE_PRIM_TRIANGLES] = DI_PT_TRILIST,
89
[PIPE_PRIM_TRIANGLE_STRIP] = DI_PT_TRISTRIP,
90
[PIPE_PRIM_TRIANGLE_FAN] = DI_PT_TRIFAN,
91
};
92
/* clang-format on */
93
94
struct pipe_context *
95
fd2_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags)
96
{
97
struct fd_screen *screen = fd_screen(pscreen);
98
struct fd2_context *fd2_ctx = CALLOC_STRUCT(fd2_context);
99
struct pipe_context *pctx;
100
101
if (!fd2_ctx)
102
return NULL;
103
104
pctx = &fd2_ctx->base.base;
105
pctx->screen = pscreen;
106
107
fd2_ctx->base.dev = fd_device_ref(screen->dev);
108
fd2_ctx->base.screen = fd_screen(pscreen);
109
110
pctx->destroy = fd2_context_destroy;
111
pctx->create_blend_state = fd2_blend_state_create;
112
pctx->create_rasterizer_state = fd2_rasterizer_state_create;
113
pctx->create_depth_stencil_alpha_state = fd2_zsa_state_create;
114
115
fd2_draw_init(pctx);
116
fd2_gmem_init(pctx);
117
fd2_texture_init(pctx);
118
fd2_prog_init(pctx);
119
fd2_emit_init(pctx);
120
121
pctx = fd_context_init(
122
&fd2_ctx->base, pscreen,
123
(screen->gpu_id >= 220) ? a22x_primtypes : a20x_primtypes, priv, flags);
124
if (!pctx)
125
return NULL;
126
127
/* construct vertex state used for solid ops (clear, and gmem<->mem) */
128
fd2_ctx->solid_vertexbuf = create_solid_vertexbuf(pctx);
129
130
fd2_query_context_init(pctx);
131
132
return pctx;
133
}
134
135