X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fgallium%2Fdrivers%2Fvc4%2Fvc4_context.h;h=654c46f3c0df6fea40135bb4736003c3b3b1bbe9;hb=38c6c0f5b499e2bcff2cc9607f67c0f1836f305b;hp=0c906488756cca0001bad5930f65269d0a94028a;hpb=e59890aebbad990a02c2c27531525804de47115d;p=mesa.git diff --git a/src/gallium/drivers/vc4/vc4_context.h b/src/gallium/drivers/vc4/vc4_context.h index 0c906488756..654c46f3c0d 100644 --- a/src/gallium/drivers/vc4/vc4_context.h +++ b/src/gallium/drivers/vc4/vc4_context.h @@ -25,13 +25,24 @@ #ifndef VC4_CONTEXT_H #define VC4_CONTEXT_H +#include + #include "pipe/p_context.h" #include "pipe/p_state.h" #include "util/u_slab.h" +#define __user +#include "vc4_drm.h" #include "vc4_bufmgr.h" #include "vc4_resource.h" #include "vc4_cl.h" +#include "vc4_qir.h" + +#ifdef USE_VC4_SIMULATOR +#define using_vc4_simulator true +#else +#define using_vc4_simulator false +#endif #define VC4_DIRTY_BLEND (1 << 0) #define VC4_DIRTY_RASTERIZER (1 << 1) @@ -39,7 +50,7 @@ #define VC4_DIRTY_FRAGTEX (1 << 3) #define VC4_DIRTY_VERTTEX (1 << 4) #define VC4_DIRTY_TEXSTATE (1 << 5) -#define VC4_DIRTY_PROG (1 << 6) + #define VC4_DIRTY_BLEND_COLOR (1 << 7) #define VC4_DIRTY_STENCIL_REF (1 << 8) #define VC4_DIRTY_SAMPLE_MASK (1 << 9) @@ -51,9 +62,25 @@ #define VC4_DIRTY_VTXBUF (1 << 15) #define VC4_DIRTY_INDEXBUF (1 << 16) #define VC4_DIRTY_SCISSOR (1 << 17) +#define VC4_DIRTY_FLAT_SHADE_FLAGS (1 << 18) +#define VC4_DIRTY_PRIM_MODE (1 << 19) +#define VC4_DIRTY_CLIP (1 << 20) +#define VC4_DIRTY_UNCOMPILED_VS (1 << 21) +#define VC4_DIRTY_UNCOMPILED_FS (1 << 22) +#define VC4_DIRTY_COMPILED_CS (1 << 23) +#define VC4_DIRTY_COMPILED_VS (1 << 24) +#define VC4_DIRTY_COMPILED_FS (1 << 25) -#define VC4_SHADER_DIRTY_VP (1 << 0) -#define VC4_SHADER_DIRTY_FP (1 << 1) +struct vc4_sampler_view { + struct pipe_sampler_view base; + uint32_t texture_p0; + uint32_t texture_p1; +}; + +struct vc4_sampler_state { + struct pipe_sampler_state base; + uint32_t texture_p1; +}; struct vc4_texture_stateobj { struct pipe_sampler_view *textures[PIPE_MAX_SAMPLERS]; @@ -63,16 +90,80 @@ struct vc4_texture_stateobj { unsigned dirty_samplers; }; -struct vc4_shader_state { +struct vc4_shader_uniform_info { + enum quniform_contents *contents; + uint32_t *data; + uint32_t count; + uint32_t num_texture_samples; +}; + +struct vc4_uncompiled_shader { + /** A name for this program, so you can track it in shader-db output. */ + uint32_t program_id; + /** How many variants of this program were compiled, for shader-db. */ + uint32_t compiled_variant_count; struct pipe_shader_state base; + const struct tgsi_token *twoside_tokens; +}; + +struct vc4_ubo_range { + /** + * offset in bytes from the start of the ubo where this range is + * uploaded. + * + * Only set once used is set. + */ + uint32_t dst_offset; + + /** + * offset in bytes from the start of the gallium uniforms where the + * data comes from. + */ + uint32_t src_offset; + + /** size in bytes of this ubo range */ + uint32_t size; +}; + +struct vc4_compiled_shader { + uint64_t program_id; struct vc4_bo *bo; - uint32_t coord_shader_offset; + struct vc4_shader_uniform_info uniforms; + + struct vc4_ubo_range *ubo_ranges; + uint32_t num_ubo_ranges; + uint32_t ubo_size; + /** + * VC4_DIRTY_* flags that, when set in vc4->dirty, mean that the + * uniforms have to be rewritten (and therefore the shader state + * reemitted). + */ + uint32_t uniform_dirty_bits; + + /** bitmask of which inputs are color inputs, for flat shade handling. */ + uint32_t color_inputs; + + uint8_t num_inputs; + + /* Byte offsets for the start of the vertex attributes 0-7, and the + * total size as "attribute" 8. + */ + uint8_t vattr_offsets[9]; + uint8_t vattrs_live; + + /** + * Array of the meanings of the VPM inputs this shader needs. + * + * It doesn't include those that aren't part of the VPM, like + * point/line coordinates. + */ + struct vc4_varying_semantic *input_semantics; }; struct vc4_program_stateobj { - struct vc4_shader_state *vs, *fs; - uint32_t dirty; + struct vc4_uncompiled_shader *bind_vs, *bind_fs; + struct vc4_compiled_shader *cs, *vs, *fs; uint8_t num_exports; /* Indexed by semantic name or TGSI_SEMANTIC_COUNT + semantic index * for TGSI_SEMANTIC_GENERIC. Special vs exports (position and point- @@ -106,16 +197,52 @@ struct vc4_context { struct vc4_screen *screen; struct vc4_cl bcl; - struct vc4_cl rcl; struct vc4_cl shader_rec; + struct vc4_cl uniforms; struct vc4_cl bo_handles; + struct vc4_cl bo_pointers; uint32_t shader_rec_count; + /** @{ Surfaces to submit rendering for. */ + struct pipe_surface *color_read; + struct pipe_surface *color_write; + struct pipe_surface *zs_read; + struct pipe_surface *zs_write; + /** @} */ + /** @{ + * Bounding box of the scissor across all queued drawing. + * + * Note that the max values are exclusive. + */ + uint32_t draw_min_x; + uint32_t draw_min_y; + uint32_t draw_max_x; + uint32_t draw_max_y; + /** @} */ + /** @{ + * Width/height of the color framebuffer being rendered to, + * for VC4_TILE_RENDERING_MODE_CONFIG. + */ + uint32_t draw_width; + uint32_t draw_height; + /** @} */ + struct util_slab_mempool transfer_pool; struct blitter_context *blitter; /** bitfield of VC4_DIRTY_* */ uint32_t dirty; + /* Bitmask of PIPE_CLEAR_* of buffers that were cleared before the + * first rendering. + */ + uint32_t cleared; + /* Bitmask of PIPE_CLEAR_* of buffers that have been rendered to + * (either clears or draws). + */ + uint32_t resolve; + uint32_t clear_color[2]; + uint32_t clear_depth; /**< 24-bit unorm depth */ + uint8_t clear_stencil; /** * Set if some drawing (triangles, blits, or just a glClear()) has @@ -124,11 +251,40 @@ struct vc4_context { */ bool needs_flush; + /** + * Set when needs_flush, and the queued rendering is not just composed + * of full-buffer clears. + */ + bool draw_call_queued; + + /** Maximum index buffer valid for the current shader_rec. */ + uint32_t max_index; + /** Last index bias baked into the current shader_rec. */ + uint32_t last_index_bias; + + struct primconvert_context *primconvert; + + struct hash_table *fs_cache, *vs_cache; + uint32_t next_uncompiled_program_id; + uint64_t next_compiled_program_id; + + struct ra_regs *regs; + unsigned int reg_class_any; + unsigned int reg_class_r4_or_a; + unsigned int reg_class_a; + + uint8_t prim_mode; + + /** Seqno of the last CL flush's job. */ + uint64_t last_emit_seqno; + + struct u_upload_mgr *uploader; + /** @{ Current pipeline state objects */ struct pipe_scissor_state scissor; struct pipe_blend_state *blend; struct vc4_rasterizer_state *rasterizer; - struct pipe_depth_stencil_alpha_state *zsa; + struct vc4_depth_stencil_alpha_state *zsa; struct vc4_texture_stateobj verttex, fragtex; @@ -141,6 +297,7 @@ struct vc4_context { unsigned sample_mask; struct pipe_framebuffer_state framebuffer; struct pipe_poly_stipple stipple; + struct pipe_clip_state clip; struct pipe_viewport_state viewport; struct vc4_constbuf_stateobj constbuf[PIPE_SHADER_TYPES]; struct vc4_vertexbuf_stateobj vertexbuf; @@ -155,25 +312,89 @@ struct vc4_rasterizer_state { uint8_t config_bits[3]; float point_size; + + /** + * Half-float (1/8/7 bits) value of polygon offset units for + * VC4_PACKET_DEPTH_OFFSET + */ + uint16_t offset_units; + /** + * Half-float (1/8/7 bits) value of polygon offset scale for + * VC4_PACKET_DEPTH_OFFSET + */ + uint16_t offset_factor; +}; + +struct vc4_depth_stencil_alpha_state { + struct pipe_depth_stencil_alpha_state base; + + /* VC4_CONFIGURATION_BITS */ + uint8_t config_bits[3]; + + /** Uniforms for stencil state. + * + * Index 0 is either the front config, or the front-and-back config. + * Index 1 is the back config if doing separate back stencil. + * Index 2 is the writemask config if it's not a common mask value. + */ + uint32_t stencil_uniforms[3]; }; +#define perf_debug(...) do { \ + if (unlikely(vc4_debug & VC4_DEBUG_PERF)) \ + fprintf(stderr, __VA_ARGS__); \ +} while (0) + static inline struct vc4_context * vc4_context(struct pipe_context *pcontext) { return (struct vc4_context *)pcontext; } +static inline struct vc4_sampler_view * +vc4_sampler_view(struct pipe_sampler_view *psview) +{ + return (struct vc4_sampler_view *)psview; +} + +static inline struct vc4_sampler_state * +vc4_sampler_state(struct pipe_sampler_state *psampler) +{ + return (struct vc4_sampler_state *)psampler; +} + struct pipe_context *vc4_context_create(struct pipe_screen *pscreen, void *priv); void vc4_draw_init(struct pipe_context *pctx); void vc4_state_init(struct pipe_context *pctx); void vc4_program_init(struct pipe_context *pctx); +void vc4_program_fini(struct pipe_context *pctx); +void vc4_query_init(struct pipe_context *pctx); void vc4_simulator_init(struct vc4_screen *screen); -void vc4_simulator_flush(struct vc4_context *vc4, - struct vc4_surface *color_surf); -void *vc4_simulator_alloc(struct vc4_screen *screen, uint32_t size); +int vc4_simulator_flush(struct vc4_context *vc4, + struct drm_vc4_submit_cl *args); + +void vc4_set_shader_uniform_dirty_flags(struct vc4_compiled_shader *shader); +void vc4_write_uniforms(struct vc4_context *vc4, + struct vc4_compiled_shader *shader, + struct vc4_constbuf_stateobj *cb, + struct vc4_texture_stateobj *texstate); void vc4_flush(struct pipe_context *pctx); +void vc4_job_init(struct vc4_context *vc4); +void vc4_job_submit(struct vc4_context *vc4); +void vc4_job_reset(struct vc4_context *vc4); +bool vc4_cl_references_bo(struct pipe_context *pctx, struct vc4_bo *bo); void vc4_emit_state(struct pipe_context *pctx); +void vc4_generate_code(struct vc4_context *vc4, struct vc4_compile *c); +struct qpu_reg *vc4_register_allocate(struct vc4_context *vc4, struct vc4_compile *c); +void vc4_update_compiled_shaders(struct vc4_context *vc4, uint8_t prim_mode); +bool vc4_rt_format_supported(enum pipe_format f); +bool vc4_rt_format_is_565(enum pipe_format f); +bool vc4_tex_format_supported(enum pipe_format f); +uint8_t vc4_get_tex_format(enum pipe_format f); +const uint8_t *vc4_get_format_swizzle(enum pipe_format f); +void vc4_init_query_functions(struct vc4_context *vc4); +void vc4_blit(struct pipe_context *pctx, const struct pipe_blit_info *blit_info); #endif /* VC4_CONTEXT_H */