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 
42 static VkResult
radv_null_ctx_create(struct radeon_winsys * _ws,enum radeon_ctx_priority priority,struct radeon_winsys_ctx ** rctx)43 radv_null_ctx_create(struct radeon_winsys *_ws, 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 
55 static void
radv_null_ctx_destroy(struct radeon_winsys_ctx * rwctx)56 radv_null_ctx_destroy(struct radeon_winsys_ctx *rwctx)
57 {
58    struct radv_null_ctx *ctx = (struct radv_null_ctx *)rwctx;
59    FREE(ctx);
60 }
61 
62 static enum radeon_bo_domain
radv_null_cs_domain(const struct radeon_winsys * _ws)63 radv_null_cs_domain(const struct radeon_winsys *_ws)
64 {
65    return RADEON_DOMAIN_GTT;
66 }
67 
68 static struct radeon_cmdbuf *
radv_null_cs_create(struct radeon_winsys * ws,enum ring_type ring_type)69 radv_null_cs_create(struct radeon_winsys *ws, enum ring_type ring_type)
70 {
71    struct radv_null_cs *cs = calloc(1, sizeof(struct radv_null_cs));
72    if (!cs)
73       return NULL;
74 
75    cs->ws = radv_null_winsys(ws);
76 
77    cs->base.buf = malloc(16384);
78    cs->base.max_dw = 4096;
79    if (!cs->base.buf) {
80       FREE(cs);
81       return NULL;
82    }
83 
84    return &cs->base;
85 }
86 
87 static VkResult
radv_null_cs_finalize(struct radeon_cmdbuf * _cs)88 radv_null_cs_finalize(struct radeon_cmdbuf *_cs)
89 {
90    return VK_SUCCESS;
91 }
92 
93 static void
radv_null_cs_destroy(struct radeon_cmdbuf * rcs)94 radv_null_cs_destroy(struct radeon_cmdbuf *rcs)
95 {
96    struct radv_null_cs *cs = radv_null_cs(rcs);
97    FREE(cs->base.buf);
98    FREE(cs);
99 }
100 
101 void
radv_null_cs_init_functions(struct radv_null_winsys * ws)102 radv_null_cs_init_functions(struct radv_null_winsys *ws)
103 {
104    ws->base.ctx_create = radv_null_ctx_create;
105    ws->base.ctx_destroy = radv_null_ctx_destroy;
106    ws->base.cs_domain = radv_null_cs_domain;
107    ws->base.cs_create = radv_null_cs_create;
108    ws->base.cs_finalize = radv_null_cs_finalize;
109    ws->base.cs_destroy = radv_null_cs_destroy;
110 }
111