101eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin/**************************************************************************
201eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin *
301eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin * Copyright 2010 VMware, Inc.
401eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin * All rights reserved.
501eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin *
601eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin * Permission is hereby granted, free of charge, to any person obtaining a
701eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin * copy of this software and associated documentation files (the
801eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin * "Software"), to deal in the Software without restriction, including
901eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin * without limitation the rights to use, copy, modify, merge, publish,
1001eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin * distribute, sub license, and/or sell copies of the Software, and to
1101eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin * permit persons to whom the Software is furnished to do so, subject to
1201eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin * the following conditions:
1301eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin *
1401eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin * The above copyright notice and this permission notice (including the
1501eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin * next paragraph) shall be included in all copies or substantial portions
1601eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin * of the Software.
1701eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin *
1801eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
1901eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2001eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
2101eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
2201eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
2301eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
2401eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2501eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin *
2601eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin **************************************************************************/
2701eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin
2801eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin/**
2901eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin * Texture sampling code generation
3001eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin * @author Jose Fonseca <jfonseca@vmware.com>
3101eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin */
3201eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin
3301eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin#include "pipe/p_defines.h"
3401eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin#include "pipe/p_shader_tokens.h"
35efc82aef35a2aac5d2ed9774f6d28f2626796416Brian Paul#include "gallivm/lp_bld_const.h"
3601eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin#include "gallivm/lp_bld_debug.h"
3701eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin#include "gallivm/lp_bld_type.h"
3801eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin#include "gallivm/lp_bld_sample.h"
3901eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin#include "gallivm/lp_bld_tgsi.h"
4001eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin
4101eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin
4201eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin#include "util/u_debug.h"
4301eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin#include "util/u_memory.h"
4401eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin#include "util/u_pointer.h"
4501eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin#include "util/u_string.h"
4601eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin
4701eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin#include "draw_llvm.h"
4801eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin
4901eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin
5001eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin/**
5101eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin * This provides the bridge between the sampler state store in
5201eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin * lp_jit_context and lp_jit_texture and the sampler code
5301eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin * generator. It provides the texture layout information required by
5401eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin * the texture sampler code generator in terms of the state stored in
5501eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin * lp_jit_context and lp_jit_texture in runtime.
5601eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin */
5701eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusinstruct draw_llvm_sampler_dynamic_state
5801eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin{
5901eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin   struct lp_sampler_dynamic_state base;
6001eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin
61c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger   const struct draw_sampler_static_state *static_state;
6201eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin};
6301eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin
6401eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin
6501eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin/**
6601eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin * This is the bridge between our sampler and the TGSI translator.
6701eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin */
6801eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusinstruct draw_llvm_sampler_soa
6901eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin{
7001eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin   struct lp_build_sampler_soa base;
7101eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin
7201eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin   struct draw_llvm_sampler_dynamic_state dynamic_state;
7301eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin};
7401eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin
7501eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin
7601eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin/**
7701eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin * Fetch the specified member of the lp_jit_texture structure.
7801eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin * \param emit_load  if TRUE, emit the LLVM load instruction to actually
7901eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin *                   fetch the field's value.  Otherwise, just emit the
8001eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin *                   GEP code to address the field.
8101eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin *
8201eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin * @sa http://llvm.org/docs/GetElementPtr.html
8301eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin */
8401eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusinstatic LLVMValueRef
8501eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusindraw_llvm_texture_member(const struct lp_sampler_dynamic_state *base,
86efc82aef35a2aac5d2ed9774f6d28f2626796416Brian Paul                         struct gallivm_state *gallivm,
878dad9455ff748c543635b24908566c3b94cb93a9Roland Scheidegger                         LLVMValueRef context_ptr,
88cbf0f666311a5cb2720a4d6f4c540da1dd33e418Roland Scheidegger                         unsigned texture_unit,
8901eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin                         unsigned member_index,
9001eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin                         const char *member_name,
9101eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin                         boolean emit_load)
9201eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin{
93efc82aef35a2aac5d2ed9774f6d28f2626796416Brian Paul   LLVMBuilderRef builder = gallivm->builder;
9401eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin   LLVMValueRef indices[4];
9501eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin   LLVMValueRef ptr;
9601eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin   LLVMValueRef res;
9701eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin
98cbf0f666311a5cb2720a4d6f4c540da1dd33e418Roland Scheidegger   debug_assert(texture_unit < PIPE_MAX_SHADER_SAMPLER_VIEWS);
9901eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin
10001eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin   /* context[0] */
101efc82aef35a2aac5d2ed9774f6d28f2626796416Brian Paul   indices[0] = lp_build_const_int32(gallivm, 0);
10201eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin   /* context[0].textures */
103efc82aef35a2aac5d2ed9774f6d28f2626796416Brian Paul   indices[1] = lp_build_const_int32(gallivm, DRAW_JIT_CTX_TEXTURES);
10401eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin   /* context[0].textures[unit] */
105cbf0f666311a5cb2720a4d6f4c540da1dd33e418Roland Scheidegger   indices[2] = lp_build_const_int32(gallivm, texture_unit);
10601eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin   /* context[0].textures[unit].member */
107efc82aef35a2aac5d2ed9774f6d28f2626796416Brian Paul   indices[3] = lp_build_const_int32(gallivm, member_index);
10801eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin
109489df4a71aca99b2eebc62c02215a5860def944dBrian Paul   ptr = LLVMBuildGEP(builder, context_ptr, indices, ARRAY_SIZE(indices), "");
11001eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin
11101eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin   if (emit_load)
11201eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin      res = LLVMBuildLoad(builder, ptr, "");
11301eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin   else
11401eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin      res = ptr;
11501eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin
116cbf0f666311a5cb2720a4d6f4c540da1dd33e418Roland Scheidegger   lp_build_name(res, "context.texture%u.%s", texture_unit, member_name);
11701eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin
11801eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin   return res;
11901eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin}
12001eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin
12101eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin
12201eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin/**
123c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger * Fetch the specified member of the lp_jit_sampler structure.
124c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger * \param emit_load  if TRUE, emit the LLVM load instruction to actually
125c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger *                   fetch the field's value.  Otherwise, just emit the
126c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger *                   GEP code to address the field.
127c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger *
128c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger * @sa http://llvm.org/docs/GetElementPtr.html
129c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger */
130c789b981b244333cfc903bcd1e2fefc010500013Roland Scheideggerstatic LLVMValueRef
131c789b981b244333cfc903bcd1e2fefc010500013Roland Scheideggerdraw_llvm_sampler_member(const struct lp_sampler_dynamic_state *base,
132c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger                         struct gallivm_state *gallivm,
1338dad9455ff748c543635b24908566c3b94cb93a9Roland Scheidegger                         LLVMValueRef context_ptr,
134cbf0f666311a5cb2720a4d6f4c540da1dd33e418Roland Scheidegger                         unsigned sampler_unit,
135c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger                         unsigned member_index,
136c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger                         const char *member_name,
137c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger                         boolean emit_load)
138c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger{
139c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger   LLVMBuilderRef builder = gallivm->builder;
140c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger   LLVMValueRef indices[4];
141c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger   LLVMValueRef ptr;
142c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger   LLVMValueRef res;
143c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger
144cbf0f666311a5cb2720a4d6f4c540da1dd33e418Roland Scheidegger   debug_assert(sampler_unit < PIPE_MAX_SAMPLERS);
145c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger
146c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger   /* context[0] */
147c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger   indices[0] = lp_build_const_int32(gallivm, 0);
148c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger   /* context[0].samplers */
149c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger   indices[1] = lp_build_const_int32(gallivm, DRAW_JIT_CTX_SAMPLERS);
150c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger   /* context[0].samplers[unit] */
151cbf0f666311a5cb2720a4d6f4c540da1dd33e418Roland Scheidegger   indices[2] = lp_build_const_int32(gallivm, sampler_unit);
152c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger   /* context[0].samplers[unit].member */
153c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger   indices[3] = lp_build_const_int32(gallivm, member_index);
154c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger
155489df4a71aca99b2eebc62c02215a5860def944dBrian Paul   ptr = LLVMBuildGEP(builder, context_ptr, indices, ARRAY_SIZE(indices), "");
156c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger
157c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger   if (emit_load)
158c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger      res = LLVMBuildLoad(builder, ptr, "");
159c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger   else
160c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger      res = ptr;
161c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger
162cbf0f666311a5cb2720a4d6f4c540da1dd33e418Roland Scheidegger   lp_build_name(res, "context.sampler%u.%s", sampler_unit, member_name);
163c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger
164c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger   return res;
165c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger}
166c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger
167c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger
168c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger/**
16901eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin * Helper macro to instantiate the functions that generate the code to
17001eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin * fetch the members of lp_jit_texture to fulfill the sampler code
17101eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin * generator requests.
17201eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin *
17301eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin * This complexity is the price we have to pay to keep the texture
17401eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin * sampler code generator a reusable module without dependencies to
17501eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin * llvmpipe internals.
17601eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin */
17701eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin#define DRAW_LLVM_TEXTURE_MEMBER(_name, _index, _emit_load)  \
17801eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin   static LLVMValueRef \
17901eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin   draw_llvm_texture_##_name( const struct lp_sampler_dynamic_state *base, \
180efc82aef35a2aac5d2ed9774f6d28f2626796416Brian Paul                              struct gallivm_state *gallivm,               \
1818dad9455ff748c543635b24908566c3b94cb93a9Roland Scheidegger                              LLVMValueRef context_ptr,                    \
182cbf0f666311a5cb2720a4d6f4c540da1dd33e418Roland Scheidegger                              unsigned texture_unit)                       \
18301eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin   { \
1848dad9455ff748c543635b24908566c3b94cb93a9Roland Scheidegger      return draw_llvm_texture_member(base, gallivm, context_ptr, \
1858dad9455ff748c543635b24908566c3b94cb93a9Roland Scheidegger                                      texture_unit, _index, #_name, _emit_load ); \
18601eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin   }
18701eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin
18801eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin
18901eebfe1b6de2e36dd3af0952fc8329b7073a100Zack RusinDRAW_LLVM_TEXTURE_MEMBER(width,      DRAW_JIT_TEXTURE_WIDTH, TRUE)
19001eebfe1b6de2e36dd3af0952fc8329b7073a100Zack RusinDRAW_LLVM_TEXTURE_MEMBER(height,     DRAW_JIT_TEXTURE_HEIGHT, TRUE)
19101eebfe1b6de2e36dd3af0952fc8329b7073a100Zack RusinDRAW_LLVM_TEXTURE_MEMBER(depth,      DRAW_JIT_TEXTURE_DEPTH, TRUE)
19208070cead0bb79d4441d8c5b900d1571bb63c670Fabian BielerDRAW_LLVM_TEXTURE_MEMBER(first_level,DRAW_JIT_TEXTURE_FIRST_LEVEL, TRUE)
19301eebfe1b6de2e36dd3af0952fc8329b7073a100Zack RusinDRAW_LLVM_TEXTURE_MEMBER(last_level, DRAW_JIT_TEXTURE_LAST_LEVEL, TRUE)
19426097c4855b97ee6e362c19df11d51fb7fd42192Roland ScheideggerDRAW_LLVM_TEXTURE_MEMBER(base_ptr,   DRAW_JIT_TEXTURE_BASE, TRUE)
19501eebfe1b6de2e36dd3af0952fc8329b7073a100Zack RusinDRAW_LLVM_TEXTURE_MEMBER(row_stride, DRAW_JIT_TEXTURE_ROW_STRIDE, FALSE)
19601eebfe1b6de2e36dd3af0952fc8329b7073a100Zack RusinDRAW_LLVM_TEXTURE_MEMBER(img_stride, DRAW_JIT_TEXTURE_IMG_STRIDE, FALSE)
19726097c4855b97ee6e362c19df11d51fb7fd42192Roland ScheideggerDRAW_LLVM_TEXTURE_MEMBER(mip_offsets, DRAW_JIT_TEXTURE_MIP_OFFSETS, FALSE)
198c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger
199c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger
200c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger#define DRAW_LLVM_SAMPLER_MEMBER(_name, _index, _emit_load)  \
201c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger   static LLVMValueRef \
202c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger   draw_llvm_sampler_##_name( const struct lp_sampler_dynamic_state *base, \
203c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger                              struct gallivm_state *gallivm,               \
2048dad9455ff748c543635b24908566c3b94cb93a9Roland Scheidegger                              LLVMValueRef context_ptr,                    \
205cbf0f666311a5cb2720a4d6f4c540da1dd33e418Roland Scheidegger                              unsigned sampler_unit)                       \
206c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger   { \
2078dad9455ff748c543635b24908566c3b94cb93a9Roland Scheidegger      return draw_llvm_sampler_member(base, gallivm, context_ptr, \
2088dad9455ff748c543635b24908566c3b94cb93a9Roland Scheidegger                                      sampler_unit, _index, #_name, _emit_load ); \
209c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger   }
210c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger
211c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger
212c789b981b244333cfc903bcd1e2fefc010500013Roland ScheideggerDRAW_LLVM_SAMPLER_MEMBER(min_lod,    DRAW_JIT_SAMPLER_MIN_LOD, TRUE)
213c789b981b244333cfc903bcd1e2fefc010500013Roland ScheideggerDRAW_LLVM_SAMPLER_MEMBER(max_lod,    DRAW_JIT_SAMPLER_MAX_LOD, TRUE)
214c789b981b244333cfc903bcd1e2fefc010500013Roland ScheideggerDRAW_LLVM_SAMPLER_MEMBER(lod_bias,   DRAW_JIT_SAMPLER_LOD_BIAS, TRUE)
215c789b981b244333cfc903bcd1e2fefc010500013Roland ScheideggerDRAW_LLVM_SAMPLER_MEMBER(border_color, DRAW_JIT_SAMPLER_BORDER_COLOR, FALSE)
21601eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin
21701eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin
21801eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusinstatic void
21901eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusindraw_llvm_sampler_soa_destroy(struct lp_build_sampler_soa *sampler)
22001eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin{
22101eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin   FREE(sampler);
22201eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin}
22301eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin
22401eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin
22501eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin/**
22601eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin * Fetch filtered values from texture.
22701eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin * The 'texel' parameter returns four vectors corresponding to R, G, B, A.
22801eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin */
22901eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusinstatic void
23001eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusindraw_llvm_sampler_soa_emit_fetch_texel(const struct lp_build_sampler_soa *base,
231efc82aef35a2aac5d2ed9774f6d28f2626796416Brian Paul                                       struct gallivm_state *gallivm,
2321863ed21ffbb3ab7fd9875dc25e32ececea79d50Roland Scheidegger                                       const struct lp_sampler_params *params)
23301eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin{
23401eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin   struct draw_llvm_sampler_soa *sampler = (struct draw_llvm_sampler_soa *)base;
2351863ed21ffbb3ab7fd9875dc25e32ececea79d50Roland Scheidegger   unsigned texture_index = params->texture_index;
2361863ed21ffbb3ab7fd9875dc25e32ececea79d50Roland Scheidegger   unsigned sampler_index = params->sampler_index;
23701eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin
238c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger   assert(texture_index < PIPE_MAX_SHADER_SAMPLER_VIEWS);
239c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger   assert(sampler_index < PIPE_MAX_SAMPLERS);
24001eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin
2411863ed21ffbb3ab7fd9875dc25e32ececea79d50Roland Scheidegger   lp_build_sample_soa(&sampler->dynamic_state.static_state[texture_index].texture_state,
242c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger                       &sampler->dynamic_state.static_state[sampler_index].sampler_state,
24301eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin                       &sampler->dynamic_state.base,
2441863ed21ffbb3ab7fd9875dc25e32ececea79d50Roland Scheidegger                       gallivm, params);
24501eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin}
24601eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin
24701eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin
2485d10d757276a599a60a68b88b21087b5824a8df7Olivier Galibert/**
2495d10d757276a599a60a68b88b21087b5824a8df7Olivier Galibert * Fetch the texture size.
2505d10d757276a599a60a68b88b21087b5824a8df7Olivier Galibert */
2515d10d757276a599a60a68b88b21087b5824a8df7Olivier Galibertstatic void
2525d10d757276a599a60a68b88b21087b5824a8df7Olivier Galibertdraw_llvm_sampler_soa_emit_size_query(const struct lp_build_sampler_soa *base,
2535d10d757276a599a60a68b88b21087b5824a8df7Olivier Galibert                                      struct gallivm_state *gallivm,
2543a26ef23e78f811abdfe657b52b9bc057b9ce5b6Dave Airlie                                      const struct lp_sampler_size_query_params *params)
2555d10d757276a599a60a68b88b21087b5824a8df7Olivier Galibert{
2565d10d757276a599a60a68b88b21087b5824a8df7Olivier Galibert   struct draw_llvm_sampler_soa *sampler = (struct draw_llvm_sampler_soa *)base;
2575d10d757276a599a60a68b88b21087b5824a8df7Olivier Galibert
2583a26ef23e78f811abdfe657b52b9bc057b9ce5b6Dave Airlie   assert(params->texture_unit < PIPE_MAX_SHADER_SAMPLER_VIEWS);
2595d10d757276a599a60a68b88b21087b5824a8df7Olivier Galibert
2605d10d757276a599a60a68b88b21087b5824a8df7Olivier Galibert   lp_build_size_query_soa(gallivm,
2613a26ef23e78f811abdfe657b52b9bc057b9ce5b6Dave Airlie                           &sampler->dynamic_state.static_state[params->texture_unit].texture_state,
2625d10d757276a599a60a68b88b21087b5824a8df7Olivier Galibert                           &sampler->dynamic_state.base,
2633a26ef23e78f811abdfe657b52b9bc057b9ce5b6Dave Airlie                           params);
2645d10d757276a599a60a68b88b21087b5824a8df7Olivier Galibert}
2655d10d757276a599a60a68b88b21087b5824a8df7Olivier Galibert
26601eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusinstruct lp_build_sampler_soa *
2678dad9455ff748c543635b24908566c3b94cb93a9Roland Scheideggerdraw_llvm_sampler_soa_create(const struct draw_sampler_static_state *static_state)
26801eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin{
26901eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin   struct draw_llvm_sampler_soa *sampler;
27001eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin
27101eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin   sampler = CALLOC_STRUCT(draw_llvm_sampler_soa);
272147fd00bb36917f8463aacd49a26e95ca0926255Edward O'Callaghan   if (!sampler)
27301eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin      return NULL;
27401eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin
27501eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin   sampler->base.destroy = draw_llvm_sampler_soa_destroy;
2761863ed21ffbb3ab7fd9875dc25e32ececea79d50Roland Scheidegger   sampler->base.emit_tex_sample = draw_llvm_sampler_soa_emit_fetch_texel;
2775d10d757276a599a60a68b88b21087b5824a8df7Olivier Galibert   sampler->base.emit_size_query = draw_llvm_sampler_soa_emit_size_query;
27801eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin   sampler->dynamic_state.base.width = draw_llvm_texture_width;
27901eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin   sampler->dynamic_state.base.height = draw_llvm_texture_height;
28001eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin   sampler->dynamic_state.base.depth = draw_llvm_texture_depth;
28108070cead0bb79d4441d8c5b900d1571bb63c670Fabian Bieler   sampler->dynamic_state.base.first_level = draw_llvm_texture_first_level;
28201eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin   sampler->dynamic_state.base.last_level = draw_llvm_texture_last_level;
28301eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin   sampler->dynamic_state.base.row_stride = draw_llvm_texture_row_stride;
28401eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin   sampler->dynamic_state.base.img_stride = draw_llvm_texture_img_stride;
28526097c4855b97ee6e362c19df11d51fb7fd42192Roland Scheidegger   sampler->dynamic_state.base.base_ptr = draw_llvm_texture_base_ptr;
28626097c4855b97ee6e362c19df11d51fb7fd42192Roland Scheidegger   sampler->dynamic_state.base.mip_offsets = draw_llvm_texture_mip_offsets;
287c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger   sampler->dynamic_state.base.min_lod = draw_llvm_sampler_min_lod;
288c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger   sampler->dynamic_state.base.max_lod = draw_llvm_sampler_max_lod;
289c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger   sampler->dynamic_state.base.lod_bias = draw_llvm_sampler_lod_bias;
290c789b981b244333cfc903bcd1e2fefc010500013Roland Scheidegger   sampler->dynamic_state.base.border_color = draw_llvm_sampler_border_color;
29101eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin   sampler->dynamic_state.static_state = static_state;
29201eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin
29301eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin   return &sampler->base;
29401eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin}
29501eebfe1b6de2e36dd3af0952fc8329b7073a100Zack Rusin
296