r300_cs.h revision 8648c2685870174cf620ef15de70ef030a8d5a20
178b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson/* 278b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson * Copyright 2008 Corbin Simpson <MostAwesomeDude@gmail.com> 378b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson * 478b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson * Permission is hereby granted, free of charge, to any person obtaining a 578b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson * copy of this software and associated documentation files (the "Software"), 678b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson * to deal in the Software without restriction, including without limitation 778b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson * on the rights to use, copy, modify, merge, publish, distribute, sub 878b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson * license, and/or sell copies of the Software, and to permit persons to whom 978b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson * the Software is furnished to do so, subject to the following conditions: 1078b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson * 1178b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson * The above copyright notice and this permission notice (including the next 1278b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson * paragraph) shall be included in all copies or substantial portions of the 1378b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson * Software. 1478b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson * 1578b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1678b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1778b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 1878b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, 1978b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 2078b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 2178b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson * USE OR OTHER DEALINGS IN THE SOFTWARE. */ 2278b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson 2378b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson#ifndef R300_CS_H 2478b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson#define R300_CS_H 2578b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson 26f176c94e49a50b05b3af9f748a67e2ebd2e1b8fdCorbin Simpson#include "util/u_math.h" 27f176c94e49a50b05b3af9f748a67e2ebd2e1b8fdCorbin Simpson 2874288078eab1971cc6ce3ae00fa55eb917b5826aCorbin Simpson#include "r300_reg.h" 29fbeeb6675733f5b2da36d40b0142dadf8cc953b4Corbin Simpson#include "r300_winsys.h" 30fbeeb6675733f5b2da36d40b0142dadf8cc953b4Corbin Simpson 3178b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson/* Yes, I know macros are ugly. However, they are much prettier than the code 3278b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson * that they neatly hide away, and don't have the cost of function setup,so 3378b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson * we're going to use them. */ 3478b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson 3578b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson#define MAX_CS_SIZE 64 * 1024 / 4 3678b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson 37ffbe28d25d755bc51d9f865ac176a110f6f8f5e0Corbin Simpson#define VERY_VERBOSE_REGISTERS 0 38ffbe28d25d755bc51d9f865ac176a110f6f8f5e0Corbin Simpson 39fbeeb6675733f5b2da36d40b0142dadf8cc953b4Corbin Simpson/* XXX stolen from radeon_drm.h */ 40fbeeb6675733f5b2da36d40b0142dadf8cc953b4Corbin Simpson#define RADEON_GEM_DOMAIN_CPU 0x1 41fbeeb6675733f5b2da36d40b0142dadf8cc953b4Corbin Simpson#define RADEON_GEM_DOMAIN_GTT 0x2 42fbeeb6675733f5b2da36d40b0142dadf8cc953b4Corbin Simpson#define RADEON_GEM_DOMAIN_VRAM 0x4 43fbeeb6675733f5b2da36d40b0142dadf8cc953b4Corbin Simpson 447961974fc28257b293961d35f15c0ce7a85f2669Corbin Simpson/* XXX stolen from radeon_reg.h */ 457961974fc28257b293961d35f15c0ce7a85f2669Corbin Simpson#define RADEON_CP_PACKET0 0x0 467961974fc28257b293961d35f15c0ce7a85f2669Corbin Simpson 4778b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson#define CP_PACKET0(register, count) \ 4878b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson (RADEON_CP_PACKET0 | ((count) << 16) | ((register) >> 2)) 4978b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson 5078b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson#define CS_LOCALS(context) \ 51fbeeb6675733f5b2da36d40b0142dadf8cc953b4Corbin Simpson struct r300_winsys* cs_winsys = context->winsys; \ 522cb90c8e805d010ba4594264dd9edbbb7f95513aCorbin Simpson struct radeon_cs* cs = cs_winsys->cs; \ 5380dc1801409f9913cc37b8fc8e68c692bc8a22caCorbin Simpson int cs_count = 0; 5478b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson 55fbeeb6675733f5b2da36d40b0142dadf8cc953b4Corbin Simpson#define CHECK_CS(size) \ 56fbeeb6675733f5b2da36d40b0142dadf8cc953b4Corbin Simpson cs_winsys->check_cs(cs, (size)) 5778b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson 5878b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson#define BEGIN_CS(size) do { \ 5978b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson CHECK_CS(size); \ 6084ec4d6bedf33bf03ff7a778632eef7b209944cbCorbin Simpson debug_printf("r300: BEGIN_CS, count %d, in %s (%s:%d)\n", \ 6184ec4d6bedf33bf03ff7a778632eef7b209944cbCorbin Simpson size, __FUNCTION__, __FILE__, __LINE__); \ 62fbeeb6675733f5b2da36d40b0142dadf8cc953b4Corbin Simpson cs_winsys->begin_cs(cs, (size), __FILE__, __FUNCTION__, __LINE__); \ 6384ec4d6bedf33bf03ff7a778632eef7b209944cbCorbin Simpson cs_count = size; \ 6478b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson} while (0) 6578b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson 66412cf4d38be628200982208b7f93bb17530bb6dbCorbin Simpson#define OUT_CS(value) do { \ 6780dc1801409f9913cc37b8fc8e68c692bc8a22caCorbin Simpson cs_winsys->write_cs_dword(cs, (value)); \ 6880dc1801409f9913cc37b8fc8e68c692bc8a22caCorbin Simpson cs_count--; \ 69412cf4d38be628200982208b7f93bb17530bb6dbCorbin Simpson} while (0) 7078b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson 71412cf4d38be628200982208b7f93bb17530bb6dbCorbin Simpson#define OUT_CS_32F(value) do { \ 72f176c94e49a50b05b3af9f748a67e2ebd2e1b8fdCorbin Simpson cs_winsys->write_cs_dword(cs, fui(value)); \ 7380dc1801409f9913cc37b8fc8e68c692bc8a22caCorbin Simpson cs_count--; \ 74412cf4d38be628200982208b7f93bb17530bb6dbCorbin Simpson} while (0) 7522877265f4fdf66c75df391d6de95bd5c1584ea3Corbin Simpson 7678b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson#define OUT_CS_REG(register, value) do { \ 77ffbe28d25d755bc51d9f865ac176a110f6f8f5e0Corbin Simpson if (VERY_VERBOSE_REGISTERS) \ 78ffbe28d25d755bc51d9f865ac176a110f6f8f5e0Corbin Simpson debug_printf("r300: writing 0x%08X to register 0x%04X\n", \ 79ffbe28d25d755bc51d9f865ac176a110f6f8f5e0Corbin Simpson value, register); \ 80c199f330322921e01c8c30e3ea69a2a5291ae8eeCorbin Simpson assert(register); \ 8178b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson OUT_CS(CP_PACKET0(register, 0)); \ 82412cf4d38be628200982208b7f93bb17530bb6dbCorbin Simpson OUT_CS(value); \ 83412cf4d38be628200982208b7f93bb17530bb6dbCorbin Simpson} while (0) 8478b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson 8522877265f4fdf66c75df391d6de95bd5c1584ea3Corbin Simpson/* Note: This expects count to be the number of registers, 8622877265f4fdf66c75df391d6de95bd5c1584ea3Corbin Simpson * not the actual packet0 count! */ 8722877265f4fdf66c75df391d6de95bd5c1584ea3Corbin Simpson#define OUT_CS_REG_SEQ(register, count) do { \ 88ffbe28d25d755bc51d9f865ac176a110f6f8f5e0Corbin Simpson if (VERY_VERBOSE_REGISTERS) \ 89ffbe28d25d755bc51d9f865ac176a110f6f8f5e0Corbin Simpson debug_printf("r300: writing register sequence of %d to 0x%04X\n", \ 90ffbe28d25d755bc51d9f865ac176a110f6f8f5e0Corbin Simpson count, register); \ 91c199f330322921e01c8c30e3ea69a2a5291ae8eeCorbin Simpson assert(register); \ 9222877265f4fdf66c75df391d6de95bd5c1584ea3Corbin Simpson OUT_CS(CP_PACKET0(register, ((count) - 1))); \ 9322877265f4fdf66c75df391d6de95bd5c1584ea3Corbin Simpson} while (0) 9422877265f4fdf66c75df391d6de95bd5c1584ea3Corbin Simpson 9578b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson#define OUT_CS_RELOC(bo, offset, rd, wd, flags) do { \ 9629a4f5493529042d1068a7d35da1e7f542474503Corbin Simpson debug_printf("r300: writing relocation for buffer %p, offset %d\n", \ 9729a4f5493529042d1068a7d35da1e7f542474503Corbin Simpson bo, offset); \ 98c199f330322921e01c8c30e3ea69a2a5291ae8eeCorbin Simpson assert(bo); \ 99fbeeb6675733f5b2da36d40b0142dadf8cc953b4Corbin Simpson OUT_CS(offset); \ 100fbeeb6675733f5b2da36d40b0142dadf8cc953b4Corbin Simpson cs_winsys->write_cs_reloc(cs, bo, rd, wd, flags); \ 1012e70971e4f1ac5278e9da67341e8c39518308d20Corbin Simpson cs_count -= 2; \ 10278b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson} while (0) 10378b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson 104902b1be0ea2a7fea27cea26915db5977f9a8f76cCorbin Simpson#define END_CS do { \ 105f2a7d4f2e8e890e69e1dfa9067db4e90df63989fCorbin Simpson debug_printf("r300: END_CS in %s (%s:%d)\n", __FUNCTION__, __FILE__, \ 106902b1be0ea2a7fea27cea26915db5977f9a8f76cCorbin Simpson __LINE__); \ 1072cb90c8e805d010ba4594264dd9edbbb7f95513aCorbin Simpson if (cs_count != 0) \ 1082cb90c8e805d010ba4594264dd9edbbb7f95513aCorbin Simpson debug_printf("r300: Warning: cs_count off by %d\n", cs_count); \ 109902b1be0ea2a7fea27cea26915db5977f9a8f76cCorbin Simpson cs_winsys->end_cs(cs, __FILE__, __FUNCTION__, __LINE__); \ 110902b1be0ea2a7fea27cea26915db5977f9a8f76cCorbin Simpson} while (0) 11178b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson 112902b1be0ea2a7fea27cea26915db5977f9a8f76cCorbin Simpson#define FLUSH_CS do { \ 113ffbe28d25d755bc51d9f865ac176a110f6f8f5e0Corbin Simpson debug_printf("r300: FLUSH_CS in %s (%s:%d)\n\n", __FUNCTION__, __FILE__, \ 114902b1be0ea2a7fea27cea26915db5977f9a8f76cCorbin Simpson __LINE__); \ 115902b1be0ea2a7fea27cea26915db5977f9a8f76cCorbin Simpson cs_winsys->flush_cs(cs); \ 116902b1be0ea2a7fea27cea26915db5977f9a8f76cCorbin Simpson} while (0) 117432ab001d042b816b5892398064e5735d0293955Corbin Simpson 118edfaa686091a4f6238b8f315a475d90ff2c2f5f5Corbin Simpson#define RADEON_ONE_REG_WR (1 << 15) 119edfaa686091a4f6238b8f315a475d90ff2c2f5f5Corbin Simpson 120edfaa686091a4f6238b8f315a475d90ff2c2f5f5Corbin Simpson#define OUT_CS_ONE_REG(register, count) do { \ 121edfaa686091a4f6238b8f315a475d90ff2c2f5f5Corbin Simpson if (VERY_VERBOSE_REGISTERS) \ 122edfaa686091a4f6238b8f315a475d90ff2c2f5f5Corbin Simpson debug_printf("r300: writing data sequence of %d to 0x%04X\n", \ 123edfaa686091a4f6238b8f315a475d90ff2c2f5f5Corbin Simpson count, register); \ 124edfaa686091a4f6238b8f315a475d90ff2c2f5f5Corbin Simpson assert(register); \ 125edfaa686091a4f6238b8f315a475d90ff2c2f5f5Corbin Simpson OUT_CS(CP_PACKET0(register, ((count) - 1)) | RADEON_ONE_REG_WR); \ 126edfaa686091a4f6238b8f315a475d90ff2c2f5f5Corbin Simpson} while (0) 127edfaa686091a4f6238b8f315a475d90ff2c2f5f5Corbin Simpson 128edfaa686091a4f6238b8f315a475d90ff2c2f5f5Corbin Simpson#define CP_PACKET3(op, count) \ 129edfaa686091a4f6238b8f315a475d90ff2c2f5f5Corbin Simpson (RADEON_CP_PACKET3 | (op) | ((count) << 16)) 130edfaa686091a4f6238b8f315a475d90ff2c2f5f5Corbin Simpson 131f411a66c0679c1aa7a9ee3d1eb633a8cbf3ef5f2Corbin Simpson#define OUT_CS_PKT3(op, count) do { \ 132edfaa686091a4f6238b8f315a475d90ff2c2f5f5Corbin Simpson OUT_CS(CP_PACKET3(op, count)); \ 133edfaa686091a4f6238b8f315a475d90ff2c2f5f5Corbin Simpson} while (0) 13429a4f5493529042d1068a7d35da1e7f542474503Corbin Simpson 1358648c2685870174cf620ef15de70ef030a8d5a20Corbin Simpson#define OUT_CS_INDEX_RELOC(bo, offset, count, rd, wd, flags) do { \ 1368648c2685870174cf620ef15de70ef030a8d5a20Corbin Simpson debug_printf("r300: writing relocation for index buffer %p," \ 1378648c2685870174cf620ef15de70ef030a8d5a20Corbin Simpson "offset %d\n", bo, offset); \ 1388648c2685870174cf620ef15de70ef030a8d5a20Corbin Simpson assert(bo); \ 1398648c2685870174cf620ef15de70ef030a8d5a20Corbin Simpson OUT_CS(offset); \ 1408648c2685870174cf620ef15de70ef030a8d5a20Corbin Simpson OUT_CS(count); \ 1418648c2685870174cf620ef15de70ef030a8d5a20Corbin Simpson cs_winsys->write_cs_reloc(cs, bo, rd, wd, flags); \ 1428648c2685870174cf620ef15de70ef030a8d5a20Corbin Simpson cs_count -= 2; \ 1438648c2685870174cf620ef15de70ef030a8d5a20Corbin Simpson} while (0) 1448648c2685870174cf620ef15de70ef030a8d5a20Corbin Simpson 14522877265f4fdf66c75df391d6de95bd5c1584ea3Corbin Simpson#endif /* R300_CS_H */ 146