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