Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. /**************************************************************************
  2.  *
  3.  * Copyright 2009 VMware, Inc.
  4.  * All Rights Reserved.
  5.  *
  6.  * Permission is hereby granted, free of charge, to any person obtaining a
  7.  * copy of this software and associated documentation files (the
  8.  * "Software"), to deal in the Software without restriction, including
  9.  * without limitation the rights to use, copy, modify, merge, publish,
  10.  * distribute, sub license, and/or sell copies of the Software, and to
  11.  * permit persons to whom the Software is furnished to do so, subject to
  12.  * the following conditions:
  13.  *
  14.  * The above copyright notice and this permission notice (including the
  15.  * next paragraph) shall be included in all copies or substantial portions
  16.  * of the Software.
  17.  *
  18.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  19.  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20.  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
  21.  * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
  22.  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  23.  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  24.  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  25.  *
  26.  **************************************************************************/
  27.  
  28. /**
  29.  * @file
  30.  * C - JIT interfaces
  31.  *
  32.  * @author Jose Fonseca <jfonseca@vmware.com>
  33.  */
  34.  
  35. #ifndef LP_JIT_H
  36. #define LP_JIT_H
  37.  
  38.  
  39. #include "gallivm/lp_bld_struct.h"
  40. #include "gallivm/lp_bld_limits.h"
  41.  
  42. #include "pipe/p_state.h"
  43. #include "lp_texture.h"
  44.  
  45.  
  46. struct lp_fragment_shader_variant;
  47. struct llvmpipe_screen;
  48.  
  49.  
  50. struct lp_jit_texture
  51. {
  52.    uint32_t width;        /* same as number of elements */
  53.    uint32_t height;
  54.    uint32_t depth;        /* doubles as array size */
  55.    uint32_t first_level;
  56.    uint32_t last_level;
  57.    const void *base;
  58.    uint32_t row_stride[LP_MAX_TEXTURE_LEVELS];
  59.    uint32_t img_stride[LP_MAX_TEXTURE_LEVELS];
  60.    uint32_t mip_offsets[LP_MAX_TEXTURE_LEVELS];
  61. };
  62.  
  63.  
  64. struct lp_jit_sampler
  65. {
  66.    float min_lod;
  67.    float max_lod;
  68.    float lod_bias;
  69.    float border_color[4];
  70. };
  71.  
  72.  
  73. enum {
  74.    LP_JIT_TEXTURE_WIDTH = 0,
  75.    LP_JIT_TEXTURE_HEIGHT,
  76.    LP_JIT_TEXTURE_DEPTH,
  77.    LP_JIT_TEXTURE_FIRST_LEVEL,
  78.    LP_JIT_TEXTURE_LAST_LEVEL,
  79.    LP_JIT_TEXTURE_BASE,
  80.    LP_JIT_TEXTURE_ROW_STRIDE,
  81.    LP_JIT_TEXTURE_IMG_STRIDE,
  82.    LP_JIT_TEXTURE_MIP_OFFSETS,
  83.    LP_JIT_TEXTURE_NUM_FIELDS  /* number of fields above */
  84. };
  85.  
  86.  
  87. enum {
  88.    LP_JIT_SAMPLER_MIN_LOD,
  89.    LP_JIT_SAMPLER_MAX_LOD,
  90.    LP_JIT_SAMPLER_LOD_BIAS,
  91.    LP_JIT_SAMPLER_BORDER_COLOR,
  92.    LP_JIT_SAMPLER_NUM_FIELDS  /* number of fields above */
  93. };
  94.  
  95.  
  96. /**
  97.  * This structure is passed directly to the generated fragment shader.
  98.  *
  99.  * It contains the derived state.
  100.  *
  101.  * Changes here must be reflected in the lp_jit_context_* macros and
  102.  * lp_jit_init_types function. Changes to the ordering should be avoided.
  103.  *
  104.  * Only use types with a clear size and padding here, in particular prefer the
  105.  * stdint.h types to the basic integer types.
  106.  */
  107. struct lp_jit_context
  108. {
  109.    const float *constants[LP_MAX_TGSI_CONST_BUFFERS];
  110.  
  111.    float alpha_ref_value;
  112.  
  113.    uint32_t stencil_ref_front, stencil_ref_back;
  114.  
  115.    uint8_t *u8_blend_color;
  116.    float *f_blend_color;
  117.  
  118.    struct lp_jit_texture textures[PIPE_MAX_SHADER_SAMPLER_VIEWS];
  119.    struct lp_jit_sampler samplers[PIPE_MAX_SAMPLERS];
  120. };
  121.  
  122.  
  123. /**
  124.  * These enum values must match the position of the fields in the
  125.  * lp_jit_context struct above.
  126.  */
  127. enum {
  128.    LP_JIT_CTX_CONSTANTS = 0,
  129.    LP_JIT_CTX_ALPHA_REF,
  130.    LP_JIT_CTX_STENCIL_REF_FRONT,
  131.    LP_JIT_CTX_STENCIL_REF_BACK,
  132.    LP_JIT_CTX_U8_BLEND_COLOR,
  133.    LP_JIT_CTX_F_BLEND_COLOR,
  134.    LP_JIT_CTX_TEXTURES,
  135.    LP_JIT_CTX_SAMPLERS,
  136.    LP_JIT_CTX_COUNT
  137. };
  138.  
  139.  
  140. #define lp_jit_context_constants(_gallivm, _ptr) \
  141.    lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_CONSTANTS, "constants")
  142.  
  143. #define lp_jit_context_alpha_ref_value(_gallivm, _ptr) \
  144.    lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_ALPHA_REF, "alpha_ref_value")
  145.  
  146. #define lp_jit_context_stencil_ref_front_value(_gallivm, _ptr) \
  147.    lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_STENCIL_REF_FRONT, "stencil_ref_front")
  148.  
  149. #define lp_jit_context_stencil_ref_back_value(_gallivm, _ptr) \
  150.    lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_STENCIL_REF_BACK, "stencil_ref_back")
  151.  
  152. #define lp_jit_context_u8_blend_color(_gallivm, _ptr) \
  153.    lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_U8_BLEND_COLOR, "u8_blend_color")
  154.  
  155. #define lp_jit_context_f_blend_color(_gallivm, _ptr) \
  156.    lp_build_struct_get(_gallivm, _ptr, LP_JIT_CTX_F_BLEND_COLOR, "f_blend_color")
  157.  
  158. #define lp_jit_context_textures(_gallivm, _ptr) \
  159.    lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_TEXTURES, "textures")
  160.  
  161. #define lp_jit_context_samplers(_gallivm, _ptr) \
  162.    lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_CTX_SAMPLERS, "samplers")
  163.  
  164.  
  165. struct lp_jit_thread_data
  166. {
  167.    uint64_t vis_counter;
  168. };
  169.  
  170.  
  171. enum {
  172.    LP_JIT_THREAD_DATA_COUNTER = 0,
  173.    LP_JIT_THREAD_DATA_COUNT
  174. };
  175.  
  176.  
  177. #define lp_jit_thread_data_counter(_gallivm, _ptr) \
  178.    lp_build_struct_get_ptr(_gallivm, _ptr, LP_JIT_THREAD_DATA_COUNTER, "counter")
  179.  
  180.  
  181. /**
  182.  * typedef for fragment shader function
  183.  *
  184.  * @param context       jit context
  185.  * @param x             block start x
  186.  * @param y             block start y
  187.  * @param facing        is front facing
  188.  * @param a0            shader input a0
  189.  * @param dadx          shader input dadx
  190.  * @param dady          shader input dady
  191.  * @param color         color buffer
  192.  * @param depth         depth buffer
  193.  * @param mask          mask of visible pixels in block
  194.  * @param thread_data   task thread data
  195.  * @param stride        color buffer row stride in bytes
  196.  * @param depth_stride  depth buffer row stride in bytes
  197.  */
  198. typedef void
  199. (*lp_jit_frag_func)(const struct lp_jit_context *context,
  200.                     uint32_t x,
  201.                     uint32_t y,
  202.                     uint32_t facing,
  203.                     const void *a0,
  204.                     const void *dadx,
  205.                     const void *dady,
  206.                     uint8_t **color,
  207.                     uint8_t *depth,
  208.                     uint32_t mask,
  209.                     struct lp_jit_thread_data *thread_data,
  210.                     unsigned *stride,
  211.                     unsigned depth_stride);
  212.  
  213.  
  214. void
  215. lp_jit_screen_cleanup(struct llvmpipe_screen *screen);
  216.  
  217.  
  218. void
  219. lp_jit_screen_init(struct llvmpipe_screen *screen);
  220.  
  221.  
  222. void
  223. lp_jit_init_types(struct lp_fragment_shader_variant *lp);
  224.  
  225.  
  226. #endif /* LP_JIT_H */
  227.