12b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley/**************************************************************************** 22b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley * Copyright (C) 2015 Intel Corporation. All Rights Reserved. 32b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley * 42b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley * Permission is hereby granted, free of charge, to any person obtaining a 52b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley * copy of this software and associated documentation files (the "Software"), 62b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley * to deal in the Software without restriction, including without limitation 72b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley * the rights to use, copy, modify, merge, publish, distribute, sublicense, 82b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley * and/or sell copies of the Software, and to permit persons to whom the 92b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley * Software is furnished to do so, subject to the following conditions: 102b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley * 112b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley * The above copyright notice and this permission notice (including the next 122b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley * paragraph) shall be included in all copies or substantial portions of the 132b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley * Software. 142b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley * 152b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 162b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 172b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 182b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 192b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 202b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 212b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley * IN THE SOFTWARE. 222b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley ***************************************************************************/ 232b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley 242b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley#include "swr_screen.h" 252b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley#include "swr_context.h" 262b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley#include "swr_resource.h" 272b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley#include "swr_fence.h" 282b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley#include "swr_query.h" 292b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley#include "jit_api.h" 302b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley 312b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley#include "util/u_draw.h" 322b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley#include "util/u_prim.h" 332b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley 342b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley/* 352b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley * Convert mesa PIPE_PRIM_X to SWR enum PRIMITIVE_TOPOLOGY 362b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley */ 372b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowleystatic INLINE enum PRIMITIVE_TOPOLOGY 382b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowleyswr_convert_prim_topology(const unsigned mode) 392b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley{ 402b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley switch (mode) { 412b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley case PIPE_PRIM_POINTS: 422b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley return TOP_POINT_LIST; 432b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley case PIPE_PRIM_LINES: 442b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley return TOP_LINE_LIST; 452b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley case PIPE_PRIM_LINE_LOOP: 462b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley return TOP_LINE_LOOP; 472b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley case PIPE_PRIM_LINE_STRIP: 482b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley return TOP_LINE_STRIP; 492b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley case PIPE_PRIM_TRIANGLES: 502b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley return TOP_TRIANGLE_LIST; 512b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley case PIPE_PRIM_TRIANGLE_STRIP: 522b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley return TOP_TRIANGLE_STRIP; 532b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley case PIPE_PRIM_TRIANGLE_FAN: 542b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley return TOP_TRIANGLE_FAN; 552b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley case PIPE_PRIM_QUADS: 562b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley return TOP_QUAD_LIST; 572b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley case PIPE_PRIM_QUAD_STRIP: 582b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley return TOP_QUAD_STRIP; 592b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley case PIPE_PRIM_POLYGON: 602b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley return TOP_TRIANGLE_FAN; /* XXX TOP_POLYGON; */ 612b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley case PIPE_PRIM_LINES_ADJACENCY: 622b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley return TOP_LINE_LIST_ADJ; 632b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley case PIPE_PRIM_LINE_STRIP_ADJACENCY: 642b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley return TOP_LISTSTRIP_ADJ; 652b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley case PIPE_PRIM_TRIANGLES_ADJACENCY: 662b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley return TOP_TRI_LIST_ADJ; 672b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley case PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY: 682b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley return TOP_TRI_STRIP_ADJ; 692b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley default: 702b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley assert(0 && "Unknown topology"); 712b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley return TOP_UNKNOWN; 722b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley } 732b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley}; 742b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley 752b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley 762b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley/* 772b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley * Draw vertex arrays, with optional indexing, optional instancing. 782b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley */ 792b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowleystatic void 802b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowleyswr_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info) 812b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley{ 822b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley struct swr_context *ctx = swr_context(pipe); 832b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley 842b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley if (!swr_check_render_cond(pipe)) 852b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley return; 862b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley 872b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley if (info->indirect) { 882b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley util_draw_indirect(pipe, info); 892b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley return; 902b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley } 912b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley 922b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley /* Update derived state, pass draw info to update function */ 9316d42f2f3dcc8bec8d75b53d1e9e9cf5af6e528cIlia Mirkin swr_update_derived(pipe, info); 942b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley 952b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley swr_update_draw_context(ctx); 962b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley 972b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley if (ctx->vs->pipe.stream_output.num_outputs) { 982b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley if (!ctx->vs->soFunc[info->mode]) { 992b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley STREAMOUT_COMPILE_STATE state = {0}; 1002b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley struct pipe_stream_output_info *so = &ctx->vs->pipe.stream_output; 1012b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley 1022b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley state.numVertsPerPrim = u_vertices_per_prim(info->mode); 1032b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley 1042b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley uint32_t offsets[MAX_SO_STREAMS] = {0}; 1052b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley uint32_t num = 0; 1062b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley 1072b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley for (uint32_t i = 0; i < so->num_outputs; i++) { 1082b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley assert(so->output[i].stream == 0); // @todo 1092b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley uint32_t output_buffer = so->output[i].output_buffer; 1102b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley if (so->output[i].dst_offset != offsets[output_buffer]) { 1112b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley // hole - need to fill 1122b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley state.stream.decl[num].bufferIndex = output_buffer; 1132b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley state.stream.decl[num].hole = true; 1142b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley state.stream.decl[num].componentMask = 1152b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley (1 << (so->output[i].dst_offset - offsets[output_buffer])) 1162b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley - 1; 1172b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley num++; 1182b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley offsets[output_buffer] = so->output[i].dst_offset; 1192b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley } 1202b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley 1212b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley state.stream.decl[num].bufferIndex = output_buffer; 1222b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley state.stream.decl[num].attribSlot = so->output[i].register_index - 1; 1232b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley state.stream.decl[num].componentMask = 1242b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley ((1 << so->output[i].num_components) - 1) 1252b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley << so->output[i].start_component; 1262b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley state.stream.decl[num].hole = false; 1272b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley num++; 1282b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley 1292b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley offsets[output_buffer] += so->output[i].num_components; 1302b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley } 1312b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley 1322b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley state.stream.numDecls = num; 1332b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley 1342b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley HANDLE hJitMgr = swr_screen(pipe->screen)->hJitMgr; 1352b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley ctx->vs->soFunc[info->mode] = JitCompileStreamout(hJitMgr, state); 1362b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley debug_printf("so shader %p\n", ctx->vs->soFunc[info->mode]); 1372b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley assert(ctx->vs->soFunc[info->mode] && "Error: SoShader = NULL"); 1382b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley } 1392b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley 1402b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley SwrSetSoFunc(ctx->swrContext, ctx->vs->soFunc[info->mode], 0); 1412b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley } 1422b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley 1432b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley struct swr_vertex_element_state *velems = ctx->velems; 1442b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley if (!velems->fsFunc 1452b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley || (velems->fsState.cutIndex != info->restart_index) 1462b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley || (velems->fsState.bEnableCutIndex != info->primitive_restart)) { 1472b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley 1482b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley velems->fsState.cutIndex = info->restart_index; 1492b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley velems->fsState.bEnableCutIndex = info->primitive_restart; 1502b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley 1512b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley /* Create Fetch Shader */ 1522b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley HANDLE hJitMgr = swr_screen(ctx->pipe.screen)->hJitMgr; 1532b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley velems->fsFunc = JitCompileFetch(hJitMgr, velems->fsState); 1542b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley 1552b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley debug_printf("fetch shader %p\n", velems->fsFunc); 1562b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley assert(velems->fsFunc && "Error: FetchShader = NULL"); 1572b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley } 1582b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley 1592b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley SwrSetFetchFunc(ctx->swrContext, velems->fsFunc); 1602b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley 161c8835a592471a0238e296f6529b5dadb431cc622Bruce Cherniak /* Set up frontend state 162c8835a592471a0238e296f6529b5dadb431cc622Bruce Cherniak * XXX setup provokingVertex & topologyProvokingVertex */ 163c8835a592471a0238e296f6529b5dadb431cc622Bruce Cherniak SWR_FRONTEND_STATE feState = {0}; 16487f0a0448fba898a7ab2a36eed9682ff8c1c6d5cTim Rowley if (ctx->rasterizer->flatshade_first) { 16587f0a0448fba898a7ab2a36eed9682ff8c1c6d5cTim Rowley feState.provokingVertex = {1, 0, 0}; 16687f0a0448fba898a7ab2a36eed9682ff8c1c6d5cTim Rowley } else { 16787f0a0448fba898a7ab2a36eed9682ff8c1c6d5cTim Rowley feState.provokingVertex = {2, 1, 2}; 16887f0a0448fba898a7ab2a36eed9682ff8c1c6d5cTim Rowley } 16987f0a0448fba898a7ab2a36eed9682ff8c1c6d5cTim Rowley 17087f0a0448fba898a7ab2a36eed9682ff8c1c6d5cTim Rowley switch (info->mode) { 17187f0a0448fba898a7ab2a36eed9682ff8c1c6d5cTim Rowley case PIPE_PRIM_TRIANGLE_FAN: 17287f0a0448fba898a7ab2a36eed9682ff8c1c6d5cTim Rowley feState.topologyProvokingVertex = feState.provokingVertex.triFan; 17387f0a0448fba898a7ab2a36eed9682ff8c1c6d5cTim Rowley break; 17487f0a0448fba898a7ab2a36eed9682ff8c1c6d5cTim Rowley case PIPE_PRIM_TRIANGLE_STRIP: 17587f0a0448fba898a7ab2a36eed9682ff8c1c6d5cTim Rowley case PIPE_PRIM_TRIANGLES: 17687f0a0448fba898a7ab2a36eed9682ff8c1c6d5cTim Rowley feState.topologyProvokingVertex = feState.provokingVertex.triStripList; 17787f0a0448fba898a7ab2a36eed9682ff8c1c6d5cTim Rowley break; 17887f0a0448fba898a7ab2a36eed9682ff8c1c6d5cTim Rowley case PIPE_PRIM_QUAD_STRIP: 17987f0a0448fba898a7ab2a36eed9682ff8c1c6d5cTim Rowley case PIPE_PRIM_QUADS: 18087f0a0448fba898a7ab2a36eed9682ff8c1c6d5cTim Rowley if (ctx->rasterizer->flatshade_first) 18187f0a0448fba898a7ab2a36eed9682ff8c1c6d5cTim Rowley feState.topologyProvokingVertex = 0; 18287f0a0448fba898a7ab2a36eed9682ff8c1c6d5cTim Rowley else 18387f0a0448fba898a7ab2a36eed9682ff8c1c6d5cTim Rowley feState.topologyProvokingVertex = 3; 18487f0a0448fba898a7ab2a36eed9682ff8c1c6d5cTim Rowley break; 18587f0a0448fba898a7ab2a36eed9682ff8c1c6d5cTim Rowley case PIPE_PRIM_LINES: 18687f0a0448fba898a7ab2a36eed9682ff8c1c6d5cTim Rowley case PIPE_PRIM_LINE_LOOP: 18787f0a0448fba898a7ab2a36eed9682ff8c1c6d5cTim Rowley case PIPE_PRIM_LINE_STRIP: 18887f0a0448fba898a7ab2a36eed9682ff8c1c6d5cTim Rowley feState.topologyProvokingVertex = feState.provokingVertex.lineStripList; 18987f0a0448fba898a7ab2a36eed9682ff8c1c6d5cTim Rowley break; 19087f0a0448fba898a7ab2a36eed9682ff8c1c6d5cTim Rowley default: 19187f0a0448fba898a7ab2a36eed9682ff8c1c6d5cTim Rowley feState.topologyProvokingVertex = 0; 19287f0a0448fba898a7ab2a36eed9682ff8c1c6d5cTim Rowley } 19387f0a0448fba898a7ab2a36eed9682ff8c1c6d5cTim Rowley 194c8835a592471a0238e296f6529b5dadb431cc622Bruce Cherniak feState.bEnableCutIndex = info->primitive_restart; 195c8835a592471a0238e296f6529b5dadb431cc622Bruce Cherniak SwrSetFrontendState(ctx->swrContext, &feState); 196c8835a592471a0238e296f6529b5dadb431cc622Bruce Cherniak 1972b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley if (info->indexed) 1982b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley SwrDrawIndexedInstanced(ctx->swrContext, 1992b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley swr_convert_prim_topology(info->mode), 2002b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley info->count, 2012b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley info->instance_count, 2022b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley info->start, 2032b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley info->index_bias, 2042b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley info->start_instance); 2052b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley else 2062b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley SwrDrawInstanced(ctx->swrContext, 2072b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley swr_convert_prim_topology(info->mode), 2082b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley info->count, 2092b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley info->instance_count, 2102b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley info->start, 2112b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley info->start_instance); 2122b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley} 2132b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley 2142b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley 2152b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowleystatic void 2162b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowleyswr_flush(struct pipe_context *pipe, 2172b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley struct pipe_fence_handle **fence, 2182b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley unsigned flags) 2192b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley{ 2202b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley struct swr_context *ctx = swr_context(pipe); 2212b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley struct swr_screen *screen = swr_screen(pipe->screen); 2222b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley struct pipe_surface *cb = ctx->framebuffer.cbufs[0]; 2232b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley 224e9d68cc3da07c4b566799bbaec2434bfc21d3e0cBruce Cherniak /* If the current renderTarget is the display surface, store tiles back to 225e9d68cc3da07c4b566799bbaec2434bfc21d3e0cBruce Cherniak * the surface, in preparation for present (swr_flush_frontbuffer). 226e9d68cc3da07c4b566799bbaec2434bfc21d3e0cBruce Cherniak * Other renderTargets get stored back when attachment changes or 227e9d68cc3da07c4b566799bbaec2434bfc21d3e0cBruce Cherniak * swr_surface_destroy */ 228e9d68cc3da07c4b566799bbaec2434bfc21d3e0cBruce Cherniak if (cb && swr_resource(cb->texture)->display_target) 229e9d68cc3da07c4b566799bbaec2434bfc21d3e0cBruce Cherniak swr_store_dirty_resource(pipe, cb->texture, SWR_TILE_RESOLVED); 2302b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley 2312b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley if (fence) 2322b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley swr_fence_reference(pipe->screen, fence, screen->flush_fence); 2332b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley} 2342b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley 2352b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowleyvoid 2362b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowleyswr_finish(struct pipe_context *pipe) 2372b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley{ 238e9d68cc3da07c4b566799bbaec2434bfc21d3e0cBruce Cherniak struct pipe_fence_handle *fence = nullptr; 2392b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley 2402b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley swr_flush(pipe, &fence, 0); 24154272e18a682c8b82d4a86b2c07b51c303d8ceadMarek Olšák swr_fence_finish(pipe->screen, NULL, fence, 0); 242e9d68cc3da07c4b566799bbaec2434bfc21d3e0cBruce Cherniak swr_fence_reference(pipe->screen, &fence, NULL); 2432b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley} 2442b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley 2452b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley 2462b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley/* 247e9d68cc3da07c4b566799bbaec2434bfc21d3e0cBruce Cherniak * Store SWR HotTiles back to renderTarget surface. 2482b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley */ 2492b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowleyvoid 250e9d68cc3da07c4b566799bbaec2434bfc21d3e0cBruce Cherniakswr_store_render_target(struct pipe_context *pipe, 2512b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley uint32_t attachment, 2522b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley enum SWR_TILE_STATE post_tile_state) 2532b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley{ 254e9d68cc3da07c4b566799bbaec2434bfc21d3e0cBruce Cherniak struct swr_context *ctx = swr_context(pipe); 2552b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley struct swr_draw_context *pDC = &ctx->swrDC; 2562b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley struct SWR_SURFACE_STATE *renderTarget = &pDC->renderTargets[attachment]; 2572b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley 2582b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley /* Only proceed if there's a valid surface to store to */ 2592b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley if (renderTarget->pBaseAddress) { 2602b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley swr_update_draw_context(ctx); 2610ff57446e3786243c6d752c91be2108595f2663eTim Rowley SWR_RECT full_rect = 2629f568e5db1e5ef3b627fffb8d12258ca0cf2dd47Ilia Mirkin {0, 0, 2639f568e5db1e5ef3b627fffb8d12258ca0cf2dd47Ilia Mirkin (int32_t)u_minify(renderTarget->width, renderTarget->lod), 2649f568e5db1e5ef3b627fffb8d12258ca0cf2dd47Ilia Mirkin (int32_t)u_minify(renderTarget->height, renderTarget->lod)}; 2652b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley SwrStoreTiles(ctx->swrContext, 266a907b7a5f74169906c04e9702f3c8fda99636c56Tim Rowley 1 << attachment, 2670ff57446e3786243c6d752c91be2108595f2663eTim Rowley post_tile_state, 2680ff57446e3786243c6d752c91be2108595f2663eTim Rowley full_rect); 2692b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley } 2702b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley} 2712b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley 272e9d68cc3da07c4b566799bbaec2434bfc21d3e0cBruce Cherniakvoid 273e9d68cc3da07c4b566799bbaec2434bfc21d3e0cBruce Cherniakswr_store_dirty_resource(struct pipe_context *pipe, 274e9d68cc3da07c4b566799bbaec2434bfc21d3e0cBruce Cherniak struct pipe_resource *resource, 275e9d68cc3da07c4b566799bbaec2434bfc21d3e0cBruce Cherniak enum SWR_TILE_STATE post_tile_state) 276e9d68cc3da07c4b566799bbaec2434bfc21d3e0cBruce Cherniak{ 277e9d68cc3da07c4b566799bbaec2434bfc21d3e0cBruce Cherniak /* Only store resource if it has been written to */ 278e9d68cc3da07c4b566799bbaec2434bfc21d3e0cBruce Cherniak if (swr_resource(resource)->status & SWR_RESOURCE_WRITE) { 279e9d68cc3da07c4b566799bbaec2434bfc21d3e0cBruce Cherniak struct swr_context *ctx = swr_context(pipe); 280e9d68cc3da07c4b566799bbaec2434bfc21d3e0cBruce Cherniak struct swr_screen *screen = swr_screen(pipe->screen); 281e9d68cc3da07c4b566799bbaec2434bfc21d3e0cBruce Cherniak struct swr_resource *spr = swr_resource(resource); 282e9d68cc3da07c4b566799bbaec2434bfc21d3e0cBruce Cherniak 283e9d68cc3da07c4b566799bbaec2434bfc21d3e0cBruce Cherniak swr_draw_context *pDC = &ctx->swrDC; 284e9d68cc3da07c4b566799bbaec2434bfc21d3e0cBruce Cherniak SWR_SURFACE_STATE *renderTargets = pDC->renderTargets; 285e9d68cc3da07c4b566799bbaec2434bfc21d3e0cBruce Cherniak for (uint32_t i = 0; i < SWR_NUM_ATTACHMENTS; i++) 2867cfb364b1a373bce6b0b273556953fbb78c139e9Ilia Mirkin if (renderTargets[i].pBaseAddress == spr->swr.pBaseAddress || 2877cfb364b1a373bce6b0b273556953fbb78c139e9Ilia Mirkin (spr->secondary.pBaseAddress && 2887cfb364b1a373bce6b0b273556953fbb78c139e9Ilia Mirkin renderTargets[i].pBaseAddress == spr->secondary.pBaseAddress)) { 289e9d68cc3da07c4b566799bbaec2434bfc21d3e0cBruce Cherniak swr_store_render_target(pipe, i, post_tile_state); 290e9d68cc3da07c4b566799bbaec2434bfc21d3e0cBruce Cherniak 291e9d68cc3da07c4b566799bbaec2434bfc21d3e0cBruce Cherniak /* Mesa thinks depth/stencil are fused, so we'll never get an 292e9d68cc3da07c4b566799bbaec2434bfc21d3e0cBruce Cherniak * explicit resource for stencil. So, if checking depth, then 293e9d68cc3da07c4b566799bbaec2434bfc21d3e0cBruce Cherniak * also check for stencil. */ 294e9d68cc3da07c4b566799bbaec2434bfc21d3e0cBruce Cherniak if (spr->has_stencil && (i == SWR_ATTACHMENT_DEPTH)) { 295e9d68cc3da07c4b566799bbaec2434bfc21d3e0cBruce Cherniak swr_store_render_target( 296e9d68cc3da07c4b566799bbaec2434bfc21d3e0cBruce Cherniak pipe, SWR_ATTACHMENT_STENCIL, post_tile_state); 297e9d68cc3da07c4b566799bbaec2434bfc21d3e0cBruce Cherniak } 298e9d68cc3da07c4b566799bbaec2434bfc21d3e0cBruce Cherniak 299e9d68cc3da07c4b566799bbaec2434bfc21d3e0cBruce Cherniak /* This fence signals StoreTiles completion */ 300e9d68cc3da07c4b566799bbaec2434bfc21d3e0cBruce Cherniak swr_fence_submit(ctx, screen->flush_fence); 301e9d68cc3da07c4b566799bbaec2434bfc21d3e0cBruce Cherniak 302e9d68cc3da07c4b566799bbaec2434bfc21d3e0cBruce Cherniak break; 303e9d68cc3da07c4b566799bbaec2434bfc21d3e0cBruce Cherniak } 304e9d68cc3da07c4b566799bbaec2434bfc21d3e0cBruce Cherniak } 305e9d68cc3da07c4b566799bbaec2434bfc21d3e0cBruce Cherniak} 3062b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley 3072b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowleyvoid 3082b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowleyswr_draw_init(struct pipe_context *pipe) 3092b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley{ 3102b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley pipe->draw_vbo = swr_draw_vbo; 3112b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley pipe->flush = swr_flush; 3122b2d3680bf164ec4f8b50436b96c3fc195318ea5Tim Rowley} 313