Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 1 | /********************************************************** |
| 2 | * Copyright 2008-2009 VMware, Inc. All rights reserved. |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person |
| 5 | * obtaining a copy of this software and associated documentation |
| 6 | * files (the "Software"), to deal in the Software without |
| 7 | * restriction, including without limitation the rights to use, copy, |
| 8 | * modify, merge, publish, distribute, sublicense, and/or sell copies |
| 9 | * of the Software, and to permit persons to whom the Software is |
| 10 | * furnished to do so, subject to the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice shall be |
| 13 | * included in all copies or substantial portions of the Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | * SOFTWARE. |
| 23 | * |
| 24 | **********************************************************/ |
| 25 | |
| 26 | #include "svga_cmd.h" |
| 27 | |
| 28 | #include "pipe/p_defines.h" |
José Fonseca | 2848688 | 2010-02-02 14:42:17 +0000 | [diff] [blame] | 29 | #include "util/u_inlines.h" |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 30 | #include "pipe/p_screen.h" |
| 31 | #include "util/u_memory.h" |
José Fonseca | cdb445f | 2010-01-03 00:47:30 +0000 | [diff] [blame] | 32 | #include "util/u_bitmask.h" |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 33 | #include "util/u_upload_mgr.h" |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 34 | |
| 35 | #include "svga_context.h" |
| 36 | #include "svga_screen.h" |
José Fonseca | 0ced789 | 2011-02-18 14:33:55 +0000 | [diff] [blame] | 37 | #include "svga_surface.h" |
Keith Whitwell | 287c94e | 2010-04-10 16:05:54 +0100 | [diff] [blame] | 38 | #include "svga_resource_texture.h" |
| 39 | #include "svga_resource_buffer.h" |
| 40 | #include "svga_resource.h" |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 41 | #include "svga_winsys.h" |
| 42 | #include "svga_swtnl.h" |
| 43 | #include "svga_draw.h" |
| 44 | #include "svga_debug.h" |
| 45 | #include "svga_state.h" |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 46 | #include "svga_winsys.h" |
| 47 | |
| 48 | #define CONST0_UPLOAD_DEFAULT_SIZE 65536 |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 49 | |
Jakob Bornecrantz | daaf542 | 2010-12-29 09:59:28 +0100 | [diff] [blame] | 50 | DEBUG_GET_ONCE_BOOL_OPTION(no_swtnl, "SVGA_NO_SWTNL", FALSE) |
| 51 | DEBUG_GET_ONCE_BOOL_OPTION(force_swtnl, "SVGA_FORCE_SWTNL", FALSE); |
| 52 | DEBUG_GET_ONCE_BOOL_OPTION(use_min_mipmap, "SVGA_USE_MIN_MIPMAP", FALSE); |
Jakob Bornecrantz | c523f31 | 2010-12-29 12:50:59 +0100 | [diff] [blame] | 53 | DEBUG_GET_ONCE_BOOL_OPTION(no_line_width, "SVGA_NO_LINE_WIDTH", FALSE); |
| 54 | DEBUG_GET_ONCE_BOOL_OPTION(force_hw_line_stipple, "SVGA_FORCE_HW_LINE_STIPPLE", FALSE); |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 55 | |
Brian Paul | c96f63c | 2016-11-01 08:17:05 -0600 | [diff] [blame] | 56 | |
| 57 | static void |
| 58 | svga_destroy(struct pipe_context *pipe) |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 59 | { |
Brian Paul | c96f63c | 2016-11-01 08:17:05 -0600 | [diff] [blame] | 60 | struct svga_context *svga = svga_context(pipe); |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 61 | unsigned shader, i; |
| 62 | |
| 63 | /* free any alternate rasterizer states used for point sprite */ |
Brian Paul | e0184b3 | 2016-04-25 09:34:40 -0600 | [diff] [blame] | 64 | for (i = 0; i < ARRAY_SIZE(svga->rasterizer_no_cull); i++) { |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 65 | if (svga->rasterizer_no_cull[i]) { |
| 66 | pipe->delete_rasterizer_state(pipe, svga->rasterizer_no_cull[i]); |
| 67 | } |
| 68 | } |
| 69 | |
Charmaine Lee | b4c4ee0 | 2017-04-04 12:47:49 -0600 | [diff] [blame] | 70 | /* free depthstencil_disable state */ |
| 71 | if (svga->depthstencil_disable) { |
| 72 | pipe->delete_depth_stencil_alpha_state(pipe, svga->depthstencil_disable); |
| 73 | } |
| 74 | |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 75 | /* free HW constant buffers */ |
Brian Paul | e0184b3 | 2016-04-25 09:34:40 -0600 | [diff] [blame] | 76 | for (shader = 0; shader < ARRAY_SIZE(svga->state.hw_draw.constbuf); shader++) { |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 77 | pipe_resource_reference(&svga->state.hw_draw.constbuf[shader], NULL); |
| 78 | } |
| 79 | |
| 80 | pipe->delete_blend_state(pipe, svga->noop_blend); |
| 81 | |
| 82 | /* free query gb object */ |
| 83 | if (svga->gb_query) { |
| 84 | pipe->destroy_query(pipe, NULL); |
| 85 | svga->gb_query = NULL; |
| 86 | } |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 87 | |
Marek Olšák | ad3d5db | 2012-09-13 00:50:54 +0200 | [diff] [blame] | 88 | util_blitter_destroy(svga->blitter); |
| 89 | |
Charmaine Lee | 5313b29 | 2016-08-17 14:53:38 -0700 | [diff] [blame] | 90 | svga_cleanup_sampler_state(svga); |
Brian Paul | c96f63c | 2016-11-01 08:17:05 -0600 | [diff] [blame] | 91 | svga_cleanup_framebuffer(svga); |
| 92 | svga_cleanup_tss_binding(svga); |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 93 | svga_cleanup_vertex_state(svga); |
Brian Paul | c96f63c | 2016-11-01 08:17:05 -0600 | [diff] [blame] | 94 | |
| 95 | svga_destroy_swtnl(svga); |
| 96 | svga_hwtnl_destroy(svga->hwtnl); |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 97 | |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 98 | svga->swc->destroy(svga->swc); |
José Fonseca | cdb445f | 2010-01-03 00:47:30 +0000 | [diff] [blame] | 99 | |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 100 | util_bitmask_destroy(svga->blend_object_id_bm); |
| 101 | util_bitmask_destroy(svga->ds_object_id_bm); |
| 102 | util_bitmask_destroy(svga->input_element_object_id_bm); |
| 103 | util_bitmask_destroy(svga->rast_object_id_bm); |
| 104 | util_bitmask_destroy(svga->sampler_object_id_bm); |
| 105 | util_bitmask_destroy(svga->sampler_view_id_bm); |
| 106 | util_bitmask_destroy(svga->shader_id_bm); |
| 107 | util_bitmask_destroy(svga->surface_view_id_bm); |
| 108 | util_bitmask_destroy(svga->stream_output_id_bm); |
| 109 | util_bitmask_destroy(svga->query_id_bm); |
| 110 | u_upload_destroy(svga->const0_upload); |
Marek Olšák | 55ad59d | 2017-01-27 00:12:37 +0100 | [diff] [blame] | 111 | u_upload_destroy(svga->pipe.stream_uploader); |
| 112 | u_upload_destroy(svga->pipe.const_uploader); |
Charmaine Lee | f1b3374 | 2016-09-06 11:29:41 -0700 | [diff] [blame] | 113 | svga_texture_transfer_map_upload_destroy(svga); |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 114 | |
| 115 | /* free user's constant buffers */ |
Brian Paul | 2f1fc8d | 2014-02-08 09:51:14 -0800 | [diff] [blame] | 116 | for (shader = 0; shader < PIPE_SHADER_TYPES; ++shader) { |
Brian Paul | e0184b3 | 2016-04-25 09:34:40 -0600 | [diff] [blame] | 117 | for (i = 0; i < ARRAY_SIZE(svga->curr.constbufs[shader]); ++i) { |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 118 | pipe_resource_reference(&svga->curr.constbufs[shader][i].buffer, NULL); |
| 119 | } |
Brian Paul | 2f1fc8d | 2014-02-08 09:51:14 -0800 | [diff] [blame] | 120 | } |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 121 | |
Brian Paul | c96f63c | 2016-11-01 08:17:05 -0600 | [diff] [blame] | 122 | FREE(svga); |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 123 | } |
| 124 | |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 125 | |
Brian Paul | c96f63c | 2016-11-01 08:17:05 -0600 | [diff] [blame] | 126 | struct pipe_context * |
| 127 | svga_context_create(struct pipe_screen *screen, void *priv, unsigned flags) |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 128 | { |
| 129 | struct svga_screen *svgascreen = svga_screen(screen); |
| 130 | struct svga_context *svga = NULL; |
| 131 | enum pipe_error ret; |
| 132 | |
Charmaine Lee | 203d884 | 2016-11-08 11:54:56 -0800 | [diff] [blame] | 133 | SVGA_STATS_TIME_PUSH(svgascreen->sws, SVGA_STATS_TIME_CREATECONTEXT); |
| 134 | |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 135 | svga = CALLOC_STRUCT(svga_context); |
Edward O'Callaghan | 13eb5f5 | 2015-12-04 22:08:22 +1100 | [diff] [blame] | 136 | if (!svga) |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 137 | goto cleanup; |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 138 | |
Brian Paul | e853ade | 2014-04-09 11:35:54 -0600 | [diff] [blame] | 139 | LIST_INITHEAD(&svga->dirty_buffers); |
| 140 | |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 141 | svga->pipe.screen = screen; |
Keith Whitwell | 7f41f54 | 2010-02-08 12:55:59 +0000 | [diff] [blame] | 142 | svga->pipe.priv = priv; |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 143 | svga->pipe.destroy = svga_destroy; |
Marek Olšák | 55ad59d | 2017-01-27 00:12:37 +0100 | [diff] [blame] | 144 | svga->pipe.stream_uploader = u_upload_create(&svga->pipe, 1024 * 1024, |
| 145 | PIPE_BIND_VERTEX_BUFFER | |
| 146 | PIPE_BIND_INDEX_BUFFER, |
| 147 | PIPE_USAGE_STREAM); |
| 148 | if (!svga->pipe.stream_uploader) |
| 149 | goto cleanup; |
| 150 | |
| 151 | svga->pipe.const_uploader = u_upload_create(&svga->pipe, 128 * 1024, |
| 152 | PIPE_BIND_CONSTANT_BUFFER, |
| 153 | PIPE_USAGE_STREAM); |
| 154 | if (!svga->pipe.const_uploader) |
| 155 | goto cleanup; |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 156 | |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 157 | svga->swc = svgascreen->sws->context_create(svgascreen->sws); |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 158 | if (!svga->swc) |
| 159 | goto cleanup; |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 160 | |
Keith Whitwell | 287c94e | 2010-04-10 16:05:54 +0100 | [diff] [blame] | 161 | svga_init_resource_functions(svga); |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 162 | svga_init_blend_functions(svga); |
| 163 | svga_init_blit_functions(svga); |
| 164 | svga_init_depth_stencil_functions(svga); |
| 165 | svga_init_draw_functions(svga); |
| 166 | svga_init_flush_functions(svga); |
| 167 | svga_init_misc_functions(svga); |
| 168 | svga_init_rasterizer_functions(svga); |
| 169 | svga_init_sampler_functions(svga); |
| 170 | svga_init_fs_functions(svga); |
| 171 | svga_init_vs_functions(svga); |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 172 | svga_init_gs_functions(svga); |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 173 | svga_init_vertex_functions(svga); |
| 174 | svga_init_constbuffer_functions(svga); |
| 175 | svga_init_query_functions(svga); |
Roland Scheidegger | 4c70014 | 2010-12-02 04:33:43 +0100 | [diff] [blame] | 176 | svga_init_surface_functions(svga); |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 177 | svga_init_stream_output_functions(svga); |
Neha Bhende | 40557ae | 2016-08-11 16:43:03 -0700 | [diff] [blame] | 178 | svga_init_clear_functions(svga); |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 179 | |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 180 | /* init misc state */ |
| 181 | svga->curr.sample_mask = ~0; |
Michel Dänzer | 13a13fc | 2010-03-12 19:52:24 +0100 | [diff] [blame] | 182 | |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 183 | /* debug */ |
Jakob Bornecrantz | daaf542 | 2010-12-29 09:59:28 +0100 | [diff] [blame] | 184 | svga->debug.no_swtnl = debug_get_option_no_swtnl(); |
| 185 | svga->debug.force_swtnl = debug_get_option_force_swtnl(); |
| 186 | svga->debug.use_min_mipmap = debug_get_option_use_min_mipmap(); |
Jakob Bornecrantz | c523f31 | 2010-12-29 12:50:59 +0100 | [diff] [blame] | 187 | svga->debug.no_line_width = debug_get_option_no_line_width(); |
| 188 | svga->debug.force_hw_line_stipple = debug_get_option_force_hw_line_stipple(); |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 189 | |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 190 | if (!(svga->blend_object_id_bm = util_bitmask_create())) |
| 191 | goto cleanup; |
| 192 | |
| 193 | if (!(svga->ds_object_id_bm = util_bitmask_create())) |
| 194 | goto cleanup; |
| 195 | |
| 196 | if (!(svga->input_element_object_id_bm = util_bitmask_create())) |
| 197 | goto cleanup; |
| 198 | |
| 199 | if (!(svga->rast_object_id_bm = util_bitmask_create())) |
| 200 | goto cleanup; |
| 201 | |
| 202 | if (!(svga->sampler_object_id_bm = util_bitmask_create())) |
| 203 | goto cleanup; |
| 204 | |
| 205 | if (!(svga->sampler_view_id_bm = util_bitmask_create())) |
| 206 | goto cleanup; |
| 207 | |
| 208 | if (!(svga->shader_id_bm = util_bitmask_create())) |
| 209 | goto cleanup; |
| 210 | |
| 211 | if (!(svga->surface_view_id_bm = util_bitmask_create())) |
| 212 | goto cleanup; |
| 213 | |
| 214 | if (!(svga->stream_output_id_bm = util_bitmask_create())) |
| 215 | goto cleanup; |
| 216 | |
| 217 | if (!(svga->query_id_bm = util_bitmask_create())) |
| 218 | goto cleanup; |
José Fonseca | cdb445f | 2010-01-03 00:47:30 +0000 | [diff] [blame] | 219 | |
Brian Paul | 8d7b913 | 2013-10-22 16:47:38 -0600 | [diff] [blame] | 220 | svga->hwtnl = svga_hwtnl_create(svga); |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 221 | if (svga->hwtnl == NULL) |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 222 | goto cleanup; |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 223 | |
José Fonseca | 0cb6329 | 2011-02-18 14:29:48 +0000 | [diff] [blame] | 224 | if (!svga_init_swtnl(svga)) |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 225 | goto cleanup; |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 226 | |
Brian Paul | c96f63c | 2016-11-01 08:17:05 -0600 | [diff] [blame] | 227 | ret = svga_emit_initial_state(svga); |
Brian Paul | 5f053bf | 2011-09-22 17:02:59 -0600 | [diff] [blame] | 228 | if (ret != PIPE_OK) |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 229 | goto cleanup; |
| 230 | |
| 231 | svga->const0_upload = u_upload_create(&svga->pipe, |
| 232 | CONST0_UPLOAD_DEFAULT_SIZE, |
Marek Olšák | ecb2da1 | 2015-12-19 17:54:31 +0100 | [diff] [blame] | 233 | PIPE_BIND_CONSTANT_BUFFER, |
| 234 | PIPE_USAGE_STREAM); |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 235 | if (!svga->const0_upload) |
| 236 | goto cleanup; |
| 237 | |
Charmaine Lee | f1b3374 | 2016-09-06 11:29:41 -0700 | [diff] [blame] | 238 | if (!svga_texture_transfer_map_upload_create(svga)) |
| 239 | goto cleanup; |
| 240 | |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 241 | /* Avoid shortcircuiting state with initial value of zero. |
| 242 | */ |
| 243 | memset(&svga->state.hw_clear, 0xcd, sizeof(svga->state.hw_clear)); |
Brian Paul | c96f63c | 2016-11-01 08:17:05 -0600 | [diff] [blame] | 244 | memset(&svga->state.hw_clear.framebuffer, 0x0, |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 245 | sizeof(svga->state.hw_clear.framebuffer)); |
Charmaine Lee | dc30ac5 | 2017-04-25 14:27:51 -0600 | [diff] [blame] | 246 | svga->state.hw_clear.num_rendertargets = 0; |
| 247 | svga->state.hw_clear.dsv = NULL; |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 248 | |
| 249 | memset(&svga->state.hw_draw, 0xcd, sizeof(svga->state.hw_draw)); |
| 250 | memset(&svga->state.hw_draw.views, 0x0, sizeof(svga->state.hw_draw.views)); |
Charmaine Lee | 3f51a3f | 2016-08-15 18:35:28 -0700 | [diff] [blame] | 251 | memset(&svga->state.hw_draw.num_samplers, 0, |
| 252 | sizeof(svga->state.hw_draw.num_samplers)); |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 253 | memset(&svga->state.hw_draw.num_sampler_views, 0, |
| 254 | sizeof(svga->state.hw_draw.num_sampler_views)); |
Charmaine Lee | 2781d60 | 2016-08-17 16:50:23 -0700 | [diff] [blame] | 255 | memset(svga->state.hw_draw.sampler_views, 0, |
| 256 | sizeof(svga->state.hw_draw.sampler_views)); |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 257 | svga->state.hw_draw.num_views = 0; |
Charmaine Lee | dbb5d2a | 2017-06-27 10:47:01 -0600 | [diff] [blame] | 258 | svga->state.hw_draw.num_backed_views = 0; |
Charmaine Lee | b4c4ee0 | 2017-04-04 12:47:49 -0600 | [diff] [blame] | 259 | svga->state.hw_draw.rasterizer_discard = FALSE; |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 260 | |
| 261 | /* Initialize the shader pointers */ |
| 262 | svga->state.hw_draw.vs = NULL; |
| 263 | svga->state.hw_draw.gs = NULL; |
| 264 | svga->state.hw_draw.fs = NULL; |
Charmaine Lee | 2b81e31 | 2016-05-02 18:17:48 -0700 | [diff] [blame] | 265 | |
| 266 | /* Initialize the currently bound buffer resources */ |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 267 | memset(svga->state.hw_draw.constbuf, 0, |
| 268 | sizeof(svga->state.hw_draw.constbuf)); |
| 269 | memset(svga->state.hw_draw.default_constbuf_size, 0, |
| 270 | sizeof(svga->state.hw_draw.default_constbuf_size)); |
| 271 | memset(svga->state.hw_draw.enabled_constbufs, 0, |
| 272 | sizeof(svga->state.hw_draw.enabled_constbufs)); |
Charmaine Lee | 47cfc83 | 2016-01-19 20:25:39 -0800 | [diff] [blame] | 273 | svga->state.hw_draw.ib = NULL; |
Charmaine Lee | 2b81e31 | 2016-05-02 18:17:48 -0700 | [diff] [blame] | 274 | svga->state.hw_draw.num_vbuffers = 0; |
| 275 | memset(svga->state.hw_draw.vbuffers, 0, |
| 276 | sizeof(svga->state.hw_draw.vbuffers)); |
Brian Paul | ee5f5e2 | 2016-08-15 09:16:05 -0600 | [diff] [blame] | 277 | svga->state.hw_draw.const0_buffer = NULL; |
| 278 | svga->state.hw_draw.const0_handle = NULL; |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 279 | |
| 280 | /* Create a no-operation blend state which we will bind whenever the |
| 281 | * requested blend state is impossible (e.g. due to having an integer |
| 282 | * render target attached). |
| 283 | * |
| 284 | * XXX: We will probably actually need 16 of these, one for each possible |
| 285 | * RGBA color mask (4 bits). Then, we would bind the one with a color mask |
| 286 | * matching the blend state it is replacing. |
| 287 | */ |
| 288 | { |
| 289 | struct pipe_blend_state noop_tmpl = {0}; |
| 290 | unsigned i; |
| 291 | |
| 292 | for (i = 0; i < PIPE_MAX_COLOR_BUFS; ++i) { |
| 293 | // Set the color mask to all-ones. Later this may change. |
| 294 | noop_tmpl.rt[i].colormask = PIPE_MASK_RGBA; |
| 295 | } |
| 296 | svga->noop_blend = svga->pipe.create_blend_state(&svga->pipe, &noop_tmpl); |
| 297 | } |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 298 | |
| 299 | svga->dirty = ~0; |
Thomas Hellstrom | d787ce7 | 2016-10-28 11:33:53 -0700 | [diff] [blame] | 300 | svga->pred.query_id = SVGA3D_INVALID_ID; |
Charmaine Lee | b4c4ee0 | 2017-04-04 12:47:49 -0600 | [diff] [blame] | 301 | svga->disable_rasterizer = FALSE; |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 302 | |
Charmaine Lee | 203d884 | 2016-11-08 11:54:56 -0800 | [diff] [blame] | 303 | goto done; |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 304 | |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 305 | cleanup: |
José Fonseca | 0cb6329 | 2011-02-18 14:29:48 +0000 | [diff] [blame] | 306 | svga_destroy_swtnl(svga); |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 307 | |
| 308 | if (svga->const0_upload) |
| 309 | u_upload_destroy(svga->const0_upload); |
Marek Olšák | 55ad59d | 2017-01-27 00:12:37 +0100 | [diff] [blame] | 310 | if (svga->pipe.const_uploader) |
| 311 | u_upload_destroy(svga->pipe.const_uploader); |
| 312 | if (svga->pipe.stream_uploader) |
| 313 | u_upload_destroy(svga->pipe.stream_uploader); |
Charmaine Lee | f1b3374 | 2016-09-06 11:29:41 -0700 | [diff] [blame] | 314 | svga_texture_transfer_map_upload_destroy(svga); |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 315 | if (svga->hwtnl) |
| 316 | svga_hwtnl_destroy(svga->hwtnl); |
| 317 | if (svga->swc) |
| 318 | svga->swc->destroy(svga->swc); |
| 319 | util_bitmask_destroy(svga->blend_object_id_bm); |
| 320 | util_bitmask_destroy(svga->ds_object_id_bm); |
| 321 | util_bitmask_destroy(svga->input_element_object_id_bm); |
| 322 | util_bitmask_destroy(svga->rast_object_id_bm); |
| 323 | util_bitmask_destroy(svga->sampler_object_id_bm); |
| 324 | util_bitmask_destroy(svga->sampler_view_id_bm); |
| 325 | util_bitmask_destroy(svga->shader_id_bm); |
| 326 | util_bitmask_destroy(svga->surface_view_id_bm); |
| 327 | util_bitmask_destroy(svga->stream_output_id_bm); |
| 328 | util_bitmask_destroy(svga->query_id_bm); |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 329 | FREE(svga); |
Charmaine Lee | 203d884 | 2016-11-08 11:54:56 -0800 | [diff] [blame] | 330 | |
| 331 | done: |
| 332 | SVGA_STATS_TIME_POP(svgascreen->sws); |
| 333 | return svga ? &svga->pipe:NULL; |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | |
Brian Paul | c96f63c | 2016-11-01 08:17:05 -0600 | [diff] [blame] | 337 | void |
| 338 | svga_context_flush(struct svga_context *svga, |
| 339 | struct pipe_fence_handle **pfence) |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 340 | { |
| 341 | struct svga_screen *svgascreen = svga_screen(svga->pipe.screen); |
José Fonseca | b845909 | 2010-05-02 23:54:42 +0100 | [diff] [blame] | 342 | struct pipe_fence_handle *fence = NULL; |
Brian Paul | 7e8cf34 | 2016-03-04 09:14:34 -0700 | [diff] [blame] | 343 | uint64_t t0; |
Keith Whitwell | b84b7f1 | 2009-11-27 12:19:28 +0000 | [diff] [blame] | 344 | |
Charmaine Lee | 2e1cfcc | 2016-08-19 08:49:17 -0600 | [diff] [blame] | 345 | SVGA_STATS_TIME_PUSH(svga_sws(svga), SVGA_STATS_TIME_CONTEXTFLUSH); |
| 346 | |
Keith Whitwell | b84b7f1 | 2009-11-27 12:19:28 +0000 | [diff] [blame] | 347 | svga->curr.nr_fbs = 0; |
| 348 | |
Brian Paul | ee5f5e2 | 2016-08-15 09:16:05 -0600 | [diff] [blame] | 349 | /* Unmap the 0th/default constant buffer. The u_upload_unmap() function |
| 350 | * will call pipe_context::transfer_flush_region() to indicate the |
| 351 | * region of the buffer which was modified (and needs to be uploaded). |
| 352 | */ |
| 353 | if (svga->state.hw_draw.const0_handle) { |
| 354 | assert(svga->state.hw_draw.const0_buffer); |
| 355 | u_upload_unmap(svga->const0_upload); |
| 356 | pipe_resource_reference(&svga->state.hw_draw.const0_buffer, NULL); |
| 357 | svga->state.hw_draw.const0_handle = NULL; |
| 358 | } |
| 359 | |
José Fonseca | b845909 | 2010-05-02 23:54:42 +0100 | [diff] [blame] | 360 | /* Ensure that texture dma uploads are processed |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 361 | * before submitting commands. |
| 362 | */ |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 363 | svga_context_flush_buffers(svga); |
| 364 | |
Brian Paul | 192ee9a | 2016-02-29 14:26:12 -0700 | [diff] [blame] | 365 | svga->hud.command_buffer_size += |
| 366 | svga->swc->get_command_buffer_size(svga->swc); |
| 367 | |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 368 | /* Flush pending commands to hardware: |
| 369 | */ |
Brian Paul | f934117 | 2016-08-02 14:27:33 -0600 | [diff] [blame] | 370 | t0 = svga_get_time(svga); |
José Fonseca | b845909 | 2010-05-02 23:54:42 +0100 | [diff] [blame] | 371 | svga->swc->flush(svga->swc, &fence); |
Brian Paul | f934117 | 2016-08-02 14:27:33 -0600 | [diff] [blame] | 372 | svga->hud.flush_time += (svga_get_time(svga) - t0); |
José Fonseca | b845909 | 2010-05-02 23:54:42 +0100 | [diff] [blame] | 373 | |
Neha Bhende | 9bc7e31 | 2015-10-09 16:10:16 -0600 | [diff] [blame] | 374 | svga->hud.num_flushes++; |
| 375 | |
Charmaine Lee | 16bd2c6 | 2017-01-26 18:46:23 -0800 | [diff] [blame] | 376 | svga_screen_cache_flush(svgascreen, svga, fence); |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 377 | |
Brian Paul | 581292a | 2016-08-31 18:28:00 -0600 | [diff] [blame] | 378 | SVGA3D_ResetLastCommand(svga->swc); |
| 379 | |
José Fonseca | 6b95cfb | 2011-04-07 16:54:37 +0100 | [diff] [blame] | 380 | /* To force the re-emission of rendertargets and texture sampler bindings on |
| 381 | * the next command buffer. |
José Fonseca | 5a70db6 | 2010-08-15 13:36:02 +0100 | [diff] [blame] | 382 | */ |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 383 | svga->rebind.flags.rendertargets = TRUE; |
| 384 | svga->rebind.flags.texture_samplers = TRUE; |
| 385 | |
Brian Paul | f84c830 | 2014-02-08 09:51:14 -0800 | [diff] [blame] | 386 | if (svga_have_gb_objects(svga)) { |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 387 | |
| 388 | svga->rebind.flags.constbufs = TRUE; |
| 389 | svga->rebind.flags.vs = TRUE; |
| 390 | svga->rebind.flags.fs = TRUE; |
| 391 | svga->rebind.flags.gs = TRUE; |
| 392 | |
| 393 | if (svga_need_to_rebind_resources(svga)) { |
| 394 | svga->rebind.flags.query = TRUE; |
| 395 | } |
Brian Paul | f84c830 | 2014-02-08 09:51:14 -0800 | [diff] [blame] | 396 | } |
José Fonseca | 369ece1 | 2011-02-23 13:32:37 +0000 | [diff] [blame] | 397 | |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 398 | if (SVGA_DEBUG & DEBUG_SYNC) { |
José Fonseca | b845909 | 2010-05-02 23:54:42 +0100 | [diff] [blame] | 399 | if (fence) |
Brian Paul | c96f63c | 2016-11-01 08:17:05 -0600 | [diff] [blame] | 400 | svga->pipe.screen->fence_finish(svga->pipe.screen, NULL, fence, |
Marek Olšák | b39bccb | 2011-03-05 21:23:54 +0100 | [diff] [blame] | 401 | PIPE_TIMEOUT_INFINITE); |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 402 | } |
José Fonseca | b845909 | 2010-05-02 23:54:42 +0100 | [diff] [blame] | 403 | |
Edward O'Callaghan | 13eb5f5 | 2015-12-04 22:08:22 +1100 | [diff] [blame] | 404 | if (pfence) |
Thomas Hellstrom | 6235846 | 2011-10-17 14:24:14 +0200 | [diff] [blame] | 405 | svgascreen->sws->fence_reference(svgascreen->sws, pfence, fence); |
| 406 | |
| 407 | svgascreen->sws->fence_reference(svgascreen->sws, &fence, NULL); |
Charmaine Lee | 2e1cfcc | 2016-08-19 08:49:17 -0600 | [diff] [blame] | 408 | |
| 409 | SVGA_STATS_TIME_POP(svga_sws(svga)); |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 413 | /** |
| 414 | * Flush pending commands and wait for completion with a fence. |
| 415 | */ |
| 416 | void |
| 417 | svga_context_finish(struct svga_context *svga) |
| 418 | { |
| 419 | struct pipe_screen *screen = svga->pipe.screen; |
| 420 | struct pipe_fence_handle *fence = NULL; |
| 421 | |
Brian Paul | 1691e29 | 2016-10-28 13:04:32 -0700 | [diff] [blame] | 422 | SVGA_STATS_TIME_PUSH(svga_sws(svga), SVGA_STATS_TIME_CONTEXTFINISH); |
| 423 | |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 424 | svga_context_flush(svga, &fence); |
Marek Olšák | 54272e1 | 2016-08-06 16:41:42 +0200 | [diff] [blame] | 425 | screen->fence_finish(screen, NULL, fence, PIPE_TIMEOUT_INFINITE); |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 426 | screen->fence_reference(screen, &fence, NULL); |
Brian Paul | 1691e29 | 2016-10-28 13:04:32 -0700 | [diff] [blame] | 427 | |
| 428 | SVGA_STATS_TIME_POP(svga_sws(svga)); |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | |
| 432 | /** |
| 433 | * Emit pending drawing commands to the command buffer. |
| 434 | * If the command buffer overflows, we flush it and retry. |
| 435 | * \sa svga_hwtnl_flush() |
| 436 | */ |
Brian Paul | c96f63c | 2016-11-01 08:17:05 -0600 | [diff] [blame] | 437 | void |
| 438 | svga_hwtnl_flush_retry(struct svga_context *svga) |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 439 | { |
| 440 | enum pipe_error ret = PIPE_OK; |
| 441 | |
Brian Paul | c96f63c | 2016-11-01 08:17:05 -0600 | [diff] [blame] | 442 | ret = svga_hwtnl_flush(svga->hwtnl); |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 443 | if (ret == PIPE_ERROR_OUT_OF_MEMORY) { |
Brian Paul | c96f63c | 2016-11-01 08:17:05 -0600 | [diff] [blame] | 444 | svga_context_flush(svga, NULL); |
| 445 | ret = svga_hwtnl_flush(svga->hwtnl); |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 446 | } |
| 447 | |
Brian Paul | e054251 | 2015-08-13 11:00:58 -0700 | [diff] [blame] | 448 | assert(ret == PIPE_OK); |
Jakob Bornecrantz | 3192633 | 2009-11-16 19:56:18 +0100 | [diff] [blame] | 449 | } |
| 450 | |
José Fonseca | 0ced789 | 2011-02-18 14:33:55 +0000 | [diff] [blame] | 451 | |
José Fonseca | 1e9d893 | 2011-10-27 19:09:25 +0100 | [diff] [blame] | 452 | /** |
| 453 | * Flush the primitive queue if this buffer is referred. |
| 454 | * |
| 455 | * Otherwise DMA commands on the referred buffer will be emitted too late. |
| 456 | */ |
Brian Paul | c96f63c | 2016-11-01 08:17:05 -0600 | [diff] [blame] | 457 | void |
| 458 | svga_hwtnl_flush_buffer(struct svga_context *svga, |
| 459 | struct pipe_resource *buffer) |
José Fonseca | 1e9d893 | 2011-10-27 19:09:25 +0100 | [diff] [blame] | 460 | { |
| 461 | if (svga_hwtnl_is_buffer_referred(svga->hwtnl, buffer)) { |
| 462 | svga_hwtnl_flush_retry(svga); |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | |
Brian Paul | c96f63c | 2016-11-01 08:17:05 -0600 | [diff] [blame] | 467 | /** |
| 468 | * Emit all operations pending on host surfaces. |
| 469 | */ |
| 470 | void |
| 471 | svga_surfaces_flush(struct svga_context *svga) |
José Fonseca | 0ced789 | 2011-02-18 14:33:55 +0000 | [diff] [blame] | 472 | { |
Charmaine Lee | 2e1cfcc | 2016-08-19 08:49:17 -0600 | [diff] [blame] | 473 | SVGA_STATS_TIME_PUSH(svga_sws(svga), SVGA_STATS_TIME_SURFACEFLUSH); |
| 474 | |
José Fonseca | 0ced789 | 2011-02-18 14:33:55 +0000 | [diff] [blame] | 475 | /* Emit buffered drawing commands. |
| 476 | */ |
Brian Paul | c96f63c | 2016-11-01 08:17:05 -0600 | [diff] [blame] | 477 | svga_hwtnl_flush_retry(svga); |
José Fonseca | 0ced789 | 2011-02-18 14:33:55 +0000 | [diff] [blame] | 478 | |
Brian Paul | 646afc6 | 2016-08-26 09:53:47 -0600 | [diff] [blame] | 479 | /* Emit back-copy from render target views to textures. |
José Fonseca | 0ced789 | 2011-02-18 14:33:55 +0000 | [diff] [blame] | 480 | */ |
Brian Paul | 646afc6 | 2016-08-26 09:53:47 -0600 | [diff] [blame] | 481 | svga_propagate_rendertargets(svga); |
José Fonseca | 0ced789 | 2011-02-18 14:33:55 +0000 | [diff] [blame] | 482 | |
Charmaine Lee | 2e1cfcc | 2016-08-19 08:49:17 -0600 | [diff] [blame] | 483 | SVGA_STATS_TIME_POP(svga_sws(svga)); |
José Fonseca | 0ced789 | 2011-02-18 14:33:55 +0000 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | |
Thomas Hellstrom | cd151ef | 2010-05-31 22:03:56 +0100 | [diff] [blame] | 487 | struct svga_winsys_context * |
Brian Paul | c96f63c | 2016-11-01 08:17:05 -0600 | [diff] [blame] | 488 | svga_winsys_context(struct pipe_context *pipe) |
Thomas Hellstrom | cd151ef | 2010-05-31 22:03:56 +0100 | [diff] [blame] | 489 | { |
Brian Paul | c96f63c | 2016-11-01 08:17:05 -0600 | [diff] [blame] | 490 | return svga_context(pipe)->swc; |
Thomas Hellstrom | cd151ef | 2010-05-31 22:03:56 +0100 | [diff] [blame] | 491 | } |