softpipe: Use the draw module's poly stipple handling, like llvmpipe.

softpipe was using the draw helper module as a testbed for the draw helper
module long ago, but we can just use the finished product.

Reviewed-by: Zoltán Böszőrményi <zboszor@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13731>
This commit is contained in:
Emma Anholt 2021-12-21 15:31:36 -08:00
parent 764d367a62
commit 0b7a0d1a49
7 changed files with 4 additions and 122 deletions

View file

@ -23,7 +23,6 @@
#include "util/u_inlines.h"
#include "util/u_math.h"
#include "util/u_memory.h"
#include "util/u_pstipple.h"
#include "pipe/p_shader_tokens.h"
#include "draw/draw_context.h"
#include "draw/draw_vertex.h"

View file

@ -35,7 +35,6 @@
#include "pipe/p_defines.h"
#include "util/u_math.h"
#include "util/u_memory.h"
#include "util/u_pstipple.h"
#include "util/u_inlines.h"
#include "util/u_upload_mgr.h"
#include "tgsi/tgsi_exec.h"
@ -60,14 +59,6 @@ softpipe_destroy( struct pipe_context *pipe )
struct softpipe_context *softpipe = softpipe_context( pipe );
uint i, sh;
#if DO_PSTIPPLE_IN_HELPER_MODULE
if (softpipe->pstipple.sampler)
pipe->delete_sampler_state(pipe, softpipe->pstipple.sampler);
pipe_resource_reference(&softpipe->pstipple.texture, NULL);
pipe_sampler_view_reference(&softpipe->pstipple.sampler_view, NULL);
#endif
if (softpipe->blitter) {
util_blitter_destroy(softpipe->blitter);
}
@ -344,20 +335,13 @@ softpipe_create_context(struct pipe_screen *screen,
draw_install_aaline_stage(softpipe->draw, &softpipe->pipe);
draw_install_aapoint_stage(softpipe->draw, &softpipe->pipe);
/* Do polygon stipple w/ texture map + frag prog? */
#if DO_PSTIPPLE_IN_DRAW_MODULE
/* Do polygon stipple w/ texture map + frag prog. */
draw_install_pstipple_stage(softpipe->draw, &softpipe->pipe);
#endif
draw_wide_point_sprites(softpipe->draw, TRUE);
sp_init_surface_functions(softpipe);
#if DO_PSTIPPLE_IN_HELPER_MODULE
/* create the polygon stipple sampler */
softpipe->pstipple.sampler = util_pstipple_create_sampler(&softpipe->pipe);
#endif
return &softpipe->pipe;
fail:

View file

@ -40,13 +40,6 @@
#include "sp_setup.h"
/** Do polygon stipple in the draw module? */
#define DO_PSTIPPLE_IN_DRAW_MODULE 0
/** Do polygon stipple with the util module? */
#define DO_PSTIPPLE_IN_HELPER_MODULE 1
struct softpipe_vbuf_render;
struct draw_context;
struct draw_stage;
@ -80,7 +73,6 @@ struct softpipe_context {
struct pipe_clip_state clip;
struct pipe_resource *constants[PIPE_SHADER_TYPES][PIPE_MAX_CONSTANT_BUFFERS];
struct pipe_framebuffer_state framebuffer;
struct pipe_poly_stipple poly_stipple;
struct pipe_scissor_state scissors[PIPE_MAX_VIEWPORTS];
struct pipe_sampler_view *sampler_views[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_SAMPLER_VIEWS];
@ -153,13 +145,6 @@ struct softpipe_context {
enum pipe_render_cond_flag render_cond_mode;
bool render_cond_cond;
/** Polygon stipple items */
struct {
struct pipe_resource *texture;
struct pipe_sampler_state *sampler;
struct pipe_sampler_view *sampler_view;
} pstipple;
/** Software quad rendering pipeline */
struct {
struct quad_stage *shade;

View file

@ -41,7 +41,7 @@
#define SP_NEW_BLEND 0x8
#define SP_NEW_CLIP 0x10
#define SP_NEW_SCISSOR 0x20
#define SP_NEW_STIPPLE 0x40
#define SP_NEW_FRAMEBUFFER 0x80
#define SP_NEW_DEPTH_STENCIL_ALPHA 0x100
#define SP_NEW_CONSTANTS 0x200
@ -64,7 +64,6 @@ struct vertex_info;
struct sp_fragment_shader_variant_key
{
boolean polygon_stipple;
};
@ -74,8 +73,6 @@ struct sp_fragment_shader_variant
struct sp_fragment_shader_variant_key key;
struct tgsi_shader_info info;
unsigned stipple_sampler_unit;
/* See comments about this elsewhere */
#if 0
struct draw_fragment_shader *draw_shader;

View file

@ -84,12 +84,10 @@ static void
softpipe_set_polygon_stipple(struct pipe_context *pipe,
const struct pipe_poly_stipple *stipple)
{
/* Actual stippling handled by draw module. */
struct softpipe_context *softpipe = softpipe_context(pipe);
draw_flush(softpipe->draw);
softpipe->poly_stipple = *stipple; /* struct copy */
softpipe->dirty |= SP_NEW_STIPPLE;
}

View file

@ -28,7 +28,6 @@
#include "util/u_inlines.h"
#include "util/u_math.h"
#include "util/u_memory.h"
#include "util/u_pstipple.h"
#include "pipe/p_shader_tokens.h"
#include "draw/draw_context.h"
#include "draw/draw_vertex.h"
@ -338,9 +337,6 @@ update_fragment_shader(struct softpipe_context *softpipe, unsigned prim)
memset(&key, 0, sizeof(key));
if (prim == PIPE_PRIM_TRIANGLES)
key.polygon_stipple = softpipe->rasterizer->poly_stipple_enable;
if (softpipe->fs) {
softpipe->fs_variant = softpipe_find_fs_variant(softpipe,
softpipe->fs, &key);
@ -377,56 +373,6 @@ update_fragment_shader(struct softpipe_context *softpipe, unsigned prim)
}
/**
* This should be called when the polygon stipple pattern changes.
* We create a new texture from the stipple pattern and create a new
* sampler view.
*/
static void
update_polygon_stipple_pattern(struct softpipe_context *softpipe)
{
struct pipe_resource *tex;
struct pipe_sampler_view *view;
tex = util_pstipple_create_stipple_texture(&softpipe->pipe,
softpipe->poly_stipple.stipple);
pipe_resource_reference(&softpipe->pstipple.texture, tex);
pipe_resource_reference(&tex, NULL);
view = util_pstipple_create_sampler_view(&softpipe->pipe,
softpipe->pstipple.texture);
pipe_sampler_view_reference(&softpipe->pstipple.sampler_view, view);
pipe_sampler_view_reference(&view, NULL);
}
/**
* Should be called when polygon stipple is enabled/disabled or when
* the fragment shader changes.
* We add/update the fragment sampler and sampler views to sample from
* the polygon stipple texture. The texture unit that we use depends on
* the fragment shader (we need to use a unit not otherwise used by the
* shader).
*/
static void
update_polygon_stipple_enable(struct softpipe_context *softpipe, unsigned prim)
{
if (prim == PIPE_PRIM_TRIANGLES &&
softpipe->fs_variant->key.polygon_stipple) {
const unsigned unit = softpipe->fs_variant->stipple_sampler_unit;
/* sampler state */
softpipe->samplers[PIPE_SHADER_FRAGMENT][unit] = softpipe->pstipple.sampler;
/* sampler view state */
softpipe_set_sampler_views(&softpipe->pipe, PIPE_SHADER_FRAGMENT,
unit, 1, 0, false, &softpipe->pstipple.sampler_view);
softpipe->dirty |= SP_NEW_SAMPLER;
}
}
/* Hopefully this will remain quite simple, otherwise need to pull in
* something like the gallium frontend mechanism.
*/
@ -442,23 +388,10 @@ softpipe_update_derived(struct softpipe_context *softpipe, unsigned prim)
softpipe->dirty |= SP_NEW_TEXTURE;
}
#if DO_PSTIPPLE_IN_HELPER_MODULE
if (softpipe->dirty & SP_NEW_STIPPLE)
/* before updating samplers! */
update_polygon_stipple_pattern(softpipe);
#endif
if (softpipe->dirty & (SP_NEW_RASTERIZER |
SP_NEW_FS))
update_fragment_shader(softpipe, prim);
#if DO_PSTIPPLE_IN_HELPER_MODULE
if (softpipe->dirty & (SP_NEW_RASTERIZER |
SP_NEW_STIPPLE |
SP_NEW_FS))
update_polygon_stipple_enable(softpipe, prim);
#endif
/* TODO: this looks suboptimal */
if (softpipe->dirty & (SP_NEW_SAMPLER |
SP_NEW_TEXTURE |

View file

@ -37,7 +37,6 @@
#include "util/ralloc.h"
#include "util/u_memory.h"
#include "util/u_inlines.h"
#include "util/u_pstipple.h"
#include "draw/draw_context.h"
#include "draw/draw_vs.h"
#include "draw/draw_gs.h"
@ -65,20 +64,7 @@ create_fs_variant(struct softpipe_context *softpipe,
if (var) {
var->key = *key;
#if DO_PSTIPPLE_IN_HELPER_MODULE
if (key->polygon_stipple) {
/* get new shader that implements polygon stippling */
var->tokens =
util_pstipple_create_fragment_shader(curfs->tokens,
&var->stipple_sampler_unit, 0,
TGSI_FILE_INPUT);
}
else
#endif
{
var->tokens = tgsi_dup_tokens(curfs->tokens);
var->stipple_sampler_unit = 0;
}
tgsi_scan_shader(var->tokens, &var->info);