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.
return name;
}
+static const char *
+get_constant_sampler_addressing_mode(enum cl_sampler_addressing_mode mode)
+{
+ switch (mode) {
+ case SAMPLER_ADDRESSING_MODE_NONE: return "none";
+ case SAMPLER_ADDRESSING_MODE_CLAMP_TO_EDGE: return "clamp_to_edge";
+ case SAMPLER_ADDRESSING_MODE_CLAMP: return "clamp";
+ case SAMPLER_ADDRESSING_MODE_REPEAT: return "repeat";
+ case SAMPLER_ADDRESSING_MODE_REPEAT_MIRRORED: return "repeat_mirrored";
+ default: unreachable("Invalid addressing mode");
+ }
+}
+
+static const char *
+get_constant_sampler_filter_mode(enum cl_sampler_filter_mode mode)
+{
+ switch (mode) {
+ case SAMPLER_FILTER_MODE_NEAREST: return "nearest";
+ case SAMPLER_FILTER_MODE_LINEAR: return "linear";
+ default: unreachable("Invalid filter mode");
+ }
+}
+
static void
print_constant(nir_constant *c, const struct glsl_type *type, 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));
FLOAT_CONTROLS_ROUNDING_MODE_RTZ_FP64 = 0x4000,
};
+/**
+* Enums to describe sampler properties used by OpenCL's inline constant samplers.
+* These values match the meanings described in the SPIR-V spec.
+*/
+enum cl_sampler_addressing_mode {
+ SAMPLER_ADDRESSING_MODE_NONE = 0,
+ SAMPLER_ADDRESSING_MODE_CLAMP_TO_EDGE = 1,
+ SAMPLER_ADDRESSING_MODE_CLAMP = 2,
+ SAMPLER_ADDRESSING_MODE_REPEAT = 3,
+ SAMPLER_ADDRESSING_MODE_REPEAT_MIRRORED = 4,
+};
+
+enum cl_sampler_filter_mode {
+ SAMPLER_FILTER_MODE_NEAREST = 0,
+ SAMPLER_FILTER_MODE_LINEAR = 1,
+};
+
#ifdef __cplusplus
} /* extern "C" */
#endif
bool integer_functions2;
bool kernel;
bool kernel_image;
+ bool literal_sampler;
bool min_lod;
bool multiview;
bool physical_storage_buffer_address;
val->constant = vtn_null_constant(b, val->type);
break;
- case SpvOpConstantSampler:
- vtn_fail("OpConstantSampler requires Kernel Capability");
- break;
-
default:
vtn_fail_with_opcode("Unhandled opcode", opcode);
}
spv_check_supported(kernel_image, cap);
break;
+ case SpvCapabilityLiteralSampler:
+ spv_check_supported(literal_sampler, cap);
+ break;
+
case SpvCapabilityImageReadWrite:
case SpvCapabilityImageMipmap:
case SpvCapabilityPipes:
case SpvCapabilityDeviceEnqueue:
- case SpvCapabilityLiteralSampler:
case SpvCapabilityGenericPointer:
vtn_warn("Unsupported OpenCL-style SPIR-V capability: %s",
spirv_capability_to_string(cap));
case SpvOpConstantFalse:
case SpvOpConstant:
case SpvOpConstantComposite:
- case SpvOpConstantSampler:
case SpvOpConstantNull:
case SpvOpSpecConstantTrue:
case SpvOpSpecConstantFalse:
case SpvOpUndef:
case SpvOpVariable:
+ case SpvOpConstantSampler:
vtn_handle_variables(b, opcode, w, count);
break;
break;
}
+ case SpvOpConstantSampler: {
+ /* Synthesize a pointer-to-sampler type, create a variable of that type,
+ * and give the variable a constant initializer with the sampler params */
+ struct vtn_type *sampler_type = vtn_value(b, w[1], vtn_value_type_type)->type;
+ struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_pointer);
+
+ struct vtn_type *ptr_type = rzalloc(b, struct vtn_type);
+ ptr_type = rzalloc(b, struct vtn_type);
+ ptr_type->base_type = vtn_base_type_pointer;
+ ptr_type->deref = sampler_type;
+ ptr_type->storage_class = SpvStorageClassUniform;
+
+ ptr_type->type = nir_address_format_to_glsl_type(
+ vtn_mode_to_address_format(b, vtn_variable_mode_function));
+
+ 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];
+
+ break;
+ }
+
case SpvOpAccessChain:
case SpvOpPtrAccessChain:
case SpvOpInBoundsAccessChain: