r300_cs.h revision 7005feabcd199e498a7c557ebdb2e47194f70d2c
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" 298bf9842fac00369b5cd3a82fb4d87db0e31848b8Marek Olšák#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 37c7dfffc5d5078e3cf1c28c230177cbbb43b91131Maciej Cencora#define VERY_VERBOSE_CS 1 38c7dfffc5d5078e3cf1c28c230177cbbb43b91131Maciej Cencora#define VERY_VERBOSE_REGISTERS 1 39ffbe28d25d755bc51d9f865ac176a110f6f8f5e0Corbin Simpson 407961974fc28257b293961d35f15c0ce7a85f2669Corbin Simpson/* XXX stolen from radeon_reg.h */ 417961974fc28257b293961d35f15c0ce7a85f2669Corbin Simpson#define RADEON_CP_PACKET0 0x0 427961974fc28257b293961d35f15c0ce7a85f2669Corbin Simpson 4378b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson#define CP_PACKET0(register, count) \ 4478b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson (RADEON_CP_PACKET0 | ((count) << 16) | ((register) >> 2)) 4578b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson 4678b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson#define CS_LOCALS(context) \ 474b01e6f614052e48971f2b2ff474fb66afc4f752Nicolai Hähnle struct r300_context* const cs_context_copy = (context); \ 4868e58a96e80865878e6881dc4d34fcc3ec24eb19Dave Airlie struct r300_winsys_screen *cs_winsys = cs_context_copy->rws; \ 494c9a8a14e56b6c45c74f2a27bfa8400b89488ee4Marek Olšák int cs_count = 0; (void) cs_count; 5078b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson 5178b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson#define BEGIN_CS(size) do { \ 527005feabcd199e498a7c557ebdb2e47194f70d2cMarek Olšák assert(r300_check_cs(cs_context_copy, (size))); \ 5390bfff0a295ce28143ecde98ed91eb6d8cfba23cCorbin Simpson if (VERY_VERBOSE_CS) { \ 544b01e6f614052e48971f2b2ff474fb66afc4f752Nicolai Hähnle DBG(cs_context_copy, DBG_CS, "r300: BEGIN_CS, count %d, in %s (%s:%d)\n", \ 5590bfff0a295ce28143ecde98ed91eb6d8cfba23cCorbin Simpson size, __FUNCTION__, __FILE__, __LINE__); \ 5690bfff0a295ce28143ecde98ed91eb6d8cfba23cCorbin Simpson } \ 57d7f4ac9f34a72efe53a1a140557f1822afbadf16Corbin Simpson cs_winsys->begin_cs(cs_winsys, (size), \ 58d7f4ac9f34a72efe53a1a140557f1822afbadf16Corbin Simpson __FILE__, __FUNCTION__, __LINE__); \ 5984ec4d6bedf33bf03ff7a778632eef7b209944cbCorbin Simpson cs_count = size; \ 6078b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson} while (0) 6178b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson 62412cf4d38be628200982208b7f93bb17530bb6dbCorbin Simpson#define OUT_CS(value) do { \ 63a6eb593072298d60286f49a09e6d3a849b684dfbMaciej Cencora if (VERY_VERBOSE_CS || VERY_VERBOSE_REGISTERS) { \ 64a6eb593072298d60286f49a09e6d3a849b684dfbMaciej Cencora DBG(cs_context_copy, DBG_CS, "r300: writing %08x\n", value); \ 65a6eb593072298d60286f49a09e6d3a849b684dfbMaciej Cencora } \ 66d7f4ac9f34a72efe53a1a140557f1822afbadf16Corbin Simpson cs_winsys->write_cs_dword(cs_winsys, (value)); \ 6780dc1801409f9913cc37b8fc8e68c692bc8a22caCorbin Simpson cs_count--; \ 68412cf4d38be628200982208b7f93bb17530bb6dbCorbin Simpson} while (0) 6978b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson 70412cf4d38be628200982208b7f93bb17530bb6dbCorbin Simpson#define OUT_CS_32F(value) do { \ 71a6eb593072298d60286f49a09e6d3a849b684dfbMaciej Cencora if (VERY_VERBOSE_CS || VERY_VERBOSE_REGISTERS) { \ 72a6eb593072298d60286f49a09e6d3a849b684dfbMaciej Cencora DBG(cs_context_copy, DBG_CS, "r300: writing %f\n", value); \ 73a6eb593072298d60286f49a09e6d3a849b684dfbMaciej Cencora } \ 74d7f4ac9f34a72efe53a1a140557f1822afbadf16Corbin Simpson cs_winsys->write_cs_dword(cs_winsys, fui(value)); \ 7580dc1801409f9913cc37b8fc8e68c692bc8a22caCorbin Simpson cs_count--; \ 76412cf4d38be628200982208b7f93bb17530bb6dbCorbin Simpson} while (0) 7722877265f4fdf66c75df391d6de95bd5c1584ea3Corbin Simpson 7878b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson#define OUT_CS_REG(register, value) do { \ 79ffbe28d25d755bc51d9f865ac176a110f6f8f5e0Corbin Simpson if (VERY_VERBOSE_REGISTERS) \ 804b01e6f614052e48971f2b2ff474fb66afc4f752Nicolai Hähnle DBG(cs_context_copy, DBG_CS, "r300: writing 0x%08X to register 0x%04X\n", \ 81ffbe28d25d755bc51d9f865ac176a110f6f8f5e0Corbin Simpson value, register); \ 82c199f330322921e01c8c30e3ea69a2a5291ae8eeCorbin Simpson assert(register); \ 83a6eb593072298d60286f49a09e6d3a849b684dfbMaciej Cencora cs_winsys->write_cs_dword(cs_winsys, CP_PACKET0(register, 0)); \ 84a6eb593072298d60286f49a09e6d3a849b684dfbMaciej Cencora cs_winsys->write_cs_dword(cs_winsys, value); \ 85a6eb593072298d60286f49a09e6d3a849b684dfbMaciej Cencora cs_count -= 2; \ 86412cf4d38be628200982208b7f93bb17530bb6dbCorbin Simpson} while (0) 8778b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson 8822877265f4fdf66c75df391d6de95bd5c1584ea3Corbin Simpson/* Note: This expects count to be the number of registers, 8922877265f4fdf66c75df391d6de95bd5c1584ea3Corbin Simpson * not the actual packet0 count! */ 9022877265f4fdf66c75df391d6de95bd5c1584ea3Corbin Simpson#define OUT_CS_REG_SEQ(register, count) do { \ 91ffbe28d25d755bc51d9f865ac176a110f6f8f5e0Corbin Simpson if (VERY_VERBOSE_REGISTERS) \ 924b01e6f614052e48971f2b2ff474fb66afc4f752Nicolai Hähnle DBG(cs_context_copy, DBG_CS, "r300: writing register sequence of %d to 0x%04X\n", \ 93ffbe28d25d755bc51d9f865ac176a110f6f8f5e0Corbin Simpson count, register); \ 94c199f330322921e01c8c30e3ea69a2a5291ae8eeCorbin Simpson assert(register); \ 95a6eb593072298d60286f49a09e6d3a849b684dfbMaciej Cencora cs_winsys->write_cs_dword(cs_winsys, CP_PACKET0((register), ((count) - 1))); \ 96a6eb593072298d60286f49a09e6d3a849b684dfbMaciej Cencora cs_count--; \ 9722877265f4fdf66c75df391d6de95bd5c1584ea3Corbin Simpson} while (0) 9822877265f4fdf66c75df391d6de95bd5c1584ea3Corbin Simpson 99c53142c3f46735f91b2f11308d08fa7e17edbf91Corbin Simpson#define OUT_CS_TABLE(values, count) do { \ 100c53142c3f46735f91b2f11308d08fa7e17edbf91Corbin Simpson if (VERY_VERBOSE_REGISTERS) \ 101c53142c3f46735f91b2f11308d08fa7e17edbf91Corbin Simpson DBG(cs_context_copy, DBG_CS, "r300: writing table of %d dwords\n", count); \ 102c53142c3f46735f91b2f11308d08fa7e17edbf91Corbin Simpson cs_winsys->write_cs_table(cs_winsys, values, count); \ 103c53142c3f46735f91b2f11308d08fa7e17edbf91Corbin Simpson cs_count -= count; \ 104c53142c3f46735f91b2f11308d08fa7e17edbf91Corbin Simpson} while (0) 105c53142c3f46735f91b2f11308d08fa7e17edbf91Corbin Simpson 10668e58a96e80865878e6881dc4d34fcc3ec24eb19Dave Airlie#define OUT_CS_BUF_RELOC(bo, offset, rd, wd, flags) do { \ 1074b01e6f614052e48971f2b2ff474fb66afc4f752Nicolai Hähnle DBG(cs_context_copy, DBG_CS, "r300: writing relocation for buffer %p, offset %d, " \ 1084550423211063010a2fa482037d8233bb80e3773Corbin Simpson "domains (%d, %d, %d)\n", \ 1094550423211063010a2fa482037d8233bb80e3773Corbin Simpson bo, offset, rd, wd, flags); \ 110c199f330322921e01c8c30e3ea69a2a5291ae8eeCorbin Simpson assert(bo); \ 111a6eb593072298d60286f49a09e6d3a849b684dfbMaciej Cencora cs_winsys->write_cs_dword(cs_winsys, offset); \ 11268e58a96e80865878e6881dc4d34fcc3ec24eb19Dave Airlie r300_buffer_write_reloc(cs_winsys, r300_buffer(bo), rd, wd, flags); \ 113a6eb593072298d60286f49a09e6d3a849b684dfbMaciej Cencora cs_count -= 3; \ 11478b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson} while (0) 11578b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson 11668e58a96e80865878e6881dc4d34fcc3ec24eb19Dave Airlie 11768e58a96e80865878e6881dc4d34fcc3ec24eb19Dave Airlie#define OUT_CS_TEX_RELOC(tex, offset, rd, wd, flags) do { \ 11868e58a96e80865878e6881dc4d34fcc3ec24eb19Dave Airlie DBG(cs_context_copy, DBG_CS, "r300: writing relocation for texture %p, offset %d, " \ 11968e58a96e80865878e6881dc4d34fcc3ec24eb19Dave Airlie "domains (%d, %d, %d)\n", \ 12068e58a96e80865878e6881dc4d34fcc3ec24eb19Dave Airlie tex, offset, rd, wd, flags); \ 12168e58a96e80865878e6881dc4d34fcc3ec24eb19Dave Airlie assert(tex); \ 12268e58a96e80865878e6881dc4d34fcc3ec24eb19Dave Airlie cs_winsys->write_cs_dword(cs_winsys, offset); \ 12368e58a96e80865878e6881dc4d34fcc3ec24eb19Dave Airlie r300_texture_write_reloc(cs_winsys, tex, rd, wd, flags); \ 12468e58a96e80865878e6881dc4d34fcc3ec24eb19Dave Airlie cs_count -= 3; \ 12568e58a96e80865878e6881dc4d34fcc3ec24eb19Dave Airlie} while (0) 12668e58a96e80865878e6881dc4d34fcc3ec24eb19Dave Airlie 12768e58a96e80865878e6881dc4d34fcc3ec24eb19Dave Airlie 12868e58a96e80865878e6881dc4d34fcc3ec24eb19Dave Airlie#define OUT_CS_BUF_RELOC_NO_OFFSET(bo, rd, wd, flags) do { \ 1298cc570a48c2e8e18622027cbd76f16a746b430bcMarek Olšák DBG(cs_context_copy, DBG_CS, "r300: writing relocation for buffer %p, " \ 1308cc570a48c2e8e18622027cbd76f16a746b430bcMarek Olšák "domains (%d, %d, %d)\n", \ 1318cc570a48c2e8e18622027cbd76f16a746b430bcMarek Olšák bo, rd, wd, flags); \ 1328cc570a48c2e8e18622027cbd76f16a746b430bcMarek Olšák assert(bo); \ 13368e58a96e80865878e6881dc4d34fcc3ec24eb19Dave Airlie r300_buffer_write_reloc(cs_winsys, r300_buffer(bo), rd, wd, flags); \ 1348cc570a48c2e8e18622027cbd76f16a746b430bcMarek Olšák cs_count -= 2; \ 1358cc570a48c2e8e18622027cbd76f16a746b430bcMarek Olšák} while (0) 1368cc570a48c2e8e18622027cbd76f16a746b430bcMarek Olšák 137902b1be0ea2a7fea27cea26915db5977f9a8f76cCorbin Simpson#define END_CS do { \ 13890bfff0a295ce28143ecde98ed91eb6d8cfba23cCorbin Simpson if (VERY_VERBOSE_CS) { \ 1394b01e6f614052e48971f2b2ff474fb66afc4f752Nicolai Hähnle DBG(cs_context_copy, DBG_CS, "r300: END_CS in %s (%s:%d)\n", __FUNCTION__, \ 14090bfff0a295ce28143ecde98ed91eb6d8cfba23cCorbin Simpson __FILE__, __LINE__); \ 14190bfff0a295ce28143ecde98ed91eb6d8cfba23cCorbin Simpson } \ 1422cb90c8e805d010ba4594264dd9edbbb7f95513aCorbin Simpson if (cs_count != 0) \ 1432cb90c8e805d010ba4594264dd9edbbb7f95513aCorbin Simpson debug_printf("r300: Warning: cs_count off by %d\n", cs_count); \ 144d7f4ac9f34a72efe53a1a140557f1822afbadf16Corbin Simpson cs_winsys->end_cs(cs_winsys, __FILE__, __FUNCTION__, __LINE__); \ 145902b1be0ea2a7fea27cea26915db5977f9a8f76cCorbin Simpson} while (0) 14678b599fb4cac469f4208ae3057b2a33e3e9913c6Corbin Simpson 147902b1be0ea2a7fea27cea26915db5977f9a8f76cCorbin Simpson#define FLUSH_CS do { \ 14890bfff0a295ce28143ecde98ed91eb6d8cfba23cCorbin Simpson if (VERY_VERBOSE_CS) { \ 1494b01e6f614052e48971f2b2ff474fb66afc4f752Nicolai Hähnle DBG(cs_context_copy, DBG_CS, "r300: FLUSH_CS in %s (%s:%d)\n\n", __FUNCTION__, \ 15090bfff0a295ce28143ecde98ed91eb6d8cfba23cCorbin Simpson __FILE__, __LINE__); \ 15190bfff0a295ce28143ecde98ed91eb6d8cfba23cCorbin Simpson } \ 152b02f1c86f5bf8b1169776975491c7df929e94e2cCorbin Simpson if (SCREEN_DBG_ON(r300->screen, DBG_STATS)) { \ 153b02f1c86f5bf8b1169776975491c7df929e94e2cCorbin Simpson r300->flush_counter++; \ 154b02f1c86f5bf8b1169776975491c7df929e94e2cCorbin Simpson } \ 155d7f4ac9f34a72efe53a1a140557f1822afbadf16Corbin Simpson cs_winsys->flush_cs(cs_winsys); \ 156902b1be0ea2a7fea27cea26915db5977f9a8f76cCorbin Simpson} while (0) 157432ab001d042b816b5892398064e5735d0293955Corbin Simpson 158edfaa686091a4f6238b8f315a475d90ff2c2f5f5Corbin Simpson#define RADEON_ONE_REG_WR (1 << 15) 159edfaa686091a4f6238b8f315a475d90ff2c2f5f5Corbin Simpson 160edfaa686091a4f6238b8f315a475d90ff2c2f5f5Corbin Simpson#define OUT_CS_ONE_REG(register, count) do { \ 161edfaa686091a4f6238b8f315a475d90ff2c2f5f5Corbin Simpson if (VERY_VERBOSE_REGISTERS) \ 1624b01e6f614052e48971f2b2ff474fb66afc4f752Nicolai Hähnle DBG(cs_context_copy, DBG_CS, "r300: writing data sequence of %d to 0x%04X\n", \ 163edfaa686091a4f6238b8f315a475d90ff2c2f5f5Corbin Simpson count, register); \ 164edfaa686091a4f6238b8f315a475d90ff2c2f5f5Corbin Simpson assert(register); \ 165a6eb593072298d60286f49a09e6d3a849b684dfbMaciej Cencora cs_winsys->write_cs_dword(cs_winsys, CP_PACKET0((register), ((count) - 1)) | RADEON_ONE_REG_WR); \ 166a6eb593072298d60286f49a09e6d3a849b684dfbMaciej Cencora cs_count--; \ 167edfaa686091a4f6238b8f315a475d90ff2c2f5f5Corbin Simpson} while (0) 168edfaa686091a4f6238b8f315a475d90ff2c2f5f5Corbin Simpson 169edfaa686091a4f6238b8f315a475d90ff2c2f5f5Corbin Simpson#define CP_PACKET3(op, count) \ 170edfaa686091a4f6238b8f315a475d90ff2c2f5f5Corbin Simpson (RADEON_CP_PACKET3 | (op) | ((count) << 16)) 171edfaa686091a4f6238b8f315a475d90ff2c2f5f5Corbin Simpson 172f411a66c0679c1aa7a9ee3d1eb633a8cbf3ef5f2Corbin Simpson#define OUT_CS_PKT3(op, count) do { \ 173a6eb593072298d60286f49a09e6d3a849b684dfbMaciej Cencora cs_winsys->write_cs_dword(cs_winsys, CP_PACKET3(op, count)); \ 174a6eb593072298d60286f49a09e6d3a849b684dfbMaciej Cencora cs_count--; \ 175edfaa686091a4f6238b8f315a475d90ff2c2f5f5Corbin Simpson} while (0) 17629a4f5493529042d1068a7d35da1e7f542474503Corbin Simpson 1778648c2685870174cf620ef15de70ef030a8d5a20Corbin Simpson#define OUT_CS_INDEX_RELOC(bo, offset, count, rd, wd, flags) do { \ 1784b01e6f614052e48971f2b2ff474fb66afc4f752Nicolai Hähnle DBG(cs_context_copy, DBG_CS, "r300: writing relocation for index buffer %p," \ 1798648c2685870174cf620ef15de70ef030a8d5a20Corbin Simpson "offset %d\n", bo, offset); \ 1808648c2685870174cf620ef15de70ef030a8d5a20Corbin Simpson assert(bo); \ 181a6eb593072298d60286f49a09e6d3a849b684dfbMaciej Cencora cs_winsys->write_cs_dword(cs_winsys, offset); \ 182a6eb593072298d60286f49a09e6d3a849b684dfbMaciej Cencora cs_winsys->write_cs_dword(cs_winsys, count); \ 183d7f4ac9f34a72efe53a1a140557f1822afbadf16Corbin Simpson cs_winsys->write_cs_reloc(cs_winsys, bo, rd, wd, flags); \ 184a6eb593072298d60286f49a09e6d3a849b684dfbMaciej Cencora cs_count -= 4; \ 1858648c2685870174cf620ef15de70ef030a8d5a20Corbin Simpson} while (0) 1868648c2685870174cf620ef15de70ef030a8d5a20Corbin Simpson 18722877265f4fdf66c75df391d6de95bd5c1584ea3Corbin Simpson#endif /* R300_CS_H */ 188