1b8e80941Smrg/* 2b8e80941Smrg * Copyright 2014, 2015 Red Hat. 3b8e80941Smrg * 4b8e80941Smrg * Permission is hereby granted, free of charge, to any person obtaining a 5b8e80941Smrg * copy of this software and associated documentation files (the "Software"), 6b8e80941Smrg * to deal in the Software without restriction, including without limitation 7b8e80941Smrg * on the rights to use, copy, modify, merge, publish, distribute, sub 8b8e80941Smrg * license, and/or sell copies of the Software, and to permit persons to whom 9b8e80941Smrg * the Software is furnished to do so, subject to the following conditions: 10b8e80941Smrg * 11b8e80941Smrg * The above copyright notice and this permission notice (including the next 12b8e80941Smrg * paragraph) shall be included in all copies or substantial portions of the 13b8e80941Smrg * Software. 14b8e80941Smrg * 15b8e80941Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16b8e80941Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17b8e80941Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 18b8e80941Smrg * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, 19b8e80941Smrg * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 20b8e80941Smrg * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 21b8e80941Smrg * USE OR OTHER DEALINGS IN THE SOFTWARE. 22b8e80941Smrg */ 23b8e80941Smrg#ifndef VIRGL_CONTEXT_H 24b8e80941Smrg#define VIRGL_CONTEXT_H 25b8e80941Smrg 26b8e80941Smrg#include "pipe/p_state.h" 27b8e80941Smrg#include "pipe/p_context.h" 28b8e80941Smrg#include "util/slab.h" 29b8e80941Smrg#include "util/list.h" 30b8e80941Smrg 31b8e80941Smrg#include "virgl_transfer_queue.h" 32b8e80941Smrg 33b8e80941Smrgstruct pipe_screen; 34b8e80941Smrgstruct tgsi_token; 35b8e80941Smrgstruct u_upload_mgr; 36b8e80941Smrgstruct virgl_cmd_buf; 37b8e80941Smrgstruct virgl_vertex_elements_state; 38b8e80941Smrg 39b8e80941Smrgstruct virgl_sampler_view { 40b8e80941Smrg struct pipe_sampler_view base; 41b8e80941Smrg uint32_t handle; 42b8e80941Smrg}; 43b8e80941Smrg 44b8e80941Smrgstruct virgl_so_target { 45b8e80941Smrg struct pipe_stream_output_target base; 46b8e80941Smrg uint32_t handle; 47b8e80941Smrg}; 48b8e80941Smrg 49b8e80941Smrgstruct virgl_textures_info { 50b8e80941Smrg struct virgl_sampler_view *views[16]; 51b8e80941Smrg uint32_t enabled_mask; 52b8e80941Smrg}; 53b8e80941Smrg 54b8e80941Smrgstruct virgl_rasterizer_state { 55b8e80941Smrg struct pipe_rasterizer_state rs; 56b8e80941Smrg uint32_t handle; 57b8e80941Smrg}; 58b8e80941Smrg 59b8e80941Smrgstruct virgl_context { 60b8e80941Smrg struct pipe_context base; 61b8e80941Smrg struct virgl_cmd_buf *cbuf; 62b8e80941Smrg unsigned cbuf_initial_cdw; 63b8e80941Smrg 64b8e80941Smrg struct virgl_textures_info samplers[PIPE_SHADER_TYPES]; 65b8e80941Smrg struct virgl_vertex_elements_state *vertex_elements; 66b8e80941Smrg 67b8e80941Smrg struct pipe_framebuffer_state framebuffer; 68b8e80941Smrg 69b8e80941Smrg struct slab_child_pool transfer_pool; 70b8e80941Smrg struct virgl_transfer_queue queue; 71b8e80941Smrg struct u_upload_mgr *uploader; 72b8e80941Smrg bool encoded_transfers; 73b8e80941Smrg 74b8e80941Smrg struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS]; 75b8e80941Smrg unsigned num_vertex_buffers; 76b8e80941Smrg boolean vertex_array_dirty; 77b8e80941Smrg 78b8e80941Smrg struct virgl_rasterizer_state rs_state; 79b8e80941Smrg struct virgl_so_target so_targets[PIPE_MAX_SO_BUFFERS]; 80b8e80941Smrg unsigned num_so_targets; 81b8e80941Smrg 82b8e80941Smrg struct pipe_resource *ubos[PIPE_SHADER_TYPES][PIPE_MAX_CONSTANT_BUFFERS]; 83b8e80941Smrg 84b8e80941Smrg struct pipe_resource *ssbos[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_BUFFERS]; 85b8e80941Smrg struct pipe_resource *images[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_BUFFERS]; 86b8e80941Smrg uint32_t num_draws, num_compute; 87b8e80941Smrg 88b8e80941Smrg struct pipe_resource *atomic_buffers[PIPE_MAX_HW_ATOMIC_BUFFERS]; 89b8e80941Smrg 90b8e80941Smrg struct primconvert_context *primconvert; 91b8e80941Smrg uint32_t hw_sub_ctx_id; 92b8e80941Smrg}; 93b8e80941Smrg 94b8e80941Smrgstatic inline struct virgl_sampler_view * 95b8e80941Smrgvirgl_sampler_view(struct pipe_sampler_view *view) 96b8e80941Smrg{ 97b8e80941Smrg return (struct virgl_sampler_view *)view; 98b8e80941Smrg}; 99b8e80941Smrg 100b8e80941Smrgstatic inline struct virgl_so_target * 101b8e80941Smrgvirgl_so_target(struct pipe_stream_output_target *target) 102b8e80941Smrg{ 103b8e80941Smrg return (struct virgl_so_target *)target; 104b8e80941Smrg} 105b8e80941Smrg 106b8e80941Smrgstatic inline struct virgl_context *virgl_context(struct pipe_context *ctx) 107b8e80941Smrg{ 108b8e80941Smrg return (struct virgl_context *)ctx; 109b8e80941Smrg} 110b8e80941Smrg 111b8e80941Smrgstruct pipe_context *virgl_context_create(struct pipe_screen *pscreen, 112b8e80941Smrg void *priv, unsigned flags); 113b8e80941Smrg 114b8e80941Smrgvoid virgl_init_blit_functions(struct virgl_context *vctx); 115b8e80941Smrgvoid virgl_init_query_functions(struct virgl_context *vctx); 116b8e80941Smrgvoid virgl_init_so_functions(struct virgl_context *vctx); 117b8e80941Smrg 118b8e80941Smrgvoid virgl_transfer_inline_write(struct pipe_context *ctx, 119b8e80941Smrg struct pipe_resource *res, 120b8e80941Smrg unsigned level, 121b8e80941Smrg unsigned usage, 122b8e80941Smrg const struct pipe_box *box, 123b8e80941Smrg const void *data, 124b8e80941Smrg unsigned stride, 125b8e80941Smrg unsigned layer_stride); 126b8e80941Smrg 127b8e80941Smrgstruct tgsi_token *virgl_tgsi_transform(struct virgl_context *vctx, const struct tgsi_token *tokens_in); 128b8e80941Smrg 129b8e80941Smrg#endif 130