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