From: Bas Nieuwenhuizen Date: Tue, 15 Jan 2019 21:18:15 +0000 (+0100) Subject: turnip: Add emit functions in a header. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ac2a845abf4edf3419acc1dec5601cbe2ea7782b;p=mesa.git turnip: Add emit functions in a header. This adds a radv-style check_space functions + emit functions. Also puts them in a header as a bunch of inlines, so (1) we can use them from meta code. (2) they are inline for performance as these are common and small. Did not put them in tu_private.h as a bunch of inlines only clutters up that huge headerfile. Precise error propagation for memory allocation failures is still todo. --- diff --git a/src/freedreno/vulkan/tu_cmd_buffer.c b/src/freedreno/vulkan/tu_cmd_buffer.c index df72d4a7b31..41bd82e3cfc 100644 --- a/src/freedreno/vulkan/tu_cmd_buffer.c +++ b/src/freedreno/vulkan/tu_cmd_buffer.c @@ -29,6 +29,8 @@ #include "vk_format.h" #include "adreno_pm4.xml.h" +#include "tu_cs.h" + void tu_bo_list_init(struct tu_bo_list *list) { @@ -200,29 +202,20 @@ tu_cmd_stream_reset(struct tu_device *dev, stream->entry_count = 0; } -static unsigned -_odd_parity_bit(unsigned val) -{ - /* See: http://graphics.stanford.edu/~seander/bithacks.html#ParityParallel - * note that we want odd parity so 0x6996 is inverted. - */ - val ^= val >> 16; - val ^= val >> 8; - val ^= val >> 4; - val &= 0xf; - return (~0x6996 >> val) & 1; -} - -static void -OUT_PKT7(struct tu_cmd_stream *stream, uint8_t opcode, uint16_t cnt) +VkResult +tu_cs_check_space(struct tu_device *dev, + struct tu_cmd_stream *stream, + size_t size) { - *stream->cur++ = CP_TYPE7_PKT | cnt | - (_odd_parity_bit(cnt) << 15) | - ((opcode & 0x7f) << 16) | - ((_odd_parity_bit(opcode) << 23)); -} + if (stream->end - stream->cur >= size) + return VK_SUCCESS; + VkResult result = tu_cmd_stream_end(stream); + if (result != VK_SUCCESS) + return result; + return tu_cmd_stream_begin(dev, stream, size); +} const struct tu_dynamic_state default_dynamic_state = { .viewport = @@ -553,11 +546,12 @@ tu_BeginCommandBuffer(VkCommandBuffer commandBuffer, &cmd_buffer->cs, 4096); /* Put some stuff in so we do not have empty command buffers. */ - OUT_PKT7(&cmd_buffer->cs, CP_NOP, 4); - *cmd_buffer->cs.cur++ = 0; - *cmd_buffer->cs.cur++ = 0; - *cmd_buffer->cs.cur++ = 0; - *cmd_buffer->cs.cur++ = 0; + tu_cs_emit_pkt7(&cmd_buffer->cs, CP_NOP, 4); + tu_cs_emit(&cmd_buffer->cs, 0); + tu_cs_emit(&cmd_buffer->cs, 0); + tu_cs_emit(&cmd_buffer->cs, 0); + tu_cs_emit(&cmd_buffer->cs, 0); + return result; } diff --git a/src/freedreno/vulkan/tu_cs.h b/src/freedreno/vulkan/tu_cs.h new file mode 100644 index 00000000000..e865c738dde --- /dev/null +++ b/src/freedreno/vulkan/tu_cs.h @@ -0,0 +1,90 @@ +/* + * Copyright © 2019 Google LLC + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ +#ifndef TU_CS_H +#define TU_CS_H + +#include "tu_private.h" + +#include "adreno_pm4.xml.h" + +void +tu_cmd_stream_init(struct tu_cmd_stream *stream); +void +tu_cmd_stream_finish(struct tu_device *dev, struct tu_cmd_stream *stream); +VkResult +tu_cmd_stream_begin(struct tu_device *dev, + struct tu_cmd_stream *stream, + uint32_t reserve_size); +VkResult +tu_cmd_stream_end(struct tu_cmd_stream *stream); +void +tu_cmd_stream_reset(struct tu_device *dev, struct tu_cmd_stream *stream); +VkResult +tu_cs_check_space(struct tu_device *dev, + struct tu_cmd_stream *stream, + size_t size); + +static inline void +tu_cs_emit(struct tu_cmd_stream *stream, uint32_t value) +{ + assert(stream->cur < stream->end); + *stream->cur = value; + ++stream->cur; +} + +static inline unsigned +tu_odd_parity_bit(unsigned val) +{ + /* See: http://graphics.stanford.edu/~seander/bithacks.html#ParityParallel + * note that we want odd parity so 0x6996 is inverted. + */ + val ^= val >> 16; + val ^= val >> 8; + val ^= val >> 4; + val &= 0xf; + return (~0x6996 >> val) & 1; +} + +static inline void +tu_cs_emit_pkt4(struct tu_cmd_stream *stream, uint16_t regindx, uint16_t cnt) +{ + tu_cs_emit(stream, CP_TYPE4_PKT | cnt | (tu_odd_parity_bit(cnt) << 7) | + ((regindx & 0x3ffff) << 8) | + ((tu_odd_parity_bit(regindx) << 27))); +} + +static inline void +tu_cs_emit_pkt7(struct tu_cmd_stream *stream, uint8_t opcode, uint16_t cnt) +{ + tu_cs_emit(stream, CP_TYPE7_PKT | cnt | (tu_odd_parity_bit(cnt) << 15) | + ((opcode & 0x7f) << 16) | + ((tu_odd_parity_bit(opcode) << 23))); +} + +static inline void +tu_cs_emit_wfi5(struct tu_cmd_stream *stream) +{ + tu_cs_emit_pkt7(stream, CP_WAIT_FOR_IDLE, 0); +} + +#endif /* TU_CS_H */