1bf215546Sopenharmony_ci/**************************************************************************
2bf215546Sopenharmony_ci *
3bf215546Sopenharmony_ci * Copyright 2009 VMware, Inc.
4bf215546Sopenharmony_ci * All Rights Reserved.
5bf215546Sopenharmony_ci *
6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the
8bf215546Sopenharmony_ci * "Software"), to deal in the Software without restriction, including
9bf215546Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish,
10bf215546Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to
11bf215546Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to
12bf215546Sopenharmony_ci * the following conditions:
13bf215546Sopenharmony_ci *
14bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the
15bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions
16bf215546Sopenharmony_ci * of the Software.
17bf215546Sopenharmony_ci *
18bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20bf215546Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21bf215546Sopenharmony_ci * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22bf215546Sopenharmony_ci * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23bf215546Sopenharmony_ci * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24bf215546Sopenharmony_ci * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25bf215546Sopenharmony_ci *
26bf215546Sopenharmony_ci **************************************************************************/
27bf215546Sopenharmony_ci
28bf215546Sopenharmony_ci/**
29bf215546Sopenharmony_ci * @file
30bf215546Sopenharmony_ci * C - JIT interfaces
31bf215546Sopenharmony_ci *
32bf215546Sopenharmony_ci * @author Jose Fonseca <jfonseca@vmware.com>
33bf215546Sopenharmony_ci */
34bf215546Sopenharmony_ci
35bf215546Sopenharmony_ci#ifndef LP_JIT_H
36bf215546Sopenharmony_ci#define LP_JIT_H
37bf215546Sopenharmony_ci
38bf215546Sopenharmony_ci
39bf215546Sopenharmony_ci#include "gallivm/lp_bld_struct.h"
40bf215546Sopenharmony_ci#include "gallivm/lp_bld_limits.h"
41bf215546Sopenharmony_ci
42bf215546Sopenharmony_ci#include "pipe/p_state.h"
43bf215546Sopenharmony_ci#include "lp_texture.h"
44bf215546Sopenharmony_ci
45bf215546Sopenharmony_ci
46bf215546Sopenharmony_cistruct lp_build_format_cache;
47bf215546Sopenharmony_cistruct lp_fragment_shader_variant;
48bf215546Sopenharmony_cistruct lp_compute_shader_variant;
49bf215546Sopenharmony_cistruct lp_rast_state;
50bf215546Sopenharmony_cistruct llvmpipe_screen;
51bf215546Sopenharmony_ci
52bf215546Sopenharmony_ci
53bf215546Sopenharmony_cistruct lp_jit_texture
54bf215546Sopenharmony_ci{
55bf215546Sopenharmony_ci   uint32_t width;        /* same as number of elements */
56bf215546Sopenharmony_ci   uint32_t height;
57bf215546Sopenharmony_ci   uint32_t depth;        /* doubles as array size */
58bf215546Sopenharmony_ci   const void *base;
59bf215546Sopenharmony_ci   uint32_t row_stride[LP_MAX_TEXTURE_LEVELS];
60bf215546Sopenharmony_ci   uint32_t img_stride[LP_MAX_TEXTURE_LEVELS];
61bf215546Sopenharmony_ci   uint32_t first_level;
62bf215546Sopenharmony_ci   uint32_t last_level;
63bf215546Sopenharmony_ci   uint32_t mip_offsets[LP_MAX_TEXTURE_LEVELS];
64bf215546Sopenharmony_ci   uint32_t num_samples;
65bf215546Sopenharmony_ci   uint32_t sample_stride;
66bf215546Sopenharmony_ci};
67bf215546Sopenharmony_ci
68bf215546Sopenharmony_ci
69bf215546Sopenharmony_cistruct lp_jit_sampler
70bf215546Sopenharmony_ci{
71bf215546Sopenharmony_ci   float min_lod;
72bf215546Sopenharmony_ci   float max_lod;
73bf215546Sopenharmony_ci   float lod_bias;
74bf215546Sopenharmony_ci   float border_color[4];
75bf215546Sopenharmony_ci   float max_aniso;
76bf215546Sopenharmony_ci};
77bf215546Sopenharmony_ci
78bf215546Sopenharmony_ci
79bf215546Sopenharmony_cistruct lp_jit_viewport
80bf215546Sopenharmony_ci{
81bf215546Sopenharmony_ci   float min_depth;
82bf215546Sopenharmony_ci   float max_depth;
83bf215546Sopenharmony_ci};
84bf215546Sopenharmony_ci
85bf215546Sopenharmony_ci
86bf215546Sopenharmony_cistruct lp_jit_image
87bf215546Sopenharmony_ci{
88bf215546Sopenharmony_ci   uint32_t width;        /* same as number of elements */
89bf215546Sopenharmony_ci   uint32_t height;
90bf215546Sopenharmony_ci   uint32_t depth;
91bf215546Sopenharmony_ci   const void *base;
92bf215546Sopenharmony_ci   uint32_t row_stride;
93bf215546Sopenharmony_ci   uint32_t img_stride;
94bf215546Sopenharmony_ci   uint32_t num_samples;
95bf215546Sopenharmony_ci   uint32_t sample_stride;
96bf215546Sopenharmony_ci};
97bf215546Sopenharmony_ci
98bf215546Sopenharmony_cienum {
99bf215546Sopenharmony_ci   LP_JIT_TEXTURE_WIDTH = 0,
100bf215546Sopenharmony_ci   LP_JIT_TEXTURE_HEIGHT,
101bf215546Sopenharmony_ci   LP_JIT_TEXTURE_DEPTH,
102bf215546Sopenharmony_ci   LP_JIT_TEXTURE_BASE,
103bf215546Sopenharmony_ci   LP_JIT_TEXTURE_ROW_STRIDE,
104bf215546Sopenharmony_ci   LP_JIT_TEXTURE_IMG_STRIDE,
105bf215546Sopenharmony_ci   LP_JIT_TEXTURE_FIRST_LEVEL,
106bf215546Sopenharmony_ci   LP_JIT_TEXTURE_LAST_LEVEL,
107bf215546Sopenharmony_ci   LP_JIT_TEXTURE_MIP_OFFSETS,
108bf215546Sopenharmony_ci   LP_JIT_TEXTURE_NUM_SAMPLES,
109bf215546Sopenharmony_ci   LP_JIT_TEXTURE_SAMPLE_STRIDE,
110bf215546Sopenharmony_ci   LP_JIT_TEXTURE_NUM_FIELDS  /* number of fields above */
111bf215546Sopenharmony_ci};
112bf215546Sopenharmony_ci
113bf215546Sopenharmony_ci
114bf215546Sopenharmony_cienum {
115bf215546Sopenharmony_ci   LP_JIT_SAMPLER_MIN_LOD,
116bf215546Sopenharmony_ci   LP_JIT_SAMPLER_MAX_LOD,
117bf215546Sopenharmony_ci   LP_JIT_SAMPLER_LOD_BIAS,
118bf215546Sopenharmony_ci   LP_JIT_SAMPLER_BORDER_COLOR,
119bf215546Sopenharmony_ci   LP_JIT_SAMPLER_MAX_ANISO,
120bf215546Sopenharmony_ci   LP_JIT_SAMPLER_NUM_FIELDS  /* number of fields above */
121bf215546Sopenharmony_ci};
122bf215546Sopenharmony_ci
123bf215546Sopenharmony_ci
124bf215546Sopenharmony_cienum {
125bf215546Sopenharmony_ci   LP_JIT_VIEWPORT_MIN_DEPTH,
126bf215546Sopenharmony_ci   LP_JIT_VIEWPORT_MAX_DEPTH,
127bf215546Sopenharmony_ci   LP_JIT_VIEWPORT_NUM_FIELDS /* number of fields above */
128bf215546Sopenharmony_ci};
129bf215546Sopenharmony_ci
130bf215546Sopenharmony_cienum {
131bf215546Sopenharmony_ci   LP_JIT_IMAGE_WIDTH = 0,
132bf215546Sopenharmony_ci   LP_JIT_IMAGE_HEIGHT,
133bf215546Sopenharmony_ci   LP_JIT_IMAGE_DEPTH,
134bf215546Sopenharmony_ci   LP_JIT_IMAGE_BASE,
135bf215546Sopenharmony_ci   LP_JIT_IMAGE_ROW_STRIDE,
136bf215546Sopenharmony_ci   LP_JIT_IMAGE_IMG_STRIDE,
137bf215546Sopenharmony_ci   LP_JIT_IMAGE_NUM_SAMPLES,
138bf215546Sopenharmony_ci   LP_JIT_IMAGE_SAMPLE_STRIDE,
139bf215546Sopenharmony_ci   LP_JIT_IMAGE_NUM_FIELDS  /* number of fields above */
140bf215546Sopenharmony_ci};
141bf215546Sopenharmony_ci
142bf215546Sopenharmony_ci
143bf215546Sopenharmony_ci/**
144bf215546Sopenharmony_ci * This structure is passed directly to the generated fragment shader.
145bf215546Sopenharmony_ci *
146bf215546Sopenharmony_ci * It contains the derived state.
147bf215546Sopenharmony_ci *
148bf215546Sopenharmony_ci * Changes here must be reflected in the lp_jit_context_* macros and
149bf215546Sopenharmony_ci * lp_jit_init_types function. Changes to the ordering should be avoided.
150bf215546Sopenharmony_ci *
151bf215546Sopenharmony_ci * Only use types with a clear size and padding here, in particular prefer the
152bf215546Sopenharmony_ci * stdint.h types to the basic integer types.
153bf215546Sopenharmony_ci */
154bf215546Sopenharmony_cistruct lp_jit_context
155bf215546Sopenharmony_ci{
156bf215546Sopenharmony_ci   const float *constants[LP_MAX_TGSI_CONST_BUFFERS];
157bf215546Sopenharmony_ci   int num_constants[LP_MAX_TGSI_CONST_BUFFERS];
158bf215546Sopenharmony_ci
159bf215546Sopenharmony_ci   struct lp_jit_texture textures[PIPE_MAX_SHADER_SAMPLER_VIEWS];
160bf215546Sopenharmony_ci   struct lp_jit_sampler samplers[PIPE_MAX_SAMPLERS];
161bf215546Sopenharmony_ci   struct lp_jit_image images[PIPE_MAX_SHADER_IMAGES];
162bf215546Sopenharmony_ci
163bf215546Sopenharmony_ci   float alpha_ref_value;
164bf215546Sopenharmony_ci
165bf215546Sopenharmony_ci   uint32_t stencil_ref_front, stencil_ref_back;
166bf215546Sopenharmony_ci
167bf215546Sopenharmony_ci   uint8_t *u8_blend_color;
168bf215546Sopenharmony_ci   float *f_blend_color;
169bf215546Sopenharmony_ci
170bf215546Sopenharmony_ci   struct lp_jit_viewport *viewports;
171bf215546Sopenharmony_ci
172bf215546Sopenharmony_ci   const uint32_t *ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
173bf215546Sopenharmony_ci   int num_ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
174bf215546Sopenharmony_ci
175bf215546Sopenharmony_ci   uint32_t sample_mask;
176bf215546Sopenharmony_ci
177bf215546Sopenharmony_ci   const float *aniso_filter_table;
178bf215546Sopenharmony_ci};
179bf215546Sopenharmony_ci
180bf215546Sopenharmony_ci
181bf215546Sopenharmony_ci/**
182bf215546Sopenharmony_ci * These enum values must match the position of the fields in the
183bf215546Sopenharmony_ci * lp_jit_context struct above.
184bf215546Sopenharmony_ci */
185bf215546Sopenharmony_cienum {
186bf215546Sopenharmony_ci   LP_JIT_CTX_CONSTANTS = 0,
187bf215546Sopenharmony_ci   LP_JIT_CTX_NUM_CONSTANTS,
188bf215546Sopenharmony_ci   LP_JIT_CTX_TEXTURES,
189bf215546Sopenharmony_ci   LP_JIT_CTX_SAMPLERS,
190bf215546Sopenharmony_ci   LP_JIT_CTX_IMAGES,
191bf215546Sopenharmony_ci   LP_JIT_CTX_ALPHA_REF,
192bf215546Sopenharmony_ci   LP_JIT_CTX_STENCIL_REF_FRONT,
193bf215546Sopenharmony_ci   LP_JIT_CTX_STENCIL_REF_BACK,
194bf215546Sopenharmony_ci   LP_JIT_CTX_U8_BLEND_COLOR,
195bf215546Sopenharmony_ci   LP_JIT_CTX_F_BLEND_COLOR,
196bf215546Sopenharmony_ci   LP_JIT_CTX_VIEWPORTS,
197bf215546Sopenharmony_ci   LP_JIT_CTX_SSBOS,
198bf215546Sopenharmony_ci   LP_JIT_CTX_NUM_SSBOS,
199bf215546Sopenharmony_ci   LP_JIT_CTX_SAMPLE_MASK,
200bf215546Sopenharmony_ci   LP_JIT_CTX_ANISO_FILTER_TABLE,
201bf215546Sopenharmony_ci   LP_JIT_CTX_COUNT
202bf215546Sopenharmony_ci};
203bf215546Sopenharmony_ci
204bf215546Sopenharmony_ci
205bf215546Sopenharmony_ci#define lp_jit_context_constants(_gallivm, _ptr) \
206bf215546Sopenharmony_ci   lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_CONSTANTS, "constants")
207bf215546Sopenharmony_ci
208bf215546Sopenharmony_ci#define lp_jit_context_num_constants(_gallivm, _ptr) \
209bf215546Sopenharmony_ci   lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_NUM_CONSTANTS, "num_constants")
210bf215546Sopenharmony_ci
211bf215546Sopenharmony_ci#define lp_jit_context_textures(_gallivm, _ptr) \
212bf215546Sopenharmony_ci   lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_TEXTURES, "textures")
213bf215546Sopenharmony_ci
214bf215546Sopenharmony_ci#define lp_jit_context_samplers(_gallivm, _ptr) \
215bf215546Sopenharmony_ci   lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_SAMPLERS, "samplers")
216bf215546Sopenharmony_ci
217bf215546Sopenharmony_ci#define lp_jit_context_images(_gallivm, _ptr) \
218bf215546Sopenharmony_ci   lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_IMAGES, "images")
219bf215546Sopenharmony_ci
220bf215546Sopenharmony_ci#define lp_jit_context_alpha_ref_value(_gallivm, _ptr) \
221bf215546Sopenharmony_ci   lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_ALPHA_REF, "alpha_ref_value")
222bf215546Sopenharmony_ci
223bf215546Sopenharmony_ci#define lp_jit_context_stencil_ref_front_value(_gallivm, _ptr) \
224bf215546Sopenharmony_ci   lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_STENCIL_REF_FRONT, "stencil_ref_front")
225bf215546Sopenharmony_ci
226bf215546Sopenharmony_ci#define lp_jit_context_stencil_ref_back_value(_gallivm, _ptr) \
227bf215546Sopenharmony_ci   lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_STENCIL_REF_BACK, "stencil_ref_back")
228bf215546Sopenharmony_ci
229bf215546Sopenharmony_ci#define lp_jit_context_u8_blend_color(_gallivm, _ptr) \
230bf215546Sopenharmony_ci   lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_U8_BLEND_COLOR, "u8_blend_color")
231bf215546Sopenharmony_ci
232bf215546Sopenharmony_ci#define lp_jit_context_f_blend_color(_gallivm, _ptr) \
233bf215546Sopenharmony_ci   lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_F_BLEND_COLOR, "f_blend_color")
234bf215546Sopenharmony_ci
235bf215546Sopenharmony_ci#define lp_jit_context_viewports(_gallivm, _ptr) \
236bf215546Sopenharmony_ci   lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_VIEWPORTS, "viewports")
237bf215546Sopenharmony_ci
238bf215546Sopenharmony_ci#define lp_jit_context_ssbos(_gallivm, _ptr) \
239bf215546Sopenharmony_ci   lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_SSBOS, "ssbos")
240bf215546Sopenharmony_ci
241bf215546Sopenharmony_ci#define lp_jit_context_num_ssbos(_gallivm, _ptr) \
242bf215546Sopenharmony_ci   lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_NUM_SSBOS, "num_ssbos")
243bf215546Sopenharmony_ci
244bf215546Sopenharmony_ci#define lp_jit_context_sample_mask(_gallivm, _ptr) \
245bf215546Sopenharmony_ci   lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_SAMPLE_MASK, "sample_mask")
246bf215546Sopenharmony_ci
247bf215546Sopenharmony_ci#define lp_jit_context_aniso_filter_table(_gallivm, _ptr) \
248bf215546Sopenharmony_ci   lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_ANISO_FILTER_TABLE, "aniso_filter_table")
249bf215546Sopenharmony_ci
250bf215546Sopenharmony_ci
251bf215546Sopenharmony_cistruct lp_jit_thread_data
252bf215546Sopenharmony_ci{
253bf215546Sopenharmony_ci   struct lp_build_format_cache *cache;
254bf215546Sopenharmony_ci   uint64_t vis_counter;
255bf215546Sopenharmony_ci   uint64_t ps_invocations;
256bf215546Sopenharmony_ci
257bf215546Sopenharmony_ci   /*
258bf215546Sopenharmony_ci    * Non-interpolated rasterizer state passed through to the fragment shader.
259bf215546Sopenharmony_ci    */
260bf215546Sopenharmony_ci   struct {
261bf215546Sopenharmony_ci      uint32_t viewport_index;
262bf215546Sopenharmony_ci      uint32_t view_index;
263bf215546Sopenharmony_ci   } raster_state;
264bf215546Sopenharmony_ci};
265bf215546Sopenharmony_ci
266bf215546Sopenharmony_ci
267bf215546Sopenharmony_cienum {
268bf215546Sopenharmony_ci   LP_JIT_THREAD_DATA_CACHE = 0,
269bf215546Sopenharmony_ci   LP_JIT_THREAD_DATA_COUNTER,
270bf215546Sopenharmony_ci   LP_JIT_THREAD_DATA_INVOCATIONS,
271bf215546Sopenharmony_ci   LP_JIT_THREAD_DATA_RASTER_STATE_VIEWPORT_INDEX,
272bf215546Sopenharmony_ci   LP_JIT_THREAD_DATA_RASTER_STATE_VIEW_INDEX,
273bf215546Sopenharmony_ci   LP_JIT_THREAD_DATA_COUNT
274bf215546Sopenharmony_ci};
275bf215546Sopenharmony_ci
276bf215546Sopenharmony_ci
277bf215546Sopenharmony_ci#define lp_jit_thread_data_cache(_gallivm, _ptr) \
278bf215546Sopenharmony_ci   lp_build_struct_get(_gallivm, _ptr, LP_JIT_THREAD_DATA_CACHE, "cache")
279bf215546Sopenharmony_ci
280bf215546Sopenharmony_ci#define lp_jit_thread_data_counter(_gallivm, _ptr) \
281bf215546Sopenharmony_ci   lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_THREAD_DATA_COUNTER, "counter")
282bf215546Sopenharmony_ci
283bf215546Sopenharmony_ci#define lp_jit_thread_data_invocations(_gallivm, _ptr) \
284bf215546Sopenharmony_ci   lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_THREAD_DATA_INVOCATIONS, "invocs")
285bf215546Sopenharmony_ci
286bf215546Sopenharmony_ci#define lp_jit_thread_data_raster_state_viewport_index(_gallivm, _ptr) \
287bf215546Sopenharmony_ci   lp_build_struct_get(_gallivm, _ptr, \
288bf215546Sopenharmony_ci                       LP_JIT_THREAD_DATA_RASTER_STATE_VIEWPORT_INDEX, \
289bf215546Sopenharmony_ci                       "raster_state.viewport_index")
290bf215546Sopenharmony_ci
291bf215546Sopenharmony_ci#define lp_jit_thread_data_raster_state_view_index(_gallivm, _ptr) \
292bf215546Sopenharmony_ci   lp_build_struct_get(_gallivm, _ptr, \
293bf215546Sopenharmony_ci                       LP_JIT_THREAD_DATA_RASTER_STATE_VIEW_INDEX, \
294bf215546Sopenharmony_ci                       "raster_state.view_index")
295bf215546Sopenharmony_ci
296bf215546Sopenharmony_ci/**
297bf215546Sopenharmony_ci * typedef for fragment shader function
298bf215546Sopenharmony_ci *
299bf215546Sopenharmony_ci * @param context       jit context
300bf215546Sopenharmony_ci * @param x             block start x
301bf215546Sopenharmony_ci * @param y             block start y
302bf215546Sopenharmony_ci * @param facing        is front facing
303bf215546Sopenharmony_ci * @param a0            shader input a0
304bf215546Sopenharmony_ci * @param dadx          shader input dadx
305bf215546Sopenharmony_ci * @param dady          shader input dady
306bf215546Sopenharmony_ci * @param color         color buffer
307bf215546Sopenharmony_ci * @param depth         depth buffer
308bf215546Sopenharmony_ci * @param mask          mask of visible pixels in block (16-bits per sample)
309bf215546Sopenharmony_ci * @param thread_data   task thread data
310bf215546Sopenharmony_ci * @param stride        color buffer row stride in bytes
311bf215546Sopenharmony_ci * @param depth_stride  depth buffer row stride in bytes
312bf215546Sopenharmony_ci */
313bf215546Sopenharmony_citypedef void
314bf215546Sopenharmony_ci(*lp_jit_frag_func)(const struct lp_jit_context *context,
315bf215546Sopenharmony_ci                    uint32_t x,
316bf215546Sopenharmony_ci                    uint32_t y,
317bf215546Sopenharmony_ci                    uint32_t facing,
318bf215546Sopenharmony_ci                    const void *a0,
319bf215546Sopenharmony_ci                    const void *dadx,
320bf215546Sopenharmony_ci                    const void *dady,
321bf215546Sopenharmony_ci                    uint8_t **color,
322bf215546Sopenharmony_ci                    uint8_t *depth,
323bf215546Sopenharmony_ci                    uint64_t mask,
324bf215546Sopenharmony_ci                    struct lp_jit_thread_data *thread_data,
325bf215546Sopenharmony_ci                    unsigned *stride,
326bf215546Sopenharmony_ci                    unsigned depth_stride,
327bf215546Sopenharmony_ci                    unsigned *color_sample_stride,
328bf215546Sopenharmony_ci                    unsigned depth_sample_stride);
329bf215546Sopenharmony_ci
330bf215546Sopenharmony_ci
331bf215546Sopenharmony_ci#define LP_MAX_LINEAR_CONSTANTS 16
332bf215546Sopenharmony_ci#define LP_MAX_LINEAR_TEXTURES 2
333bf215546Sopenharmony_ci#define LP_MAX_LINEAR_INPUTS 8
334bf215546Sopenharmony_ci
335bf215546Sopenharmony_ci
336bf215546Sopenharmony_ci/**
337bf215546Sopenharmony_ci * This structure is passed directly to the generated fragment shader.
338bf215546Sopenharmony_ci *
339bf215546Sopenharmony_ci * It contains the derived state.
340bf215546Sopenharmony_ci *
341bf215546Sopenharmony_ci * Changes here must be reflected in the lp_jit_linear_context_* macros and
342bf215546Sopenharmony_ci * lp_jit_init_types function. Changes to the ordering should be avoided.
343bf215546Sopenharmony_ci *
344bf215546Sopenharmony_ci * Only use types with a clear size and padding here, in particular prefer the
345bf215546Sopenharmony_ci * stdint.h types to the basic integer types.
346bf215546Sopenharmony_ci */
347bf215546Sopenharmony_cistruct lp_jit_linear_context
348bf215546Sopenharmony_ci{
349bf215546Sopenharmony_ci   /**
350bf215546Sopenharmony_ci    * Constants in 8bit unorm values.
351bf215546Sopenharmony_ci    */
352bf215546Sopenharmony_ci   const uint8_t (*constants)[4];
353bf215546Sopenharmony_ci   struct lp_linear_elem *tex[LP_MAX_LINEAR_TEXTURES];
354bf215546Sopenharmony_ci   struct lp_linear_elem *inputs[LP_MAX_LINEAR_INPUTS];
355bf215546Sopenharmony_ci
356bf215546Sopenharmony_ci   uint8_t *color0;
357bf215546Sopenharmony_ci   uint32_t blend_color;
358bf215546Sopenharmony_ci
359bf215546Sopenharmony_ci   uint8_t alpha_ref_value;
360bf215546Sopenharmony_ci};
361bf215546Sopenharmony_ci
362bf215546Sopenharmony_ci
363bf215546Sopenharmony_ci/**
364bf215546Sopenharmony_ci * These enum values must match the position of the fields in the
365bf215546Sopenharmony_ci * lp_jit_linear_context struct above.
366bf215546Sopenharmony_ci */
367bf215546Sopenharmony_cienum {
368bf215546Sopenharmony_ci   LP_JIT_LINEAR_CTX_CONSTANTS = 0,
369bf215546Sopenharmony_ci   LP_JIT_LINEAR_CTX_TEX,
370bf215546Sopenharmony_ci   LP_JIT_LINEAR_CTX_INPUTS,
371bf215546Sopenharmony_ci   LP_JIT_LINEAR_CTX_COLOR0,
372bf215546Sopenharmony_ci   LP_JIT_LINEAR_CTX_BLEND_COLOR,
373bf215546Sopenharmony_ci   LP_JIT_LINEAR_CTX_ALPHA_REF,
374bf215546Sopenharmony_ci   LP_JIT_LINEAR_CTX_COUNT
375bf215546Sopenharmony_ci};
376bf215546Sopenharmony_ci
377bf215546Sopenharmony_ci
378bf215546Sopenharmony_ci#define lp_jit_linear_context_constants(_gallivm, _ptr) \
379bf215546Sopenharmony_ci   lp_build_struct_get(_gallivm, _ptr, LP_JIT_LINEAR_CTX_CONSTANTS, "constants")
380bf215546Sopenharmony_ci
381bf215546Sopenharmony_ci#define lp_jit_linear_context_tex(_gallivm, _ptr) \
382bf215546Sopenharmony_ci   lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_LINEAR_CTX_TEX, "tex")
383bf215546Sopenharmony_ci
384bf215546Sopenharmony_ci#define lp_jit_linear_context_inputs(_gallivm, _ptr) \
385bf215546Sopenharmony_ci   lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_LINEAR_CTX_INPUTS, "inputs")
386bf215546Sopenharmony_ci
387bf215546Sopenharmony_ci#define lp_jit_linear_context_color0(_gallivm, _ptr) \
388bf215546Sopenharmony_ci   lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_LINEAR_CTX_COLOR0, "color0")
389bf215546Sopenharmony_ci
390bf215546Sopenharmony_ci#define lp_jit_linear_context_blend_color(_gallivm, _ptr) \
391bf215546Sopenharmony_ci   lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_LINEAR_CTX_BLEND_COLOR, "blend_color")
392bf215546Sopenharmony_ci
393bf215546Sopenharmony_ci#define lp_jit_linear_context_alpha_ref(_gallivm, _ptr) \
394bf215546Sopenharmony_ci   lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_LINEAR_CTX_ALPHA_REF, "alpha_ref_value")
395bf215546Sopenharmony_ci
396bf215546Sopenharmony_ci
397bf215546Sopenharmony_citypedef const uint8_t *
398bf215546Sopenharmony_ci(*lp_jit_linear_llvm_func)(struct lp_jit_linear_context *context,
399bf215546Sopenharmony_ci                           uint32_t x,
400bf215546Sopenharmony_ci                           uint32_t y,
401bf215546Sopenharmony_ci                           uint32_t w);
402bf215546Sopenharmony_ci
403bf215546Sopenharmony_ci/* We're not really jitting this, but I need to get into the
404bf215546Sopenharmony_ci * rast_state struct to call the function we actually are jitting.
405bf215546Sopenharmony_ci */
406bf215546Sopenharmony_citypedef boolean
407bf215546Sopenharmony_ci(*lp_jit_linear_func)(const struct lp_rast_state *state,
408bf215546Sopenharmony_ci                      uint32_t x,
409bf215546Sopenharmony_ci                      uint32_t y,
410bf215546Sopenharmony_ci                      uint32_t w,
411bf215546Sopenharmony_ci                      uint32_t h,
412bf215546Sopenharmony_ci                      const float (*a0)[4],
413bf215546Sopenharmony_ci                      const float (*dadx)[4],
414bf215546Sopenharmony_ci                      const float (*dady)[4],
415bf215546Sopenharmony_ci                      uint8_t *color,
416bf215546Sopenharmony_ci                      uint32_t color_stride);
417bf215546Sopenharmony_ci
418bf215546Sopenharmony_ci
419bf215546Sopenharmony_cistruct lp_jit_cs_thread_data
420bf215546Sopenharmony_ci{
421bf215546Sopenharmony_ci   struct lp_build_format_cache *cache;
422bf215546Sopenharmony_ci   void *shared;
423bf215546Sopenharmony_ci};
424bf215546Sopenharmony_ci
425bf215546Sopenharmony_ci
426bf215546Sopenharmony_cienum {
427bf215546Sopenharmony_ci   LP_JIT_CS_THREAD_DATA_CACHE = 0,
428bf215546Sopenharmony_ci   LP_JIT_CS_THREAD_DATA_SHARED = 1,
429bf215546Sopenharmony_ci   LP_JIT_CS_THREAD_DATA_COUNT
430bf215546Sopenharmony_ci};
431bf215546Sopenharmony_ci
432bf215546Sopenharmony_ci
433bf215546Sopenharmony_ci#define lp_jit_cs_thread_data_cache(_gallivm, _ptr) \
434bf215546Sopenharmony_ci   lp_build_struct_get(_gallivm, _ptr, LP_JIT_CS_THREAD_DATA_CACHE, "cache")
435bf215546Sopenharmony_ci
436bf215546Sopenharmony_ci#define lp_jit_cs_thread_data_shared(_gallivm, _ptr) \
437bf215546Sopenharmony_ci   lp_build_struct_get(_gallivm, _ptr, LP_JIT_CS_THREAD_DATA_SHARED, "shared")
438bf215546Sopenharmony_ci
439bf215546Sopenharmony_ci
440bf215546Sopenharmony_cistruct lp_jit_cs_context
441bf215546Sopenharmony_ci{
442bf215546Sopenharmony_ci   const float *constants[LP_MAX_TGSI_CONST_BUFFERS];
443bf215546Sopenharmony_ci   int num_constants[LP_MAX_TGSI_CONST_BUFFERS];
444bf215546Sopenharmony_ci
445bf215546Sopenharmony_ci   struct lp_jit_texture textures[PIPE_MAX_SHADER_SAMPLER_VIEWS];
446bf215546Sopenharmony_ci   struct lp_jit_sampler samplers[PIPE_MAX_SAMPLERS];
447bf215546Sopenharmony_ci   struct lp_jit_image images[PIPE_MAX_SHADER_IMAGES];
448bf215546Sopenharmony_ci
449bf215546Sopenharmony_ci   const uint32_t *ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
450bf215546Sopenharmony_ci   int num_ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
451bf215546Sopenharmony_ci
452bf215546Sopenharmony_ci   void *kernel_args;
453bf215546Sopenharmony_ci
454bf215546Sopenharmony_ci   uint32_t shared_size;
455bf215546Sopenharmony_ci
456bf215546Sopenharmony_ci   const float *aniso_filter_table;
457bf215546Sopenharmony_ci};
458bf215546Sopenharmony_ci
459bf215546Sopenharmony_ci/**
460bf215546Sopenharmony_ci * These enum values must match the position of the fields in the
461bf215546Sopenharmony_ci * lp_jit_context struct above.
462bf215546Sopenharmony_ci */
463bf215546Sopenharmony_cienum {
464bf215546Sopenharmony_ci   LP_JIT_CS_CTX_CONSTANTS = 0,
465bf215546Sopenharmony_ci   LP_JIT_CS_CTX_NUM_CONSTANTS,
466bf215546Sopenharmony_ci   LP_JIT_CS_CTX_TEXTURES, /* must match the LP_JIT_CTX_TEXTURES */
467bf215546Sopenharmony_ci   LP_JIT_CS_CTX_SAMPLERS,
468bf215546Sopenharmony_ci   LP_JIT_CS_CTX_IMAGES,
469bf215546Sopenharmony_ci   LP_JIT_CS_CTX_SSBOS,
470bf215546Sopenharmony_ci   LP_JIT_CS_CTX_NUM_SSBOS,
471bf215546Sopenharmony_ci   LP_JIT_CS_CTX_KERNEL_ARGS,
472bf215546Sopenharmony_ci   LP_JIT_CS_CTX_SHARED_SIZE,
473bf215546Sopenharmony_ci   LP_JIT_CS_CTX_ANISO_FILTER_TABLE,
474bf215546Sopenharmony_ci   LP_JIT_CS_CTX_COUNT
475bf215546Sopenharmony_ci};
476bf215546Sopenharmony_ci
477bf215546Sopenharmony_ci#define lp_jit_cs_context_constants(_gallivm, _ptr) \
478bf215546Sopenharmony_ci   lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_CONSTANTS, "constants")
479bf215546Sopenharmony_ci
480bf215546Sopenharmony_ci#define lp_jit_cs_context_num_constants(_gallivm, _ptr) \
481bf215546Sopenharmony_ci   lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_NUM_CONSTANTS, "num_constants")
482bf215546Sopenharmony_ci
483bf215546Sopenharmony_ci#define lp_jit_cs_context_textures(_gallivm, _ptr) \
484bf215546Sopenharmony_ci   lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_TEXTURES, "textures")
485bf215546Sopenharmony_ci
486bf215546Sopenharmony_ci#define lp_jit_cs_context_samplers(_gallivm, _ptr) \
487bf215546Sopenharmony_ci   lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_SAMPLERS, "samplers")
488bf215546Sopenharmony_ci
489bf215546Sopenharmony_ci#define lp_jit_cs_context_images(_gallivm, _ptr) \
490bf215546Sopenharmony_ci   lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_IMAGES, "images")
491bf215546Sopenharmony_ci
492bf215546Sopenharmony_ci#define lp_jit_cs_context_ssbos(_gallivm, _ptr) \
493bf215546Sopenharmony_ci   lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_SSBOS, "ssbos")
494bf215546Sopenharmony_ci
495bf215546Sopenharmony_ci#define lp_jit_cs_context_num_ssbos(_gallivm, _ptr) \
496bf215546Sopenharmony_ci   lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_NUM_SSBOS, "num_ssbos")
497bf215546Sopenharmony_ci
498bf215546Sopenharmony_ci#define lp_jit_cs_context_shared_size(_gallivm, _ptr) \
499bf215546Sopenharmony_ci   lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CS_CTX_SHARED_SIZE, "shared_size")
500bf215546Sopenharmony_ci
501bf215546Sopenharmony_ci#define lp_jit_cs_context_kernel_args(_gallivm, _ptr) \
502bf215546Sopenharmony_ci   lp_build_struct_get(_gallivm, _ptr, LP_JIT_CS_CTX_KERNEL_ARGS, "kernel_args")
503bf215546Sopenharmony_ci
504bf215546Sopenharmony_ci#define lp_jit_cs_context_aniso_filter_table(_gallivm, _ptr) \
505bf215546Sopenharmony_ci   lp_build_struct_get(_gallivm, _ptr, LP_JIT_CS_CTX_ANISO_FILTER_TABLE, "aniso_filter_table")
506bf215546Sopenharmony_ci
507bf215546Sopenharmony_ci
508bf215546Sopenharmony_citypedef void
509bf215546Sopenharmony_ci(*lp_jit_cs_func)(const struct lp_jit_cs_context *context,
510bf215546Sopenharmony_ci                  uint32_t x,
511bf215546Sopenharmony_ci                  uint32_t y,
512bf215546Sopenharmony_ci                  uint32_t z,
513bf215546Sopenharmony_ci                  uint32_t grid_x,
514bf215546Sopenharmony_ci                  uint32_t grid_y,
515bf215546Sopenharmony_ci                  uint32_t grid_z,
516bf215546Sopenharmony_ci                  uint32_t grid_size_x,
517bf215546Sopenharmony_ci                  uint32_t grid_size_y,
518bf215546Sopenharmony_ci                  uint32_t grid_size_z,
519bf215546Sopenharmony_ci                  uint32_t work_dim,
520bf215546Sopenharmony_ci                  struct lp_jit_cs_thread_data *thread_data);
521bf215546Sopenharmony_ci
522bf215546Sopenharmony_civoid
523bf215546Sopenharmony_cilp_jit_screen_cleanup(struct llvmpipe_screen *screen);
524bf215546Sopenharmony_ci
525bf215546Sopenharmony_ciboolean
526bf215546Sopenharmony_cilp_jit_screen_init(struct llvmpipe_screen *screen);
527bf215546Sopenharmony_ci
528bf215546Sopenharmony_civoid
529bf215546Sopenharmony_cilp_jit_init_types(struct lp_fragment_shader_variant *lp);
530bf215546Sopenharmony_ci
531bf215546Sopenharmony_civoid
532bf215546Sopenharmony_cilp_jit_init_cs_types(struct lp_compute_shader_variant *lp);
533bf215546Sopenharmony_ci
534bf215546Sopenharmony_ci
535bf215546Sopenharmony_ci#endif /* LP_JIT_H */
536