break;
case SpvOpImageQuerySamples:
+ texop = nir_texop_texture_samples;
+ break;
+
default:
unreachable("Unhandled opcode");
}
unsigned idx = 4;
- bool has_coord = false;
+ struct nir_ssa_def *coord;
+ unsigned coord_components;
switch (opcode) {
case SpvOpImageSampleImplicitLod:
case SpvOpImageSampleExplicitLod:
case SpvOpImageDrefGather:
case SpvOpImageQueryLod: {
/* All these types have the coordinate as their first real argument */
- struct vtn_ssa_value *coord = vtn_ssa_value(b, w[idx++]);
- has_coord = true;
- p->src = nir_src_for_ssa(coord->def);
+ switch (sampler_dim) {
+ case GLSL_SAMPLER_DIM_1D:
+ case GLSL_SAMPLER_DIM_BUF:
+ coord_components = 1;
+ break;
+ case GLSL_SAMPLER_DIM_2D:
+ case GLSL_SAMPLER_DIM_RECT:
+ case GLSL_SAMPLER_DIM_MS:
+ coord_components = 2;
+ break;
+ case GLSL_SAMPLER_DIM_3D:
+ case GLSL_SAMPLER_DIM_CUBE:
+ coord_components = 3;
+ break;
+ default:
+ unreachable("Invalid sampler type");
+ }
+
+ if (is_array && texop != nir_texop_lod)
+ coord_components++;
+
+ coord = vtn_ssa_value(b, w[idx++])->def;
+ p->src = nir_src_for_ssa(coord);
p->src_type = nir_tex_src_coord;
p++;
break;
}
+ default:
+ coord = NULL;
+ coord_components = 0;
+ break;
+ }
+
+ switch (opcode) {
+ case SpvOpImageSampleProjImplicitLod:
+ case SpvOpImageSampleProjExplicitLod:
+ case SpvOpImageSampleProjDrefImplicitLod:
+ case SpvOpImageSampleProjDrefExplicitLod:
+ /* These have the projector as the last coordinate component */
+ p->src = nir_src_for_ssa(nir_channel(&b->nb, coord, coord_components));
+ p->src_type = nir_tex_src_projector;
+ p++;
+ break;
+
default:
break;
}
memcpy(instr->src, srcs, instr->num_srcs * sizeof(*instr->src));
+ instr->coord_components = coord_components;
instr->sampler_dim = sampler_dim;
instr->is_array = is_array;
instr->is_shadow = is_shadow;
is_shadow && glsl_get_components(ret_type->type) == 1;
instr->component = gather_component;
- if (has_coord) {
- switch (instr->sampler_dim) {
- case GLSL_SAMPLER_DIM_1D:
- case GLSL_SAMPLER_DIM_BUF:
- instr->coord_components = 1;
- break;
- case GLSL_SAMPLER_DIM_2D:
- case GLSL_SAMPLER_DIM_RECT:
- case GLSL_SAMPLER_DIM_MS:
- instr->coord_components = 2;
- break;
- case GLSL_SAMPLER_DIM_3D:
- case GLSL_SAMPLER_DIM_CUBE:
- instr->coord_components = 3;
- break;
- default:
- assert("Invalid sampler type");
- }
-
- if (instr->is_array && instr->op != nir_texop_lod)
- instr->coord_components++;
- } else {
- instr->coord_components = 0;
- }
-
switch (glsl_get_sampler_result_type(image_type)) {
case GLSL_TYPE_FLOAT: instr->dest_type = nir_type_float; break;
case GLSL_TYPE_INT: instr->dest_type = nir_type_int; break;
nir_builder_instr_insert(&b->nb, &instr->instr);
}
+static void
+fill_common_atomic_sources(struct vtn_builder *b, SpvOp opcode,
+ const uint32_t *w, nir_src *src)
+{
+ switch (opcode) {
+ case SpvOpAtomicIIncrement:
+ src[0] = nir_src_for_ssa(nir_imm_int(&b->nb, 1));
+ break;
+
+ case SpvOpAtomicIDecrement:
+ src[0] = nir_src_for_ssa(nir_imm_int(&b->nb, -1));
+ break;
+
+ case SpvOpAtomicISub:
+ src[0] =
+ nir_src_for_ssa(nir_ineg(&b->nb, vtn_ssa_value(b, w[6])->def));
+ break;
+
+ case SpvOpAtomicCompareExchange:
+ src[0] = nir_src_for_ssa(vtn_ssa_value(b, w[8])->def);
+ src[1] = nir_src_for_ssa(vtn_ssa_value(b, w[7])->def);
+ break;
+ /* Fall through */
+
+ case SpvOpAtomicExchange:
+ case SpvOpAtomicIAdd:
+ case SpvOpAtomicSMin:
+ case SpvOpAtomicUMin:
+ case SpvOpAtomicSMax:
+ case SpvOpAtomicUMax:
+ case SpvOpAtomicAnd:
+ case SpvOpAtomicOr:
+ case SpvOpAtomicXor:
+ src[0] = nir_src_for_ssa(vtn_ssa_value(b, w[6])->def);
+ break;
+
+ default:
+ unreachable("Invalid SPIR-V atomic");
+ }
+}
+
static nir_ssa_def *
get_image_coord(struct vtn_builder *b, uint32_t value)
{
image = *vtn_value(b, w[3], vtn_value_type_image_pointer)->image;
break;
+ case SpvOpAtomicLoad: {
+ image.image =
+ vtn_value(b, w[3], vtn_value_type_access_chain)->access_chain;
+ break;
+ }
+
+ case SpvOpAtomicStore: {
+ image.image =
+ vtn_value(b, w[1], vtn_value_type_access_chain)->access_chain;
+ break;
+ }
+
case SpvOpImageQuerySize:
image.image =
vtn_value(b, w[3], vtn_value_type_access_chain)->access_chain;
OP(ImageQuerySize, size)
OP(ImageRead, load)
OP(ImageWrite, store)
+ OP(AtomicLoad, load)
+ OP(AtomicStore, store)
OP(AtomicExchange, atomic_exchange)
OP(AtomicCompareExchange, atomic_comp_swap)
OP(AtomicIIncrement, atomic_add)
}
switch (opcode) {
+ case SpvOpAtomicLoad:
case SpvOpImageQuerySize:
case SpvOpImageRead:
break;
+ case SpvOpAtomicStore:
+ intrin->src[2] = nir_src_for_ssa(vtn_ssa_value(b, w[4])->def);
+ break;
case SpvOpImageWrite:
intrin->src[2] = nir_src_for_ssa(vtn_ssa_value(b, w[3])->def);
break;
+
case SpvOpAtomicIIncrement:
- intrin->src[2] = nir_src_for_ssa(nir_imm_int(&b->nb, 1));
- break;
case SpvOpAtomicIDecrement:
- intrin->src[2] = nir_src_for_ssa(nir_imm_int(&b->nb, -1));
- break;
-
case SpvOpAtomicExchange:
case SpvOpAtomicIAdd:
case SpvOpAtomicSMin:
case SpvOpAtomicAnd:
case SpvOpAtomicOr:
case SpvOpAtomicXor:
- intrin->src[2] = nir_src_for_ssa(vtn_ssa_value(b, w[6])->def);
- break;
-
- case SpvOpAtomicCompareExchange:
- intrin->src[2] = nir_src_for_ssa(vtn_ssa_value(b, w[7])->def);
- intrin->src[3] = nir_src_for_ssa(vtn_ssa_value(b, w[6])->def);
- break;
-
- case SpvOpAtomicISub:
- intrin->src[2] = nir_src_for_ssa(nir_ineg(&b->nb, vtn_ssa_value(b, w[6])->def));
+ fill_common_atomic_sources(b, opcode, w, &intrin->src[2]);
break;
default:
get_ssbo_nir_atomic_op(SpvOp opcode)
{
switch (opcode) {
+ case SpvOpAtomicLoad: return nir_intrinsic_load_ssbo;
+ case SpvOpAtomicStore: return nir_intrinsic_store_ssbo;
#define OP(S, N) case SpvOp##S: return nir_intrinsic_ssbo_##N;
OP(AtomicExchange, atomic_exchange)
OP(AtomicCompareExchange, atomic_comp_swap)
get_shared_nir_atomic_op(SpvOp opcode)
{
switch (opcode) {
+ case SpvOpAtomicLoad: return nir_intrinsic_load_var;
+ case SpvOpAtomicStore: return nir_intrinsic_store_var;
#define OP(S, N) case SpvOp##S: return nir_intrinsic_var_##N;
OP(AtomicExchange, atomic_exchange)
OP(AtomicCompareExchange, atomic_comp_swap)
}
static void
-fill_common_atomic_sources(struct vtn_builder *b, SpvOp opcode,
- const uint32_t *w, nir_src *src)
+vtn_handle_ssbo_or_shared_atomic(struct vtn_builder *b, SpvOp opcode,
+ const uint32_t *w, unsigned count)
{
+ struct vtn_access_chain *chain;
+ nir_intrinsic_instr *atomic;
+
switch (opcode) {
+ case SpvOpAtomicLoad:
+ case SpvOpAtomicExchange:
+ case SpvOpAtomicCompareExchange:
+ case SpvOpAtomicCompareExchangeWeak:
case SpvOpAtomicIIncrement:
- src[0] = nir_src_for_ssa(nir_imm_int(&b->nb, 1));
- break;
-
case SpvOpAtomicIDecrement:
- src[0] = nir_src_for_ssa(nir_imm_int(&b->nb, -1));
- break;
-
- case SpvOpAtomicISub:
- src[0] =
- nir_src_for_ssa(nir_ineg(&b->nb, vtn_ssa_value(b, w[6])->def));
- break;
-
- case SpvOpAtomicCompareExchange:
- src[0] = nir_src_for_ssa(vtn_ssa_value(b, w[7])->def);
- src[1] = nir_src_for_ssa(vtn_ssa_value(b, w[8])->def);
- break;
- /* Fall through */
-
- case SpvOpAtomicExchange:
case SpvOpAtomicIAdd:
+ case SpvOpAtomicISub:
case SpvOpAtomicSMin:
case SpvOpAtomicUMin:
case SpvOpAtomicSMax:
case SpvOpAtomicAnd:
case SpvOpAtomicOr:
case SpvOpAtomicXor:
- src[0] = nir_src_for_ssa(vtn_ssa_value(b, w[6])->def);
+ chain =
+ vtn_value(b, w[3], vtn_value_type_access_chain)->access_chain;
+ break;
+
+ case SpvOpAtomicStore:
+ chain =
+ vtn_value(b, w[1], vtn_value_type_access_chain)->access_chain;
break;
default:
unreachable("Invalid SPIR-V atomic");
}
-}
-
-static void
-vtn_handle_ssbo_or_shared_atomic(struct vtn_builder *b, SpvOp opcode,
- const uint32_t *w, unsigned count)
-{
- struct vtn_access_chain *chain =
- vtn_value(b, w[3], vtn_value_type_access_chain)->access_chain;
- nir_intrinsic_instr *atomic;
/*
SpvScope scope = w[4];
nir_intrinsic_op op = get_ssbo_nir_atomic_op(opcode);
atomic = nir_intrinsic_instr_create(b->nb.shader, op);
- atomic->src[0] = nir_src_for_ssa(index);
- atomic->src[1] = nir_src_for_ssa(offset);
- fill_common_atomic_sources(b, opcode, w, &atomic->src[2]);
+
+ switch (opcode) {
+ case SpvOpAtomicLoad:
+ atomic->num_components = glsl_get_vector_elements(type->type);
+ atomic->src[0] = nir_src_for_ssa(index);
+ atomic->src[1] = nir_src_for_ssa(offset);
+ break;
+
+ case SpvOpAtomicStore:
+ atomic->num_components = glsl_get_vector_elements(type->type);
+ nir_intrinsic_set_write_mask(atomic, (1 << atomic->num_components) - 1);
+ atomic->src[0] = nir_src_for_ssa(vtn_ssa_value(b, w[4])->def);
+ atomic->src[1] = nir_src_for_ssa(index);
+ atomic->src[2] = nir_src_for_ssa(offset);
+ break;
+
+ case SpvOpAtomicExchange:
+ case SpvOpAtomicCompareExchange:
+ case SpvOpAtomicCompareExchangeWeak:
+ case SpvOpAtomicIIncrement:
+ case SpvOpAtomicIDecrement:
+ case SpvOpAtomicIAdd:
+ case SpvOpAtomicISub:
+ case SpvOpAtomicSMin:
+ case SpvOpAtomicUMin:
+ case SpvOpAtomicSMax:
+ case SpvOpAtomicUMax:
+ case SpvOpAtomicAnd:
+ case SpvOpAtomicOr:
+ case SpvOpAtomicXor:
+ atomic->src[0] = nir_src_for_ssa(index);
+ atomic->src[1] = nir_src_for_ssa(offset);
+ fill_common_atomic_sources(b, opcode, w, &atomic->src[2]);
+ break;
+
+ default:
+ unreachable("Invalid SPIR-V atomic");
+ }
}
- nir_ssa_dest_init(&atomic->instr, &atomic->dest, 1, 32, NULL);
+ if (opcode != SpvOpAtomicStore) {
+ struct vtn_type *type = vtn_value(b, w[1], vtn_value_type_type)->type;
- struct vtn_type *type = vtn_value(b, w[1], vtn_value_type_type)->type;
- struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_ssa);
- val->ssa = rzalloc(b, struct vtn_ssa_value);
- val->ssa->def = &atomic->dest.ssa;
- val->ssa->type = type->type;
+ nir_ssa_dest_init(&atomic->instr, &atomic->dest,
+ glsl_get_vector_elements(type->type),
+ glsl_get_bit_size(type->type), NULL);
+
+ struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_ssa);
+ val->ssa = rzalloc(b, struct vtn_ssa_value);
+ val->ssa->def = &atomic->dest.ssa;
+ val->ssa->type = type->type;
+ }
nir_builder_instr_insert(&b->nb, &atomic->instr);
}
break;
}
+ case SpvOpAtomicLoad:
case SpvOpAtomicExchange:
case SpvOpAtomicCompareExchange:
case SpvOpAtomicCompareExchangeWeak:
break;
}
+ case SpvOpAtomicStore: {
+ struct vtn_value *pointer = vtn_untyped_value(b, w[1]);
+ if (pointer->value_type == vtn_value_type_image_pointer) {
+ vtn_handle_image(b, opcode, w, count);
+ } else {
+ assert(pointer->value_type == vtn_value_type_access_chain);
+ vtn_handle_ssbo_or_shared_atomic(b, opcode, w, count);
+ }
+ break;
+ }
+
case SpvOpSNegate:
case SpvOpFNegate:
case SpvOpNot: