sna_render.h revision 42542f5f
103b705cfSriastradh#ifndef SNA_RENDER_H 203b705cfSriastradh#define SNA_RENDER_H 303b705cfSriastradh 403b705cfSriastradh#include "compiler.h" 503b705cfSriastradh 603b705cfSriastradh#include <picturestr.h> 703b705cfSriastradh 803b705cfSriastradh#include <stdbool.h> 903b705cfSriastradh#include <stdint.h> 1003b705cfSriastradh#include <pthread.h> 1103b705cfSriastradh#include "atomic.h" 1203b705cfSriastradh 1303b705cfSriastradh#define GRADIENT_CACHE_SIZE 16 1403b705cfSriastradh 1503b705cfSriastradh#define GXinvalid 0xff 1603b705cfSriastradh 1703b705cfSriastradhstruct sna; 1803b705cfSriastradhstruct sna_glyph; 1903b705cfSriastradhstruct sna_video; 2003b705cfSriastradhstruct sna_video_frame; 2103b705cfSriastradhstruct brw_compile; 2203b705cfSriastradh 2303b705cfSriastradhstruct sna_composite_rectangles { 2403b705cfSriastradh struct sna_coordinate { 2503b705cfSriastradh int16_t x, y; 2603b705cfSriastradh } src, mask, dst; 2703b705cfSriastradh int16_t width, height; 2803b705cfSriastradh}; 2903b705cfSriastradh 3003b705cfSriastradhstruct sna_composite_op { 3103b705cfSriastradh fastcall void (*blt)(struct sna *sna, const struct sna_composite_op *op, 3203b705cfSriastradh const struct sna_composite_rectangles *r); 3303b705cfSriastradh fastcall void (*box)(struct sna *sna, 3403b705cfSriastradh const struct sna_composite_op *op, 3503b705cfSriastradh const BoxRec *box); 3603b705cfSriastradh void (*boxes)(struct sna *sna, const struct sna_composite_op *op, 3703b705cfSriastradh const BoxRec *box, int nbox); 3803b705cfSriastradh void (*thread_boxes)(struct sna *sna, const struct sna_composite_op *op, 3903b705cfSriastradh const BoxRec *box, int nbox); 4003b705cfSriastradh void (*done)(struct sna *sna, const struct sna_composite_op *op); 4103b705cfSriastradh 4203b705cfSriastradh struct sna_damage **damage; 4303b705cfSriastradh 4403b705cfSriastradh uint32_t op; 4503b705cfSriastradh 4603b705cfSriastradh struct { 4742542f5fSchristos PixmapPtr pixmap; /* XXX */ 4803b705cfSriastradh CARD32 format; 4903b705cfSriastradh struct kgem_bo *bo; 5003b705cfSriastradh int16_t x, y; 5103b705cfSriastradh uint16_t width, height; 5203b705cfSriastradh } dst; 5303b705cfSriastradh 5403b705cfSriastradh struct sna_composite_channel { 5503b705cfSriastradh struct kgem_bo *bo; 5603b705cfSriastradh PictTransform *transform; 5703b705cfSriastradh uint16_t width; 5803b705cfSriastradh uint16_t height; 5903b705cfSriastradh uint32_t pict_format; 6003b705cfSriastradh uint32_t card_format; 6103b705cfSriastradh uint32_t filter; 6203b705cfSriastradh uint32_t repeat; 6303b705cfSriastradh uint32_t is_affine : 1; 6403b705cfSriastradh uint32_t is_solid : 1; 6503b705cfSriastradh uint32_t is_linear : 1; 6603b705cfSriastradh uint32_t is_opaque : 1; 6703b705cfSriastradh uint32_t alpha_fixup : 1; 6803b705cfSriastradh uint32_t rb_reversed : 1; 6903b705cfSriastradh int16_t offset[2]; 7003b705cfSriastradh float scale[2]; 7103b705cfSriastradh 7203b705cfSriastradh pixman_transform_t embedded_transform; 7303b705cfSriastradh 7403b705cfSriastradh union { 7503b705cfSriastradh struct { 7603b705cfSriastradh float dx, dy, offset; 7703b705cfSriastradh } linear; 7803b705cfSriastradh struct { 7903b705cfSriastradh uint32_t pixel; 8003b705cfSriastradh } gen2; 8103b705cfSriastradh struct gen3_shader_channel { 8203b705cfSriastradh int type; 8303b705cfSriastradh uint32_t mode; 8403b705cfSriastradh uint32_t constants; 8503b705cfSriastradh } gen3; 8603b705cfSriastradh } u; 8703b705cfSriastradh } src, mask; 8803b705cfSriastradh uint32_t is_affine : 1; 8903b705cfSriastradh uint32_t has_component_alpha : 1; 9003b705cfSriastradh uint32_t need_magic_ca_pass : 1; 9103b705cfSriastradh uint32_t rb_reversed : 1; 9203b705cfSriastradh 9303b705cfSriastradh int16_t floats_per_vertex; 9403b705cfSriastradh int16_t floats_per_rect; 9503b705cfSriastradh fastcall void (*prim_emit)(struct sna *sna, 9603b705cfSriastradh const struct sna_composite_op *op, 9703b705cfSriastradh const struct sna_composite_rectangles *r); 9803b705cfSriastradh fastcall void (*emit_boxes)(const struct sna_composite_op *op, 9903b705cfSriastradh const BoxRec *box, int nbox, 10003b705cfSriastradh float *v); 10103b705cfSriastradh 10203b705cfSriastradh struct sna_composite_redirect { 10303b705cfSriastradh struct kgem_bo *real_bo; 10403b705cfSriastradh struct sna_damage **real_damage, *damage; 10503b705cfSriastradh BoxRec box; 10603b705cfSriastradh } redirect; 10703b705cfSriastradh 10803b705cfSriastradh union { 10903b705cfSriastradh struct sna_blt_state { 11003b705cfSriastradh PixmapPtr src_pixmap; 11103b705cfSriastradh int16_t sx, sy; 11203b705cfSriastradh 11303b705cfSriastradh uint32_t inplace :1; 11403b705cfSriastradh uint32_t overwrites:1; 11503b705cfSriastradh uint32_t bpp : 6; 11642542f5fSchristos uint32_t alu : 4; 11703b705cfSriastradh 11803b705cfSriastradh uint32_t cmd; 11903b705cfSriastradh uint32_t br13; 12003b705cfSriastradh uint32_t pitch[2]; 12103b705cfSriastradh uint32_t pixel; 12203b705cfSriastradh struct kgem_bo *bo[2]; 12303b705cfSriastradh } blt; 12403b705cfSriastradh 12503b705cfSriastradh struct { 12603b705cfSriastradh float constants[8]; 12703b705cfSriastradh uint32_t num_constants; 12803b705cfSriastradh } gen3; 12903b705cfSriastradh 13003b705cfSriastradh struct { 13103b705cfSriastradh int wm_kernel; 13203b705cfSriastradh int ve_id; 13303b705cfSriastradh } gen4; 13403b705cfSriastradh 13503b705cfSriastradh struct { 13603b705cfSriastradh int16_t wm_kernel; 13703b705cfSriastradh int16_t ve_id; 13803b705cfSriastradh } gen5; 13903b705cfSriastradh 14003b705cfSriastradh struct { 14103b705cfSriastradh uint32_t flags; 14203b705cfSriastradh } gen6; 14303b705cfSriastradh 14403b705cfSriastradh struct { 14503b705cfSriastradh uint32_t flags; 14603b705cfSriastradh } gen7; 14742542f5fSchristos 14842542f5fSchristos struct { 14942542f5fSchristos uint32_t flags; 15042542f5fSchristos } gen8; 15103b705cfSriastradh } u; 15203b705cfSriastradh 15303b705cfSriastradh void *priv; 15403b705cfSriastradh}; 15503b705cfSriastradh 15603b705cfSriastradhstruct sna_opacity_box { 15703b705cfSriastradh BoxRec box; 15803b705cfSriastradh float alpha; 15903b705cfSriastradh} tightly_packed; 16003b705cfSriastradh 16103b705cfSriastradhstruct sna_composite_spans_op { 16203b705cfSriastradh struct sna_composite_op base; 16303b705cfSriastradh 16403b705cfSriastradh fastcall void (*box)(struct sna *sna, 16503b705cfSriastradh const struct sna_composite_spans_op *op, 16603b705cfSriastradh const BoxRec *box, 16703b705cfSriastradh float opacity); 16803b705cfSriastradh void (*boxes)(struct sna *sna, 16903b705cfSriastradh const struct sna_composite_spans_op *op, 17003b705cfSriastradh const BoxRec *box, int nbox, 17103b705cfSriastradh float opacity); 17203b705cfSriastradh 17303b705cfSriastradh fastcall void (*thread_boxes)(struct sna *sna, 17403b705cfSriastradh const struct sna_composite_spans_op *op, 17503b705cfSriastradh const struct sna_opacity_box *box, 17603b705cfSriastradh int nbox); 17703b705cfSriastradh 17803b705cfSriastradh fastcall void (*done)(struct sna *sna, 17903b705cfSriastradh const struct sna_composite_spans_op *op); 18003b705cfSriastradh 18103b705cfSriastradh fastcall void (*prim_emit)(struct sna *sna, 18203b705cfSriastradh const struct sna_composite_spans_op *op, 18303b705cfSriastradh const BoxRec *box, 18403b705cfSriastradh float opacity); 18503b705cfSriastradh fastcall void (*emit_boxes)(const struct sna_composite_spans_op *op, 18603b705cfSriastradh const struct sna_opacity_box *box, int nbox, 18703b705cfSriastradh float *v); 18803b705cfSriastradh}; 18903b705cfSriastradh 19003b705cfSriastradhstruct sna_fill_op { 19103b705cfSriastradh struct sna_composite_op base; 19203b705cfSriastradh 19303b705cfSriastradh void (*blt)(struct sna *sna, const struct sna_fill_op *op, 19403b705cfSriastradh int16_t x, int16_t y, int16_t w, int16_t h); 19503b705cfSriastradh fastcall void (*box)(struct sna *sna, 19603b705cfSriastradh const struct sna_fill_op *op, 19703b705cfSriastradh const BoxRec *box); 19803b705cfSriastradh fastcall void (*boxes)(struct sna *sna, 19903b705cfSriastradh const struct sna_fill_op *op, 20003b705cfSriastradh const BoxRec *box, 20103b705cfSriastradh int count); 20242542f5fSchristos fastcall void (*points)(struct sna *sna, 20342542f5fSchristos const struct sna_fill_op *op, 20442542f5fSchristos int16_t dx, int16_t dy, 20542542f5fSchristos const DDXPointRec *points, 20642542f5fSchristos int count); 20703b705cfSriastradh void (*done)(struct sna *sna, const struct sna_fill_op *op); 20803b705cfSriastradh}; 20903b705cfSriastradh 21003b705cfSriastradhstruct sna_copy_op { 21103b705cfSriastradh struct sna_composite_op base; 21203b705cfSriastradh 21303b705cfSriastradh void (*blt)(struct sna *sna, const struct sna_copy_op *op, 21403b705cfSriastradh int16_t sx, int16_t sy, 21503b705cfSriastradh int16_t w, int16_t h, 21603b705cfSriastradh int16_t dx, int16_t dy); 21703b705cfSriastradh void (*done)(struct sna *sna, const struct sna_copy_op *op); 21803b705cfSriastradh}; 21903b705cfSriastradh 22003b705cfSriastradhstruct sna_render { 22103b705cfSriastradh pthread_mutex_t lock; 22203b705cfSriastradh pthread_cond_t wait; 22303b705cfSriastradh int active; 22403b705cfSriastradh 22503b705cfSriastradh int max_3d_size; 22603b705cfSriastradh int max_3d_pitch; 22703b705cfSriastradh 22803b705cfSriastradh unsigned prefer_gpu; 22903b705cfSriastradh#define PREFER_GPU_BLT 0x1 23003b705cfSriastradh#define PREFER_GPU_RENDER 0x2 23103b705cfSriastradh#define PREFER_GPU_SPANS 0x4 23203b705cfSriastradh 23303b705cfSriastradh bool (*composite)(struct sna *sna, uint8_t op, 23403b705cfSriastradh PicturePtr dst, PicturePtr src, PicturePtr mask, 23503b705cfSriastradh int16_t src_x, int16_t src_y, 23603b705cfSriastradh int16_t msk_x, int16_t msk_y, 23703b705cfSriastradh int16_t dst_x, int16_t dst_y, 23803b705cfSriastradh int16_t w, int16_t h, 23942542f5fSchristos unsigned flags, 24003b705cfSriastradh struct sna_composite_op *tmp); 24142542f5fSchristos#define COMPOSITE_PARTIAL 0x1 24242542f5fSchristos#define COMPOSITE_FALLBACK 0x80000000 24303b705cfSriastradh 24403b705cfSriastradh bool (*check_composite_spans)(struct sna *sna, uint8_t op, 24503b705cfSriastradh PicturePtr dst, PicturePtr src, 24603b705cfSriastradh int16_t w, int16_t h, unsigned flags); 24703b705cfSriastradh bool (*composite_spans)(struct sna *sna, uint8_t op, 24803b705cfSriastradh PicturePtr dst, PicturePtr src, 24903b705cfSriastradh int16_t src_x, int16_t src_y, 25003b705cfSriastradh int16_t dst_x, int16_t dst_y, 25103b705cfSriastradh int16_t w, int16_t h, 25203b705cfSriastradh unsigned flags, 25303b705cfSriastradh struct sna_composite_spans_op *tmp); 25403b705cfSriastradh#define COMPOSITE_SPANS_RECTILINEAR 0x1 25503b705cfSriastradh#define COMPOSITE_SPANS_INPLACE_HINT 0x2 25603b705cfSriastradh 25703b705cfSriastradh bool (*video)(struct sna *sna, 25803b705cfSriastradh struct sna_video *video, 25903b705cfSriastradh struct sna_video_frame *frame, 26003b705cfSriastradh RegionPtr dstRegion, 26103b705cfSriastradh PixmapPtr pixmap); 26203b705cfSriastradh 26303b705cfSriastradh bool (*fill_boxes)(struct sna *sna, 26403b705cfSriastradh CARD8 op, 26503b705cfSriastradh PictFormat format, 26603b705cfSriastradh const xRenderColor *color, 26742542f5fSchristos const DrawableRec *dst, struct kgem_bo *dst_bo, 26803b705cfSriastradh const BoxRec *box, int n); 26903b705cfSriastradh bool (*fill)(struct sna *sna, uint8_t alu, 27003b705cfSriastradh PixmapPtr dst, struct kgem_bo *dst_bo, 27142542f5fSchristos uint32_t color, unsigned flags, 27203b705cfSriastradh struct sna_fill_op *tmp); 27342542f5fSchristos#define FILL_BOXES 0x1 27442542f5fSchristos#define FILL_POINTS 0x2 27542542f5fSchristos#define FILL_SPANS 0x4 27603b705cfSriastradh bool (*fill_one)(struct sna *sna, PixmapPtr dst, struct kgem_bo *dst_bo, 27703b705cfSriastradh uint32_t color, 27803b705cfSriastradh int16_t x1, int16_t y1, int16_t x2, int16_t y2, 27903b705cfSriastradh uint8_t alu); 28003b705cfSriastradh bool (*clear)(struct sna *sna, PixmapPtr dst, struct kgem_bo *dst_bo); 28103b705cfSriastradh 28203b705cfSriastradh bool (*copy_boxes)(struct sna *sna, uint8_t alu, 28342542f5fSchristos const DrawableRec *src, struct kgem_bo *src_bo, int16_t src_dx, int16_t src_dy, 28442542f5fSchristos const DrawableRec *dst, struct kgem_bo *dst_bo, int16_t dst_dx, int16_t dst_dy, 28503b705cfSriastradh const BoxRec *box, int n, unsigned flags); 28603b705cfSriastradh#define COPY_LAST 0x1 28703b705cfSriastradh#define COPY_SYNC 0x2 28842542f5fSchristos#define COPY_NO_OVERLAP 0x4 28903b705cfSriastradh 29003b705cfSriastradh bool (*copy)(struct sna *sna, uint8_t alu, 29103b705cfSriastradh PixmapPtr src, struct kgem_bo *src_bo, 29203b705cfSriastradh PixmapPtr dst, struct kgem_bo *dst_bo, 29303b705cfSriastradh struct sna_copy_op *op); 29403b705cfSriastradh 29503b705cfSriastradh void (*flush)(struct sna *sna); 29603b705cfSriastradh void (*reset)(struct sna *sna); 29703b705cfSriastradh void (*fini)(struct sna *sna); 29803b705cfSriastradh 29903b705cfSriastradh struct sna_alpha_cache { 30003b705cfSriastradh struct kgem_bo *cache_bo; 30103b705cfSriastradh struct kgem_bo *bo[256+7]; 30203b705cfSriastradh } alpha_cache; 30303b705cfSriastradh 30403b705cfSriastradh struct sna_solid_cache { 30503b705cfSriastradh struct kgem_bo *cache_bo; 30603b705cfSriastradh struct kgem_bo *bo[1024]; 30742542f5fSchristos uint32_t color[1024]; 30803b705cfSriastradh int last; 30903b705cfSriastradh int size; 31003b705cfSriastradh int dirty; 31103b705cfSriastradh } solid_cache; 31203b705cfSriastradh 31303b705cfSriastradh struct { 31403b705cfSriastradh struct sna_gradient_cache { 31503b705cfSriastradh struct kgem_bo *bo; 31603b705cfSriastradh int nstops; 31703b705cfSriastradh PictGradientStop *stops; 31803b705cfSriastradh } cache[GRADIENT_CACHE_SIZE]; 31903b705cfSriastradh int size; 32003b705cfSriastradh } gradient_cache; 32103b705cfSriastradh 32203b705cfSriastradh struct sna_glyph_cache{ 32303b705cfSriastradh PicturePtr picture; 32403b705cfSriastradh struct sna_glyph **glyphs; 32503b705cfSriastradh uint16_t count; 32603b705cfSriastradh uint16_t evict; 32703b705cfSriastradh } glyph[2]; 32803b705cfSriastradh pixman_image_t *white_image; 32903b705cfSriastradh PicturePtr white_picture; 33003b705cfSriastradh 33103b705cfSriastradh uint16_t vb_id; 33203b705cfSriastradh uint16_t vertex_offset; 33303b705cfSriastradh uint16_t vertex_start; 33403b705cfSriastradh uint16_t vertex_index; 33503b705cfSriastradh uint16_t vertex_used; 33603b705cfSriastradh uint16_t vertex_size; 33703b705cfSriastradh uint16_t vertex_reloc[16]; 33803b705cfSriastradh int nvertex_reloc; 33903b705cfSriastradh 34003b705cfSriastradh struct kgem_bo *vbo; 34103b705cfSriastradh float *vertices; 34203b705cfSriastradh 34303b705cfSriastradh float vertex_data[1024]; 34403b705cfSriastradh}; 34503b705cfSriastradh 34603b705cfSriastradhstruct gen2_render_state { 34703b705cfSriastradh uint32_t target; 34803b705cfSriastradh bool need_invariant; 34903b705cfSriastradh uint32_t logic_op_enabled; 35003b705cfSriastradh uint32_t ls1, ls2, vft; 35103b705cfSriastradh uint32_t diffuse; 35203b705cfSriastradh uint32_t specular; 35303b705cfSriastradh}; 35403b705cfSriastradh 35503b705cfSriastradhstruct gen3_render_state { 35603b705cfSriastradh uint32_t current_dst; 35703b705cfSriastradh bool need_invariant; 35803b705cfSriastradh uint32_t tex_count; 35903b705cfSriastradh uint32_t last_drawrect_limit; 36003b705cfSriastradh uint32_t last_target; 36103b705cfSriastradh uint32_t last_blend; 36203b705cfSriastradh uint32_t last_constants; 36303b705cfSriastradh uint32_t last_sampler; 36403b705cfSriastradh uint32_t last_shader; 36503b705cfSriastradh uint32_t last_diffuse; 36603b705cfSriastradh uint32_t last_specular; 36703b705cfSriastradh 36803b705cfSriastradh uint16_t last_vertex_offset; 36903b705cfSriastradh uint16_t floats_per_vertex; 37003b705cfSriastradh uint16_t last_floats_per_vertex; 37103b705cfSriastradh 37203b705cfSriastradh uint32_t tex_map[4]; 37303b705cfSriastradh uint32_t tex_handle[2]; 37403b705cfSriastradh uint32_t tex_delta[2]; 37503b705cfSriastradh}; 37603b705cfSriastradh 37703b705cfSriastradhstruct gen4_render_state { 37803b705cfSriastradh struct kgem_bo *general_bo; 37903b705cfSriastradh 38003b705cfSriastradh uint32_t vs; 38103b705cfSriastradh uint32_t sf; 38203b705cfSriastradh uint32_t wm; 38303b705cfSriastradh uint32_t cc; 38403b705cfSriastradh 38503b705cfSriastradh int ve_id; 38603b705cfSriastradh uint32_t drawrect_offset; 38703b705cfSriastradh uint32_t drawrect_limit; 38803b705cfSriastradh uint32_t last_pipelined_pointers; 38903b705cfSriastradh uint16_t last_primitive; 39003b705cfSriastradh int16_t floats_per_vertex; 39103b705cfSriastradh uint16_t surface_table; 39203b705cfSriastradh 39303b705cfSriastradh bool needs_invariant; 39403b705cfSriastradh bool needs_urb; 39503b705cfSriastradh}; 39603b705cfSriastradh 39703b705cfSriastradhstruct gen5_render_state { 39803b705cfSriastradh struct kgem_bo *general_bo; 39903b705cfSriastradh 40003b705cfSriastradh uint32_t vs; 40103b705cfSriastradh uint32_t sf[2]; 40203b705cfSriastradh uint32_t wm; 40303b705cfSriastradh uint32_t cc; 40403b705cfSriastradh 40503b705cfSriastradh int ve_id; 40603b705cfSriastradh uint32_t drawrect_offset; 40703b705cfSriastradh uint32_t drawrect_limit; 40803b705cfSriastradh uint32_t last_pipelined_pointers; 40903b705cfSriastradh uint16_t last_primitive; 41003b705cfSriastradh int16_t floats_per_vertex; 41103b705cfSriastradh uint16_t surface_table; 41203b705cfSriastradh 41303b705cfSriastradh bool needs_invariant; 41403b705cfSriastradh}; 41503b705cfSriastradh 41603b705cfSriastradhenum { 41703b705cfSriastradh GEN6_WM_KERNEL_NOMASK = 0, 41803b705cfSriastradh GEN6_WM_KERNEL_NOMASK_P, 41903b705cfSriastradh 42003b705cfSriastradh GEN6_WM_KERNEL_MASK, 42103b705cfSriastradh GEN6_WM_KERNEL_MASK_P, 42203b705cfSriastradh 42303b705cfSriastradh GEN6_WM_KERNEL_MASKCA, 42403b705cfSriastradh GEN6_WM_KERNEL_MASKCA_P, 42503b705cfSriastradh 42603b705cfSriastradh GEN6_WM_KERNEL_MASKSA, 42703b705cfSriastradh GEN6_WM_KERNEL_MASKSA_P, 42803b705cfSriastradh 42903b705cfSriastradh GEN6_WM_KERNEL_OPACITY, 43003b705cfSriastradh GEN6_WM_KERNEL_OPACITY_P, 43103b705cfSriastradh 43203b705cfSriastradh GEN6_WM_KERNEL_VIDEO_PLANAR, 43303b705cfSriastradh GEN6_WM_KERNEL_VIDEO_PACKED, 43403b705cfSriastradh GEN6_KERNEL_COUNT 43503b705cfSriastradh}; 43603b705cfSriastradh 43703b705cfSriastradhstruct gen6_render_state { 43842542f5fSchristos unsigned gt; 43903b705cfSriastradh const struct gt_info *info; 44003b705cfSriastradh struct kgem_bo *general_bo; 44103b705cfSriastradh 44203b705cfSriastradh uint32_t vs_state; 44303b705cfSriastradh uint32_t sf_state; 44403b705cfSriastradh uint32_t sf_mask_state; 44503b705cfSriastradh uint32_t wm_state; 44603b705cfSriastradh uint32_t wm_kernel[GEN6_KERNEL_COUNT][3]; 44703b705cfSriastradh 44803b705cfSriastradh uint32_t cc_blend; 44903b705cfSriastradh 45003b705cfSriastradh uint32_t drawrect_offset; 45103b705cfSriastradh uint32_t drawrect_limit; 45203b705cfSriastradh uint32_t blend; 45303b705cfSriastradh uint32_t samplers; 45403b705cfSriastradh uint32_t kernel; 45503b705cfSriastradh 45603b705cfSriastradh uint16_t num_sf_outputs; 45703b705cfSriastradh uint16_t ve_id; 45803b705cfSriastradh uint16_t last_primitive; 45903b705cfSriastradh int16_t floats_per_vertex; 46003b705cfSriastradh uint16_t surface_table; 46103b705cfSriastradh 46203b705cfSriastradh bool needs_invariant; 46303b705cfSriastradh bool first_state_packet; 46403b705cfSriastradh}; 46503b705cfSriastradh 46603b705cfSriastradhenum { 46703b705cfSriastradh GEN7_WM_KERNEL_NOMASK = 0, 46803b705cfSriastradh GEN7_WM_KERNEL_NOMASK_P, 46903b705cfSriastradh 47003b705cfSriastradh GEN7_WM_KERNEL_MASK, 47103b705cfSriastradh GEN7_WM_KERNEL_MASK_P, 47203b705cfSriastradh 47303b705cfSriastradh GEN7_WM_KERNEL_MASKCA, 47403b705cfSriastradh GEN7_WM_KERNEL_MASKCA_P, 47503b705cfSriastradh 47603b705cfSriastradh GEN7_WM_KERNEL_MASKSA, 47703b705cfSriastradh GEN7_WM_KERNEL_MASKSA_P, 47803b705cfSriastradh 47903b705cfSriastradh GEN7_WM_KERNEL_OPACITY, 48003b705cfSriastradh GEN7_WM_KERNEL_OPACITY_P, 48103b705cfSriastradh 48203b705cfSriastradh GEN7_WM_KERNEL_VIDEO_PLANAR, 48303b705cfSriastradh GEN7_WM_KERNEL_VIDEO_PACKED, 48403b705cfSriastradh GEN7_WM_KERNEL_COUNT 48503b705cfSriastradh}; 48603b705cfSriastradh 48703b705cfSriastradhstruct gen7_render_state { 48842542f5fSchristos unsigned gt; 48903b705cfSriastradh const struct gt_info *info; 49003b705cfSriastradh struct kgem_bo *general_bo; 49103b705cfSriastradh 49203b705cfSriastradh uint32_t vs_state; 49303b705cfSriastradh uint32_t sf_state; 49403b705cfSriastradh uint32_t sf_mask_state; 49503b705cfSriastradh uint32_t wm_state; 49603b705cfSriastradh uint32_t wm_kernel[GEN7_WM_KERNEL_COUNT][3]; 49703b705cfSriastradh 49803b705cfSriastradh uint32_t cc_blend; 49903b705cfSriastradh 50003b705cfSriastradh uint32_t drawrect_offset; 50103b705cfSriastradh uint32_t drawrect_limit; 50203b705cfSriastradh uint32_t blend; 50303b705cfSriastradh uint32_t samplers; 50403b705cfSriastradh uint32_t kernel; 50503b705cfSriastradh 50603b705cfSriastradh uint16_t num_sf_outputs; 50703b705cfSriastradh uint16_t ve_id; 50803b705cfSriastradh uint16_t last_primitive; 50903b705cfSriastradh int16_t floats_per_vertex; 51003b705cfSriastradh uint16_t surface_table; 51103b705cfSriastradh 51203b705cfSriastradh bool needs_invariant; 51303b705cfSriastradh bool emit_flush; 51403b705cfSriastradh}; 51503b705cfSriastradh 51642542f5fSchristos 51742542f5fSchristosenum { 51842542f5fSchristos GEN8_WM_KERNEL_NOMASK = 0, 51942542f5fSchristos GEN8_WM_KERNEL_NOMASK_P, 52042542f5fSchristos 52142542f5fSchristos GEN8_WM_KERNEL_MASK, 52242542f5fSchristos GEN8_WM_KERNEL_MASK_P, 52342542f5fSchristos 52442542f5fSchristos GEN8_WM_KERNEL_MASKCA, 52542542f5fSchristos GEN8_WM_KERNEL_MASKCA_P, 52642542f5fSchristos 52742542f5fSchristos GEN8_WM_KERNEL_MASKSA, 52842542f5fSchristos GEN8_WM_KERNEL_MASKSA_P, 52942542f5fSchristos 53042542f5fSchristos GEN8_WM_KERNEL_OPACITY, 53142542f5fSchristos GEN8_WM_KERNEL_OPACITY_P, 53242542f5fSchristos 53342542f5fSchristos GEN8_WM_KERNEL_VIDEO_PLANAR, 53442542f5fSchristos GEN8_WM_KERNEL_VIDEO_PACKED, 53542542f5fSchristos GEN8_WM_KERNEL_COUNT 53642542f5fSchristos}; 53742542f5fSchristos 53842542f5fSchristosstruct gen8_render_state { 53942542f5fSchristos unsigned gt; 54042542f5fSchristos 54142542f5fSchristos struct kgem_bo *general_bo; 54242542f5fSchristos 54342542f5fSchristos uint32_t vs_state; 54442542f5fSchristos uint32_t sf_state; 54542542f5fSchristos uint32_t sf_mask_state; 54642542f5fSchristos uint32_t wm_state; 54742542f5fSchristos uint32_t wm_kernel[GEN8_WM_KERNEL_COUNT][3]; 54842542f5fSchristos 54942542f5fSchristos uint32_t cc_blend; 55042542f5fSchristos 55142542f5fSchristos uint32_t drawrect_offset; 55242542f5fSchristos uint32_t drawrect_limit; 55342542f5fSchristos uint32_t blend; 55442542f5fSchristos uint32_t samplers; 55542542f5fSchristos uint32_t kernel; 55642542f5fSchristos 55742542f5fSchristos uint16_t num_sf_outputs; 55842542f5fSchristos uint16_t ve_id; 55942542f5fSchristos uint16_t last_primitive; 56042542f5fSchristos int16_t floats_per_vertex; 56142542f5fSchristos uint16_t surface_table; 56242542f5fSchristos 56342542f5fSchristos bool needs_invariant; 56442542f5fSchristos bool emit_flush; 56542542f5fSchristos}; 56642542f5fSchristos 56703b705cfSriastradhstruct sna_static_stream { 56803b705cfSriastradh uint32_t size, used; 56903b705cfSriastradh uint8_t *data; 57003b705cfSriastradh}; 57103b705cfSriastradh 57203b705cfSriastradhint sna_static_stream_init(struct sna_static_stream *stream); 57303b705cfSriastradhuint32_t sna_static_stream_add(struct sna_static_stream *stream, 57403b705cfSriastradh const void *data, uint32_t len, uint32_t align); 57503b705cfSriastradhvoid *sna_static_stream_map(struct sna_static_stream *stream, 57603b705cfSriastradh uint32_t len, uint32_t align); 57703b705cfSriastradhuint32_t sna_static_stream_offsetof(struct sna_static_stream *stream, 57803b705cfSriastradh void *ptr); 57903b705cfSriastradhunsigned sna_static_stream_compile_sf(struct sna *sna, 58003b705cfSriastradh struct sna_static_stream *stream, 58103b705cfSriastradh bool (*compile)(struct brw_compile *)); 58203b705cfSriastradh 58303b705cfSriastradhunsigned sna_static_stream_compile_wm(struct sna *sna, 58403b705cfSriastradh struct sna_static_stream *stream, 58503b705cfSriastradh bool (*compile)(struct brw_compile *, int), 58603b705cfSriastradh int width); 58703b705cfSriastradhstruct kgem_bo *sna_static_stream_fini(struct sna *sna, 58803b705cfSriastradh struct sna_static_stream *stream); 58903b705cfSriastradh 59003b705cfSriastradhstruct kgem_bo * 59103b705cfSriastradhsna_render_get_solid(struct sna *sna, 59203b705cfSriastradh uint32_t color); 59303b705cfSriastradh 59403b705cfSriastradhvoid 59503b705cfSriastradhsna_render_flush_solid(struct sna *sna); 59603b705cfSriastradh 59703b705cfSriastradhstruct kgem_bo * 59803b705cfSriastradhsna_render_get_gradient(struct sna *sna, 59903b705cfSriastradh PictGradient *pattern); 60003b705cfSriastradh 60103b705cfSriastradhbool 60203b705cfSriastradhsna_gradient_is_opaque(const PictGradient *gradient); 60303b705cfSriastradh 60403b705cfSriastradhuint32_t sna_rgba_for_color(uint32_t color, int depth); 60503b705cfSriastradhuint32_t sna_rgba_to_color(uint32_t rgba, uint32_t format); 60603b705cfSriastradhbool sna_get_rgba_from_pixel(uint32_t pixel, 60703b705cfSriastradh uint16_t *red, 60803b705cfSriastradh uint16_t *green, 60903b705cfSriastradh uint16_t *blue, 61003b705cfSriastradh uint16_t *alpha, 61103b705cfSriastradh uint32_t format); 61203b705cfSriastradhbool sna_picture_is_solid(PicturePtr picture, uint32_t *color); 61303b705cfSriastradh 61403b705cfSriastradhconst char *no_render_init(struct sna *sna); 61503b705cfSriastradhconst char *gen2_render_init(struct sna *sna, const char *backend); 61603b705cfSriastradhconst char *gen3_render_init(struct sna *sna, const char *backend); 61703b705cfSriastradhconst char *gen4_render_init(struct sna *sna, const char *backend); 61803b705cfSriastradhconst char *gen5_render_init(struct sna *sna, const char *backend); 61903b705cfSriastradhconst char *gen6_render_init(struct sna *sna, const char *backend); 62003b705cfSriastradhconst char *gen7_render_init(struct sna *sna, const char *backend); 62142542f5fSchristosconst char *gen8_render_init(struct sna *sna, const char *backend); 62203b705cfSriastradh 62303b705cfSriastradhbool sna_tiling_composite(uint32_t op, 62403b705cfSriastradh PicturePtr src, 62503b705cfSriastradh PicturePtr mask, 62603b705cfSriastradh PicturePtr dst, 62703b705cfSriastradh int16_t src_x, int16_t src_y, 62803b705cfSriastradh int16_t mask_x, int16_t mask_y, 62903b705cfSriastradh int16_t dst_x, int16_t dst_y, 63003b705cfSriastradh int16_t width, int16_t height, 63103b705cfSriastradh struct sna_composite_op *tmp); 63203b705cfSriastradhbool sna_tiling_composite_spans(uint32_t op, 63303b705cfSriastradh PicturePtr src, 63403b705cfSriastradh PicturePtr dst, 63503b705cfSriastradh int16_t src_x, int16_t src_y, 63603b705cfSriastradh int16_t dst_x, int16_t dst_y, 63703b705cfSriastradh int16_t width, int16_t height, 63803b705cfSriastradh unsigned flags, 63903b705cfSriastradh struct sna_composite_spans_op *tmp); 64003b705cfSriastradhbool sna_tiling_fill_boxes(struct sna *sna, 64103b705cfSriastradh CARD8 op, 64203b705cfSriastradh PictFormat format, 64303b705cfSriastradh const xRenderColor *color, 64442542f5fSchristos const DrawableRec *dst, struct kgem_bo *dst_bo, 64503b705cfSriastradh const BoxRec *box, int n); 64603b705cfSriastradh 64703b705cfSriastradhbool sna_tiling_copy_boxes(struct sna *sna, uint8_t alu, 64842542f5fSchristos const DrawableRec *src, struct kgem_bo *src_bo, int16_t src_dx, int16_t src_dy, 64942542f5fSchristos const DrawableRec *dst, struct kgem_bo *dst_bo, int16_t dst_dx, int16_t dst_dy, 65003b705cfSriastradh const BoxRec *box, int n); 65103b705cfSriastradh 65203b705cfSriastradhbool sna_tiling_blt_copy_boxes(struct sna *sna, uint8_t alu, 65303b705cfSriastradh struct kgem_bo *src_bo, int16_t src_dx, int16_t src_dy, 65403b705cfSriastradh struct kgem_bo *dst_bo, int16_t dst_dx, int16_t dst_dy, 65503b705cfSriastradh int bpp, const BoxRec *box, int nbox); 65603b705cfSriastradh 65742542f5fSchristosbool sna_tiling_blt_composite(struct sna *sna, 65842542f5fSchristos struct sna_composite_op *op, 65942542f5fSchristos struct kgem_bo *bo, 66042542f5fSchristos int bpp, 66142542f5fSchristos uint32_t alpha_fixup); 66242542f5fSchristos 66303b705cfSriastradhbool sna_blt_composite(struct sna *sna, 66403b705cfSriastradh uint32_t op, 66503b705cfSriastradh PicturePtr src, 66603b705cfSriastradh PicturePtr dst, 66703b705cfSriastradh int16_t src_x, int16_t src_y, 66803b705cfSriastradh int16_t dst_x, int16_t dst_y, 66903b705cfSriastradh int16_t width, int16_t height, 67042542f5fSchristos unsigned flags, 67142542f5fSchristos struct sna_composite_op *tmp); 67203b705cfSriastradhbool sna_blt_composite__convert(struct sna *sna, 67303b705cfSriastradh int x, int y, 67403b705cfSriastradh int width, int height, 67503b705cfSriastradh struct sna_composite_op *tmp); 67603b705cfSriastradh 67703b705cfSriastradhbool sna_blt_fill(struct sna *sna, uint8_t alu, 67803b705cfSriastradh struct kgem_bo *bo, 67903b705cfSriastradh int bpp, 68003b705cfSriastradh uint32_t pixel, 68103b705cfSriastradh struct sna_fill_op *fill); 68203b705cfSriastradh 68303b705cfSriastradhbool sna_blt_copy(struct sna *sna, uint8_t alu, 68403b705cfSriastradh struct kgem_bo *src, 68503b705cfSriastradh struct kgem_bo *dst, 68603b705cfSriastradh int bpp, 68703b705cfSriastradh struct sna_copy_op *copy); 68803b705cfSriastradh 68903b705cfSriastradhbool sna_blt_fill_boxes(struct sna *sna, uint8_t alu, 69003b705cfSriastradh struct kgem_bo *bo, 69103b705cfSriastradh int bpp, 69203b705cfSriastradh uint32_t pixel, 69303b705cfSriastradh const BoxRec *box, int n); 69403b705cfSriastradh 69503b705cfSriastradhbool sna_blt_copy_boxes(struct sna *sna, uint8_t alu, 69603b705cfSriastradh struct kgem_bo *src_bo, int16_t src_dx, int16_t src_dy, 69703b705cfSriastradh struct kgem_bo *dst_bo, int16_t dst_dx, int16_t dst_dy, 69803b705cfSriastradh int bpp, 69903b705cfSriastradh const BoxRec *box, int n); 70042542f5fSchristosbool sna_blt_copy_boxes__with_alpha(struct sna *sna, uint8_t alu, 70142542f5fSchristos struct kgem_bo *src_bo, int16_t src_dx, int16_t src_dy, 70242542f5fSchristos struct kgem_bo *dst_bo, int16_t dst_dx, int16_t dst_dy, 70342542f5fSchristos int bpp, int alpha_fixup, 70442542f5fSchristos const BoxRec *box, int nbox); 70503b705cfSriastradhbool sna_blt_copy_boxes_fallback(struct sna *sna, uint8_t alu, 70642542f5fSchristos const DrawableRec *src, struct kgem_bo *src_bo, int16_t src_dx, int16_t src_dy, 70742542f5fSchristos const DrawableRec *dst, struct kgem_bo *dst_bo, int16_t dst_dx, int16_t dst_dy, 70803b705cfSriastradh const BoxRec *box, int nbox); 70903b705cfSriastradh 71003b705cfSriastradhbool _sna_get_pixel_from_rgba(uint32_t *pixel, 71103b705cfSriastradh uint16_t red, 71203b705cfSriastradh uint16_t green, 71303b705cfSriastradh uint16_t blue, 71403b705cfSriastradh uint16_t alpha, 71503b705cfSriastradh uint32_t format); 71603b705cfSriastradh 71703b705cfSriastradhstatic inline bool 71803b705cfSriastradhsna_get_pixel_from_rgba(uint32_t * pixel, 71903b705cfSriastradh uint16_t red, 72003b705cfSriastradh uint16_t green, 72103b705cfSriastradh uint16_t blue, 72203b705cfSriastradh uint16_t alpha, 72303b705cfSriastradh uint32_t format) 72403b705cfSriastradh{ 72503b705cfSriastradh switch (format) { 72603b705cfSriastradh case PICT_x8r8g8b8: 72703b705cfSriastradh alpha = 0xffff; 72803b705cfSriastradh /* fall through to re-use a8r8g8b8 expansion */ 72903b705cfSriastradh case PICT_a8r8g8b8: 73003b705cfSriastradh *pixel = ((alpha >> 8 << 24) | 73103b705cfSriastradh (red >> 8 << 16) | 73203b705cfSriastradh (green & 0xff00) | 73303b705cfSriastradh (blue >> 8)); 73403b705cfSriastradh return TRUE; 73503b705cfSriastradh case PICT_a8: 73603b705cfSriastradh *pixel = alpha >> 8; 73703b705cfSriastradh return TRUE; 73803b705cfSriastradh } 73903b705cfSriastradh 74003b705cfSriastradh return _sna_get_pixel_from_rgba(pixel, red, green, blue, alpha, format); 74103b705cfSriastradh} 74203b705cfSriastradh 74303b705cfSriastradhstruct kgem_bo * 74403b705cfSriastradh__sna_render_pixmap_bo(struct sna *sna, 74503b705cfSriastradh PixmapPtr pixmap, 74603b705cfSriastradh const BoxRec *box, 74703b705cfSriastradh bool blt); 74803b705cfSriastradh 74903b705cfSriastradhint 75003b705cfSriastradhsna_render_pixmap_bo(struct sna *sna, 75103b705cfSriastradh struct sna_composite_channel *channel, 75203b705cfSriastradh PixmapPtr pixmap, 75303b705cfSriastradh int16_t x, int16_t y, 75403b705cfSriastradh int16_t w, int16_t h, 75503b705cfSriastradh int16_t dst_x, int16_t dst_y); 75603b705cfSriastradh 75703b705cfSriastradhbool 75803b705cfSriastradhsna_render_pixmap_partial(struct sna *sna, 75942542f5fSchristos const DrawableRec *draw, 76003b705cfSriastradh struct kgem_bo *bo, 76103b705cfSriastradh struct sna_composite_channel *channel, 76203b705cfSriastradh int16_t x, int16_t y, 76303b705cfSriastradh int16_t w, int16_t h); 76403b705cfSriastradh 76503b705cfSriastradhint 76603b705cfSriastradhsna_render_picture_extract(struct sna *sna, 76703b705cfSriastradh PicturePtr picture, 76803b705cfSriastradh struct sna_composite_channel *channel, 76903b705cfSriastradh int16_t x, int16_t y, 77003b705cfSriastradh int16_t w, int16_t h, 77103b705cfSriastradh int16_t dst_x, int16_t dst_y); 77203b705cfSriastradh 77303b705cfSriastradhint 77403b705cfSriastradhsna_render_picture_approximate_gradient(struct sna *sna, 77503b705cfSriastradh PicturePtr picture, 77603b705cfSriastradh struct sna_composite_channel *channel, 77703b705cfSriastradh int16_t x, int16_t y, 77803b705cfSriastradh int16_t w, int16_t h, 77903b705cfSriastradh int16_t dst_x, int16_t dst_y); 78003b705cfSriastradh 78103b705cfSriastradhint 78203b705cfSriastradhsna_render_picture_fixup(struct sna *sna, 78303b705cfSriastradh PicturePtr picture, 78403b705cfSriastradh struct sna_composite_channel *channel, 78503b705cfSriastradh int16_t x, int16_t y, 78603b705cfSriastradh int16_t w, int16_t h, 78703b705cfSriastradh int16_t dst_x, int16_t dst_y); 78803b705cfSriastradh 78903b705cfSriastradhint 79003b705cfSriastradhsna_render_picture_convert(struct sna *sna, 79103b705cfSriastradh PicturePtr picture, 79203b705cfSriastradh struct sna_composite_channel *channel, 79303b705cfSriastradh PixmapPtr pixmap, 79403b705cfSriastradh int16_t x, int16_t y, 79503b705cfSriastradh int16_t w, int16_t h, 79603b705cfSriastradh int16_t dst_x, int16_t dst_y, 79703b705cfSriastradh bool fixup_alpha); 79803b705cfSriastradh 79903b705cfSriastradhinline static void sna_render_composite_redirect_init(struct sna_composite_op *op) 80003b705cfSriastradh{ 80103b705cfSriastradh struct sna_composite_redirect *t = &op->redirect; 80203b705cfSriastradh t->real_bo = NULL; 80303b705cfSriastradh t->damage = NULL; 80403b705cfSriastradh} 80503b705cfSriastradh 80603b705cfSriastradhbool 80703b705cfSriastradhsna_render_composite_redirect(struct sna *sna, 80803b705cfSriastradh struct sna_composite_op *op, 80903b705cfSriastradh int x, int y, int width, int height, 81003b705cfSriastradh bool partial); 81103b705cfSriastradh 81203b705cfSriastradhvoid 81303b705cfSriastradhsna_render_composite_redirect_done(struct sna *sna, 81403b705cfSriastradh const struct sna_composite_op *op); 81503b705cfSriastradh 81603b705cfSriastradhbool 81703b705cfSriastradhsna_render_copy_boxes__overlap(struct sna *sna, uint8_t alu, 81842542f5fSchristos const DrawableRec *draw, struct kgem_bo *bo, 81942542f5fSchristos int16_t src_dx, int16_t src_dy, 82042542f5fSchristos int16_t dst_dx, int16_t dst_dy, 82103b705cfSriastradh const BoxRec *box, int n, const BoxRec *extents); 82203b705cfSriastradh 82303b705cfSriastradhbool 82403b705cfSriastradhsna_composite_mask_is_opaque(PicturePtr mask); 82503b705cfSriastradh 82603b705cfSriastradhvoid sna_vertex_init(struct sna *sna); 82703b705cfSriastradh 82803b705cfSriastradhstatic inline void sna_vertex_lock(struct sna_render *r) 82903b705cfSriastradh{ 83003b705cfSriastradh pthread_mutex_lock(&r->lock); 83103b705cfSriastradh} 83203b705cfSriastradh 83303b705cfSriastradhstatic inline void sna_vertex_acquire__locked(struct sna_render *r) 83403b705cfSriastradh{ 83503b705cfSriastradh r->active++; 83603b705cfSriastradh} 83703b705cfSriastradh 83803b705cfSriastradhstatic inline void sna_vertex_unlock(struct sna_render *r) 83903b705cfSriastradh{ 84003b705cfSriastradh pthread_mutex_unlock(&r->lock); 84103b705cfSriastradh} 84203b705cfSriastradh 84303b705cfSriastradhstatic inline void sna_vertex_release__locked(struct sna_render *r) 84403b705cfSriastradh{ 84503b705cfSriastradh assert(r->active > 0); 84603b705cfSriastradh if (--r->active == 0) 84703b705cfSriastradh pthread_cond_signal(&r->wait); 84803b705cfSriastradh} 84903b705cfSriastradh 85003b705cfSriastradhstatic inline bool sna_vertex_wait__locked(struct sna_render *r) 85103b705cfSriastradh{ 85203b705cfSriastradh bool was_active = r->active; 85303b705cfSriastradh while (r->active) 85403b705cfSriastradh pthread_cond_wait(&r->wait, &r->lock); 85503b705cfSriastradh return was_active; 85603b705cfSriastradh} 85703b705cfSriastradh 85803b705cfSriastradh#define alphaless(format) PICT_FORMAT(PICT_FORMAT_BPP(format), \ 85903b705cfSriastradh PICT_FORMAT_TYPE(format), \ 86003b705cfSriastradh 0, \ 86103b705cfSriastradh PICT_FORMAT_R(format), \ 86203b705cfSriastradh PICT_FORMAT_G(format), \ 86303b705cfSriastradh PICT_FORMAT_B(format)) 86403b705cfSriastradh 86503b705cfSriastradh#endif /* SNA_RENDER_H */ 866