/* * Draw vertex arrays, with optional indexing, optional instancing. */ static void swr_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info) { struct swr_context *ctx = swr_context(pipe); if (!swr_check_render_cond(pipe)) return; if (info->indirect) { util_draw_indirect(pipe, info); return; } /* Update derived state, pass draw info to update function */ if (ctx->dirty) swr_update_derived(pipe, info); swr_update_draw_context(ctx); if (ctx->vs->pipe.stream_output.num_outputs) { if (!ctx->vs->soFunc[info->mode]) { STREAMOUT_COMPILE_STATE state = {0}; struct pipe_stream_output_info *so = &ctx->vs->pipe.stream_output; state.numVertsPerPrim = u_vertices_per_prim(info->mode); uint32_t offsets[MAX_SO_STREAMS] = {0}; uint32_t num = 0; for (uint32_t i = 0; i < so->num_outputs; i++) { assert(so->output[i].stream == 0); // @todo uint32_t output_buffer = so->output[i].output_buffer; if (so->output[i].dst_offset != offsets[output_buffer]) { // hole - need to fill state.stream.decl[num].bufferIndex = output_buffer; state.stream.decl[num].hole = true; state.stream.decl[num].componentMask = (1 << (so->output[i].dst_offset - offsets[output_buffer])) - 1; num++; offsets[output_buffer] = so->output[i].dst_offset; } state.stream.decl[num].bufferIndex = output_buffer; state.stream.decl[num].attribSlot = so->output[i].register_index - 1; state.stream.decl[num].componentMask = ((1 << so->output[i].num_components) - 1) << so->output[i].start_component; state.stream.decl[num].hole = false; num++; offsets[output_buffer] += so->output[i].num_components; } state.stream.numDecls = num; HANDLE hJitMgr = swr_screen(pipe->screen)->hJitMgr; ctx->vs->soFunc[info->mode] = JitCompileStreamout(hJitMgr, state); debug_printf("so shader %p\n", ctx->vs->soFunc[info->mode]); assert(ctx->vs->soFunc[info->mode] && "Error: SoShader = NULL"); } SwrSetSoFunc(ctx->swrContext, ctx->vs->soFunc[info->mode], 0); } struct swr_vertex_element_state *velems = ctx->velems; if (!velems->fsFunc || (velems->fsState.cutIndex != info->restart_index) || (velems->fsState.bEnableCutIndex != info->primitive_restart)) { velems->fsState.cutIndex = info->restart_index; velems->fsState.bEnableCutIndex = info->primitive_restart; /* Create Fetch Shader */ HANDLE hJitMgr = swr_screen(ctx->pipe.screen)->hJitMgr; velems->fsFunc = JitCompileFetch(hJitMgr, velems->fsState); debug_printf("fetch shader %p\n", velems->fsFunc); assert(velems->fsFunc && "Error: FetchShader = NULL"); } SwrSetFetchFunc(ctx->swrContext, velems->fsFunc); /* Set up frontend state * XXX setup provokingVertex & topologyProvokingVertex */ SWR_FRONTEND_STATE feState = {0}; if (ctx->rasterizer->flatshade_first) { feState.provokingVertex = {1, 0, 0}; } else { feState.provokingVertex = {2, 1, 2}; } switch (info->mode) { case PIPE_PRIM_TRIANGLE_FAN: feState.topologyProvokingVertex = feState.provokingVertex.triFan; break; case PIPE_PRIM_TRIANGLE_STRIP: case PIPE_PRIM_TRIANGLES: feState.topologyProvokingVertex = feState.provokingVertex.triStripList; break; case PIPE_PRIM_QUAD_STRIP: case PIPE_PRIM_QUADS: if (ctx->rasterizer->flatshade_first) feState.topologyProvokingVertex = 0; else feState.topologyProvokingVertex = 3; break; case PIPE_PRIM_LINES: case PIPE_PRIM_LINE_LOOP: case PIPE_PRIM_LINE_STRIP: feState.topologyProvokingVertex = feState.provokingVertex.lineStripList; break; default: feState.topologyProvokingVertex = 0; } feState.bEnableCutIndex = info->primitive_restart; SwrSetFrontendState(ctx->swrContext, &feState); if (info->indexed) SwrDrawIndexedInstanced(ctx->swrContext, swr_convert_prim_topology(info->mode), info->count, info->instance_count, info->start, info->index_bias, info->start_instance); else SwrDrawInstanced(ctx->swrContext, swr_convert_prim_topology(info->mode), info->count, info->instance_count, info->start, info->start_instance); }
/* * Draw vertex arrays, with optional indexing, optional instancing. */ static void swr_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info) { struct swr_context *ctx = swr_context(pipe); if (!info->count_from_stream_output && !info->indirect && !info->primitive_restart && !u_trim_pipe_prim(info->mode, (unsigned*)&info->count)) return; if (!swr_check_render_cond(pipe)) return; if (info->indirect) { util_draw_indirect(pipe, info); return; } /* If indexed draw, force vertex validation since index buffer comes * from draw info. */ if (info->index_size) ctx->dirty |= SWR_NEW_VERTEX; /* Update derived state, pass draw info to update function. */ swr_update_derived(pipe, info); swr_update_draw_context(ctx); if (ctx->vs->pipe.stream_output.num_outputs) { if (!ctx->vs->soFunc[info->mode]) { STREAMOUT_COMPILE_STATE state = {0}; struct pipe_stream_output_info *so = &ctx->vs->pipe.stream_output; state.numVertsPerPrim = u_vertices_per_prim(info->mode); uint32_t offsets[MAX_SO_STREAMS] = {0}; uint32_t num = 0; for (uint32_t i = 0; i < so->num_outputs; i++) { assert(so->output[i].stream == 0); // @todo uint32_t output_buffer = so->output[i].output_buffer; if (so->output[i].dst_offset != offsets[output_buffer]) { // hole - need to fill state.stream.decl[num].bufferIndex = output_buffer; state.stream.decl[num].hole = true; state.stream.decl[num].componentMask = (1 << (so->output[i].dst_offset - offsets[output_buffer])) - 1; num++; offsets[output_buffer] = so->output[i].dst_offset; } unsigned attrib_slot = so->output[i].register_index; attrib_slot = swr_so_adjust_attrib(attrib_slot, ctx->vs); state.stream.decl[num].bufferIndex = output_buffer; state.stream.decl[num].attribSlot = attrib_slot; state.stream.decl[num].componentMask = ((1 << so->output[i].num_components) - 1) << so->output[i].start_component; state.stream.decl[num].hole = false; num++; offsets[output_buffer] += so->output[i].num_components; } state.stream.numDecls = num; HANDLE hJitMgr = swr_screen(pipe->screen)->hJitMgr; ctx->vs->soFunc[info->mode] = JitCompileStreamout(hJitMgr, state); debug_printf("so shader %p\n", ctx->vs->soFunc[info->mode]); assert(ctx->vs->soFunc[info->mode] && "Error: SoShader = NULL"); } ctx->api.pfnSwrSetSoFunc(ctx->swrContext, ctx->vs->soFunc[info->mode], 0); } struct swr_vertex_element_state *velems = ctx->velems; if (info->primitive_restart) velems->fsState.cutIndex = info->restart_index; else velems->fsState.cutIndex = 0; velems->fsState.bEnableCutIndex = info->primitive_restart; velems->fsState.bPartialVertexBuffer = (info->min_index > 0); swr_jit_fetch_key key; swr_generate_fetch_key(key, velems); auto search = velems->map.find(key); if (search != velems->map.end()) { velems->fsFunc = search->second; } else { HANDLE hJitMgr = swr_screen(ctx->pipe.screen)->hJitMgr; velems->fsFunc = JitCompileFetch(hJitMgr, velems->fsState); debug_printf("fetch shader %p\n", velems->fsFunc); assert(velems->fsFunc && "Error: FetchShader = NULL"); velems->map.insert(std::make_pair(key, velems->fsFunc)); } ctx->api.pfnSwrSetFetchFunc(ctx->swrContext, velems->fsFunc); /* Set up frontend state * XXX setup provokingVertex & topologyProvokingVertex */ SWR_FRONTEND_STATE feState = {0}; // feState.vsVertexSize seeds the PA size that is used as an interface // between all the shader stages, so it has to be large enough to // incorporate all interfaces between stages // max of gs and vs num_outputs feState.vsVertexSize = ctx->vs->info.base.num_outputs; if (ctx->gs && ctx->gs->info.base.num_outputs > feState.vsVertexSize) { feState.vsVertexSize = ctx->gs->info.base.num_outputs; } if (ctx->vs->info.base.num_outputs) { // gs does not adjust for position in SGV slot at input from vs if (!ctx->gs) feState.vsVertexSize--; } // other (non-SGV) slots start at VERTEX_ATTRIB_START_SLOT feState.vsVertexSize += VERTEX_ATTRIB_START_SLOT; // The PA in the clipper does not handle BE vertex sizes // different from FE. Increase vertexsize only for the cases that needed it // primid needs a slot if (ctx->fs->info.base.uses_primid) feState.vsVertexSize++; // sprite coord enable if (ctx->rasterizer->sprite_coord_enable) feState.vsVertexSize++; if (ctx->rasterizer->flatshade_first) { feState.provokingVertex = {1, 0, 0}; } else { feState.provokingVertex = {2, 1, 2}; } enum pipe_prim_type topology; if (ctx->gs) topology = (pipe_prim_type)ctx->gs->info.base.properties[TGSI_PROPERTY_GS_OUTPUT_PRIM]; else topology = info->mode; switch (topology) { case PIPE_PRIM_TRIANGLE_FAN: feState.topologyProvokingVertex = feState.provokingVertex.triFan; break; case PIPE_PRIM_TRIANGLE_STRIP: case PIPE_PRIM_TRIANGLES: feState.topologyProvokingVertex = feState.provokingVertex.triStripList; break; case PIPE_PRIM_QUAD_STRIP: case PIPE_PRIM_QUADS: if (ctx->rasterizer->flatshade_first) feState.topologyProvokingVertex = 0; else feState.topologyProvokingVertex = 3; break; case PIPE_PRIM_LINES: case PIPE_PRIM_LINE_LOOP: case PIPE_PRIM_LINE_STRIP: feState.topologyProvokingVertex = feState.provokingVertex.lineStripList; break; default: feState.topologyProvokingVertex = 0; } feState.bEnableCutIndex = info->primitive_restart; ctx->api.pfnSwrSetFrontendState(ctx->swrContext, &feState); if (info->index_size) ctx->api.pfnSwrDrawIndexedInstanced(ctx->swrContext, swr_convert_prim_topology(info->mode), info->count, info->instance_count, info->start, info->index_bias, info->start_instance); else ctx->api.pfnSwrDrawInstanced(ctx->swrContext, swr_convert_prim_topology(info->mode), info->count, info->instance_count, info->start, info->start_instance); /* On large client-buffer draw, we used client buffer directly, without * copy. Block until draw is finished. * VMD is an example application that benefits from this. */ if (ctx->dirty & SWR_LARGE_CLIENT_DRAW) { struct swr_screen *screen = swr_screen(pipe->screen); swr_fence_submit(ctx, screen->flush_fence); swr_fence_finish(pipe->screen, NULL, screen->flush_fence, 0); } }
static void swr_blit(struct pipe_context *pipe, const struct pipe_blit_info *blit_info) { struct swr_context *ctx = swr_context(pipe); /* Make a copy of the const blit_info, so we can modify it */ struct pipe_blit_info info = *blit_info; if (info.render_condition_enable && !swr_check_render_cond(pipe)) return; if (info.src.resource->nr_samples > 1 && info.dst.resource->nr_samples <= 1 && !util_format_is_depth_or_stencil(info.src.resource->format) && !util_format_is_pure_integer(info.src.resource->format)) { debug_printf("swr_blit: color resolve : %d -> %d\n", info.src.resource->nr_samples, info.dst.resource->nr_samples); /* Resolve is done as part of the surface store. */ swr_store_dirty_resource(pipe, info.src.resource, SWR_TILE_RESOLVED); struct pipe_resource *src_resource = info.src.resource; struct pipe_resource *resolve_target = swr_resource(src_resource)->resolve_target; /* The resolve target becomes the new source for the blit. */ info.src.resource = resolve_target; } if (util_try_blit_via_copy_region(pipe, &info)) { return; /* done */ } if (info.mask & PIPE_MASK_S) { debug_printf("swr: cannot blit stencil, skipping\n"); info.mask &= ~PIPE_MASK_S; } if (!util_blitter_is_blit_supported(ctx->blitter, &info)) { debug_printf("swr: blit unsupported %s -> %s\n", util_format_short_name(info.src.resource->format), util_format_short_name(info.dst.resource->format)); return; } if (ctx->active_queries) { ctx->api.pfnSwrEnableStatsFE(ctx->swrContext, FALSE); ctx->api.pfnSwrEnableStatsBE(ctx->swrContext, FALSE); } util_blitter_save_vertex_buffer_slot(ctx->blitter, ctx->vertex_buffer); util_blitter_save_vertex_elements(ctx->blitter, (void *)ctx->velems); util_blitter_save_vertex_shader(ctx->blitter, (void *)ctx->vs); util_blitter_save_geometry_shader(ctx->blitter, (void*)ctx->gs); util_blitter_save_so_targets( ctx->blitter, ctx->num_so_targets, (struct pipe_stream_output_target **)ctx->so_targets); util_blitter_save_rasterizer(ctx->blitter, (void *)ctx->rasterizer); util_blitter_save_viewport(ctx->blitter, &ctx->viewport); util_blitter_save_scissor(ctx->blitter, &ctx->scissor); util_blitter_save_fragment_shader(ctx->blitter, ctx->fs); util_blitter_save_blend(ctx->blitter, (void *)ctx->blend); util_blitter_save_depth_stencil_alpha(ctx->blitter, (void *)ctx->depth_stencil); util_blitter_save_stencil_ref(ctx->blitter, &ctx->stencil_ref); util_blitter_save_sample_mask(ctx->blitter, ctx->sample_mask); util_blitter_save_framebuffer(ctx->blitter, &ctx->framebuffer); util_blitter_save_fragment_sampler_states( ctx->blitter, ctx->num_samplers[PIPE_SHADER_FRAGMENT], (void **)ctx->samplers[PIPE_SHADER_FRAGMENT]); util_blitter_save_fragment_sampler_views( ctx->blitter, ctx->num_sampler_views[PIPE_SHADER_FRAGMENT], ctx->sampler_views[PIPE_SHADER_FRAGMENT]); util_blitter_save_render_condition(ctx->blitter, ctx->render_cond_query, ctx->render_cond_cond, ctx->render_cond_mode); util_blitter_blit(ctx->blitter, &info); if (ctx->active_queries) { ctx->api.pfnSwrEnableStatsFE(ctx->swrContext, TRUE); ctx->api.pfnSwrEnableStatsBE(ctx->swrContext, TRUE); } }
static void swr_blit(struct pipe_context *pipe, const struct pipe_blit_info *blit_info) { struct swr_context *ctx = swr_context(pipe); struct pipe_blit_info info = *blit_info; if (blit_info->render_condition_enable && !swr_check_render_cond(pipe)) return; if (info.src.resource->nr_samples > 1 && info.dst.resource->nr_samples <= 1 && !util_format_is_depth_or_stencil(info.src.resource->format) && !util_format_is_pure_integer(info.src.resource->format)) { debug_printf("swr: color resolve unimplemented\n"); return; } if (util_try_blit_via_copy_region(pipe, &info)) { return; /* done */ } if (info.mask & PIPE_MASK_S) { debug_printf("swr: cannot blit stencil, skipping\n"); info.mask &= ~PIPE_MASK_S; } if (!util_blitter_is_blit_supported(ctx->blitter, &info)) { debug_printf("swr: blit unsupported %s -> %s\n", util_format_short_name(info.src.resource->format), util_format_short_name(info.dst.resource->format)); return; } /* XXX turn off occlusion and streamout queries */ util_blitter_save_vertex_buffer_slot(ctx->blitter, ctx->vertex_buffer); util_blitter_save_vertex_elements(ctx->blitter, (void *)ctx->velems); util_blitter_save_vertex_shader(ctx->blitter, (void *)ctx->vs); /*util_blitter_save_geometry_shader(ctx->blitter, (void*)ctx->gs);*/ util_blitter_save_so_targets( ctx->blitter, ctx->num_so_targets, (struct pipe_stream_output_target **)ctx->so_targets); util_blitter_save_rasterizer(ctx->blitter, (void *)ctx->rasterizer); util_blitter_save_viewport(ctx->blitter, &ctx->viewport); util_blitter_save_scissor(ctx->blitter, &ctx->scissor); util_blitter_save_fragment_shader(ctx->blitter, ctx->fs); util_blitter_save_blend(ctx->blitter, (void *)ctx->blend); util_blitter_save_depth_stencil_alpha(ctx->blitter, (void *)ctx->depth_stencil); util_blitter_save_stencil_ref(ctx->blitter, &ctx->stencil_ref); util_blitter_save_sample_mask(ctx->blitter, ctx->sample_mask); util_blitter_save_framebuffer(ctx->blitter, &ctx->framebuffer); util_blitter_save_fragment_sampler_states( ctx->blitter, ctx->num_samplers[PIPE_SHADER_FRAGMENT], (void **)ctx->samplers[PIPE_SHADER_FRAGMENT]); util_blitter_save_fragment_sampler_views( ctx->blitter, ctx->num_sampler_views[PIPE_SHADER_FRAGMENT], ctx->sampler_views[PIPE_SHADER_FRAGMENT]); util_blitter_save_render_condition(ctx->blitter, ctx->render_cond_query, ctx->render_cond_cond, ctx->render_cond_mode); util_blitter_blit(ctx->blitter, &info); }