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 31struct radv_null_cs { 32 struct radeon_cmdbuf base; 33 struct radv_null_winsys *ws; 34}; 35 36static inline struct radv_null_cs * 37radv_null_cs(struct radeon_cmdbuf *base) 38{ 39 return (struct radv_null_cs *)base; 40} 41 42static VkResult 43radv_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 55static void 56radv_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 62static enum radeon_bo_domain 63radv_null_cs_domain(const struct radeon_winsys *_ws) 64{ 65 return RADEON_DOMAIN_GTT; 66} 67 68static struct radeon_cmdbuf * 69radv_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 87static VkResult 88radv_null_cs_finalize(struct radeon_cmdbuf *_cs) 89{ 90 return VK_SUCCESS; 91} 92 93static void 94radv_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 101void 102radv_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