Path: blob/21.2-virgl/src/intel/blorp/blorp_priv.h
7237 views
/*1* Copyright © 2012 Intel Corporation2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20* IN THE SOFTWARE.21*/2223#ifndef BLORP_PRIV_H24#define BLORP_PRIV_H2526#include <stdint.h>2728#include "common/intel_measure.h"29#include "compiler/nir/nir.h"30#include "compiler/brw_compiler.h"3132#include "blorp.h"3334#ifdef __cplusplus35extern "C" {36#endif3738/**39* Binding table indices used by BLORP.40*/41enum {42BLORP_RENDERBUFFER_BT_INDEX,43BLORP_TEXTURE_BT_INDEX,44BLORP_NUM_BT_ENTRIES45};4647struct brw_blorp_surface_info48{49bool enabled;5051struct isl_surf surf;52struct blorp_address addr;5354struct isl_surf aux_surf;55struct blorp_address aux_addr;56enum isl_aux_usage aux_usage;5758union isl_color_value clear_color;59struct blorp_address clear_color_addr;6061struct isl_view view;6263/* Z offset into a 3-D texture or slice of a 2-D array texture. */64float z_offset;6566uint32_t tile_x_sa, tile_y_sa;67};6869void70brw_blorp_surface_info_init(struct blorp_context *blorp,71struct brw_blorp_surface_info *info,72const struct blorp_surf *surf,73unsigned int level, float layer,74enum isl_format format, bool is_render_target);75void76blorp_surf_convert_to_single_slice(const struct isl_device *isl_dev,77struct brw_blorp_surface_info *info);78void79surf_fake_rgb_with_red(const struct isl_device *isl_dev,80struct brw_blorp_surface_info *info);81void82blorp_surf_convert_to_uncompressed(const struct isl_device *isl_dev,83struct brw_blorp_surface_info *info,84uint32_t *x, uint32_t *y,85uint32_t *width, uint32_t *height);86void87blorp_surf_fake_interleaved_msaa(const struct isl_device *isl_dev,88struct brw_blorp_surface_info *info);89void90blorp_surf_retile_w_to_y(const struct isl_device *isl_dev,91struct brw_blorp_surface_info *info);929394struct brw_blorp_coord_transform95{96float multiplier;97float offset;98};99100/**101* Bounding rectangle telling pixel discard which pixels are not to be102* touched. This is needed in when surfaces are configured as something else103* what they really are:104*105* - writing W-tiled stencil as Y-tiled106* - writing interleaved multisampled as single sampled.107*108* See blorp_nir_discard_if_outside_rect().109*/110struct brw_blorp_discard_rect111{112uint32_t x0;113uint32_t x1;114uint32_t y0;115uint32_t y1;116};117118/**119* Grid needed for blended and scaled blits of integer formats, see120* blorp_nir_manual_blend_bilinear().121*/122struct brw_blorp_rect_grid123{124float x1;125float y1;126float pad[2];127};128129struct blorp_surf_offset {130uint32_t x;131uint32_t y;132};133134struct brw_blorp_wm_inputs135{136uint32_t clear_color[4];137138struct brw_blorp_discard_rect discard_rect;139struct brw_blorp_rect_grid rect_grid;140struct brw_blorp_coord_transform coord_transform[2];141142struct blorp_surf_offset src_offset;143struct blorp_surf_offset dst_offset;144145/* (1/width, 1/height) for the source surface */146float src_inv_size[2];147148/* Minimum layer setting works for all the textures types but texture_3d149* for which the setting has no effect. Use the z-coordinate instead.150*/151float src_z;152153/* Pad out to an integral number of registers */154uint32_t pad[1];155};156157#define BLORP_CREATE_NIR_INPUT(shader, name, type) ({ \158nir_variable *input = nir_variable_create((shader), nir_var_shader_in, \159type, #name); \160if ((shader)->info.stage == MESA_SHADER_FRAGMENT) \161input->data.interpolation = INTERP_MODE_FLAT; \162input->data.location = VARYING_SLOT_VAR0 + \163offsetof(struct brw_blorp_wm_inputs, name) / (4 * sizeof(float)); \164input->data.location_frac = \165(offsetof(struct brw_blorp_wm_inputs, name) / sizeof(float)) % 4; \166input; \167})168169struct blorp_vs_inputs {170uint32_t base_layer;171uint32_t _instance_id; /* Set in hardware by SGVS */172uint32_t pad[2];173};174175static inline unsigned176brw_blorp_get_urb_length(const struct brw_wm_prog_data *prog_data)177{178if (prog_data == NULL)179return 1;180181/* From the BSpec: 3D Pipeline - Strips and Fans - 3DSTATE_SBE182*183* read_length = ceiling((max_source_attr+1)/2)184*/185return MAX2((prog_data->num_varying_inputs + 1) / 2, 1);186}187188struct blorp_params189{190uint32_t x0;191uint32_t y0;192uint32_t x1;193uint32_t y1;194float z;195uint8_t stencil_mask;196uint8_t stencil_ref;197struct brw_blorp_surface_info depth;198struct brw_blorp_surface_info stencil;199uint32_t depth_format;200struct brw_blorp_surface_info src;201struct brw_blorp_surface_info dst;202enum isl_aux_op hiz_op;203bool full_surface_hiz_op;204enum isl_aux_op fast_clear_op;205bool color_write_disable[4];206struct brw_blorp_wm_inputs wm_inputs;207struct blorp_vs_inputs vs_inputs;208bool dst_clear_color_as_input;209unsigned num_samples;210unsigned num_draw_buffers;211unsigned num_layers;212uint32_t vs_prog_kernel;213struct brw_vs_prog_data *vs_prog_data;214uint32_t sf_prog_kernel;215struct brw_sf_prog_data *sf_prog_data;216uint32_t wm_prog_kernel;217struct brw_wm_prog_data *wm_prog_data;218219bool use_pre_baked_binding_table;220uint32_t pre_baked_binding_table_offset;221enum intel_measure_snapshot_type snapshot_type;222};223224void blorp_params_init(struct blorp_params *params);225226enum blorp_shader_type {227BLORP_SHADER_TYPE_COPY,228BLORP_SHADER_TYPE_BLIT,229BLORP_SHADER_TYPE_CLEAR,230BLORP_SHADER_TYPE_MCS_PARTIAL_RESOLVE,231BLORP_SHADER_TYPE_LAYER_OFFSET_VS,232BLORP_SHADER_TYPE_GFX4_SF,233};234235struct brw_blorp_base_key236{237char name[8];238enum blorp_shader_type shader_type;239};240241#define BRW_BLORP_BASE_KEY_INIT(_type) \242(struct brw_blorp_base_key) { \243.name = "blorp", \244.shader_type = _type, \245}246247struct brw_blorp_blit_prog_key248{249struct brw_blorp_base_key base;250251/* Number of samples per pixel that have been configured in the surface252* state for texturing from.253*/254unsigned tex_samples;255256/* MSAA layout that has been configured in the surface state for texturing257* from.258*/259enum isl_msaa_layout tex_layout;260261enum isl_aux_usage tex_aux_usage;262263/* Actual number of samples per pixel in the source image. */264unsigned src_samples;265266/* Actual MSAA layout used by the source image. */267enum isl_msaa_layout src_layout;268269/* The swizzle to apply to the source in the shader */270struct isl_swizzle src_swizzle;271272/* The format of the source if format-specific workarounds are needed273* and 0 (ISL_FORMAT_R32G32B32A32_FLOAT) if the destination is natively274* renderable.275*/276enum isl_format src_format;277278/* True if the source requires normalized coordinates */279bool src_coords_normalized;280281/* Number of samples per pixel that have been configured in the render282* target.283*/284unsigned rt_samples;285286/* MSAA layout that has been configured in the render target. */287enum isl_msaa_layout rt_layout;288289/* Actual number of samples per pixel in the destination image. */290unsigned dst_samples;291292/* Actual MSAA layout used by the destination image. */293enum isl_msaa_layout dst_layout;294295/* The swizzle to apply to the destination in the shader */296struct isl_swizzle dst_swizzle;297298/* The format of the destination if format-specific workarounds are needed299* and 0 (ISL_FORMAT_R32G32B32A32_FLOAT) if the destination is natively300* renderable.301*/302enum isl_format dst_format;303304/* Whether or not the format workarounds are a bitcast operation */305bool format_bit_cast;306307/** True if we need to perform SINT -> UINT clamping. */308bool sint32_to_uint;309310/** True if we need to perform UINT -> SINT clamping. */311bool uint32_to_sint;312313/* Type of the data to be read from the texture (one of314* nir_type_(int|uint|float)).315*/316nir_alu_type texture_data_type;317318/* True if the source image is W tiled. If true, the surface state for the319* source image must be configured as Y tiled, and tex_samples must be 0.320*/321bool src_tiled_w;322323/* True if the destination image is W tiled. If true, the surface state324* for the render target must be configured as Y tiled, and rt_samples must325* be 0.326*/327bool dst_tiled_w;328329/* True if the destination is an RGB format. If true, the surface state330* for the render target must be configured as red with three times the331* normal width. We need to do this because you cannot render to332* non-power-of-two formats.333*/334bool dst_rgb;335336isl_surf_usage_flags_t dst_usage;337338enum blorp_filter filter;339340/* True if the rectangle being sent through the rendering pipeline might be341* larger than the destination rectangle, so the WM program should kill any342* pixels that are outside the destination rectangle.343*/344bool use_kill;345346/**347* True if the WM program should be run in MSDISPMODE_PERSAMPLE with more348* than one sample per pixel.349*/350bool persample_msaa_dispatch;351352/* True if this blit operation may involve intratile offsets on the source.353* In this case, we need to add the offset before texturing.354*/355bool need_src_offset;356357/* True if this blit operation may involve intratile offsets on the358* destination. In this case, we need to add the offset to gl_FragCoord.359*/360bool need_dst_offset;361362/* Scale factors between the pixel grid and the grid of samples. We're363* using grid of samples for bilinear filetring in multisample scaled blits.364*/365float x_scale;366float y_scale;367};368369/**370* \name BLORP internals371* \{372*373* Used internally by gfx6_blorp_exec() and gfx7_blorp_exec().374*/375376void brw_blorp_init_wm_prog_key(struct brw_wm_prog_key *wm_key);377378const char *blorp_shader_type_to_name(enum blorp_shader_type type);379380const unsigned *381blorp_compile_fs(struct blorp_context *blorp, void *mem_ctx,382struct nir_shader *nir,383struct brw_wm_prog_key *wm_key,384bool use_repclear,385struct brw_wm_prog_data *wm_prog_data);386387const unsigned *388blorp_compile_vs(struct blorp_context *blorp, void *mem_ctx,389struct nir_shader *nir,390struct brw_vs_prog_data *vs_prog_data);391392bool393blorp_ensure_sf_program(struct blorp_batch *batch,394struct blorp_params *params);395396/** \} */397398#ifdef __cplusplus399} /* end extern "C" */400#endif /* __cplusplus */401402#endif /* BLORP_PRIV_H */403404405