mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-28 21:10:12 +01:00
gallivm: Implement vulkan textures
Reviewed-by: Dave Airlie <airlied@redhat.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22828>
This commit is contained in:
parent
eb140fa936
commit
573b8f23c2
4 changed files with 374 additions and 36 deletions
|
|
@ -66,6 +66,77 @@ struct lp_bld_llvm_image_soa
|
|||
unsigned nr_images;
|
||||
};
|
||||
|
||||
static LLVMValueRef
|
||||
load_texture_functions_ptr(struct gallivm_state *gallivm, LLVMValueRef descriptor,
|
||||
uint32_t offset1, uint32_t offset2)
|
||||
{
|
||||
LLVMBuilderRef builder = gallivm->builder;
|
||||
|
||||
LLVMValueRef texture_base_offset = lp_build_const_int64(gallivm, offset1);
|
||||
LLVMValueRef texture_base_ptr = LLVMBuildAdd(builder, descriptor, texture_base_offset, "");
|
||||
|
||||
LLVMTypeRef texture_base_type = LLVMInt64TypeInContext(gallivm->context);
|
||||
LLVMTypeRef texture_base_ptr_type = LLVMPointerType(texture_base_type, 0);
|
||||
|
||||
texture_base_ptr = LLVMBuildIntToPtr(builder, texture_base_ptr, texture_base_ptr_type, "");
|
||||
/* struct lp_texture_functions * */
|
||||
LLVMValueRef texture_base = LLVMBuildLoad2(builder, texture_base_type, texture_base_ptr, "");
|
||||
|
||||
LLVMValueRef functions_offset = lp_build_const_int64(gallivm, offset2);
|
||||
return LLVMBuildAdd(builder, texture_base, functions_offset, "");
|
||||
}
|
||||
|
||||
static LLVMValueRef
|
||||
widen_to_simd_width(struct gallivm_state *gallivm, LLVMValueRef value)
|
||||
{
|
||||
LLVMBuilderRef builder = gallivm->builder;
|
||||
LLVMTypeRef type = LLVMTypeOf(value);
|
||||
|
||||
if (LLVMGetTypeKind(type) == LLVMVectorTypeKind) {
|
||||
LLVMTypeRef element_type = LLVMGetElementType(type);
|
||||
uint32_t element_count = LLVMGetVectorSize(type);
|
||||
LLVMValueRef elements[8] = { 0 };
|
||||
for (uint32_t i = 0; i < lp_native_vector_width / 32; i++) {
|
||||
if (i < element_count)
|
||||
elements[i] = LLVMBuildExtractElement(builder, value, lp_build_const_int32(gallivm, i), "");
|
||||
else
|
||||
elements[i] = elements[0];
|
||||
}
|
||||
|
||||
LLVMTypeRef result_type = LLVMVectorType(element_type, lp_native_vector_width / 32);
|
||||
LLVMValueRef result = LLVMGetUndef(result_type);
|
||||
for (unsigned i = 0; i < lp_native_vector_width / 32; i++)
|
||||
result = LLVMBuildInsertElement(builder, result, elements[i], lp_build_const_int32(gallivm, i), "");
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
static LLVMValueRef
|
||||
truncate_to_type_width(struct gallivm_state *gallivm, LLVMValueRef value, struct lp_type target_type)
|
||||
{
|
||||
LLVMBuilderRef builder = gallivm->builder;
|
||||
LLVMTypeRef type = LLVMTypeOf(value);
|
||||
|
||||
if (LLVMGetTypeKind(type) == LLVMVectorTypeKind) {
|
||||
LLVMTypeRef element_type = LLVMGetElementType(type);
|
||||
|
||||
LLVMValueRef elements[8];
|
||||
for (uint32_t i = 0; i < target_type.length; i++)
|
||||
elements[i] = LLVMBuildExtractElement(builder, value, lp_build_const_int32(gallivm, i), "");
|
||||
|
||||
LLVMTypeRef result_type = LLVMVectorType(element_type, target_type.length);
|
||||
LLVMValueRef result = LLVMGetUndef(result_type);
|
||||
for (unsigned i = 0; i < target_type.length; i++)
|
||||
result = LLVMBuildInsertElement(builder, result, elements[i], lp_build_const_int32(gallivm, i), "");
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch filtered values from texture.
|
||||
|
|
@ -77,6 +148,138 @@ lp_bld_llvm_sampler_soa_emit_fetch_texel(const struct lp_build_sampler_soa *base
|
|||
const struct lp_sampler_params *params)
|
||||
{
|
||||
struct lp_bld_llvm_sampler_soa *sampler = (struct lp_bld_llvm_sampler_soa *)base;
|
||||
LLVMBuilderRef builder = gallivm->builder;
|
||||
|
||||
if (params->texture_resource) {
|
||||
LLVMTypeRef out_data_type = lp_build_vec_type(gallivm, params->type);
|
||||
|
||||
LLVMValueRef out_data[4];
|
||||
for (uint32_t i = 0; i < 4; i++) {
|
||||
out_data[i] = lp_build_alloca(gallivm, out_data_type, "");
|
||||
LLVMBuildStore(builder, lp_build_const_vec(gallivm, params->type, 0), out_data[i]);
|
||||
}
|
||||
|
||||
struct lp_type uint_type = lp_uint_type(params->type);
|
||||
LLVMValueRef uint_zero = lp_build_const_int_vec(gallivm, uint_type, 0);
|
||||
|
||||
LLVMValueRef bitmask = LLVMBuildICmp(builder, LLVMIntNE, params->exec_mask, uint_zero, "exec_bitvec");
|
||||
|
||||
LLVMTypeRef bitmask_type = LLVMIntTypeInContext(gallivm->context, uint_type.length);
|
||||
bitmask = LLVMBuildBitCast(builder, bitmask, bitmask_type, "exec_bitmask");
|
||||
|
||||
LLVMValueRef any_active = LLVMBuildICmp(builder, LLVMIntNE, bitmask, LLVMConstInt(bitmask_type, 0, false), "any_active");
|
||||
|
||||
struct lp_build_if_state if_state;
|
||||
lp_build_if(&if_state, gallivm, any_active);
|
||||
|
||||
LLVMValueRef consts = lp_jit_resources_constants(gallivm, params->resources_type, params->resources_ptr);
|
||||
|
||||
LLVMValueRef texture_descriptor = lp_llvm_descriptor_base(gallivm, consts, params->texture_resource, LP_MAX_TGSI_CONST_BUFFERS);
|
||||
|
||||
enum lp_sampler_op_type op_type = (params->sample_key & LP_SAMPLER_OP_TYPE_MASK) >> LP_SAMPLER_OP_TYPE_SHIFT;
|
||||
uint32_t functions_offset = op_type == LP_SAMPLER_OP_FETCH ? offsetof(struct lp_texture_functions, fetch_functions)
|
||||
: offsetof(struct lp_texture_functions, sample_functions);
|
||||
|
||||
LLVMValueRef texture_base_ptr = load_texture_functions_ptr(
|
||||
gallivm, texture_descriptor, offsetof(union lp_descriptor, sample_functions), functions_offset);
|
||||
|
||||
LLVMTypeRef texture_function_type = lp_build_sample_function_type(gallivm, params->sample_key);
|
||||
LLVMTypeRef texture_function_ptr_type = LLVMPointerType(texture_function_type, 0);
|
||||
LLVMTypeRef texture_functions_type = LLVMPointerType(texture_function_ptr_type, 0);
|
||||
LLVMTypeRef texture_base_type = LLVMPointerType(texture_functions_type, 0);
|
||||
LLVMTypeRef texture_base_ptr_type = LLVMPointerType(texture_base_type, 0);
|
||||
|
||||
texture_base_ptr = LLVMBuildIntToPtr(builder, texture_base_ptr, texture_base_ptr_type, "");
|
||||
LLVMValueRef texture_base = LLVMBuildLoad2(builder, texture_base_type, texture_base_ptr, "");
|
||||
|
||||
LLVMValueRef texture_functions;
|
||||
LLVMValueRef sampler_desc_ptr;
|
||||
if (op_type == LP_SAMPLER_OP_FETCH) {
|
||||
texture_functions = texture_base;
|
||||
sampler_desc_ptr = LLVMGetUndef(LLVMInt64TypeInContext(gallivm->context));
|
||||
} else {
|
||||
sampler_desc_ptr = lp_llvm_descriptor_base(gallivm, consts, params->sampler_resource, LP_MAX_TGSI_CONST_BUFFERS);
|
||||
|
||||
LLVMValueRef sampler_index_offset = lp_build_const_int64(gallivm, offsetof(union lp_descriptor, sampler_index));
|
||||
LLVMValueRef sampler_index_ptr = LLVMBuildAdd(builder, sampler_desc_ptr, sampler_index_offset, "");
|
||||
|
||||
LLVMTypeRef sampler_index_type = LLVMInt32TypeInContext(gallivm->context);
|
||||
LLVMTypeRef sampler_index_ptr_type = LLVMPointerType(sampler_index_type, 0);
|
||||
|
||||
sampler_index_ptr = LLVMBuildIntToPtr(builder, sampler_index_ptr, sampler_index_ptr_type, "");
|
||||
LLVMValueRef sampler_index = LLVMBuildLoad2(builder, sampler_index_type, sampler_index_ptr, "");
|
||||
|
||||
LLVMValueRef texture_functions_ptr = LLVMBuildGEP2(builder, texture_functions_type, texture_base, &sampler_index, 1, "");
|
||||
texture_functions = LLVMBuildLoad2(builder, texture_functions_type, texture_functions_ptr, "");
|
||||
}
|
||||
|
||||
LLVMValueRef sample_key = lp_build_const_int32(gallivm, params->sample_key);
|
||||
LLVMValueRef texture_function_ptr = LLVMBuildGEP2(builder, texture_function_ptr_type, texture_functions, &sample_key, 1, "");
|
||||
LLVMValueRef texture_function = LLVMBuildLoad2(builder, texture_function_ptr_type, texture_function_ptr, "");
|
||||
|
||||
LLVMValueRef args[LP_MAX_TEX_FUNC_ARGS];
|
||||
uint32_t num_args = 0;
|
||||
|
||||
args[num_args++] = texture_descriptor;
|
||||
args[num_args++] = sampler_desc_ptr;
|
||||
|
||||
args[num_args++] = params->aniso_filter_table;
|
||||
|
||||
LLVMTypeRef coord_type;
|
||||
if (op_type == LP_SAMPLER_OP_FETCH)
|
||||
coord_type = lp_build_int_vec_type(gallivm, params->type);
|
||||
else
|
||||
coord_type = lp_build_vec_type(gallivm, params->type);
|
||||
|
||||
for (uint32_t i = 0; i < 4; i++) {
|
||||
if (LLVMIsUndef(params->coords[i]))
|
||||
args[num_args++] = LLVMGetUndef(coord_type);
|
||||
else
|
||||
args[num_args++] = params->coords[i];
|
||||
}
|
||||
|
||||
if (params->sample_key & LP_SAMPLER_SHADOW)
|
||||
args[num_args++] = params->coords[4];
|
||||
|
||||
if (params->sample_key & LP_SAMPLER_FETCH_MS)
|
||||
args[num_args++] = params->ms_index;
|
||||
|
||||
if (params->sample_key & LP_SAMPLER_OFFSETS) {
|
||||
for (uint32_t i = 0; i < 3; i++) {
|
||||
if (params->offsets[i])
|
||||
args[num_args++] = params->offsets[i];
|
||||
else
|
||||
args[num_args++] = LLVMGetUndef(lp_build_int_vec_type(gallivm, params->type));
|
||||
}
|
||||
}
|
||||
|
||||
enum lp_sampler_lod_control lod_control = (params->sample_key & LP_SAMPLER_LOD_CONTROL_MASK) >> LP_SAMPLER_LOD_CONTROL_SHIFT;
|
||||
if (lod_control == LP_SAMPLER_LOD_BIAS || lod_control == LP_SAMPLER_LOD_EXPLICIT)
|
||||
args[num_args++] = params->lod;
|
||||
|
||||
if (params->type.length != lp_native_vector_width / 32)
|
||||
for (uint32_t i = 0; i < num_args; i++)
|
||||
args[i] = widen_to_simd_width(gallivm, args[i]);
|
||||
|
||||
LLVMValueRef result = LLVMBuildCall2(builder, texture_function_type, texture_function, args, num_args, "");
|
||||
|
||||
for (unsigned i = 0; i < 4; i++) {
|
||||
params->texel[i] = LLVMBuildExtractValue(gallivm->builder, result, i, "");
|
||||
|
||||
if (params->type.length != lp_native_vector_width / 32)
|
||||
params->texel[i] = truncate_to_type_width(gallivm, params->texel[i], params->type);
|
||||
|
||||
LLVMBuildStore(builder, params->texel[i], out_data[i]);
|
||||
}
|
||||
|
||||
lp_build_endif(&if_state);
|
||||
|
||||
for (unsigned i = 0; i < 4; i++)
|
||||
params->texel[i] = LLVMBuildLoad2(gallivm->builder, out_data_type, out_data[i], "");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const unsigned texture_index = params->texture_index;
|
||||
const unsigned sampler_index = params->sampler_index;
|
||||
|
||||
|
|
@ -123,6 +326,78 @@ lp_bld_llvm_sampler_soa_emit_size_query(const struct lp_build_sampler_soa *base,
|
|||
struct gallivm_state *gallivm,
|
||||
const struct lp_sampler_size_query_params *params)
|
||||
{
|
||||
LLVMBuilderRef builder = gallivm->builder;
|
||||
|
||||
if (params->resource) {
|
||||
LLVMTypeRef out_data_type = lp_build_vec_type(gallivm, params->int_type);
|
||||
|
||||
LLVMValueRef out_data[4];
|
||||
for (uint32_t i = 0; i < 4; i++) {
|
||||
out_data[i] = lp_build_alloca(gallivm, out_data_type, "");
|
||||
LLVMBuildStore(builder, lp_build_const_vec(gallivm, params->int_type, 0), out_data[i]);
|
||||
}
|
||||
|
||||
struct lp_type uint_type = lp_uint_type(params->int_type);
|
||||
LLVMValueRef uint_zero = lp_build_const_int_vec(gallivm, uint_type, 0);
|
||||
|
||||
LLVMValueRef bitmask = LLVMBuildICmp(builder, LLVMIntNE, params->exec_mask, uint_zero, "exec_bitvec");
|
||||
|
||||
LLVMTypeRef bitmask_type = LLVMIntTypeInContext(gallivm->context, uint_type.length);
|
||||
bitmask = LLVMBuildBitCast(builder, bitmask, bitmask_type, "exec_bitmask");
|
||||
|
||||
LLVMValueRef any_active = LLVMBuildICmp(builder, LLVMIntNE, bitmask, LLVMConstInt(bitmask_type, 0, false), "any_active");
|
||||
|
||||
struct lp_build_if_state if_state;
|
||||
lp_build_if(&if_state, gallivm, any_active);
|
||||
|
||||
LLVMValueRef consts = lp_jit_resources_constants(gallivm, params->resources_type, params->resources_ptr);
|
||||
|
||||
LLVMValueRef texture_descriptor = lp_llvm_descriptor_base(gallivm, consts, params->resource, LP_MAX_TGSI_CONST_BUFFERS);
|
||||
|
||||
uint32_t functions_offset = params->samples_only ? offsetof(struct lp_texture_functions, samples_function)
|
||||
: offsetof(struct lp_texture_functions, size_function);
|
||||
|
||||
LLVMValueRef texture_base_ptr = load_texture_functions_ptr(
|
||||
gallivm, texture_descriptor, offsetof(union lp_descriptor, sample_functions), functions_offset);
|
||||
|
||||
LLVMTypeRef texture_function_type = lp_build_size_function_type(gallivm, params);
|
||||
LLVMTypeRef texture_function_ptr_type = LLVMPointerType(texture_function_type, 0);
|
||||
LLVMTypeRef texture_function_ptr_ptr_type = LLVMPointerType(texture_function_ptr_type, 0);
|
||||
|
||||
texture_base_ptr = LLVMBuildIntToPtr(builder, texture_base_ptr, texture_function_ptr_ptr_type, "");
|
||||
LLVMValueRef texture_function = LLVMBuildLoad2(builder, texture_function_ptr_type, texture_base_ptr, "");
|
||||
|
||||
LLVMValueRef args[LP_MAX_TEX_FUNC_ARGS];
|
||||
uint32_t num_args = 0;
|
||||
|
||||
args[num_args++] = texture_descriptor;
|
||||
|
||||
if (!params->samples_only)
|
||||
args[num_args++] = params->explicit_lod;
|
||||
|
||||
if (params->int_type.length != lp_native_vector_width / 32)
|
||||
for (uint32_t i = 0; i < num_args; i++)
|
||||
args[i] = widen_to_simd_width(gallivm, args[i]);
|
||||
|
||||
LLVMValueRef result = LLVMBuildCall2(builder, texture_function_type, texture_function, args, num_args, "");
|
||||
|
||||
for (unsigned i = 0; i < 4; i++) {
|
||||
params->sizes_out[i] = LLVMBuildExtractValue(gallivm->builder, result, i, "");
|
||||
|
||||
if (params->int_type.length != lp_native_vector_width / 32)
|
||||
params->sizes_out[i] = truncate_to_type_width(gallivm, params->sizes_out[i], params->int_type);
|
||||
|
||||
LLVMBuildStore(builder, params->sizes_out[i], out_data[i]);
|
||||
}
|
||||
|
||||
lp_build_endif(&if_state);
|
||||
|
||||
for (unsigned i = 0; i < 4; i++)
|
||||
params->sizes_out[i] = LLVMBuildLoad2(gallivm->builder, out_data_type, out_data[i], "");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
struct lp_bld_llvm_sampler_soa *sampler = (struct lp_bld_llvm_sampler_soa *)base;
|
||||
|
||||
assert(params->texture_unit < PIPE_MAX_SHADER_SAMPLER_VIEWS);
|
||||
|
|
|
|||
|
|
@ -349,33 +349,51 @@ lp_build_llvm_texture_member(struct gallivm_state *gallivm,
|
|||
LLVMTypeRef *out_type)
|
||||
{
|
||||
LLVMBuilderRef builder = gallivm->builder;
|
||||
LLVMValueRef indices[4];
|
||||
|
||||
assert(texture_unit < PIPE_MAX_SHADER_SAMPLER_VIEWS);
|
||||
LLVMValueRef ptr;
|
||||
if (gallivm->texture_descriptor) {
|
||||
static_assert(offsetof(union lp_descriptor, texture) == 0, "Invalid texture offset!");
|
||||
LLVMValueRef texture_ptr = gallivm->texture_descriptor;
|
||||
|
||||
/* resources[0] */
|
||||
indices[0] = lp_build_const_int32(gallivm, 0);
|
||||
/* resources[0].textures */
|
||||
indices[1] = lp_build_const_int32(gallivm, LP_JIT_RES_TEXTURES);
|
||||
/* resources[0].textures[unit] */
|
||||
indices[2] = lp_build_const_int32(gallivm, texture_unit);
|
||||
if (texture_unit_offset) {
|
||||
indices[2] = LLVMBuildAdd(gallivm->builder, indices[2],
|
||||
texture_unit_offset, "");
|
||||
LLVMValueRef cond =
|
||||
LLVMBuildICmp(gallivm->builder, LLVMIntULT,
|
||||
indices[2],
|
||||
lp_build_const_int32(gallivm,
|
||||
PIPE_MAX_SHADER_SAMPLER_VIEWS), "");
|
||||
indices[2] = LLVMBuildSelect(gallivm->builder, cond, indices[2],
|
||||
lp_build_const_int32(gallivm,
|
||||
texture_unit), "");
|
||||
LLVMTypeRef texture_ptr_type = LLVMStructGetTypeAtIndex(resources_type, LP_JIT_RES_TEXTURES);
|
||||
LLVMTypeRef texture_type = LLVMGetElementType(texture_ptr_type);
|
||||
texture_ptr_type = LLVMPointerType(texture_type, 0);
|
||||
|
||||
texture_ptr = LLVMBuildIntToPtr(builder, texture_ptr, texture_ptr_type, "");
|
||||
|
||||
LLVMValueRef indices[2] = {
|
||||
lp_build_const_int32(gallivm, 0),
|
||||
lp_build_const_int32(gallivm, member_index),
|
||||
};
|
||||
ptr = LLVMBuildGEP2(builder, texture_type, texture_ptr, indices, ARRAY_SIZE(indices), "");
|
||||
} else {
|
||||
LLVMValueRef indices[4];
|
||||
|
||||
assert(texture_unit < PIPE_MAX_SHADER_SAMPLER_VIEWS);
|
||||
|
||||
/* resources[0] */
|
||||
indices[0] = lp_build_const_int32(gallivm, 0);
|
||||
/* resources[0].textures */
|
||||
indices[1] = lp_build_const_int32(gallivm, LP_JIT_RES_TEXTURES);
|
||||
/* resources[0].textures[unit] */
|
||||
indices[2] = lp_build_const_int32(gallivm, texture_unit);
|
||||
if (texture_unit_offset) {
|
||||
indices[2] = LLVMBuildAdd(gallivm->builder, indices[2],
|
||||
texture_unit_offset, "");
|
||||
LLVMValueRef cond =
|
||||
LLVMBuildICmp(gallivm->builder, LLVMIntULT,
|
||||
indices[2],
|
||||
lp_build_const_int32(gallivm,
|
||||
PIPE_MAX_SHADER_SAMPLER_VIEWS), "");
|
||||
indices[2] = LLVMBuildSelect(gallivm->builder, cond, indices[2],
|
||||
lp_build_const_int32(gallivm,
|
||||
texture_unit), "");
|
||||
}
|
||||
/* resources[0].textures[unit].member */
|
||||
indices[3] = lp_build_const_int32(gallivm, member_index);
|
||||
|
||||
ptr = LLVMBuildGEP2(builder, resources_type, resources_ptr, indices, ARRAY_SIZE(indices), "");
|
||||
}
|
||||
/* resources[0].textures[unit].member */
|
||||
indices[3] = lp_build_const_int32(gallivm, member_index);
|
||||
|
||||
LLVMValueRef ptr =
|
||||
LLVMBuildGEP2(builder, resources_type, resources_ptr, indices, ARRAY_SIZE(indices), "");
|
||||
|
||||
LLVMValueRef res;
|
||||
if (emit_load) {
|
||||
|
|
@ -463,21 +481,39 @@ lp_build_llvm_sampler_member(struct gallivm_state *gallivm,
|
|||
bool emit_load)
|
||||
{
|
||||
LLVMBuilderRef builder = gallivm->builder;
|
||||
LLVMValueRef indices[4];
|
||||
|
||||
assert(sampler_unit < PIPE_MAX_SAMPLERS);
|
||||
LLVMValueRef ptr;
|
||||
if (gallivm->sampler_descriptor) {
|
||||
LLVMValueRef sampler_offset = lp_build_const_int64(gallivm, offsetof(union lp_descriptor, sampler));
|
||||
LLVMValueRef sampler_ptr = LLVMBuildAdd(builder, gallivm->sampler_descriptor, sampler_offset, "");
|
||||
|
||||
/* resources[0] */
|
||||
indices[0] = lp_build_const_int32(gallivm, 0);
|
||||
/* resources[0].samplers */
|
||||
indices[1] = lp_build_const_int32(gallivm, LP_JIT_RES_SAMPLERS);
|
||||
/* resources[0].samplers[unit] */
|
||||
indices[2] = lp_build_const_int32(gallivm, sampler_unit);
|
||||
/* resources[0].samplers[unit].member */
|
||||
indices[3] = lp_build_const_int32(gallivm, member_index);
|
||||
LLVMTypeRef sampler_ptr_type = LLVMStructGetTypeAtIndex(resources_type, LP_JIT_RES_SAMPLERS);
|
||||
LLVMTypeRef sampler_type = LLVMGetElementType(sampler_ptr_type);
|
||||
sampler_ptr_type = LLVMPointerType(sampler_type, 0);
|
||||
|
||||
LLVMValueRef ptr =
|
||||
LLVMBuildGEP2(builder, resources_type, resources_ptr, indices, ARRAY_SIZE(indices), "");
|
||||
sampler_ptr = LLVMBuildIntToPtr(builder, sampler_ptr, sampler_ptr_type, "");
|
||||
|
||||
LLVMValueRef indices[2] = {
|
||||
lp_build_const_int32(gallivm, 0),
|
||||
lp_build_const_int32(gallivm, member_index),
|
||||
};
|
||||
ptr = LLVMBuildGEP2(builder, sampler_type, sampler_ptr, indices, ARRAY_SIZE(indices), "");
|
||||
} else {
|
||||
LLVMValueRef indices[4];
|
||||
|
||||
assert(sampler_unit < PIPE_MAX_SAMPLERS);
|
||||
|
||||
/* resources[0] */
|
||||
indices[0] = lp_build_const_int32(gallivm, 0);
|
||||
/* resources[0].samplers */
|
||||
indices[1] = lp_build_const_int32(gallivm, LP_JIT_RES_SAMPLERS);
|
||||
/* resources[0].samplers[unit] */
|
||||
indices[2] = lp_build_const_int32(gallivm, sampler_unit);
|
||||
/* resources[0].samplers[unit].member */
|
||||
indices[3] = lp_build_const_int32(gallivm, member_index);
|
||||
|
||||
ptr = LLVMBuildGEP2(builder, resources_type, resources_ptr, indices, ARRAY_SIZE(indices), "");
|
||||
}
|
||||
|
||||
LLVMValueRef res;
|
||||
if (emit_load) {
|
||||
|
|
|
|||
|
|
@ -2293,6 +2293,7 @@ visit_txs(struct lp_build_nir_context *bld_base, nir_tex_instr *instr)
|
|||
LLVMValueRef sizes_out[NIR_MAX_VEC_COMPONENTS];
|
||||
LLVMValueRef explicit_lod = NULL;
|
||||
LLVMValueRef texture_unit_offset = NULL;
|
||||
LLVMValueRef resource = NULL;
|
||||
|
||||
for (unsigned i = 0; i < instr->num_srcs; i++) {
|
||||
switch (instr->src[i].src_type) {
|
||||
|
|
@ -2304,6 +2305,9 @@ visit_txs(struct lp_build_nir_context *bld_base, nir_tex_instr *instr)
|
|||
case nir_tex_src_texture_offset:
|
||||
texture_unit_offset = get_src(bld_base, instr->src[i].src);
|
||||
break;
|
||||
case nir_tex_src_texture_handle:
|
||||
resource = get_src(bld_base, instr->src[i].src);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
@ -2319,6 +2323,9 @@ visit_txs(struct lp_build_nir_context *bld_base, nir_tex_instr *instr)
|
|||
|
||||
if (instr->op == nir_texop_query_levels)
|
||||
params.explicit_lod = bld_base->uint_bld.zero;
|
||||
|
||||
params.resource = resource;
|
||||
|
||||
bld_base->tex_size(bld_base, ¶ms);
|
||||
assign_dest(bld_base, &instr->dest,
|
||||
&sizes_out[instr->op == nir_texop_query_levels ? 3 : 0]);
|
||||
|
|
@ -2434,6 +2441,9 @@ visit_tex(struct lp_build_nir_context *bld_base, nir_tex_instr *instr)
|
|||
LLVMValueRef coord_undef = LLVMGetUndef(bld_base->base.vec_type);
|
||||
unsigned coord_vals = is_aos(bld_base) ? 1 : instr->coord_components;
|
||||
|
||||
LLVMValueRef texture_resource = NULL;
|
||||
LLVMValueRef sampler_resource = NULL;
|
||||
|
||||
for (unsigned i = 0; i < instr->num_srcs; i++) {
|
||||
switch (instr->src[i].src_type) {
|
||||
case nir_tex_src_coord: {
|
||||
|
|
@ -2524,6 +2534,12 @@ visit_tex(struct lp_build_nir_context *bld_base, nir_tex_instr *instr)
|
|||
break;
|
||||
case nir_tex_src_sampler_offset:
|
||||
break;
|
||||
case nir_tex_src_texture_handle:
|
||||
texture_resource = get_src(bld_base, instr->src[i].src);
|
||||
break;
|
||||
case nir_tex_src_sampler_handle:
|
||||
sampler_resource = get_src(bld_base, instr->src[i].src);
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
break;
|
||||
|
|
@ -2532,6 +2548,9 @@ visit_tex(struct lp_build_nir_context *bld_base, nir_tex_instr *instr)
|
|||
if (!sampler_deref_instr)
|
||||
sampler_deref_instr = texture_deref_instr;
|
||||
|
||||
if (!sampler_resource)
|
||||
sampler_resource = texture_resource;
|
||||
|
||||
switch (instr->op) {
|
||||
case nir_texop_tex:
|
||||
case nir_texop_tg4:
|
||||
|
|
@ -2584,6 +2603,8 @@ visit_tex(struct lp_build_nir_context *bld_base, nir_tex_instr *instr)
|
|||
params.lod = explicit_lod;
|
||||
params.ms_index = ms_index;
|
||||
params.aniso_filter_table = bld_base->aniso_filter_table;
|
||||
params.texture_resource = texture_resource;
|
||||
params.sampler_resource = sampler_resource;
|
||||
bld_base->tex(bld_base, ¶ms);
|
||||
|
||||
if (nir_dest_bit_size(instr->dest) != 32) {
|
||||
|
|
|
|||
|
|
@ -1786,6 +1786,7 @@ static void emit_tex(struct lp_build_nir_context *bld_base,
|
|||
params->resources_ptr = bld->resources_ptr;
|
||||
params->thread_data_type = bld->thread_data_type;
|
||||
params->thread_data_ptr = bld->thread_data_ptr;
|
||||
params->exec_mask = mask_vec(bld_base);
|
||||
|
||||
if (params->texture_index_offset && bld_base->shader->info.stage != MESA_SHADER_FRAGMENT) {
|
||||
/* this is horrible but this can be dynamic */
|
||||
|
|
@ -1858,6 +1859,11 @@ static void emit_tex_size(struct lp_build_nir_context *bld_base,
|
|||
params->texture_unit_offset = LLVMBuildExtractElement(bld_base->base.gallivm->builder,
|
||||
params->texture_unit_offset,
|
||||
lp_build_const_int32(bld_base->base.gallivm, 0), "");
|
||||
|
||||
params->exec_mask = mask_vec(bld_base);
|
||||
if (params->resource)
|
||||
params->resource = build_resource_to_scalar(bld_base, params->resource);
|
||||
|
||||
bld->sampler->emit_size_query(bld->sampler,
|
||||
bld->bld_base.base.gallivm,
|
||||
params);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue