101e04c3fSmrg/*
201e04c3fSmrg * Copyright (c) 2012-2015 Etnaviv Project
301e04c3fSmrg *
401e04c3fSmrg * Permission is hereby granted, free of charge, to any person obtaining a
501e04c3fSmrg * copy of this software and associated documentation files (the "Software"),
601e04c3fSmrg * to deal in the Software without restriction, including without limitation
701e04c3fSmrg * the rights to use, copy, modify, merge, publish, distribute, sub license,
801e04c3fSmrg * and/or sell copies of the Software, and to permit persons to whom the
901e04c3fSmrg * Software is furnished to do so, subject to the following conditions:
1001e04c3fSmrg *
1101e04c3fSmrg * The above copyright notice and this permission notice (including the
1201e04c3fSmrg * next paragraph) shall be included in all copies or substantial portions
1301e04c3fSmrg * of the Software.
1401e04c3fSmrg *
1501e04c3fSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1601e04c3fSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1701e04c3fSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
1801e04c3fSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1901e04c3fSmrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
2001e04c3fSmrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2101e04c3fSmrg * DEALINGS IN THE SOFTWARE.
2201e04c3fSmrg */
2301e04c3fSmrg
2401e04c3fSmrg#ifndef H_ETNA_INTERNAL
2501e04c3fSmrg#define H_ETNA_INTERNAL
2601e04c3fSmrg
2701e04c3fSmrg#include <assert.h>
2801e04c3fSmrg#include <stdbool.h>
2901e04c3fSmrg#include <stdint.h>
3001e04c3fSmrg
3101e04c3fSmrg#include "hw/state.xml.h"
3201e04c3fSmrg#include "hw/state_3d.xml.h"
3301e04c3fSmrg
347ec681f3Smrg#include "drm/etnaviv_drmif.h"
3501e04c3fSmrg
3601e04c3fSmrg#define ETNA_NUM_INPUTS (16)
377ec681f3Smrg#define ETNA_NUM_VARYINGS 16
3801e04c3fSmrg#define ETNA_NUM_LOD (14)
3901e04c3fSmrg#define ETNA_NUM_LAYERS (6)
4001e04c3fSmrg#define ETNA_MAX_UNIFORMS (256)
417ec681f3Smrg#define ETNA_MAX_CONST_BUF 16
4201e04c3fSmrg#define ETNA_MAX_PIXELPIPES 2
4301e04c3fSmrg
4401e04c3fSmrg/* All RS operations must have width%16 = 0 */
4501e04c3fSmrg#define ETNA_RS_WIDTH_MASK (16 - 1)
4601e04c3fSmrg/* RS tiled operations must have height%4 = 0 */
4701e04c3fSmrg#define ETNA_RS_HEIGHT_MASK (3)
4801e04c3fSmrg/* PE render targets must be aligned to 64 bytes */
4901e04c3fSmrg#define ETNA_PE_ALIGNMENT (64)
5001e04c3fSmrg
5101e04c3fSmrg/* These demarcate the margin (fixp16) between the computed sizes and the
5201e04c3fSmrg  value sent to the chip. These have been set to the numbers used by the
5301e04c3fSmrg  Vivante driver on gc2000. They used to be -1 for scissor right and bottom. I
5401e04c3fSmrg  am not sure whether older hardware was relying on these or they were just a
5501e04c3fSmrg  guess. But if so, these need to be moved to the _specs structure.
5601e04c3fSmrg*/
5701e04c3fSmrg#define ETNA_SE_SCISSOR_MARGIN_RIGHT (0x1119)
5801e04c3fSmrg#define ETNA_SE_SCISSOR_MARGIN_BOTTOM (0x1111)
5901e04c3fSmrg#define ETNA_SE_CLIP_MARGIN_RIGHT (0xffff)
6001e04c3fSmrg#define ETNA_SE_CLIP_MARGIN_BOTTOM (0xffff)
6101e04c3fSmrg
6201e04c3fSmrg/* GPU chip 3D specs */
6301e04c3fSmrgstruct etna_specs {
6401e04c3fSmrg   /* HALTI (gross architecture) level. -1 for pre-HALTI. */
6501e04c3fSmrg   int halti : 8;
6601e04c3fSmrg   /* supports SUPERTILE (64x64) tiling? */
6701e04c3fSmrg   unsigned can_supertile : 1;
6801e04c3fSmrg   /* needs z=(z+w)/2, for older GCxxx */
6901e04c3fSmrg   unsigned vs_need_z_div : 1;
7001e04c3fSmrg   /* supports trigonometric instructions */
7101e04c3fSmrg   unsigned has_sin_cos_sqrt : 1;
7201e04c3fSmrg   /* has SIGN/FLOOR/CEIL instructions */
7301e04c3fSmrg   unsigned has_sign_floor_ceil : 1;
7401e04c3fSmrg   /* can use VS_RANGE, PS_RANGE registers*/
7501e04c3fSmrg   unsigned has_shader_range_registers : 1;
7601e04c3fSmrg   /* has the new sin/cos/log functions */
7701e04c3fSmrg   unsigned has_new_transcendentals : 1;
7801e04c3fSmrg   /* has the new dp2/dpX_norm instructions, among others */
7901e04c3fSmrg   unsigned has_halti2_instructions : 1;
807ec681f3Smrg   /* has V4_COMPRESSION */
817ec681f3Smrg   unsigned v4_compression : 1;
8201e04c3fSmrg   /* supports single-buffer rendering with multiple pixel pipes */
8301e04c3fSmrg   unsigned single_buffer : 1;
8401e04c3fSmrg   /* has unified uniforms memory */
8501e04c3fSmrg   unsigned has_unified_uniforms : 1;
8601e04c3fSmrg   /* can load shader instructions from memory */
8701e04c3fSmrg   unsigned has_icache : 1;
8801e04c3fSmrg   /* ASTC texture support (and has associated states) */
8901e04c3fSmrg   unsigned tex_astc : 1;
9001e04c3fSmrg   /* has BLT engine instead of RS */
9101e04c3fSmrg   unsigned use_blt : 1;
9201e04c3fSmrg   /* can use any kind of wrapping mode on npot textures */
9301e04c3fSmrg   unsigned npot_tex_any_wrap : 1;
947ec681f3Smrg   /* supports seamless cube map */
957ec681f3Smrg   unsigned seamless_cube_map : 1;
9601e04c3fSmrg   /* number of bits per TS tile */
9701e04c3fSmrg   unsigned bits_per_tile;
9801e04c3fSmrg   /* clear value for TS (dependent on bits_per_tile) */
9901e04c3fSmrg   uint32_t ts_clear_value;
10001e04c3fSmrg   /* base of vertex texture units */
10101e04c3fSmrg   unsigned vertex_sampler_offset;
10201e04c3fSmrg   /* number of fragment sampler units */
10301e04c3fSmrg   unsigned fragment_sampler_count;
10401e04c3fSmrg   /* number of vertex sampler units */
10501e04c3fSmrg   unsigned vertex_sampler_count;
10601e04c3fSmrg   /* size of vertex shader output buffer */
10701e04c3fSmrg   unsigned vertex_output_buffer_size;
10801e04c3fSmrg   /* maximum number of vertex element configurations */
10901e04c3fSmrg   unsigned vertex_max_elements;
11001e04c3fSmrg   /* size of a cached vertex (?) */
11101e04c3fSmrg   unsigned vertex_cache_size;
11201e04c3fSmrg   /* number of shader cores */
11301e04c3fSmrg   unsigned shader_core_count;
11401e04c3fSmrg   /* number of vertex streams */
11501e04c3fSmrg   unsigned stream_count;
11601e04c3fSmrg   /* vertex shader memory address*/
11701e04c3fSmrg   uint32_t vs_offset;
11801e04c3fSmrg   /* pixel shader memory address*/
11901e04c3fSmrg   uint32_t ps_offset;
12001e04c3fSmrg   /* vertex shader uniforms address*/
12101e04c3fSmrg   uint32_t vs_uniforms_offset;
12201e04c3fSmrg   /* pixel shader uniforms address*/
12301e04c3fSmrg   uint32_t ps_uniforms_offset;
12401e04c3fSmrg   /* vertex/fragment shader max instructions */
12501e04c3fSmrg   uint32_t max_instructions;
12601e04c3fSmrg   /* maximum number of varyings */
12701e04c3fSmrg   unsigned max_varyings;
12801e04c3fSmrg   /* maximum number of registers */
12901e04c3fSmrg   unsigned max_registers;
13001e04c3fSmrg   /* maximum vertex uniforms */
13101e04c3fSmrg   unsigned max_vs_uniforms;
13201e04c3fSmrg   /* maximum pixel uniforms */
13301e04c3fSmrg   unsigned max_ps_uniforms;
13401e04c3fSmrg   /* maximum texture size */
13501e04c3fSmrg   unsigned max_texture_size;
13601e04c3fSmrg   /* maximum texture size */
13701e04c3fSmrg   unsigned max_rendertarget_size;
13801e04c3fSmrg   /* available pixel pipes */
13901e04c3fSmrg   unsigned pixel_pipes;
14001e04c3fSmrg   /* number of constants */
14101e04c3fSmrg   unsigned num_constants;
14201e04c3fSmrg};
14301e04c3fSmrg
14401e04c3fSmrg/* Compiled Gallium state. All the different compiled state atoms are woven
14501e04c3fSmrg * together and uploaded only when it is necessary to synchronize the state,
14601e04c3fSmrg * for example before rendering. */
14701e04c3fSmrg
14801e04c3fSmrg/* Compiled pipe_blend_color */
14901e04c3fSmrgstruct compiled_blend_color {
15001e04c3fSmrg   float color[4];
15101e04c3fSmrg   uint32_t PE_ALPHA_BLEND_COLOR;
1527ec681f3Smrg   uint32_t PE_ALPHA_COLOR_EXT0;
1537ec681f3Smrg   uint32_t PE_ALPHA_COLOR_EXT1;
15401e04c3fSmrg};
15501e04c3fSmrg
15601e04c3fSmrg/* Compiled pipe_stencil_ref */
15701e04c3fSmrgstruct compiled_stencil_ref {
1587ec681f3Smrg   uint32_t PE_STENCIL_CONFIG[2];
1597ec681f3Smrg   uint32_t PE_STENCIL_CONFIG_EXT[2];
16001e04c3fSmrg};
16101e04c3fSmrg
16201e04c3fSmrg/* Compiled pipe_viewport_state */
16301e04c3fSmrgstruct compiled_viewport_state {
16401e04c3fSmrg   uint32_t PA_VIEWPORT_SCALE_X;
16501e04c3fSmrg   uint32_t PA_VIEWPORT_SCALE_Y;
16601e04c3fSmrg   uint32_t PA_VIEWPORT_SCALE_Z;
16701e04c3fSmrg   uint32_t PA_VIEWPORT_OFFSET_X;
16801e04c3fSmrg   uint32_t PA_VIEWPORT_OFFSET_Y;
16901e04c3fSmrg   uint32_t PA_VIEWPORT_OFFSET_Z;
17001e04c3fSmrg   uint32_t SE_SCISSOR_LEFT;
17101e04c3fSmrg   uint32_t SE_SCISSOR_TOP;
17201e04c3fSmrg   uint32_t SE_SCISSOR_RIGHT;
17301e04c3fSmrg   uint32_t SE_SCISSOR_BOTTOM;
17401e04c3fSmrg   uint32_t PE_DEPTH_NEAR;
17501e04c3fSmrg   uint32_t PE_DEPTH_FAR;
17601e04c3fSmrg};
17701e04c3fSmrg
17801e04c3fSmrg/* Compiled pipe_framebuffer_state */
17901e04c3fSmrgstruct compiled_framebuffer_state {
18001e04c3fSmrg   uint32_t GL_MULTI_SAMPLE_CONFIG;
18101e04c3fSmrg   uint32_t PE_COLOR_FORMAT;
18201e04c3fSmrg   uint32_t PE_DEPTH_CONFIG;
18301e04c3fSmrg   struct etna_reloc PE_DEPTH_ADDR;
18401e04c3fSmrg   struct etna_reloc PE_PIPE_DEPTH_ADDR[ETNA_MAX_PIXELPIPES];
18501e04c3fSmrg   uint32_t PE_DEPTH_STRIDE;
18601e04c3fSmrg   uint32_t PE_HDEPTH_CONTROL;
18701e04c3fSmrg   uint32_t PE_DEPTH_NORMALIZE;
18801e04c3fSmrg   struct etna_reloc PE_COLOR_ADDR;
18901e04c3fSmrg   struct etna_reloc PE_PIPE_COLOR_ADDR[ETNA_MAX_PIXELPIPES];
19001e04c3fSmrg   uint32_t PE_COLOR_STRIDE;
1917ec681f3Smrg   uint32_t PE_MEM_CONFIG;
19201e04c3fSmrg   uint32_t RA_MULTISAMPLE_UNK00E04;
19301e04c3fSmrg   uint32_t RA_MULTISAMPLE_UNK00E10[VIVS_RA_MULTISAMPLE_UNK00E10__LEN];
19401e04c3fSmrg   uint32_t RA_CENTROID_TABLE[VIVS_RA_CENTROID_TABLE__LEN];
19501e04c3fSmrg   uint32_t TS_MEM_CONFIG;
19601e04c3fSmrg   uint32_t TS_DEPTH_CLEAR_VALUE;
19701e04c3fSmrg   struct etna_reloc TS_DEPTH_STATUS_BASE;
19801e04c3fSmrg   struct etna_reloc TS_DEPTH_SURFACE_BASE;
19901e04c3fSmrg   uint32_t TS_COLOR_CLEAR_VALUE;
2007ec681f3Smrg   uint32_t TS_COLOR_CLEAR_VALUE_EXT;
20101e04c3fSmrg   struct etna_reloc TS_COLOR_STATUS_BASE;
20201e04c3fSmrg   struct etna_reloc TS_COLOR_SURFACE_BASE;
20301e04c3fSmrg   uint32_t PE_LOGIC_OP;
2047ec681f3Smrg   uint32_t PS_CONTROL;
2057ec681f3Smrg   uint32_t PS_CONTROL_EXT;
20601e04c3fSmrg   bool msaa_mode; /* adds input (and possible temp) to PS */
20701e04c3fSmrg};
20801e04c3fSmrg
20901e04c3fSmrg/* Compiled context->create_vertex_elements_state */
21001e04c3fSmrgstruct compiled_vertex_elements_state {
21101e04c3fSmrg   unsigned num_elements;
21201e04c3fSmrg   uint32_t FE_VERTEX_ELEMENT_CONFIG[VIVS_FE_VERTEX_ELEMENT_CONFIG__LEN];
21301e04c3fSmrg   uint32_t NFE_GENERIC_ATTRIB_CONFIG0[VIVS_NFE_GENERIC_ATTRIB__LEN];
21401e04c3fSmrg   uint32_t NFE_GENERIC_ATTRIB_SCALE[VIVS_NFE_GENERIC_ATTRIB__LEN];
21501e04c3fSmrg   uint32_t NFE_GENERIC_ATTRIB_CONFIG1[VIVS_NFE_GENERIC_ATTRIB__LEN];
2167ec681f3Smrg   unsigned num_buffers;
2177ec681f3Smrg   uint32_t NFE_VERTEX_STREAMS_VERTEX_DIVISOR[VIVS_NFE_VERTEX_STREAMS__LEN];
21801e04c3fSmrg};
21901e04c3fSmrg
22001e04c3fSmrg/* Compiled context->set_vertex_buffer result */
22101e04c3fSmrgstruct compiled_set_vertex_buffer {
22201e04c3fSmrg   uint32_t FE_VERTEX_STREAM_CONTROL;
22301e04c3fSmrg   struct etna_reloc FE_VERTEX_STREAM_BASE_ADDR;
22401e04c3fSmrg};
22501e04c3fSmrg
22601e04c3fSmrg/* Compiled linked VS+PS shader state */
22701e04c3fSmrgstruct compiled_shader_state {
22801e04c3fSmrg   uint32_t RA_CONTROL;
22901e04c3fSmrg   uint32_t PA_ATTRIBUTE_ELEMENT_COUNT;
23001e04c3fSmrg   uint32_t PA_CONFIG;
23101e04c3fSmrg   uint32_t PA_SHADER_ATTRIBUTES[VIVS_PA_SHADER_ATTRIBUTES__LEN];
23201e04c3fSmrg   uint32_t VS_END_PC;
23301e04c3fSmrg   uint32_t VS_OUTPUT_COUNT; /* number of outputs if point size per vertex disabled */
23401e04c3fSmrg   uint32_t VS_OUTPUT_COUNT_PSIZE; /* number of outputs of point size per vertex enabled */
23501e04c3fSmrg   uint32_t VS_INPUT_COUNT;
23601e04c3fSmrg   uint32_t VS_TEMP_REGISTER_CONTROL;
23701e04c3fSmrg   uint32_t VS_OUTPUT[4];
23801e04c3fSmrg   uint32_t VS_INPUT[4];
23901e04c3fSmrg   uint32_t VS_LOAD_BALANCING;
24001e04c3fSmrg   uint32_t VS_START_PC;
24101e04c3fSmrg   uint32_t PS_END_PC;
24201e04c3fSmrg   uint32_t PS_OUTPUT_REG;
24301e04c3fSmrg   uint32_t PS_INPUT_COUNT;
24401e04c3fSmrg   uint32_t PS_INPUT_COUNT_MSAA; /* Adds an input */
24501e04c3fSmrg   uint32_t PS_TEMP_REGISTER_CONTROL;
24601e04c3fSmrg   uint32_t PS_TEMP_REGISTER_CONTROL_MSAA; /* Adds a temporary if needed to make space for extra input */
24701e04c3fSmrg   uint32_t PS_START_PC;
24801e04c3fSmrg   uint32_t GL_VARYING_TOTAL_COMPONENTS;
2497ec681f3Smrg   uint32_t GL_VARYING_NUM_COMPONENTS[2];
25001e04c3fSmrg   uint32_t GL_VARYING_COMPONENT_USE[2];
25101e04c3fSmrg   uint32_t GL_HALTI5_SH_SPECIALS;
2527ec681f3Smrg   uint32_t FE_HALTI5_ID_CONFIG;
25301e04c3fSmrg   unsigned vs_inst_mem_size;
25401e04c3fSmrg   unsigned ps_inst_mem_size;
25501e04c3fSmrg   uint32_t *VS_INST_MEM;
25601e04c3fSmrg   uint32_t *PS_INST_MEM;
25701e04c3fSmrg   struct etna_reloc PS_INST_ADDR;
25801e04c3fSmrg   struct etna_reloc VS_INST_ADDR;
2597ec681f3Smrg   unsigned writes_z:1;
2607ec681f3Smrg   unsigned uses_discard:1;
26101e04c3fSmrg};
26201e04c3fSmrg
26301e04c3fSmrg/* Helpers to assist creating and setting bitarrays (eg, for varyings).
26401e04c3fSmrg * field_size must be a power of two, and <= 32. */
26501e04c3fSmrg#define DEFINE_ETNA_BITARRAY(name, num, field_size) \
26601e04c3fSmrg   uint32_t name[(num) * (field_size) / 32]
26701e04c3fSmrg
26801e04c3fSmrgstatic inline void
26901e04c3fSmrgetna_bitarray_set(uint32_t *array, size_t array_size, size_t field_size,
27001e04c3fSmrg                  size_t index, uint32_t value)
27101e04c3fSmrg{
27201e04c3fSmrg   size_t shift = (index * field_size) % 32;
27301e04c3fSmrg   size_t offset = (index * field_size) / 32;
27401e04c3fSmrg
27501e04c3fSmrg   assert(index < array_size * 32 / field_size);
27601e04c3fSmrg   assert(value < 1 << field_size);
27701e04c3fSmrg
27801e04c3fSmrg   array[offset] |= value << shift;
27901e04c3fSmrg}
28001e04c3fSmrg
28101e04c3fSmrg#define etna_bitarray_set(array, field_size, index, value) \
28201e04c3fSmrg   etna_bitarray_set((array), ARRAY_SIZE(array), field_size, index, value)
28301e04c3fSmrg
28401e04c3fSmrg#endif
285