1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright (c) 2011-2013 Luc Verhaegen <libv@skynet.be> 3bf215546Sopenharmony_ci * Copyright (c) 2017-2019 Lima Project 4bf215546Sopenharmony_ci * 5bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 6bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 7bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 8bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sub license, 9bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 10bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 11bf215546Sopenharmony_ci * 12bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the 13bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions 14bf215546Sopenharmony_ci * of the Software. 15bf215546Sopenharmony_ci * 16bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 19bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22bf215546Sopenharmony_ci * DEALINGS IN THE SOFTWARE. 23bf215546Sopenharmony_ci * 24bf215546Sopenharmony_ci */ 25bf215546Sopenharmony_ci 26bf215546Sopenharmony_ci#ifndef H_LIMA_GPU 27bf215546Sopenharmony_ci#define H_LIMA_GPU 28bf215546Sopenharmony_ci 29bf215546Sopenharmony_ci#include <stdint.h> 30bf215546Sopenharmony_ci#include <assert.h> 31bf215546Sopenharmony_ci 32bf215546Sopenharmony_ci#include <util/u_dynarray.h> 33bf215546Sopenharmony_ci 34bf215546Sopenharmony_cistruct lima_gp_frame_reg { 35bf215546Sopenharmony_ci uint32_t vs_cmd_start; 36bf215546Sopenharmony_ci uint32_t vs_cmd_end; 37bf215546Sopenharmony_ci uint32_t plbu_cmd_start; 38bf215546Sopenharmony_ci uint32_t plbu_cmd_end; 39bf215546Sopenharmony_ci uint32_t tile_heap_start; 40bf215546Sopenharmony_ci uint32_t tile_heap_end; 41bf215546Sopenharmony_ci}; 42bf215546Sopenharmony_ci 43bf215546Sopenharmony_cistruct lima_pp_frame_reg { 44bf215546Sopenharmony_ci uint32_t plbu_array_address; 45bf215546Sopenharmony_ci uint32_t render_address; 46bf215546Sopenharmony_ci uint32_t unused_0; 47bf215546Sopenharmony_ci uint32_t flags; 48bf215546Sopenharmony_ci uint32_t clear_value_depth; 49bf215546Sopenharmony_ci uint32_t clear_value_stencil; 50bf215546Sopenharmony_ci uint32_t clear_value_color; 51bf215546Sopenharmony_ci uint32_t clear_value_color_1; 52bf215546Sopenharmony_ci uint32_t clear_value_color_2; 53bf215546Sopenharmony_ci uint32_t clear_value_color_3; 54bf215546Sopenharmony_ci uint32_t width; 55bf215546Sopenharmony_ci uint32_t height; 56bf215546Sopenharmony_ci uint32_t fragment_stack_address; 57bf215546Sopenharmony_ci uint32_t fragment_stack_size; 58bf215546Sopenharmony_ci uint32_t unused_1; 59bf215546Sopenharmony_ci uint32_t unused_2; 60bf215546Sopenharmony_ci uint32_t one; 61bf215546Sopenharmony_ci uint32_t supersampled_height; 62bf215546Sopenharmony_ci uint32_t dubya; 63bf215546Sopenharmony_ci uint32_t onscreen; 64bf215546Sopenharmony_ci uint32_t blocking; 65bf215546Sopenharmony_ci uint32_t scale; 66bf215546Sopenharmony_ci uint32_t channel_layout; 67bf215546Sopenharmony_ci}; 68bf215546Sopenharmony_ci 69bf215546Sopenharmony_cistruct lima_pp_wb_reg { 70bf215546Sopenharmony_ci uint32_t type; 71bf215546Sopenharmony_ci uint32_t address; 72bf215546Sopenharmony_ci uint32_t pixel_format; 73bf215546Sopenharmony_ci uint32_t downsample_factor; 74bf215546Sopenharmony_ci uint32_t pixel_layout; 75bf215546Sopenharmony_ci uint32_t pitch; 76bf215546Sopenharmony_ci uint32_t flags; 77bf215546Sopenharmony_ci uint32_t mrt_bits; 78bf215546Sopenharmony_ci uint32_t mrt_pitch; 79bf215546Sopenharmony_ci uint32_t unused0; 80bf215546Sopenharmony_ci uint32_t unused1; 81bf215546Sopenharmony_ci uint32_t unused2; 82bf215546Sopenharmony_ci}; 83bf215546Sopenharmony_ci 84bf215546Sopenharmony_cistruct lima_render_state { 85bf215546Sopenharmony_ci uint32_t blend_color_bg; 86bf215546Sopenharmony_ci uint32_t blend_color_ra; 87bf215546Sopenharmony_ci uint32_t alpha_blend; 88bf215546Sopenharmony_ci uint32_t depth_test; 89bf215546Sopenharmony_ci uint32_t depth_range; 90bf215546Sopenharmony_ci uint32_t stencil_front; 91bf215546Sopenharmony_ci uint32_t stencil_back; 92bf215546Sopenharmony_ci uint32_t stencil_test; 93bf215546Sopenharmony_ci uint32_t multi_sample; 94bf215546Sopenharmony_ci uint32_t shader_address; 95bf215546Sopenharmony_ci uint32_t varying_types; 96bf215546Sopenharmony_ci uint32_t uniforms_address; 97bf215546Sopenharmony_ci uint32_t textures_address; 98bf215546Sopenharmony_ci uint32_t aux0; 99bf215546Sopenharmony_ci uint32_t aux1; 100bf215546Sopenharmony_ci uint32_t varyings_address; 101bf215546Sopenharmony_ci}; 102bf215546Sopenharmony_ci 103bf215546Sopenharmony_ci/* plbu commands */ 104bf215546Sopenharmony_ci#define PLBU_CMD_BEGIN(array, max) { \ 105bf215546Sopenharmony_ci int i = 0, max_n = max; \ 106bf215546Sopenharmony_ci struct util_dynarray *plbu_cmd_array = array; \ 107bf215546Sopenharmony_ci uint32_t *plbu_cmd = util_dynarray_ensure_cap(plbu_cmd_array, plbu_cmd_array->size + max_n * 4); 108bf215546Sopenharmony_ci 109bf215546Sopenharmony_ci#define PLBU_CMD_END() \ 110bf215546Sopenharmony_ci assert(i <= max_n); \ 111bf215546Sopenharmony_ci plbu_cmd_array->size += i * 4; \ 112bf215546Sopenharmony_ci} 113bf215546Sopenharmony_ci 114bf215546Sopenharmony_ci#define PLBU_CMD_CURRENT_POS() \ 115bf215546Sopenharmony_ci (util_dynarray_num_elements(plbu_cmd_array, uint32_t) + i) 116bf215546Sopenharmony_ci 117bf215546Sopenharmony_ci#define PLBU_CMD(v1, v2) \ 118bf215546Sopenharmony_ci do { \ 119bf215546Sopenharmony_ci plbu_cmd[i++] = v1; \ 120bf215546Sopenharmony_ci plbu_cmd[i++] = v2; \ 121bf215546Sopenharmony_ci } while (0) 122bf215546Sopenharmony_ci 123bf215546Sopenharmony_ci#define PLBU_CMD_BLOCK_STEP(shift_min, shift_h, shift_w) \ 124bf215546Sopenharmony_ci PLBU_CMD(((shift_min) << 28) | ((shift_h) << 16) | (shift_w), 0x1000010C) 125bf215546Sopenharmony_ci#define PLBU_CMD_TILED_DIMENSIONS(tiled_w, tiled_h) \ 126bf215546Sopenharmony_ci PLBU_CMD((((tiled_w) - 1) << 24) | (((tiled_h) - 1) << 8), 0x10000109) 127bf215546Sopenharmony_ci#define PLBU_CMD_BLOCK_STRIDE(block_w) PLBU_CMD((block_w) & 0xff, 0x30000000) 128bf215546Sopenharmony_ci#define PLBU_CMD_ARRAY_ADDRESS(gp_stream, block_num) \ 129bf215546Sopenharmony_ci PLBU_CMD(gp_stream, 0x28000000 | ((block_num) - 1) | 1) 130bf215546Sopenharmony_ci#define PLBU_CMD_VIEWPORT_LEFT(v) PLBU_CMD(v, 0x10000107) 131bf215546Sopenharmony_ci#define PLBU_CMD_VIEWPORT_RIGHT(v) PLBU_CMD(v, 0x10000108) 132bf215546Sopenharmony_ci#define PLBU_CMD_VIEWPORT_BOTTOM(v) PLBU_CMD(v, 0x10000105) 133bf215546Sopenharmony_ci#define PLBU_CMD_VIEWPORT_TOP(v) PLBU_CMD(v, 0x10000106) 134bf215546Sopenharmony_ci#define PLBU_CMD_ARRAYS_SEMAPHORE_BEGIN() PLBU_CMD(0x00010002, 0x60000000) 135bf215546Sopenharmony_ci#define PLBU_CMD_ARRAYS_SEMAPHORE_END() PLBU_CMD(0x00010001, 0x60000000) 136bf215546Sopenharmony_ci#define PLBU_CMD_PRIMITIVE_SETUP(force_point_size, cull, index_size) \ 137bf215546Sopenharmony_ci PLBU_CMD(0x2200 | ((force_point_size) ? 0x1000 : 0) | \ 138bf215546Sopenharmony_ci (cull) | ((index_size) << 9), 0x1000010B) 139bf215546Sopenharmony_ci#define PLBU_CMD_RSW_VERTEX_ARRAY(rsw, gl_pos) \ 140bf215546Sopenharmony_ci PLBU_CMD(rsw, 0x80000000 | ((gl_pos) >> 4)) 141bf215546Sopenharmony_ci#define PLBU_CMD_SCISSORS(minx, maxx, miny, maxy) \ 142bf215546Sopenharmony_ci PLBU_CMD(((minx) << 30) | ((maxy) - 1) << 15 | (miny), \ 143bf215546Sopenharmony_ci 0x70000000 | ((maxx) - 1) << 13 | ((minx) >> 2)) 144bf215546Sopenharmony_ci#define PLBU_CMD_UNKNOWN1() PLBU_CMD(0x00000000, 0x1000010A) 145bf215546Sopenharmony_ci#define PLBU_CMD_UNKNOWN2() PLBU_CMD(0x00000200, 0x1000010B) 146bf215546Sopenharmony_ci#define PLBU_CMD_LOW_PRIM_SIZE(v) PLBU_CMD(v, 0x1000010D) 147bf215546Sopenharmony_ci#define PLBU_CMD_DEPTH_RANGE_NEAR(v) PLBU_CMD(v, 0x1000010E) 148bf215546Sopenharmony_ci#define PLBU_CMD_DEPTH_RANGE_FAR(v) PLBU_CMD(v, 0x1000010F) 149bf215546Sopenharmony_ci#define PLBU_CMD_INDEXED_DEST(gl_pos) PLBU_CMD(gl_pos, 0x10000100) 150bf215546Sopenharmony_ci#define PLBU_CMD_INDEXED_PT_SIZE(pt_size) PLBU_CMD(pt_size, 0x10000102) 151bf215546Sopenharmony_ci#define PLBU_CMD_INDICES(va) PLBU_CMD(va, 0x10000101) 152bf215546Sopenharmony_ci#define PLBU_CMD_DRAW_ARRAYS(mode, start, count) \ 153bf215546Sopenharmony_ci PLBU_CMD(((count) << 24) | (start), (((mode) & 0x1F) << 16) | ((count) >> 8)) 154bf215546Sopenharmony_ci#define PLBU_CMD_DRAW_ELEMENTS(mode, start, count) \ 155bf215546Sopenharmony_ci PLBU_CMD(((count) << 24) | (start), \ 156bf215546Sopenharmony_ci 0x00200000 | (((mode) & 0x1F) << 16) | ((count) >> 8)) 157bf215546Sopenharmony_ci 158bf215546Sopenharmony_ci/* vs commands */ 159bf215546Sopenharmony_ci#define VS_CMD_BEGIN(array, max) { \ 160bf215546Sopenharmony_ci int i = 0, max_n = max; \ 161bf215546Sopenharmony_ci struct util_dynarray *vs_cmd_array = array; \ 162bf215546Sopenharmony_ci uint32_t *vs_cmd = util_dynarray_ensure_cap(vs_cmd_array, vs_cmd_array->size + max_n * 4); 163bf215546Sopenharmony_ci 164bf215546Sopenharmony_ci#define VS_CMD_END() \ 165bf215546Sopenharmony_ci assert(i <= max_n); \ 166bf215546Sopenharmony_ci vs_cmd_array->size += i * 4; \ 167bf215546Sopenharmony_ci} 168bf215546Sopenharmony_ci 169bf215546Sopenharmony_ci#define VS_CMD(v1, v2) \ 170bf215546Sopenharmony_ci do { \ 171bf215546Sopenharmony_ci vs_cmd[i++] = v1; \ 172bf215546Sopenharmony_ci vs_cmd[i++] = v2; \ 173bf215546Sopenharmony_ci } while (0) 174bf215546Sopenharmony_ci 175bf215546Sopenharmony_ci#define VS_CMD_ARRAYS_SEMAPHORE_BEGIN_1() VS_CMD(0x00028000, 0x50000000) 176bf215546Sopenharmony_ci#define VS_CMD_ARRAYS_SEMAPHORE_BEGIN_2() VS_CMD(0x00000001, 0x50000000) 177bf215546Sopenharmony_ci#define VS_CMD_ARRAYS_SEMAPHORE_END(index_draw) \ 178bf215546Sopenharmony_ci VS_CMD((index_draw) ? 0x00018000 : 0x00000000, 0x50000000) 179bf215546Sopenharmony_ci#define VS_CMD_UNIFORMS_ADDRESS(addr, size) \ 180bf215546Sopenharmony_ci VS_CMD(addr, 0x30000000 | ((size) << 12)) 181bf215546Sopenharmony_ci#define VS_CMD_SHADER_ADDRESS(addr, size) \ 182bf215546Sopenharmony_ci VS_CMD(addr, 0x40000000 | ((size) << 12)) 183bf215546Sopenharmony_ci#define VS_CMD_SHADER_INFO(prefetch, size) \ 184bf215546Sopenharmony_ci VS_CMD(((prefetch) << 20) | ((((size) >> 4) - 1) << 10), 0x10000040) 185bf215546Sopenharmony_ci#define VS_CMD_VARYING_ATTRIBUTE_COUNT(nv, na) \ 186bf215546Sopenharmony_ci VS_CMD((((nv) - 1) << 8) | (((na) - 1) << 24), 0x10000042) 187bf215546Sopenharmony_ci#define VS_CMD_UNKNOWN1() VS_CMD(0x00000003, 0x10000041) 188bf215546Sopenharmony_ci#define VS_CMD_UNKNOWN2() VS_CMD(0x00000000, 0x60000000) 189bf215546Sopenharmony_ci#define VS_CMD_ATTRIBUTES_ADDRESS(addr, na) \ 190bf215546Sopenharmony_ci VS_CMD(addr, 0x20000000 | ((na) << 17)) 191bf215546Sopenharmony_ci#define VS_CMD_VARYINGS_ADDRESS(addr, nv) \ 192bf215546Sopenharmony_ci VS_CMD(addr, 0x20000008 | ((nv) << 17)) 193bf215546Sopenharmony_ci#define VS_CMD_DRAW(num, index_draw) \ 194bf215546Sopenharmony_ci VS_CMD(((num) << 24) | ((index_draw) ? 1 : 0), ((num) >> 8)) 195bf215546Sopenharmony_ci 196bf215546Sopenharmony_ci#endif 197