| 1 |
/* |
| 2 |
* Copyright © 2013 Rob Clark <[email protected]> |
| 3 |
* SPDX-License-Identifier: MIT |
| 4 |
* |
| 5 |
* Authors: |
| 6 |
* Rob Clark <[email protected]> |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "fd2_context.h" |
| 10 |
#include "fd2_blend.h" |
| 11 |
#include "fd2_draw.h" |
| 12 |
#include "fd2_emit.h" |
| 13 |
#include "fd2_gmem.h" |
| 14 |
#include "fd2_program.h" |
| 15 |
#include "fd2_query.h" |
| 16 |
#include "fd2_rasterizer.h" |
| 17 |
#include "fd2_texture.h" |
| 18 |
#include "fd2_zsa.h" |
| 19 |
|
| 20 |
static void |
| 21 |
fd2_context_destroy(struct pipe_context *pctx) in_dt |
| 22 |
{ |
| 23 |
fd_context_destroy(pctx); |
| 24 |
free(pctx); |
| 25 |
} |
| 26 |
|
| 27 |
static struct pipe_resource * |
| 28 |
create_solid_vertexbuf(struct pipe_context *pctx) |
| 29 |
{ |
| 30 |
/* clang-format off */ |
| 31 |
static const float init_shader_const[] = { |
| 32 |
/* for clear/gmem2mem/mem2gmem (vertices): */ |
| 33 |
-1.000000f, +1.000000f, +1.000000f, |
| 34 |
+1.000000f, +1.000000f, +1.000000f, |
| 35 |
-1.000000f, -1.000000f, +1.000000f, |
| 36 |
/* for mem2gmem: (tex coords) */ |
| 37 |
+0.000000f, +0.000000f, |
| 38 |
+1.000000f, +0.000000f, |
| 39 |
+0.000000f, +1.000000f, |
| 40 |
/* SCREEN_SCISSOR_BR value (must be at 60 byte offset in page) */ |
| 41 |
0.0f, |
| 42 |
/* zero indices dummy draw workaround (3 16-bit zeros) */ |
| 43 |
0.0f, 0.0f, |
| 44 |
}; |
| 45 |
/* clang-format on */ |
| 46 |
|
| 47 |
struct pipe_resource *prsc = |
| 48 |
pipe_buffer_create(pctx->screen, PIPE_BIND_CUSTOM, PIPE_USAGE_IMMUTABLE, |
| 49 |
sizeof(init_shader_const)); |
| 50 |
pipe_buffer_write(pctx, prsc, 0, sizeof(init_shader_const), |
| 51 |
init_shader_const); |
| 52 |
return prsc; |
| 53 |
} |
| 54 |
|
| 55 |
struct pipe_context * |
| 56 |
fd2_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags) |
| 57 |
{ |
| 58 |
struct fd_screen *screen = fd_screen(pscreen); |
| 59 |
struct fd2_context *fd2_ctx = CALLOC_STRUCT(fd2_context); |
| 60 |
struct pipe_context *pctx; |
| 61 |
|
| 62 |
if (!fd2_ctx) |
| 63 |
return NULL; |
| 64 |
|
| 65 |
pctx = &fd2_ctx->base.base; |
| 66 |
pctx->screen = pscreen; |
| 67 |
|
| 68 |
fd2_ctx->base.flags = flags; |
| 69 |
fd2_ctx->base.dev = fd_device_ref(screen->dev); |
| 70 |
fd2_ctx->base.screen = fd_screen(pscreen); |
| 71 |
|
| 72 |
pctx->destroy = fd2_context_destroy; |
| 73 |
pctx->create_blend_state = fd2_blend_state_create; |
| 74 |
pctx->create_rasterizer_state = fd2_rasterizer_state_create; |
| 75 |
pctx->create_depth_stencil_alpha_state = fd2_zsa_state_create; |
| 76 |
|
| 77 |
fd2_draw_init(pctx); |
| 78 |
fd2_gmem_init(pctx); |
| 79 |
fd2_texture_init(pctx); |
| 80 |
fd2_prog_init(pctx); |
| 81 |
fd2_emit_init(pctx); |
| 82 |
|
| 83 |
pctx = fd_context_init(&fd2_ctx->base, pscreen, priv, flags); |
| 84 |
if (!pctx) |
| 85 |
return NULL; |
| 86 |
|
| 87 |
/* construct vertex state used for solid ops (clear, and gmem<->mem) */ |
| 88 |
fd2_ctx->solid_vertexbuf = create_solid_vertexbuf(pctx); |
| 89 |
|
| 90 |
fd2_query_context_init(pctx); |
| 91 |
|
| 92 |
return pctx; |
| 93 |
} |