Commit 265fae06 authored by Jesse Natalie's avatar Jesse Natalie Committed by Erik Faye-Lund

Rework constant samplers to use nir_variable::data instead of constant_initializer

parent 0c3ea157
......@@ -544,6 +544,16 @@ typedef struct nir_variable {
enum pipe_format format;
} image;
struct {
/**
* For OpenCL inline samplers. See cl_sampler_addressing_mode and cl_sampler_filter_mode
*/
unsigned is_inline_sampler : 1;
unsigned addressing_mode : 3;
unsigned normalized_coordinates : 1;
unsigned filter_mode : 1;
} sampler;
struct {
/**
* Transform feedback buffer.
......
......@@ -440,13 +440,6 @@ print_constant(nir_constant *c, const struct glsl_type *type, print_state *state
}
break;
case GLSL_TYPE_SAMPLER:
fprintf(fp, "%s, %s, %s",
get_constant_sampler_addressing_mode(c->values[0].u32),
c->values[1].u32 ? "true" : "false",
get_constant_sampler_filter_mode(c->values[2].u32));
break;
default:
unreachable("not reached");
}
......@@ -603,6 +596,12 @@ print_var_decl(nir_variable *var, print_state *state)
print_constant(var->constant_initializer, var->type, state);
fprintf(fp, " }");
}
if (glsl_type_is_sampler(var->type) && var->data.sampler.is_inline_sampler) {
fprintf(fp, " = { %s, %s, %s }",
get_constant_sampler_addressing_mode(var->data.sampler.addressing_mode),
var->data.sampler.normalized_coordinates ? "true" : "false",
get_constant_sampler_filter_mode(var->data.sampler.filter_mode));
}
if (var->pointer_initializer)
fprintf(fp, " = &%s", get_var_name(var->pointer_initializer, state));
......
......@@ -2636,12 +2636,14 @@ vtn_handle_variables(struct vtn_builder *b, SpvOp opcode,
ptr_type->type = nir_address_format_to_glsl_type(
vtn_mode_to_address_format(b, vtn_variable_mode_function));
nir_constant *sampler_constant = rzalloc(b, nir_constant);
sampler_constant->values[0].u32 = w[3]; /*Addressing mode*/
sampler_constant->values[1].u32 = w[4]; /*Normalized coordinates*/
sampler_constant->values[2].u32 = w[5]; /*Filter mode*/
vtn_create_variable(b, val, ptr_type, ptr_type->storage_class, NULL, NULL);
nir_variable *nir_var = val->pointer->var->var;
nir_var->data.sampler.is_inline_sampler = true;
nir_var->data.sampler.addressing_mode = w[3];
nir_var->data.sampler.normalized_coordinates = w[4];
nir_var->data.sampler.filter_mode = w[5];
vtn_create_variable(b, val, ptr_type, ptr_type->storage_class, sampler_constant, NULL);
break;
}
......
......@@ -1388,17 +1388,23 @@ clc_to_dxil(struct clc_context *ctx,
// Assign bindings for constant samplers
nir_foreach_variable_safe(var, &nir->uniforms) {
if (glsl_type_is_sampler(var->type) &&
var->constant_initializer) {
if (glsl_type_is_sampler(var->type) && var->data.sampler.is_inline_sampler) {
int_sampler_states[sampler_id].wrap[0] =
int_sampler_states[sampler_id].wrap[0] =
int_sampler_states[sampler_id].wrap[0] =
wrap_from_cl_addressing(var->constant_initializer->values[0].u32);
wrap_from_cl_addressing(var->data.sampler.addressing_mode);
int_sampler_states[sampler_id].is_nonnormalized_coords =
!var->constant_initializer->values[1].u32;
!var->data.sampler.normalized_coordinates;
int_sampler_states[sampler_id].is_linear_filtering =
var->constant_initializer->values[2].u32 == SAMPLER_FILTER_MODE_LINEAR;
var->data.sampler.filter_mode == SAMPLER_FILTER_MODE_LINEAR;
var->data.binding = sampler_id++;
assert(metadata->num_const_samplers < CLC_MAX_SAMPLERS);
metadata->const_samplers[metadata->num_const_samplers].sampler_id = var->data.binding;
metadata->const_samplers[metadata->num_const_samplers].addressing_mode = var->data.sampler.addressing_mode;
metadata->const_samplers[metadata->num_const_samplers].normalized_coords = var->data.sampler.normalized_coordinates;
metadata->const_samplers[metadata->num_const_samplers].filter_mode = var->data.sampler.filter_mode;
metadata->num_const_samplers++;
}
}
......@@ -1574,15 +1580,6 @@ clc_to_dxil(struct clc_context *ctx,
metadata->num_consts++;
} else
unreachable("unexpected constant initializer");
} else if (var->data.mode == nir_var_uniform &&
glsl_type_is_sampler(var->type) &&
var->constant_initializer) {
assert(metadata->num_const_samplers < CLC_MAX_SAMPLERS);
metadata->const_samplers[metadata->num_const_samplers].sampler_id = var->data.binding;
metadata->const_samplers[metadata->num_const_samplers].addressing_mode = var->constant_initializer->values[0].u32;
metadata->const_samplers[metadata->num_const_samplers].normalized_coords = var->constant_initializer->values[1].u32;
metadata->const_samplers[metadata->num_const_samplers].filter_mode = var->constant_initializer->values[2].u32;
metadata->num_const_samplers++;
}
}
......
......@@ -360,18 +360,11 @@ static nir_variable *
find_identical_const_sampler(nir_shader *nir, nir_variable *sampler)
{
nir_foreach_variable(uniform, &nir->uniforms) {
if (!glsl_type_is_sampler(uniform->type) || !uniform->constant_initializer)
if (!glsl_type_is_sampler(uniform->type) || !uniform->data.sampler.is_inline_sampler)
continue;
bool match = true;
for (int i = 0; i < 3; ++i) {
if (uniform->constant_initializer->values[i].u32 !=
sampler->constant_initializer->values[i].u32) {
match = false;
break;
}
}
if (match)
if (uniform->data.sampler.addressing_mode == sampler->data.sampler.addressing_mode &&
uniform->data.sampler.normalized_coordinates == sampler->data.sampler.normalized_coordinates &&
uniform->data.sampler.filter_mode == sampler->data.sampler.filter_mode)
return uniform;
}
unreachable("Should have at least found the input sampler");
......@@ -404,9 +397,9 @@ clc_nir_dedupe_const_samplers(nir_shader *nir)
continue;
assert(sampler->data.mode == nir_var_shader_in ||
(sampler->data.mode == nir_var_uniform && sampler->constant_initializer));
(sampler->data.mode == nir_var_uniform && sampler->data.sampler.is_inline_sampler));
if (!sampler->constant_initializer)
if (!sampler->data.sampler.is_inline_sampler)
continue;
nir_variable *replacement = find_identical_const_sampler(nir, sampler);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment