• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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, struct radeon_winsys_ctx **rctx)
44 {
45    struct radv_null_ctx *ctx = CALLOC_STRUCT(radv_null_ctx);
46 
47    if (!ctx)
48       return VK_ERROR_OUT_OF_HOST_MEMORY;
49 
50    *rctx = (struct radeon_winsys_ctx *)ctx;
51    return VK_SUCCESS;
52 }
53 
54 static void
radv_null_ctx_destroy(struct radeon_winsys_ctx * rwctx)55 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 enum radeon_bo_domain
radv_null_cs_domain(const struct radeon_winsys * _ws)62 radv_null_cs_domain(const struct radeon_winsys *_ws)
63 {
64    return RADEON_DOMAIN_GTT;
65 }
66 
67 static struct radeon_cmdbuf *
radv_null_cs_create(struct radeon_winsys * ws,enum amd_ip_type ip_type,UNUSED bool is_secondary)68 radv_null_cs_create(struct radeon_winsys *ws, enum amd_ip_type ip_type, UNUSED bool is_secondary)
69 {
70    struct radv_null_cs *cs = calloc(1, sizeof(struct radv_null_cs));
71    if (!cs)
72       return NULL;
73 
74    cs->ws = radv_null_winsys(ws);
75 
76    cs->base.buf = malloc(16384);
77    cs->base.max_dw = 4096;
78    if (!cs->base.buf) {
79       FREE(cs);
80       return NULL;
81    }
82 
83    return &cs->base;
84 }
85 
86 static VkResult
radv_null_cs_finalize(struct radeon_cmdbuf * _cs)87 radv_null_cs_finalize(struct radeon_cmdbuf *_cs)
88 {
89    return VK_SUCCESS;
90 }
91 
92 static void
radv_null_cs_destroy(struct radeon_cmdbuf * rcs)93 radv_null_cs_destroy(struct radeon_cmdbuf *rcs)
94 {
95    struct radv_null_cs *cs = radv_null_cs(rcs);
96    FREE(cs->base.buf);
97    FREE(cs);
98 }
99 
100 void
radv_null_cs_init_functions(struct radv_null_winsys * ws)101 radv_null_cs_init_functions(struct radv_null_winsys *ws)
102 {
103    ws->base.ctx_create = radv_null_ctx_create;
104    ws->base.ctx_destroy = radv_null_ctx_destroy;
105    ws->base.cs_domain = radv_null_cs_domain;
106    ws->base.cs_create = radv_null_cs_create;
107    ws->base.cs_finalize = radv_null_cs_finalize;
108    ws->base.cs_destroy = radv_null_cs_destroy;
109 }
110