1f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/**************************************************************************
2f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
3f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Copyright 2010 VMware, Inc.
4f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * All rights reserved.
5f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
6f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Permission is hereby granted, free of charge, to any person obtaining a
7f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * copy of this software and associated documentation files (the
8f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * "Software"), to deal in the Software without restriction, including
9f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * without limitation the rights to use, copy, modify, merge, publish,
10f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * distribute, sub license, and/or sell copies of the Software, and to
11f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * permit persons to whom the Software is furnished to do so, subject to
12f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * the following conditions:
13f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
14f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * The above copyright notice and this permission notice (including the
15f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * next paragraph) shall be included in all copies or substantial portions
16f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * of the Software.
17f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
18f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
26f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org **************************************************************************/
27f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
28f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/**
29f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Texture sampling code generation
30f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * @author Jose Fonseca <jfonseca@vmware.com>
31f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
32f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
33f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "pipe/p_defines.h"
34f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "pipe/p_shader_tokens.h"
35f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "gallivm/lp_bld_const.h"
36f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "gallivm/lp_bld_debug.h"
37f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "gallivm/lp_bld_type.h"
38f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "gallivm/lp_bld_sample.h"
39f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "gallivm/lp_bld_tgsi.h"
40f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
41f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
42f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "util/u_debug.h"
43f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "util/u_memory.h"
44f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "util/u_pointer.h"
45f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "util/u_string.h"
46f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
47f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "draw_llvm.h"
48f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
49f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
50f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/**
51f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * This provides the bridge between the sampler state store in
52f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * lp_jit_context and lp_jit_texture and the sampler code
53f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * generator. It provides the texture layout information required by
54f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * the texture sampler code generator in terms of the state stored in
55f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * lp_jit_context and lp_jit_texture in runtime.
56f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
57f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct draw_llvm_sampler_dynamic_state
58f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
59f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   struct lp_sampler_dynamic_state base;
60f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
61f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   const struct lp_sampler_static_state *static_state;
62f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
63f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   LLVMValueRef context_ptr;
64f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
65f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
66f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
67f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/**
68f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * This is the bridge between our sampler and the TGSI translator.
69f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
70f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct draw_llvm_sampler_soa
71f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
72f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   struct lp_build_sampler_soa base;
73f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
74f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   struct draw_llvm_sampler_dynamic_state dynamic_state;
75f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
76f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
77f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
78f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/**
79f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Fetch the specified member of the lp_jit_texture structure.
80f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * \param emit_load  if TRUE, emit the LLVM load instruction to actually
81f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *                   fetch the field's value.  Otherwise, just emit the
82f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *                   GEP code to address the field.
83f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
84f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * @sa http://llvm.org/docs/GetElementPtr.html
85f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
86f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic LLVMValueRef
87f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgdraw_llvm_texture_member(const struct lp_sampler_dynamic_state *base,
88f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                         struct gallivm_state *gallivm,
89f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                         unsigned unit,
90f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                         unsigned member_index,
91f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                         const char *member_name,
92f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                         boolean emit_load)
93f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
94f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   LLVMBuilderRef builder = gallivm->builder;
95f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   struct draw_llvm_sampler_dynamic_state *state =
96f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      (struct draw_llvm_sampler_dynamic_state *)base;
97f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   LLVMValueRef indices[4];
98f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   LLVMValueRef ptr;
99f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   LLVMValueRef res;
100f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
101f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   debug_assert(unit < PIPE_MAX_SAMPLERS);
102f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
103f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   /* context[0] */
104f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   indices[0] = lp_build_const_int32(gallivm, 0);
105f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   /* context[0].textures */
106f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   indices[1] = lp_build_const_int32(gallivm, DRAW_JIT_CTX_TEXTURES);
107f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   /* context[0].textures[unit] */
108f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   indices[2] = lp_build_const_int32(gallivm, unit);
109f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   /* context[0].textures[unit].member */
110f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   indices[3] = lp_build_const_int32(gallivm, member_index);
111f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
112f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   ptr = LLVMBuildGEP(builder, state->context_ptr, indices, Elements(indices), "");
113f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
114f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (emit_load)
115f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      res = LLVMBuildLoad(builder, ptr, "");
116f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   else
117f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      res = ptr;
118f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
119f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   lp_build_name(res, "context.texture%u.%s", unit, member_name);
120f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
121f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   return res;
122f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
123f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
124f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
125f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/**
126f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Helper macro to instantiate the functions that generate the code to
127f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * fetch the members of lp_jit_texture to fulfill the sampler code
128f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * generator requests.
129f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
130f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * This complexity is the price we have to pay to keep the texture
131f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * sampler code generator a reusable module without dependencies to
132f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * llvmpipe internals.
133f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
134f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define DRAW_LLVM_TEXTURE_MEMBER(_name, _index, _emit_load)  \
135f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   static LLVMValueRef \
136f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   draw_llvm_texture_##_name( const struct lp_sampler_dynamic_state *base, \
137f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                              struct gallivm_state *gallivm,               \
138f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                              unsigned unit)                            \
139f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   { \
140f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      return draw_llvm_texture_member(base, gallivm, unit, _index, #_name, _emit_load ); \
141f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
142f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
143f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
144f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgDRAW_LLVM_TEXTURE_MEMBER(width,      DRAW_JIT_TEXTURE_WIDTH, TRUE)
145f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgDRAW_LLVM_TEXTURE_MEMBER(height,     DRAW_JIT_TEXTURE_HEIGHT, TRUE)
146f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgDRAW_LLVM_TEXTURE_MEMBER(depth,      DRAW_JIT_TEXTURE_DEPTH, TRUE)
147f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgDRAW_LLVM_TEXTURE_MEMBER(first_level,DRAW_JIT_TEXTURE_FIRST_LEVEL, TRUE)
148f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgDRAW_LLVM_TEXTURE_MEMBER(last_level, DRAW_JIT_TEXTURE_LAST_LEVEL, TRUE)
149f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgDRAW_LLVM_TEXTURE_MEMBER(row_stride, DRAW_JIT_TEXTURE_ROW_STRIDE, FALSE)
150f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgDRAW_LLVM_TEXTURE_MEMBER(img_stride, DRAW_JIT_TEXTURE_IMG_STRIDE, FALSE)
151f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgDRAW_LLVM_TEXTURE_MEMBER(data_ptr,   DRAW_JIT_TEXTURE_DATA, FALSE)
152f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgDRAW_LLVM_TEXTURE_MEMBER(min_lod,    DRAW_JIT_TEXTURE_MIN_LOD, TRUE)
153f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgDRAW_LLVM_TEXTURE_MEMBER(max_lod,    DRAW_JIT_TEXTURE_MAX_LOD, TRUE)
154f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgDRAW_LLVM_TEXTURE_MEMBER(lod_bias,   DRAW_JIT_TEXTURE_LOD_BIAS, TRUE)
155f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgDRAW_LLVM_TEXTURE_MEMBER(border_color, DRAW_JIT_TEXTURE_BORDER_COLOR, FALSE)
156f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
157f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
158f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic void
159f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgdraw_llvm_sampler_soa_destroy(struct lp_build_sampler_soa *sampler)
160f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
161f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   FREE(sampler);
162f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
163f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
164f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
165f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/**
166f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Fetch filtered values from texture.
167f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * The 'texel' parameter returns four vectors corresponding to R, G, B, A.
168f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
169f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic void
170f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgdraw_llvm_sampler_soa_emit_fetch_texel(const struct lp_build_sampler_soa *base,
171f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                       struct gallivm_state *gallivm,
172f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                       struct lp_type type,
173f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                       unsigned unit,
174f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                       unsigned num_coords,
175f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                       const LLVMValueRef *coords,
176f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                       const struct lp_derivatives *derivs,
177f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                       LLVMValueRef lod_bias, /* optional */
178f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                       LLVMValueRef explicit_lod, /* optional */
179f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                       LLVMValueRef *texel)
180f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
181f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   struct draw_llvm_sampler_soa *sampler = (struct draw_llvm_sampler_soa *)base;
182f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
183f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   assert(unit < PIPE_MAX_SAMPLERS);
184f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
185f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   lp_build_sample_soa(gallivm,
186f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                       &sampler->dynamic_state.static_state[unit],
187f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                       &sampler->dynamic_state.base,
188f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                       type,
189f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                       unit,
190f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                       num_coords, coords,
191f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                       derivs,
192f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                       lod_bias, explicit_lod,
193f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                       texel);
194f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
195f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
196f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
197f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/**
198f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Fetch the texture size.
199f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
200f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic void
201f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgdraw_llvm_sampler_soa_emit_size_query(const struct lp_build_sampler_soa *base,
202f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                      struct gallivm_state *gallivm,
203f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                      struct lp_type type,
204f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                      unsigned unit,
205f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                      LLVMValueRef explicit_lod, /* optional */
206f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                      LLVMValueRef *sizes_out)
207f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
208f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   struct draw_llvm_sampler_soa *sampler = (struct draw_llvm_sampler_soa *)base;
209f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
210f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   assert(unit < PIPE_MAX_SAMPLERS);
211f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
212f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   lp_build_size_query_soa(gallivm,
213f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                           &sampler->dynamic_state.static_state[unit],
214f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                           &sampler->dynamic_state.base,
215f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org			   type,
216f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                           unit,
217f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                           explicit_lod,
218f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                           sizes_out);
219f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
220f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
221f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct lp_build_sampler_soa *
222f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgdraw_llvm_sampler_soa_create(const struct lp_sampler_static_state *static_state,
223f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                             LLVMValueRef context_ptr)
224f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
225f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   struct draw_llvm_sampler_soa *sampler;
226f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
227f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   sampler = CALLOC_STRUCT(draw_llvm_sampler_soa);
228f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if(!sampler)
229f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      return NULL;
230f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
231f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   sampler->base.destroy = draw_llvm_sampler_soa_destroy;
232f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   sampler->base.emit_fetch_texel = draw_llvm_sampler_soa_emit_fetch_texel;
233f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   sampler->base.emit_size_query = draw_llvm_sampler_soa_emit_size_query;
234f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   sampler->dynamic_state.base.width = draw_llvm_texture_width;
235f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   sampler->dynamic_state.base.height = draw_llvm_texture_height;
236f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   sampler->dynamic_state.base.depth = draw_llvm_texture_depth;
237f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   sampler->dynamic_state.base.first_level = draw_llvm_texture_first_level;
238f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   sampler->dynamic_state.base.last_level = draw_llvm_texture_last_level;
239f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   sampler->dynamic_state.base.row_stride = draw_llvm_texture_row_stride;
240f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   sampler->dynamic_state.base.img_stride = draw_llvm_texture_img_stride;
241f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   sampler->dynamic_state.base.data_ptr = draw_llvm_texture_data_ptr;
242f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   sampler->dynamic_state.base.min_lod = draw_llvm_texture_min_lod;
243f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   sampler->dynamic_state.base.max_lod = draw_llvm_texture_max_lod;
244f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   sampler->dynamic_state.base.lod_bias = draw_llvm_texture_lod_bias;
245f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   sampler->dynamic_state.base.border_color = draw_llvm_texture_border_color;
246f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   sampler->dynamic_state.static_state = static_state;
247f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   sampler->dynamic_state.context_ptr = context_ptr;
248f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
249f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   return &sampler->base;
250f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
251f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
252