1 /*
2 * Copyright © 2020 Valve Corporation
3 *
4 * based on amdgpu winsys.
5 * Copyright © 2016 Red Hat.
6 * Copyright © 2016 Bas Nieuwenhuizen
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
17 * Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25 * IN THE SOFTWARE.
26 */
27
28 #include "radv_null_cs.h"
29 #include "util/u_memory.h"
30
31 struct radv_null_cs {
32 struct radeon_cmdbuf base;
33 struct radv_null_winsys *ws;
34 };
35
36 static inline struct radv_null_cs *
radv_null_cs(struct radeon_cmdbuf * base)37 radv_null_cs(struct radeon_cmdbuf *base)
38 {
39 return (struct radv_null_cs*)base;
40 }
41
radv_null_ctx_create(struct radeon_winsys * _ws,enum radeon_ctx_priority priority,struct radeon_winsys_ctx ** rctx)42 static VkResult radv_null_ctx_create(struct radeon_winsys *_ws,
43 enum radeon_ctx_priority priority,
44 struct radeon_winsys_ctx **rctx)
45 {
46 struct radv_null_ctx *ctx = CALLOC_STRUCT(radv_null_ctx);
47
48 if (!ctx)
49 return VK_ERROR_OUT_OF_HOST_MEMORY;
50
51 *rctx = (struct radeon_winsys_ctx *)ctx;
52 return VK_SUCCESS;
53 }
54
radv_null_ctx_destroy(struct radeon_winsys_ctx * rwctx)55 static void radv_null_ctx_destroy(struct radeon_winsys_ctx *rwctx)
56 {
57 struct radv_null_ctx *ctx = (struct radv_null_ctx *)rwctx;
58 FREE(ctx);
59 }
60
61 static struct radeon_cmdbuf *
radv_null_cs_create(struct radeon_winsys * ws,enum ring_type ring_type)62 radv_null_cs_create(struct radeon_winsys *ws,
63 enum ring_type ring_type)
64 {
65 struct radv_null_cs *cs = calloc(1, sizeof(struct radv_null_cs));
66 if (!cs)
67 return NULL;
68
69 cs->ws = radv_null_winsys(ws);
70
71 cs->base.buf = malloc(16384);
72 cs->base.max_dw = 4096;
73 if (!cs->base.buf) {
74 FREE(cs);
75 return NULL;
76 }
77
78 return &cs->base;
79 }
80
radv_null_cs_finalize(struct radeon_cmdbuf * _cs)81 static VkResult radv_null_cs_finalize(struct radeon_cmdbuf *_cs)
82 {
83 return VK_SUCCESS;
84 }
85
radv_null_cs_destroy(struct radeon_cmdbuf * rcs)86 static void radv_null_cs_destroy(struct radeon_cmdbuf *rcs)
87 {
88 struct radv_null_cs *cs = radv_null_cs(rcs);
89 FREE(cs->base.buf);
90 FREE(cs);
91 }
92
radv_null_cs_init_functions(struct radv_null_winsys * ws)93 void radv_null_cs_init_functions(struct radv_null_winsys *ws)
94 {
95 ws->base.ctx_create = radv_null_ctx_create;
96 ws->base.ctx_destroy = radv_null_ctx_destroy;
97 ws->base.cs_create = radv_null_cs_create;
98 ws->base.cs_finalize = radv_null_cs_finalize;
99 ws->base.cs_destroy = radv_null_cs_destroy;
100
101 }
102