2015-04-29 01:43:16 +01:00
|
|
|
/*
|
|
|
|
* Copyright © 2015 Intel Corporation
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
* Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
|
|
* IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Jason Ekstrand (jason@jlekstrand.net)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2015-12-28 19:49:33 +00:00
|
|
|
#include "vtn_private.h"
|
|
|
|
#include "nir/nir_vla.h"
|
|
|
|
#include "nir/nir_control_flow.h"
|
2016-01-13 04:02:04 +00:00
|
|
|
#include "nir/nir_constant_expressions.h"
|
2016-06-02 22:32:56 +01:00
|
|
|
#include "spirv_info.h"
|
|
|
|
|
|
|
|
void
|
|
|
|
_vtn_warn(const char *file, int line, const char *msg, ...)
|
|
|
|
{
|
|
|
|
char *formatted;
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, msg);
|
|
|
|
formatted = ralloc_vasprintf(NULL, msg, args);
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
fprintf(stderr, "%s:%d WARNING: %s\n", file, line, formatted);
|
|
|
|
|
|
|
|
ralloc_free(formatted);
|
|
|
|
}
|
2015-04-29 01:43:16 +01:00
|
|
|
|
2015-12-23 22:14:39 +00:00
|
|
|
static struct vtn_ssa_value *
|
|
|
|
vtn_undef_ssa_value(struct vtn_builder *b, const struct glsl_type *type)
|
|
|
|
{
|
|
|
|
struct vtn_ssa_value *val = rzalloc(b, struct vtn_ssa_value);
|
|
|
|
val->type = type;
|
|
|
|
|
|
|
|
if (glsl_type_is_vector_or_scalar(type)) {
|
|
|
|
unsigned num_components = glsl_get_vector_elements(val->type);
|
2016-05-11 20:05:09 +01:00
|
|
|
unsigned bit_size = glsl_get_bit_size(val->type);
|
2016-03-25 17:40:45 +00:00
|
|
|
val->def = nir_ssa_undef(&b->nb, num_components, bit_size);
|
2015-12-23 22:14:39 +00:00
|
|
|
} else {
|
|
|
|
unsigned elems = glsl_get_length(val->type);
|
|
|
|
val->elems = ralloc_array(b, struct vtn_ssa_value *, elems);
|
|
|
|
if (glsl_type_is_matrix(type)) {
|
|
|
|
const struct glsl_type *elem_type =
|
|
|
|
glsl_vector_type(glsl_get_base_type(type),
|
|
|
|
glsl_get_vector_elements(type));
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < elems; i++)
|
|
|
|
val->elems[i] = vtn_undef_ssa_value(b, elem_type);
|
|
|
|
} else if (glsl_type_is_array(type)) {
|
|
|
|
const struct glsl_type *elem_type = glsl_get_array_element(type);
|
|
|
|
for (unsigned i = 0; i < elems; i++)
|
|
|
|
val->elems[i] = vtn_undef_ssa_value(b, elem_type);
|
|
|
|
} else {
|
|
|
|
for (unsigned i = 0; i < elems; i++) {
|
|
|
|
const struct glsl_type *elem_type = glsl_get_struct_field(type, i);
|
|
|
|
val->elems[i] = vtn_undef_ssa_value(b, elem_type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2015-08-31 20:48:04 +01:00
|
|
|
static struct vtn_ssa_value *
|
|
|
|
vtn_const_ssa_value(struct vtn_builder *b, nir_constant *constant,
|
|
|
|
const struct glsl_type *type)
|
2015-05-04 18:22:52 +01:00
|
|
|
{
|
2015-08-31 20:48:04 +01:00
|
|
|
struct hash_entry *entry = _mesa_hash_table_search(b->const_table, constant);
|
|
|
|
|
|
|
|
if (entry)
|
|
|
|
return entry->data;
|
|
|
|
|
|
|
|
struct vtn_ssa_value *val = rzalloc(b, struct vtn_ssa_value);
|
|
|
|
val->type = type;
|
|
|
|
|
|
|
|
switch (glsl_get_base_type(type)) {
|
|
|
|
case GLSL_TYPE_INT:
|
|
|
|
case GLSL_TYPE_UINT:
|
|
|
|
case GLSL_TYPE_BOOL:
|
|
|
|
case GLSL_TYPE_FLOAT:
|
|
|
|
case GLSL_TYPE_DOUBLE:
|
|
|
|
if (glsl_type_is_vector_or_scalar(type)) {
|
|
|
|
unsigned num_components = glsl_get_vector_elements(val->type);
|
|
|
|
nir_load_const_instr *load =
|
2016-04-14 04:25:39 +01:00
|
|
|
nir_load_const_instr_create(b->shader, num_components, 32);
|
2015-08-31 20:48:04 +01:00
|
|
|
|
2016-11-30 06:19:28 +00:00
|
|
|
load->value = constant->values[0];
|
2015-08-31 20:48:04 +01:00
|
|
|
|
|
|
|
nir_instr_insert_before_cf_list(&b->impl->body, &load->instr);
|
|
|
|
val->def = &load->def;
|
|
|
|
} else {
|
|
|
|
assert(glsl_type_is_matrix(type));
|
|
|
|
unsigned rows = glsl_get_vector_elements(val->type);
|
|
|
|
unsigned columns = glsl_get_matrix_columns(val->type);
|
|
|
|
val->elems = ralloc_array(b, struct vtn_ssa_value *, columns);
|
2015-05-06 20:35:30 +01:00
|
|
|
|
2015-08-31 20:48:04 +01:00
|
|
|
for (unsigned i = 0; i < columns; i++) {
|
|
|
|
struct vtn_ssa_value *col_val = rzalloc(b, struct vtn_ssa_value);
|
|
|
|
col_val->type = glsl_get_column_type(val->type);
|
|
|
|
nir_load_const_instr *load =
|
2016-04-14 04:25:39 +01:00
|
|
|
nir_load_const_instr_create(b->shader, rows, 32);
|
2015-05-06 20:35:30 +01:00
|
|
|
|
2016-11-30 06:19:28 +00:00
|
|
|
load->value = constant->values[i];
|
2015-08-31 20:48:04 +01:00
|
|
|
|
|
|
|
nir_instr_insert_before_cf_list(&b->impl->body, &load->instr);
|
|
|
|
col_val->def = &load->def;
|
|
|
|
|
|
|
|
val->elems[i] = col_val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GLSL_TYPE_ARRAY: {
|
|
|
|
unsigned elems = glsl_get_length(val->type);
|
|
|
|
val->elems = ralloc_array(b, struct vtn_ssa_value *, elems);
|
|
|
|
const struct glsl_type *elem_type = glsl_get_array_element(val->type);
|
|
|
|
for (unsigned i = 0; i < elems; i++)
|
|
|
|
val->elems[i] = vtn_const_ssa_value(b, constant->elements[i],
|
|
|
|
elem_type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case GLSL_TYPE_STRUCT: {
|
|
|
|
unsigned elems = glsl_get_length(val->type);
|
|
|
|
val->elems = ralloc_array(b, struct vtn_ssa_value *, elems);
|
|
|
|
for (unsigned i = 0; i < elems; i++) {
|
|
|
|
const struct glsl_type *elem_type =
|
|
|
|
glsl_get_struct_field(val->type, i);
|
|
|
|
val->elems[i] = vtn_const_ssa_value(b, constant->elements[i],
|
|
|
|
elem_type);
|
|
|
|
}
|
|
|
|
break;
|
2015-05-06 20:35:30 +01:00
|
|
|
}
|
|
|
|
|
2015-08-31 20:48:04 +01:00
|
|
|
default:
|
|
|
|
unreachable("bad constant type");
|
|
|
|
}
|
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct vtn_ssa_value *
|
|
|
|
vtn_ssa_value(struct vtn_builder *b, uint32_t value_id)
|
|
|
|
{
|
|
|
|
struct vtn_value *val = vtn_untyped_value(b, value_id);
|
|
|
|
switch (val->value_type) {
|
2015-12-23 22:14:39 +00:00
|
|
|
case vtn_value_type_undef:
|
|
|
|
return vtn_undef_ssa_value(b, val->type->type);
|
|
|
|
|
2015-08-31 20:48:04 +01:00
|
|
|
case vtn_value_type_constant:
|
|
|
|
return vtn_const_ssa_value(b, val->constant, val->const_type);
|
|
|
|
|
2015-05-06 20:35:30 +01:00
|
|
|
case vtn_value_type_ssa:
|
|
|
|
return val->ssa;
|
2015-12-23 19:10:58 +00:00
|
|
|
|
2016-01-21 01:11:55 +00:00
|
|
|
case vtn_value_type_access_chain:
|
2015-12-23 19:10:58 +00:00
|
|
|
/* This is needed for function parameters */
|
2016-01-21 01:11:55 +00:00
|
|
|
return vtn_variable_load(b, val->access_chain);
|
2015-12-23 19:10:58 +00:00
|
|
|
|
2015-05-06 20:35:30 +01:00
|
|
|
default:
|
|
|
|
unreachable("Invalid type for an SSA value");
|
|
|
|
}
|
2015-05-04 18:22:52 +01:00
|
|
|
}
|
|
|
|
|
2015-04-29 01:43:16 +01:00
|
|
|
static char *
|
|
|
|
vtn_string_literal(struct vtn_builder *b, const uint32_t *words,
|
2016-01-11 18:31:25 +00:00
|
|
|
unsigned word_count, unsigned *words_used)
|
2015-04-29 01:43:16 +01:00
|
|
|
{
|
2016-01-11 18:31:25 +00:00
|
|
|
char *dup = ralloc_strndup(b, (char *)words, word_count * sizeof(*words));
|
|
|
|
if (words_used) {
|
|
|
|
/* Ammount of space taken by the string (including the null) */
|
|
|
|
unsigned len = strlen(dup) + 1;
|
|
|
|
*words_used = DIV_ROUND_UP(len, sizeof(*words));
|
|
|
|
}
|
|
|
|
return dup;
|
2015-04-29 01:43:16 +01:00
|
|
|
}
|
|
|
|
|
2015-12-29 02:19:40 +00:00
|
|
|
const uint32_t *
|
2015-05-01 22:00:57 +01:00
|
|
|
vtn_foreach_instruction(struct vtn_builder *b, const uint32_t *start,
|
|
|
|
const uint32_t *end, vtn_instruction_handler handler)
|
|
|
|
{
|
2016-01-20 02:44:44 +00:00
|
|
|
b->file = NULL;
|
|
|
|
b->line = -1;
|
|
|
|
b->col = -1;
|
|
|
|
|
2015-05-01 22:00:57 +01:00
|
|
|
const uint32_t *w = start;
|
|
|
|
while (w < end) {
|
|
|
|
SpvOp opcode = w[0] & SpvOpCodeMask;
|
|
|
|
unsigned count = w[0] >> SpvWordCountShift;
|
|
|
|
assert(count >= 1 && w + count <= end);
|
|
|
|
|
2016-01-20 02:44:44 +00:00
|
|
|
switch (opcode) {
|
|
|
|
case SpvOpNop:
|
|
|
|
break; /* Do nothing */
|
2015-11-20 23:02:45 +00:00
|
|
|
|
2016-01-20 02:44:44 +00:00
|
|
|
case SpvOpLine:
|
|
|
|
b->file = vtn_value(b, w[1], vtn_value_type_string)->str;
|
|
|
|
b->line = w[2];
|
|
|
|
b->col = w[3];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SpvOpNoLine:
|
|
|
|
b->file = NULL;
|
|
|
|
b->line = -1;
|
|
|
|
b->col = -1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (!handler(b, opcode, w, count))
|
|
|
|
return w;
|
|
|
|
break;
|
|
|
|
}
|
2015-05-01 22:00:57 +01:00
|
|
|
|
|
|
|
w += count;
|
|
|
|
}
|
|
|
|
assert(w == end);
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
2015-04-29 22:32:55 +01:00
|
|
|
static void
|
|
|
|
vtn_handle_extension(struct vtn_builder *b, SpvOp opcode,
|
|
|
|
const uint32_t *w, unsigned count)
|
|
|
|
{
|
|
|
|
switch (opcode) {
|
2015-05-04 23:17:56 +01:00
|
|
|
case SpvOpExtInstImport: {
|
|
|
|
struct vtn_value *val = vtn_push_value(b, w[1], vtn_value_type_extension);
|
|
|
|
if (strcmp((const char *)&w[2], "GLSL.std.450") == 0) {
|
|
|
|
val->ext_handler = vtn_handle_glsl450_instruction;
|
|
|
|
} else {
|
|
|
|
assert(!"Unsupported extension");
|
|
|
|
}
|
2015-04-29 22:32:55 +01:00
|
|
|
break;
|
2015-05-04 23:17:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
case SpvOpExtInst: {
|
|
|
|
struct vtn_value *val = vtn_value(b, w[3], vtn_value_type_extension);
|
|
|
|
bool handled = val->ext_handler(b, w[4], w, count);
|
|
|
|
(void)handled;
|
|
|
|
assert(handled);
|
|
|
|
break;
|
|
|
|
}
|
2015-04-29 22:32:55 +01:00
|
|
|
|
|
|
|
default:
|
|
|
|
unreachable("Unhandled opcode");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-29 01:43:16 +01:00
|
|
|
static void
|
|
|
|
_foreach_decoration_helper(struct vtn_builder *b,
|
|
|
|
struct vtn_value *base_value,
|
2015-11-20 23:15:38 +00:00
|
|
|
int parent_member,
|
2015-04-29 01:43:16 +01:00
|
|
|
struct vtn_value *value,
|
2015-05-04 20:25:09 +01:00
|
|
|
vtn_decoration_foreach_cb cb, void *data)
|
2015-04-29 01:43:16 +01:00
|
|
|
{
|
|
|
|
for (struct vtn_decoration *dec = value->decoration; dec; dec = dec->next) {
|
2015-11-20 23:15:38 +00:00
|
|
|
int member;
|
2015-12-31 00:38:16 +00:00
|
|
|
if (dec->scope == VTN_DEC_DECORATION) {
|
2015-11-20 23:15:38 +00:00
|
|
|
member = parent_member;
|
2015-12-31 00:38:16 +00:00
|
|
|
} else if (dec->scope >= VTN_DEC_STRUCT_MEMBER0) {
|
2015-11-20 23:15:38 +00:00
|
|
|
assert(parent_member == -1);
|
2015-12-31 00:38:16 +00:00
|
|
|
member = dec->scope - VTN_DEC_STRUCT_MEMBER0;
|
|
|
|
} else {
|
|
|
|
/* Not a decoration */
|
|
|
|
continue;
|
2015-08-31 20:48:04 +01:00
|
|
|
}
|
|
|
|
|
2015-04-29 01:43:16 +01:00
|
|
|
if (dec->group) {
|
|
|
|
assert(dec->group->value_type == vtn_value_type_decoration_group);
|
2015-11-20 23:15:38 +00:00
|
|
|
_foreach_decoration_helper(b, base_value, member, dec->group,
|
2015-08-31 20:48:04 +01:00
|
|
|
cb, data);
|
2015-04-29 01:43:16 +01:00
|
|
|
} else {
|
2015-11-20 23:15:38 +00:00
|
|
|
cb(b, base_value, member, dec, data);
|
2015-04-29 01:43:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Iterates (recursively if needed) over all of the decorations on a value
|
|
|
|
*
|
|
|
|
* This function iterates over all of the decorations applied to a given
|
|
|
|
* value. If it encounters a decoration group, it recurses into the group
|
|
|
|
* and iterates over all of those decorations as well.
|
|
|
|
*/
|
2015-05-04 20:25:09 +01:00
|
|
|
void
|
2015-04-29 01:43:16 +01:00
|
|
|
vtn_foreach_decoration(struct vtn_builder *b, struct vtn_value *value,
|
2015-05-04 20:25:09 +01:00
|
|
|
vtn_decoration_foreach_cb cb, void *data)
|
2015-04-29 01:43:16 +01:00
|
|
|
{
|
2015-08-31 20:48:04 +01:00
|
|
|
_foreach_decoration_helper(b, value, -1, value, cb, data);
|
2015-04-29 01:43:16 +01:00
|
|
|
}
|
|
|
|
|
2015-12-31 00:38:16 +00:00
|
|
|
void
|
|
|
|
vtn_foreach_execution_mode(struct vtn_builder *b, struct vtn_value *value,
|
|
|
|
vtn_execution_mode_foreach_cb cb, void *data)
|
|
|
|
{
|
|
|
|
for (struct vtn_decoration *dec = value->decoration; dec; dec = dec->next) {
|
|
|
|
if (dec->scope != VTN_DEC_EXECUTION_MODE)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
assert(dec->group == NULL);
|
|
|
|
cb(b, value, dec, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-29 01:43:16 +01:00
|
|
|
static void
|
|
|
|
vtn_handle_decoration(struct vtn_builder *b, SpvOp opcode,
|
|
|
|
const uint32_t *w, unsigned count)
|
|
|
|
{
|
2015-08-31 20:48:04 +01:00
|
|
|
const uint32_t *w_end = w + count;
|
|
|
|
const uint32_t target = w[1];
|
|
|
|
w += 2;
|
|
|
|
|
2015-04-29 01:43:16 +01:00
|
|
|
switch (opcode) {
|
|
|
|
case SpvOpDecorationGroup:
|
2016-01-02 19:51:40 +00:00
|
|
|
vtn_push_value(b, target, vtn_value_type_decoration_group);
|
2015-04-29 01:43:16 +01:00
|
|
|
break;
|
|
|
|
|
2015-12-31 00:38:16 +00:00
|
|
|
case SpvOpDecorate:
|
2015-08-31 20:48:04 +01:00
|
|
|
case SpvOpMemberDecorate:
|
2015-12-31 00:38:16 +00:00
|
|
|
case SpvOpExecutionMode: {
|
2015-08-31 20:48:04 +01:00
|
|
|
struct vtn_value *val = &b->values[target];
|
2015-04-29 01:43:16 +01:00
|
|
|
|
|
|
|
struct vtn_decoration *dec = rzalloc(b, struct vtn_decoration);
|
2015-12-31 00:38:16 +00:00
|
|
|
switch (opcode) {
|
|
|
|
case SpvOpDecorate:
|
|
|
|
dec->scope = VTN_DEC_DECORATION;
|
|
|
|
break;
|
|
|
|
case SpvOpMemberDecorate:
|
|
|
|
dec->scope = VTN_DEC_STRUCT_MEMBER0 + *(w++);
|
|
|
|
break;
|
|
|
|
case SpvOpExecutionMode:
|
|
|
|
dec->scope = VTN_DEC_EXECUTION_MODE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
unreachable("Invalid decoration opcode");
|
|
|
|
}
|
2015-08-31 20:48:04 +01:00
|
|
|
dec->decoration = *(w++);
|
|
|
|
dec->literals = w;
|
2015-04-29 01:43:16 +01:00
|
|
|
|
|
|
|
/* Link into the list */
|
|
|
|
dec->next = val->decoration;
|
|
|
|
val->decoration = dec;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-08-31 20:48:04 +01:00
|
|
|
case SpvOpGroupMemberDecorate:
|
2015-04-29 01:43:16 +01:00
|
|
|
case SpvOpGroupDecorate: {
|
2016-01-02 19:51:40 +00:00
|
|
|
struct vtn_value *group =
|
|
|
|
vtn_value(b, target, vtn_value_type_decoration_group);
|
2015-12-31 00:38:16 +00:00
|
|
|
|
2015-08-31 20:48:04 +01:00
|
|
|
for (; w < w_end; w++) {
|
2016-01-02 19:51:40 +00:00
|
|
|
struct vtn_value *val = vtn_untyped_value(b, *w);
|
2015-04-29 01:43:16 +01:00
|
|
|
struct vtn_decoration *dec = rzalloc(b, struct vtn_decoration);
|
2016-01-02 19:51:40 +00:00
|
|
|
|
2015-04-29 01:43:16 +01:00
|
|
|
dec->group = group;
|
2016-01-02 19:51:40 +00:00
|
|
|
if (opcode == SpvOpGroupDecorate) {
|
|
|
|
dec->scope = VTN_DEC_DECORATION;
|
|
|
|
} else {
|
2016-02-10 23:35:34 +00:00
|
|
|
dec->scope = VTN_DEC_STRUCT_MEMBER0 + *(++w);
|
2016-01-02 19:51:40 +00:00
|
|
|
}
|
2015-04-29 01:43:16 +01:00
|
|
|
|
|
|
|
/* Link into the list */
|
|
|
|
dec->next = val->decoration;
|
|
|
|
val->decoration = dec;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-08-31 20:48:04 +01:00
|
|
|
default:
|
|
|
|
unreachable("Unhandled opcode");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct member_decoration_ctx {
|
2016-02-10 23:34:35 +00:00
|
|
|
unsigned num_fields;
|
2015-08-31 20:48:04 +01:00
|
|
|
struct glsl_struct_field *fields;
|
|
|
|
struct vtn_type *type;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* does a shallow copy of a vtn_type */
|
|
|
|
|
|
|
|
static struct vtn_type *
|
|
|
|
vtn_type_copy(struct vtn_builder *b, struct vtn_type *src)
|
|
|
|
{
|
|
|
|
struct vtn_type *dest = ralloc(b, struct vtn_type);
|
|
|
|
dest->type = src->type;
|
|
|
|
dest->is_builtin = src->is_builtin;
|
|
|
|
if (src->is_builtin)
|
|
|
|
dest->builtin = src->builtin;
|
|
|
|
|
2016-01-21 18:58:03 +00:00
|
|
|
if (!glsl_type_is_scalar(src->type)) {
|
2015-08-31 20:48:04 +01:00
|
|
|
switch (glsl_get_base_type(src->type)) {
|
|
|
|
case GLSL_TYPE_INT:
|
|
|
|
case GLSL_TYPE_UINT:
|
|
|
|
case GLSL_TYPE_BOOL:
|
|
|
|
case GLSL_TYPE_FLOAT:
|
|
|
|
case GLSL_TYPE_DOUBLE:
|
2016-01-21 18:58:03 +00:00
|
|
|
case GLSL_TYPE_ARRAY:
|
2015-08-31 20:48:04 +01:00
|
|
|
dest->row_major = src->row_major;
|
|
|
|
dest->stride = src->stride;
|
2016-01-21 18:58:03 +00:00
|
|
|
dest->array_element = src->array_element;
|
2015-08-31 20:48:04 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GLSL_TYPE_STRUCT: {
|
|
|
|
unsigned elems = glsl_get_length(src->type);
|
|
|
|
|
|
|
|
dest->members = ralloc_array(b, struct vtn_type *, elems);
|
|
|
|
memcpy(dest->members, src->members, elems * sizeof(struct vtn_type *));
|
|
|
|
|
|
|
|
dest->offsets = ralloc_array(b, unsigned, elems);
|
|
|
|
memcpy(dest->offsets, src->offsets, elems * sizeof(unsigned));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
unreachable("unhandled type");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return dest;
|
|
|
|
}
|
|
|
|
|
2016-01-12 09:04:41 +00:00
|
|
|
static struct vtn_type *
|
|
|
|
mutable_matrix_member(struct vtn_builder *b, struct vtn_type *type, int member)
|
|
|
|
{
|
|
|
|
type->members[member] = vtn_type_copy(b, type->members[member]);
|
|
|
|
type = type->members[member];
|
|
|
|
|
|
|
|
/* We may have an array of matrices.... Oh, joy! */
|
|
|
|
while (glsl_type_is_array(type->type)) {
|
|
|
|
type->array_element = vtn_type_copy(b, type->array_element);
|
|
|
|
type = type->array_element;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(glsl_type_is_matrix(type->type));
|
|
|
|
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
2015-08-31 20:48:04 +01:00
|
|
|
static void
|
|
|
|
struct_member_decoration_cb(struct vtn_builder *b,
|
|
|
|
struct vtn_value *val, int member,
|
|
|
|
const struct vtn_decoration *dec, void *void_ctx)
|
|
|
|
{
|
|
|
|
struct member_decoration_ctx *ctx = void_ctx;
|
|
|
|
|
|
|
|
if (member < 0)
|
|
|
|
return;
|
|
|
|
|
2016-02-10 23:34:35 +00:00
|
|
|
assert(member < ctx->num_fields);
|
|
|
|
|
2015-08-31 20:48:04 +01:00
|
|
|
switch (dec->decoration) {
|
2016-04-20 18:32:59 +01:00
|
|
|
case SpvDecorationNonWritable:
|
2016-05-20 04:58:32 +01:00
|
|
|
case SpvDecorationNonReadable:
|
2015-08-31 20:48:04 +01:00
|
|
|
case SpvDecorationRelaxedPrecision:
|
2016-05-24 21:59:10 +01:00
|
|
|
case SpvDecorationVolatile:
|
|
|
|
case SpvDecorationCoherent:
|
|
|
|
case SpvDecorationUniform:
|
2015-08-31 20:48:04 +01:00
|
|
|
break; /* FIXME: Do nothing with this for now. */
|
2015-10-06 22:44:38 +01:00
|
|
|
case SpvDecorationNoPerspective:
|
2016-07-07 10:02:38 +01:00
|
|
|
ctx->fields[member].interpolation = INTERP_MODE_NOPERSPECTIVE;
|
2015-08-31 20:48:04 +01:00
|
|
|
break;
|
|
|
|
case SpvDecorationFlat:
|
2016-07-07 10:02:38 +01:00
|
|
|
ctx->fields[member].interpolation = INTERP_MODE_FLAT;
|
2015-08-31 20:48:04 +01:00
|
|
|
break;
|
|
|
|
case SpvDecorationCentroid:
|
|
|
|
ctx->fields[member].centroid = true;
|
|
|
|
break;
|
|
|
|
case SpvDecorationSample:
|
|
|
|
ctx->fields[member].sample = true;
|
|
|
|
break;
|
2016-05-24 21:59:10 +01:00
|
|
|
case SpvDecorationStream:
|
|
|
|
/* Vulkan only allows one GS stream */
|
|
|
|
assert(dec->literals[0] == 0);
|
|
|
|
break;
|
2015-08-31 20:48:04 +01:00
|
|
|
case SpvDecorationLocation:
|
|
|
|
ctx->fields[member].location = dec->literals[0];
|
|
|
|
break;
|
2016-05-24 21:59:10 +01:00
|
|
|
case SpvDecorationComponent:
|
|
|
|
break; /* FIXME: What should we do with these? */
|
2015-08-31 20:48:04 +01:00
|
|
|
case SpvDecorationBuiltIn:
|
2016-01-12 09:04:41 +00:00
|
|
|
ctx->type->members[member] = vtn_type_copy(b, ctx->type->members[member]);
|
2015-08-31 20:48:04 +01:00
|
|
|
ctx->type->members[member]->is_builtin = true;
|
|
|
|
ctx->type->members[member]->builtin = dec->literals[0];
|
|
|
|
ctx->type->builtin_block = true;
|
|
|
|
break;
|
|
|
|
case SpvDecorationOffset:
|
|
|
|
ctx->type->offsets[member] = dec->literals[0];
|
|
|
|
break;
|
2015-09-05 17:47:11 +01:00
|
|
|
case SpvDecorationMatrixStride:
|
2016-01-12 09:04:41 +00:00
|
|
|
mutable_matrix_member(b, ctx->type, member)->stride = dec->literals[0];
|
2015-09-05 17:47:11 +01:00
|
|
|
break;
|
2015-09-05 02:26:32 +01:00
|
|
|
case SpvDecorationColMajor:
|
|
|
|
break; /* Nothing to do here. Column-major is the default. */
|
2016-01-08 00:55:56 +00:00
|
|
|
case SpvDecorationRowMajor:
|
2016-01-12 09:04:41 +00:00
|
|
|
mutable_matrix_member(b, ctx->type, member)->row_major = true;
|
2016-01-08 00:55:56 +00:00
|
|
|
break;
|
2016-05-24 21:59:10 +01:00
|
|
|
|
|
|
|
case SpvDecorationPatch:
|
2016-06-02 22:34:15 +01:00
|
|
|
vtn_warn("Tessellation not yet supported");
|
|
|
|
break;
|
2016-05-24 21:59:10 +01:00
|
|
|
|
|
|
|
case SpvDecorationSpecId:
|
|
|
|
case SpvDecorationBlock:
|
|
|
|
case SpvDecorationBufferBlock:
|
|
|
|
case SpvDecorationArrayStride:
|
|
|
|
case SpvDecorationGLSLShared:
|
|
|
|
case SpvDecorationGLSLPacked:
|
|
|
|
case SpvDecorationInvariant:
|
|
|
|
case SpvDecorationRestrict:
|
|
|
|
case SpvDecorationAliased:
|
|
|
|
case SpvDecorationConstant:
|
|
|
|
case SpvDecorationIndex:
|
|
|
|
case SpvDecorationBinding:
|
|
|
|
case SpvDecorationDescriptorSet:
|
2016-06-02 22:36:58 +01:00
|
|
|
case SpvDecorationLinkageAttributes:
|
2016-05-24 21:59:10 +01:00
|
|
|
case SpvDecorationNoContraction:
|
|
|
|
case SpvDecorationInputAttachmentIndex:
|
2016-06-02 22:34:15 +01:00
|
|
|
vtn_warn("Decoration not allowed on struct members: %s",
|
|
|
|
spirv_decoration_to_string(dec->decoration));
|
|
|
|
break;
|
2016-05-24 21:59:10 +01:00
|
|
|
|
|
|
|
case SpvDecorationXfbBuffer:
|
|
|
|
case SpvDecorationXfbStride:
|
2016-06-02 22:34:15 +01:00
|
|
|
vtn_warn("Vulkan does not have transform feedback");
|
|
|
|
break;
|
2016-05-24 21:59:10 +01:00
|
|
|
|
|
|
|
case SpvDecorationCPacked:
|
|
|
|
case SpvDecorationSaturatedConversion:
|
|
|
|
case SpvDecorationFuncParamAttr:
|
|
|
|
case SpvDecorationFPRoundingMode:
|
|
|
|
case SpvDecorationFPFastMathMode:
|
|
|
|
case SpvDecorationAlignment:
|
2016-06-02 22:34:15 +01:00
|
|
|
vtn_warn("Decoraiton only allowed for CL-style kernels: %s",
|
|
|
|
spirv_decoration_to_string(dec->decoration));
|
|
|
|
break;
|
2015-08-31 20:48:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
type_decoration_cb(struct vtn_builder *b,
|
|
|
|
struct vtn_value *val, int member,
|
|
|
|
const struct vtn_decoration *dec, void *ctx)
|
|
|
|
{
|
|
|
|
struct vtn_type *type = val->type;
|
|
|
|
|
|
|
|
if (member != -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (dec->decoration) {
|
|
|
|
case SpvDecorationArrayStride:
|
|
|
|
type->stride = dec->literals[0];
|
|
|
|
break;
|
|
|
|
case SpvDecorationBlock:
|
|
|
|
type->block = true;
|
|
|
|
break;
|
|
|
|
case SpvDecorationBufferBlock:
|
|
|
|
type->buffer_block = true;
|
|
|
|
break;
|
|
|
|
case SpvDecorationGLSLShared:
|
|
|
|
case SpvDecorationGLSLPacked:
|
|
|
|
/* Ignore these, since we get explicit offsets anyways */
|
2015-04-29 01:43:16 +01:00
|
|
|
break;
|
|
|
|
|
2016-05-24 21:59:10 +01:00
|
|
|
case SpvDecorationRowMajor:
|
|
|
|
case SpvDecorationColMajor:
|
|
|
|
case SpvDecorationMatrixStride:
|
|
|
|
case SpvDecorationBuiltIn:
|
|
|
|
case SpvDecorationNoPerspective:
|
|
|
|
case SpvDecorationFlat:
|
|
|
|
case SpvDecorationPatch:
|
|
|
|
case SpvDecorationCentroid:
|
|
|
|
case SpvDecorationSample:
|
|
|
|
case SpvDecorationVolatile:
|
|
|
|
case SpvDecorationCoherent:
|
|
|
|
case SpvDecorationNonWritable:
|
|
|
|
case SpvDecorationNonReadable:
|
|
|
|
case SpvDecorationUniform:
|
2015-10-22 04:36:25 +01:00
|
|
|
case SpvDecorationStream:
|
2016-05-24 21:59:10 +01:00
|
|
|
case SpvDecorationLocation:
|
|
|
|
case SpvDecorationComponent:
|
|
|
|
case SpvDecorationOffset:
|
|
|
|
case SpvDecorationXfbBuffer:
|
|
|
|
case SpvDecorationXfbStride:
|
2016-06-02 22:34:15 +01:00
|
|
|
vtn_warn("Decoraiton only allowed for struct members: %s",
|
|
|
|
spirv_decoration_to_string(dec->decoration));
|
|
|
|
break;
|
2015-10-22 04:36:25 +01:00
|
|
|
|
2016-05-24 21:59:10 +01:00
|
|
|
case SpvDecorationRelaxedPrecision:
|
|
|
|
case SpvDecorationSpecId:
|
|
|
|
case SpvDecorationInvariant:
|
|
|
|
case SpvDecorationRestrict:
|
|
|
|
case SpvDecorationAliased:
|
|
|
|
case SpvDecorationConstant:
|
|
|
|
case SpvDecorationIndex:
|
|
|
|
case SpvDecorationBinding:
|
|
|
|
case SpvDecorationDescriptorSet:
|
|
|
|
case SpvDecorationLinkageAttributes:
|
|
|
|
case SpvDecorationNoContraction:
|
|
|
|
case SpvDecorationInputAttachmentIndex:
|
2016-06-02 22:34:15 +01:00
|
|
|
vtn_warn("Decoraiton not allowed on types: %s",
|
|
|
|
spirv_decoration_to_string(dec->decoration));
|
|
|
|
break;
|
2016-05-24 21:59:10 +01:00
|
|
|
|
|
|
|
case SpvDecorationCPacked:
|
|
|
|
case SpvDecorationSaturatedConversion:
|
|
|
|
case SpvDecorationFuncParamAttr:
|
|
|
|
case SpvDecorationFPRoundingMode:
|
|
|
|
case SpvDecorationFPFastMathMode:
|
|
|
|
case SpvDecorationAlignment:
|
2016-06-02 22:34:15 +01:00
|
|
|
vtn_warn("Decoraiton only allowed for CL-style kernels: %s",
|
|
|
|
spirv_decoration_to_string(dec->decoration));
|
|
|
|
break;
|
2015-04-29 01:43:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-13 23:52:52 +00:00
|
|
|
static unsigned
|
|
|
|
translate_image_format(SpvImageFormat format)
|
|
|
|
{
|
|
|
|
switch (format) {
|
|
|
|
case SpvImageFormatUnknown: return 0; /* GL_NONE */
|
|
|
|
case SpvImageFormatRgba32f: return 0x8814; /* GL_RGBA32F */
|
|
|
|
case SpvImageFormatRgba16f: return 0x881A; /* GL_RGBA16F */
|
|
|
|
case SpvImageFormatR32f: return 0x822E; /* GL_R32F */
|
|
|
|
case SpvImageFormatRgba8: return 0x8058; /* GL_RGBA8 */
|
|
|
|
case SpvImageFormatRgba8Snorm: return 0x8F97; /* GL_RGBA8_SNORM */
|
|
|
|
case SpvImageFormatRg32f: return 0x8230; /* GL_RG32F */
|
|
|
|
case SpvImageFormatRg16f: return 0x822F; /* GL_RG16F */
|
|
|
|
case SpvImageFormatR11fG11fB10f: return 0x8C3A; /* GL_R11F_G11F_B10F */
|
|
|
|
case SpvImageFormatR16f: return 0x822D; /* GL_R16F */
|
|
|
|
case SpvImageFormatRgba16: return 0x805B; /* GL_RGBA16 */
|
|
|
|
case SpvImageFormatRgb10A2: return 0x8059; /* GL_RGB10_A2 */
|
|
|
|
case SpvImageFormatRg16: return 0x822C; /* GL_RG16 */
|
|
|
|
case SpvImageFormatRg8: return 0x822B; /* GL_RG8 */
|
|
|
|
case SpvImageFormatR16: return 0x822A; /* GL_R16 */
|
|
|
|
case SpvImageFormatR8: return 0x8229; /* GL_R8 */
|
|
|
|
case SpvImageFormatRgba16Snorm: return 0x8F9B; /* GL_RGBA16_SNORM */
|
|
|
|
case SpvImageFormatRg16Snorm: return 0x8F99; /* GL_RG16_SNORM */
|
|
|
|
case SpvImageFormatRg8Snorm: return 0x8F95; /* GL_RG8_SNORM */
|
|
|
|
case SpvImageFormatR16Snorm: return 0x8F98; /* GL_R16_SNORM */
|
|
|
|
case SpvImageFormatR8Snorm: return 0x8F94; /* GL_R8_SNORM */
|
|
|
|
case SpvImageFormatRgba32i: return 0x8D82; /* GL_RGBA32I */
|
|
|
|
case SpvImageFormatRgba16i: return 0x8D88; /* GL_RGBA16I */
|
|
|
|
case SpvImageFormatRgba8i: return 0x8D8E; /* GL_RGBA8I */
|
|
|
|
case SpvImageFormatR32i: return 0x8235; /* GL_R32I */
|
|
|
|
case SpvImageFormatRg32i: return 0x823B; /* GL_RG32I */
|
|
|
|
case SpvImageFormatRg16i: return 0x8239; /* GL_RG16I */
|
|
|
|
case SpvImageFormatRg8i: return 0x8237; /* GL_RG8I */
|
|
|
|
case SpvImageFormatR16i: return 0x8233; /* GL_R16I */
|
|
|
|
case SpvImageFormatR8i: return 0x8231; /* GL_R8I */
|
|
|
|
case SpvImageFormatRgba32ui: return 0x8D70; /* GL_RGBA32UI */
|
|
|
|
case SpvImageFormatRgba16ui: return 0x8D76; /* GL_RGBA16UI */
|
|
|
|
case SpvImageFormatRgba8ui: return 0x8D7C; /* GL_RGBA8UI */
|
|
|
|
case SpvImageFormatR32ui: return 0x8236; /* GL_R32UI */
|
|
|
|
case SpvImageFormatRgb10a2ui: return 0x906F; /* GL_RGB10_A2UI */
|
|
|
|
case SpvImageFormatRg32ui: return 0x823C; /* GL_RG32UI */
|
|
|
|
case SpvImageFormatRg16ui: return 0x823A; /* GL_RG16UI */
|
|
|
|
case SpvImageFormatRg8ui: return 0x8238; /* GL_RG8UI */
|
|
|
|
case SpvImageFormatR16ui: return 0x823A; /* GL_RG16UI */
|
|
|
|
case SpvImageFormatR8ui: return 0x8232; /* GL_R8UI */
|
|
|
|
default:
|
|
|
|
assert(!"Invalid image format");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-31 20:48:04 +01:00
|
|
|
static void
|
2015-04-29 01:43:16 +01:00
|
|
|
vtn_handle_type(struct vtn_builder *b, SpvOp opcode,
|
2015-08-31 20:48:04 +01:00
|
|
|
const uint32_t *w, unsigned count)
|
2015-04-29 01:43:16 +01:00
|
|
|
{
|
2015-08-31 20:48:04 +01:00
|
|
|
struct vtn_value *val = vtn_push_value(b, w[1], vtn_value_type_type);
|
|
|
|
|
|
|
|
val->type = rzalloc(b, struct vtn_type);
|
|
|
|
val->type->is_builtin = false;
|
2016-01-21 20:41:45 +00:00
|
|
|
val->type->val = val;
|
2015-08-31 20:48:04 +01:00
|
|
|
|
2015-04-29 22:36:01 +01:00
|
|
|
switch (opcode) {
|
|
|
|
case SpvOpTypeVoid:
|
2015-08-31 20:48:04 +01:00
|
|
|
val->type->type = glsl_void_type();
|
|
|
|
break;
|
2015-04-29 22:36:01 +01:00
|
|
|
case SpvOpTypeBool:
|
2015-08-31 20:48:04 +01:00
|
|
|
val->type->type = glsl_bool_type();
|
|
|
|
break;
|
2016-02-01 22:59:01 +00:00
|
|
|
case SpvOpTypeInt: {
|
|
|
|
const bool signedness = w[3];
|
|
|
|
val->type->type = (signedness ? glsl_int_type() : glsl_uint_type());
|
2015-08-31 20:48:04 +01:00
|
|
|
break;
|
2016-02-01 22:59:01 +00:00
|
|
|
}
|
2015-04-29 22:36:01 +01:00
|
|
|
case SpvOpTypeFloat:
|
2015-08-31 20:48:04 +01:00
|
|
|
val->type->type = glsl_float_type();
|
|
|
|
break;
|
2015-04-29 22:36:01 +01:00
|
|
|
|
|
|
|
case SpvOpTypeVector: {
|
2016-01-08 00:55:56 +00:00
|
|
|
struct vtn_type *base = vtn_value(b, w[2], vtn_value_type_type)->type;
|
2015-08-31 20:48:04 +01:00
|
|
|
unsigned elems = w[3];
|
2015-04-29 22:36:01 +01:00
|
|
|
|
2016-01-08 00:55:56 +00:00
|
|
|
assert(glsl_type_is_scalar(base->type));
|
|
|
|
val->type->type = glsl_vector_type(glsl_get_base_type(base->type), elems);
|
|
|
|
|
|
|
|
/* Vectors implicitly have sizeof(base_type) stride. For now, this
|
|
|
|
* is always 4 bytes. This will have to change if we want to start
|
|
|
|
* supporting doubles or half-floats.
|
|
|
|
*/
|
|
|
|
val->type->stride = 4;
|
|
|
|
val->type->array_element = base;
|
2015-08-31 20:48:04 +01:00
|
|
|
break;
|
2015-04-29 22:36:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
case SpvOpTypeMatrix: {
|
2016-01-08 00:55:56 +00:00
|
|
|
struct vtn_type *base = vtn_value(b, w[2], vtn_value_type_type)->type;
|
2015-08-31 20:48:04 +01:00
|
|
|
unsigned columns = w[3];
|
|
|
|
|
|
|
|
assert(glsl_type_is_vector(base->type));
|
|
|
|
val->type->type = glsl_matrix_type(glsl_get_base_type(base->type),
|
|
|
|
glsl_get_vector_elements(base->type),
|
|
|
|
columns);
|
2016-01-11 20:39:16 +00:00
|
|
|
assert(!glsl_type_is_error(val->type->type));
|
2015-08-31 20:48:04 +01:00
|
|
|
val->type->array_element = base;
|
|
|
|
val->type->row_major = false;
|
|
|
|
val->type->stride = 0;
|
|
|
|
break;
|
2015-04-29 22:36:01 +01:00
|
|
|
}
|
|
|
|
|
2015-11-20 20:49:20 +00:00
|
|
|
case SpvOpTypeRuntimeArray:
|
2015-08-31 20:48:04 +01:00
|
|
|
case SpvOpTypeArray: {
|
|
|
|
struct vtn_type *array_element =
|
|
|
|
vtn_value(b, w[2], vtn_value_type_type)->type;
|
2015-11-20 20:49:20 +00:00
|
|
|
|
2015-12-18 00:36:23 +00:00
|
|
|
unsigned length;
|
|
|
|
if (opcode == SpvOpTypeRuntimeArray) {
|
|
|
|
/* A length of 0 is used to denote unsized arrays */
|
|
|
|
length = 0;
|
|
|
|
} else {
|
|
|
|
length =
|
2016-11-30 06:19:28 +00:00
|
|
|
vtn_value(b, w[3], vtn_value_type_constant)->constant->values[0].u32[0];
|
2015-12-18 00:36:23 +00:00
|
|
|
}
|
2015-11-20 20:49:20 +00:00
|
|
|
|
|
|
|
val->type->type = glsl_array_type(array_element->type, length);
|
2015-08-31 20:48:04 +01:00
|
|
|
val->type->array_element = array_element;
|
|
|
|
val->type->stride = 0;
|
|
|
|
break;
|
|
|
|
}
|
2015-04-29 22:36:01 +01:00
|
|
|
|
|
|
|
case SpvOpTypeStruct: {
|
2015-08-31 20:48:04 +01:00
|
|
|
unsigned num_fields = count - 2;
|
|
|
|
val->type->members = ralloc_array(b, struct vtn_type *, num_fields);
|
|
|
|
val->type->offsets = ralloc_array(b, unsigned, num_fields);
|
|
|
|
|
2015-04-29 22:36:01 +01:00
|
|
|
NIR_VLA(struct glsl_struct_field, fields, count);
|
2015-08-31 20:48:04 +01:00
|
|
|
for (unsigned i = 0; i < num_fields; i++) {
|
|
|
|
val->type->members[i] =
|
|
|
|
vtn_value(b, w[i + 2], vtn_value_type_type)->type;
|
2015-12-29 21:15:17 +00:00
|
|
|
fields[i] = (struct glsl_struct_field) {
|
|
|
|
.type = val->type->members[i]->type,
|
|
|
|
.name = ralloc_asprintf(b, "field%d", i),
|
|
|
|
.location = -1,
|
|
|
|
};
|
2015-04-29 22:36:01 +01:00
|
|
|
}
|
2015-08-31 20:48:04 +01:00
|
|
|
|
|
|
|
struct member_decoration_ctx ctx = {
|
2016-02-10 23:34:35 +00:00
|
|
|
.num_fields = num_fields,
|
2015-08-31 20:48:04 +01:00
|
|
|
.fields = fields,
|
|
|
|
.type = val->type
|
|
|
|
};
|
|
|
|
|
|
|
|
vtn_foreach_decoration(b, val, struct_member_decoration_cb, &ctx);
|
|
|
|
|
|
|
|
const char *name = val->name ? val->name : "struct";
|
|
|
|
|
|
|
|
val->type->type = glsl_struct_type(fields, num_fields, name);
|
|
|
|
break;
|
2015-04-29 22:36:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
case SpvOpTypeFunction: {
|
2015-08-31 20:48:04 +01:00
|
|
|
const struct glsl_type *return_type =
|
|
|
|
vtn_value(b, w[2], vtn_value_type_type)->type->type;
|
|
|
|
NIR_VLA(struct glsl_function_param, params, count - 3);
|
|
|
|
for (unsigned i = 0; i < count - 3; i++) {
|
|
|
|
params[i].type = vtn_value(b, w[i + 3], vtn_value_type_type)->type->type;
|
2015-04-29 22:36:01 +01:00
|
|
|
|
|
|
|
/* FIXME: */
|
2015-08-31 20:48:04 +01:00
|
|
|
params[i].in = true;
|
|
|
|
params[i].out = true;
|
2015-04-29 22:36:01 +01:00
|
|
|
}
|
2015-08-31 20:48:04 +01:00
|
|
|
val->type->type = glsl_function_type(return_type, params, count - 3);
|
|
|
|
break;
|
2015-04-29 22:36:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
case SpvOpTypePointer:
|
|
|
|
/* FIXME: For now, we'll just do the really lame thing and return
|
|
|
|
* the same type. The validator should ensure that the proper number
|
|
|
|
* of dereferences happen
|
|
|
|
*/
|
2015-08-31 20:48:04 +01:00
|
|
|
val->type = vtn_value(b, w[3], vtn_value_type_type)->type;
|
|
|
|
break;
|
2015-04-29 22:36:01 +01:00
|
|
|
|
2015-08-31 20:48:04 +01:00
|
|
|
case SpvOpTypeImage: {
|
2015-05-16 20:34:15 +01:00
|
|
|
const struct glsl_type *sampled_type =
|
2015-08-31 20:48:04 +01:00
|
|
|
vtn_value(b, w[2], vtn_value_type_type)->type->type;
|
2015-05-16 20:34:15 +01:00
|
|
|
|
|
|
|
assert(glsl_type_is_vector_or_scalar(sampled_type));
|
|
|
|
|
|
|
|
enum glsl_sampler_dim dim;
|
2015-08-31 20:48:04 +01:00
|
|
|
switch ((SpvDim)w[3]) {
|
2015-05-16 20:34:15 +01:00
|
|
|
case SpvDim1D: dim = GLSL_SAMPLER_DIM_1D; break;
|
|
|
|
case SpvDim2D: dim = GLSL_SAMPLER_DIM_2D; break;
|
|
|
|
case SpvDim3D: dim = GLSL_SAMPLER_DIM_3D; break;
|
|
|
|
case SpvDimCube: dim = GLSL_SAMPLER_DIM_CUBE; break;
|
|
|
|
case SpvDimRect: dim = GLSL_SAMPLER_DIM_RECT; break;
|
|
|
|
case SpvDimBuffer: dim = GLSL_SAMPLER_DIM_BUF; break;
|
2016-09-15 02:08:28 +01:00
|
|
|
case SpvDimSubpassData: dim = GLSL_SAMPLER_DIM_SUBPASS; break;
|
2015-05-16 20:34:15 +01:00
|
|
|
default:
|
|
|
|
unreachable("Invalid SPIR-V Sampler dimension");
|
|
|
|
}
|
|
|
|
|
2015-08-31 20:48:04 +01:00
|
|
|
bool is_shadow = w[4];
|
|
|
|
bool is_array = w[5];
|
2015-11-13 23:52:52 +00:00
|
|
|
bool multisampled = w[6];
|
|
|
|
unsigned sampled = w[7];
|
|
|
|
SpvImageFormat format = w[8];
|
|
|
|
|
2016-01-19 00:01:00 +00:00
|
|
|
if (count > 9)
|
|
|
|
val->type->access_qualifier = w[9];
|
|
|
|
else
|
|
|
|
val->type->access_qualifier = SpvAccessQualifierReadWrite;
|
|
|
|
|
2016-02-22 05:42:33 +00:00
|
|
|
if (multisampled) {
|
|
|
|
assert(dim == GLSL_SAMPLER_DIM_2D);
|
|
|
|
dim = GLSL_SAMPLER_DIM_MS;
|
|
|
|
}
|
2015-11-13 23:52:52 +00:00
|
|
|
|
|
|
|
val->type->image_format = translate_image_format(format);
|
|
|
|
|
|
|
|
if (sampled == 1) {
|
|
|
|
val->type->type = glsl_sampler_type(dim, is_shadow, is_array,
|
|
|
|
glsl_get_base_type(sampled_type));
|
|
|
|
} else if (sampled == 2) {
|
2016-09-15 02:08:28 +01:00
|
|
|
assert((dim == GLSL_SAMPLER_DIM_SUBPASS) || format);
|
2015-11-13 23:52:52 +00:00
|
|
|
assert(!is_shadow);
|
|
|
|
val->type->type = glsl_image_type(dim, is_array,
|
|
|
|
glsl_get_base_type(sampled_type));
|
|
|
|
} else {
|
|
|
|
assert(!"We need to know if the image will be sampled");
|
|
|
|
}
|
2015-08-31 20:48:04 +01:00
|
|
|
break;
|
2015-05-16 20:34:15 +01:00
|
|
|
}
|
|
|
|
|
2015-08-31 20:48:04 +01:00
|
|
|
case SpvOpTypeSampledImage:
|
|
|
|
val->type = vtn_value(b, w[2], vtn_value_type_type)->type;
|
|
|
|
break;
|
|
|
|
|
2015-11-15 06:32:54 +00:00
|
|
|
case SpvOpTypeSampler:
|
|
|
|
/* The actual sampler type here doesn't really matter. It gets
|
|
|
|
* thrown away the moment you combine it with an image. What really
|
|
|
|
* matters is that it's a sampler type as opposed to an integer type
|
|
|
|
* so the backend knows what to do.
|
|
|
|
*/
|
2016-02-25 00:10:08 +00:00
|
|
|
val->type->type = glsl_bare_sampler_type();
|
2015-11-15 06:32:54 +00:00
|
|
|
break;
|
|
|
|
|
2015-04-29 22:36:01 +01:00
|
|
|
case SpvOpTypeOpaque:
|
|
|
|
case SpvOpTypeEvent:
|
|
|
|
case SpvOpTypeDeviceEvent:
|
|
|
|
case SpvOpTypeReserveId:
|
|
|
|
case SpvOpTypeQueue:
|
|
|
|
case SpvOpTypePipe:
|
|
|
|
default:
|
|
|
|
unreachable("Unhandled opcode");
|
|
|
|
}
|
2015-08-31 20:48:04 +01:00
|
|
|
|
|
|
|
vtn_foreach_decoration(b, val, type_decoration_cb, NULL);
|
2015-04-29 01:43:16 +01:00
|
|
|
}
|
|
|
|
|
2016-01-05 00:57:01 +00:00
|
|
|
static nir_constant *
|
|
|
|
vtn_null_constant(struct vtn_builder *b, const struct glsl_type *type)
|
|
|
|
{
|
|
|
|
nir_constant *c = rzalloc(b, nir_constant);
|
|
|
|
|
|
|
|
switch (glsl_get_base_type(type)) {
|
|
|
|
case GLSL_TYPE_INT:
|
|
|
|
case GLSL_TYPE_UINT:
|
|
|
|
case GLSL_TYPE_BOOL:
|
|
|
|
case GLSL_TYPE_FLOAT:
|
|
|
|
case GLSL_TYPE_DOUBLE:
|
|
|
|
/* Nothing to do here. It's already initialized to zero */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GLSL_TYPE_ARRAY:
|
|
|
|
assert(glsl_get_length(type) > 0);
|
|
|
|
c->num_elements = glsl_get_length(type);
|
|
|
|
c->elements = ralloc_array(b, nir_constant *, c->num_elements);
|
|
|
|
|
|
|
|
c->elements[0] = vtn_null_constant(b, glsl_get_array_element(type));
|
|
|
|
for (unsigned i = 1; i < c->num_elements; i++)
|
|
|
|
c->elements[i] = c->elements[0];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GLSL_TYPE_STRUCT:
|
|
|
|
c->num_elements = glsl_get_length(type);
|
|
|
|
c->elements = ralloc_array(b, nir_constant *, c->num_elements);
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < c->num_elements; i++) {
|
|
|
|
c->elements[i] = vtn_null_constant(b, glsl_get_struct_field(type, i));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
unreachable("Invalid type for null constant");
|
|
|
|
}
|
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2016-01-13 00:28:28 +00:00
|
|
|
static void
|
|
|
|
spec_constant_deocoration_cb(struct vtn_builder *b, struct vtn_value *v,
|
|
|
|
int member, const struct vtn_decoration *dec,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
assert(member == -1);
|
|
|
|
if (dec->decoration != SpvDecorationSpecId)
|
|
|
|
return;
|
|
|
|
|
|
|
|
uint32_t *const_value = data;
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < b->num_specializations; i++) {
|
|
|
|
if (b->specializations[i].id == dec->literals[0]) {
|
|
|
|
*const_value = b->specializations[i].data;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t
|
|
|
|
get_specialization(struct vtn_builder *b, struct vtn_value *val,
|
|
|
|
uint32_t const_value)
|
|
|
|
{
|
|
|
|
vtn_foreach_decoration(b, val, spec_constant_deocoration_cb, &const_value);
|
|
|
|
return const_value;
|
|
|
|
}
|
|
|
|
|
2016-06-01 19:20:22 +01:00
|
|
|
static void
|
|
|
|
handle_workgroup_size_decoration_cb(struct vtn_builder *b,
|
|
|
|
struct vtn_value *val,
|
|
|
|
int member,
|
|
|
|
const struct vtn_decoration *dec,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
assert(member == -1);
|
|
|
|
if (dec->decoration != SpvDecorationBuiltIn ||
|
|
|
|
dec->literals[0] != SpvBuiltInWorkgroupSize)
|
|
|
|
return;
|
|
|
|
|
|
|
|
assert(val->const_type == glsl_vector_type(GLSL_TYPE_UINT, 3));
|
|
|
|
|
2016-11-30 06:19:28 +00:00
|
|
|
b->shader->info->cs.local_size[0] = val->constant->values[0].u32[0];
|
|
|
|
b->shader->info->cs.local_size[1] = val->constant->values[0].u32[1];
|
|
|
|
b->shader->info->cs.local_size[2] = val->constant->values[0].u32[2];
|
2016-06-01 19:20:22 +01:00
|
|
|
}
|
|
|
|
|
2015-04-29 01:43:16 +01:00
|
|
|
static void
|
|
|
|
vtn_handle_constant(struct vtn_builder *b, SpvOp opcode,
|
|
|
|
const uint32_t *w, unsigned count)
|
|
|
|
{
|
2015-05-04 20:02:24 +01:00
|
|
|
struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_constant);
|
2015-08-31 20:48:04 +01:00
|
|
|
val->const_type = vtn_value(b, w[1], vtn_value_type_type)->type->type;
|
2015-12-31 02:51:57 +00:00
|
|
|
val->constant = rzalloc(b, nir_constant);
|
2015-04-30 02:14:11 +01:00
|
|
|
switch (opcode) {
|
|
|
|
case SpvOpConstantTrue:
|
2015-08-31 20:48:04 +01:00
|
|
|
assert(val->const_type == glsl_bool_type());
|
2016-11-30 06:19:28 +00:00
|
|
|
val->constant->values[0].u32[0] = NIR_TRUE;
|
2015-04-30 02:14:11 +01:00
|
|
|
break;
|
|
|
|
case SpvOpConstantFalse:
|
2015-08-31 20:48:04 +01:00
|
|
|
assert(val->const_type == glsl_bool_type());
|
2016-11-30 06:19:28 +00:00
|
|
|
val->constant->values[0].u32[0] = NIR_FALSE;
|
2015-04-30 02:14:11 +01:00
|
|
|
break;
|
2016-01-13 00:28:28 +00:00
|
|
|
|
|
|
|
case SpvOpSpecConstantTrue:
|
|
|
|
case SpvOpSpecConstantFalse: {
|
|
|
|
assert(val->const_type == glsl_bool_type());
|
|
|
|
uint32_t int_val =
|
|
|
|
get_specialization(b, val, (opcode == SpvOpSpecConstantTrue));
|
2016-11-30 06:19:28 +00:00
|
|
|
val->constant->values[0].u32[0] = int_val ? NIR_TRUE : NIR_FALSE;
|
2016-01-13 00:28:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-04-30 02:14:11 +01:00
|
|
|
case SpvOpConstant:
|
2015-08-31 20:48:04 +01:00
|
|
|
assert(glsl_type_is_scalar(val->const_type));
|
2016-11-30 06:19:28 +00:00
|
|
|
val->constant->values[0].u32[0] = w[3];
|
2015-04-30 02:14:11 +01:00
|
|
|
break;
|
2016-01-13 00:28:28 +00:00
|
|
|
case SpvOpSpecConstant:
|
|
|
|
assert(glsl_type_is_scalar(val->const_type));
|
2016-11-30 06:19:28 +00:00
|
|
|
val->constant->values[0].u32[0] = get_specialization(b, val, w[3]);
|
2016-01-13 00:28:28 +00:00
|
|
|
break;
|
|
|
|
case SpvOpSpecConstantComposite:
|
2015-04-30 02:14:11 +01:00
|
|
|
case SpvOpConstantComposite: {
|
|
|
|
unsigned elem_count = count - 3;
|
|
|
|
nir_constant **elems = ralloc_array(b, nir_constant *, elem_count);
|
|
|
|
for (unsigned i = 0; i < elem_count; i++)
|
|
|
|
elems[i] = vtn_value(b, w[i + 3], vtn_value_type_constant)->constant;
|
|
|
|
|
2015-08-31 20:48:04 +01:00
|
|
|
switch (glsl_get_base_type(val->const_type)) {
|
2015-04-30 02:14:11 +01:00
|
|
|
case GLSL_TYPE_UINT:
|
|
|
|
case GLSL_TYPE_INT:
|
|
|
|
case GLSL_TYPE_FLOAT:
|
|
|
|
case GLSL_TYPE_BOOL:
|
2015-08-31 20:48:04 +01:00
|
|
|
if (glsl_type_is_matrix(val->const_type)) {
|
|
|
|
assert(glsl_get_matrix_columns(val->const_type) == elem_count);
|
2015-04-30 02:14:11 +01:00
|
|
|
for (unsigned i = 0; i < elem_count; i++)
|
2016-11-30 06:19:28 +00:00
|
|
|
val->constant->values[i] = elems[i]->values[0];
|
2015-04-30 02:14:11 +01:00
|
|
|
} else {
|
2015-08-31 20:48:04 +01:00
|
|
|
assert(glsl_type_is_vector(val->const_type));
|
|
|
|
assert(glsl_get_vector_elements(val->const_type) == elem_count);
|
2015-04-30 02:14:11 +01:00
|
|
|
for (unsigned i = 0; i < elem_count; i++)
|
2016-11-30 06:19:28 +00:00
|
|
|
val->constant->values[0].u32[i] = elems[i]->values[0].u32[0];
|
2015-04-30 02:14:11 +01:00
|
|
|
}
|
|
|
|
ralloc_free(elems);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GLSL_TYPE_STRUCT:
|
|
|
|
case GLSL_TYPE_ARRAY:
|
2015-05-04 20:02:24 +01:00
|
|
|
ralloc_steal(val->constant, elems);
|
2015-12-31 02:51:57 +00:00
|
|
|
val->constant->num_elements = elem_count;
|
2015-05-04 20:02:24 +01:00
|
|
|
val->constant->elements = elems;
|
2015-04-30 02:14:11 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
unreachable("Unsupported type for constants");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-01-13 04:02:04 +00:00
|
|
|
case SpvOpSpecConstantOp: {
|
|
|
|
SpvOp opcode = get_specialization(b, val, w[3]);
|
|
|
|
switch (opcode) {
|
|
|
|
case SpvOpVectorShuffle: {
|
|
|
|
struct vtn_value *v0 = vtn_value(b, w[4], vtn_value_type_constant);
|
|
|
|
struct vtn_value *v1 = vtn_value(b, w[5], vtn_value_type_constant);
|
|
|
|
unsigned len0 = glsl_get_vector_elements(v0->const_type);
|
|
|
|
unsigned len1 = glsl_get_vector_elements(v1->const_type);
|
|
|
|
|
|
|
|
uint32_t u[8];
|
|
|
|
for (unsigned i = 0; i < len0; i++)
|
2016-11-30 06:19:28 +00:00
|
|
|
u[i] = v0->constant->values[0].u32[i];
|
2016-01-13 04:02:04 +00:00
|
|
|
for (unsigned i = 0; i < len1; i++)
|
2016-11-30 06:19:28 +00:00
|
|
|
u[len0 + i] = v1->constant->values[0].u32[i];
|
2016-01-13 04:02:04 +00:00
|
|
|
|
|
|
|
for (unsigned i = 0; i < count - 6; i++) {
|
|
|
|
uint32_t comp = w[i + 6];
|
|
|
|
if (comp == (uint32_t)-1) {
|
2016-11-30 06:19:28 +00:00
|
|
|
val->constant->values[0].u32[i] = 0xdeadbeef;
|
2016-01-13 04:02:04 +00:00
|
|
|
} else {
|
2016-11-30 06:19:28 +00:00
|
|
|
val->constant->values[0].u32[i] = u[comp];
|
2016-01-13 04:02:04 +00:00
|
|
|
}
|
|
|
|
}
|
2016-06-01 18:34:04 +01:00
|
|
|
break;
|
2016-01-13 04:02:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case SpvOpCompositeExtract:
|
|
|
|
case SpvOpCompositeInsert: {
|
|
|
|
struct vtn_value *comp;
|
|
|
|
unsigned deref_start;
|
|
|
|
struct nir_constant **c;
|
|
|
|
if (opcode == SpvOpCompositeExtract) {
|
|
|
|
comp = vtn_value(b, w[4], vtn_value_type_constant);
|
|
|
|
deref_start = 5;
|
|
|
|
c = &comp->constant;
|
|
|
|
} else {
|
|
|
|
comp = vtn_value(b, w[5], vtn_value_type_constant);
|
|
|
|
deref_start = 6;
|
|
|
|
val->constant = nir_constant_clone(comp->constant,
|
|
|
|
(nir_variable *)b);
|
|
|
|
c = &val->constant;
|
|
|
|
}
|
|
|
|
|
|
|
|
int elem = -1;
|
2016-11-30 06:19:28 +00:00
|
|
|
int col = 0;
|
2016-01-13 04:02:04 +00:00
|
|
|
const struct glsl_type *type = comp->const_type;
|
|
|
|
for (unsigned i = deref_start; i < count; i++) {
|
|
|
|
switch (glsl_get_base_type(type)) {
|
|
|
|
case GLSL_TYPE_UINT:
|
|
|
|
case GLSL_TYPE_INT:
|
|
|
|
case GLSL_TYPE_FLOAT:
|
|
|
|
case GLSL_TYPE_BOOL:
|
|
|
|
/* If we hit this granularity, we're picking off an element */
|
|
|
|
if (glsl_type_is_matrix(type)) {
|
2016-11-30 06:19:28 +00:00
|
|
|
assert(col == 0 && elem == -1);
|
|
|
|
col = w[i];
|
|
|
|
elem = 0;
|
2016-01-13 04:02:04 +00:00
|
|
|
type = glsl_get_column_type(type);
|
|
|
|
} else {
|
2016-11-30 06:19:28 +00:00
|
|
|
assert(elem <= 0 && glsl_type_is_vector(type));
|
|
|
|
elem = w[i];
|
2016-01-13 04:02:04 +00:00
|
|
|
type = glsl_scalar_type(glsl_get_base_type(type));
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
|
|
|
|
case GLSL_TYPE_ARRAY:
|
|
|
|
c = &(*c)->elements[w[i]];
|
|
|
|
type = glsl_get_array_element(type);
|
|
|
|
continue;
|
|
|
|
|
|
|
|
case GLSL_TYPE_STRUCT:
|
|
|
|
c = &(*c)->elements[w[i]];
|
|
|
|
type = glsl_get_struct_field(type, w[i]);
|
|
|
|
continue;
|
|
|
|
|
|
|
|
default:
|
|
|
|
unreachable("Invalid constant type");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (opcode == SpvOpCompositeExtract) {
|
|
|
|
if (elem == -1) {
|
|
|
|
val->constant = *c;
|
|
|
|
} else {
|
|
|
|
unsigned num_components = glsl_get_vector_elements(type);
|
|
|
|
for (unsigned i = 0; i < num_components; i++)
|
2016-11-30 06:19:28 +00:00
|
|
|
val->constant->values[0].u32[i] = (*c)->values[col].u32[elem + i];
|
2016-01-13 04:02:04 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
struct vtn_value *insert =
|
|
|
|
vtn_value(b, w[4], vtn_value_type_constant);
|
|
|
|
assert(insert->const_type == type);
|
|
|
|
if (elem == -1) {
|
|
|
|
*c = insert->constant;
|
|
|
|
} else {
|
|
|
|
unsigned num_components = glsl_get_vector_elements(type);
|
|
|
|
for (unsigned i = 0; i < num_components; i++)
|
2016-11-30 06:19:28 +00:00
|
|
|
(*c)->values[col].u32[elem + i] = insert->constant->values[0].u32[i];
|
2016-01-13 04:02:04 +00:00
|
|
|
}
|
|
|
|
}
|
2016-06-01 18:34:04 +01:00
|
|
|
break;
|
2016-01-13 04:02:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
default: {
|
|
|
|
bool swap;
|
|
|
|
nir_op op = vtn_nir_alu_op_for_spirv_opcode(opcode, &swap);
|
|
|
|
|
|
|
|
unsigned num_components = glsl_get_vector_elements(val->const_type);
|
2016-03-25 00:30:14 +00:00
|
|
|
unsigned bit_size =
|
2016-05-11 20:05:09 +01:00
|
|
|
glsl_get_bit_size(val->const_type);
|
2016-01-13 04:02:04 +00:00
|
|
|
|
2016-05-16 20:48:00 +01:00
|
|
|
nir_const_value src[4];
|
2016-01-13 04:02:04 +00:00
|
|
|
assert(count <= 7);
|
|
|
|
for (unsigned i = 0; i < count - 4; i++) {
|
|
|
|
nir_constant *c =
|
|
|
|
vtn_value(b, w[4 + i], vtn_value_type_constant)->constant;
|
|
|
|
|
|
|
|
unsigned j = swap ? 1 - i : i;
|
2016-03-25 00:30:14 +00:00
|
|
|
assert(bit_size == 32);
|
2016-11-30 06:19:28 +00:00
|
|
|
src[j] = c->values[0];
|
2016-01-13 04:02:04 +00:00
|
|
|
}
|
|
|
|
|
2016-11-30 06:19:28 +00:00
|
|
|
val->constant->values[0] =
|
|
|
|
nir_eval_const_opcode(op, num_components, bit_size, src);
|
2016-06-01 18:34:04 +01:00
|
|
|
break;
|
2016-01-13 04:02:04 +00:00
|
|
|
} /* default */
|
|
|
|
}
|
2016-06-01 18:34:04 +01:00
|
|
|
break;
|
2016-01-13 04:02:04 +00:00
|
|
|
}
|
|
|
|
|
2016-01-05 00:57:01 +00:00
|
|
|
case SpvOpConstantNull:
|
|
|
|
val->constant = vtn_null_constant(b, val->const_type);
|
|
|
|
break;
|
|
|
|
|
2016-01-05 01:04:26 +00:00
|
|
|
case SpvOpConstantSampler:
|
|
|
|
assert(!"OpConstantSampler requires Kernel Capability");
|
|
|
|
break;
|
|
|
|
|
2015-04-30 02:14:11 +01:00
|
|
|
default:
|
|
|
|
unreachable("Unhandled opcode");
|
|
|
|
}
|
2016-06-01 19:20:22 +01:00
|
|
|
|
|
|
|
/* Now that we have the value, update the workgroup size if needed */
|
|
|
|
vtn_foreach_decoration(b, val, handle_workgroup_size_decoration_cb, NULL);
|
2015-04-29 01:43:16 +01:00
|
|
|
}
|
|
|
|
|
2015-04-30 04:10:20 +01:00
|
|
|
static void
|
2015-05-04 18:23:09 +01:00
|
|
|
vtn_handle_function_call(struct vtn_builder *b, SpvOp opcode,
|
|
|
|
const uint32_t *w, unsigned count)
|
2015-04-30 04:10:20 +01:00
|
|
|
{
|
2015-12-28 18:56:31 +00:00
|
|
|
struct nir_function *callee =
|
|
|
|
vtn_value(b, w[3], vtn_value_type_function)->func->impl->function;
|
2015-12-18 23:07:16 +00:00
|
|
|
|
2015-12-28 18:56:31 +00:00
|
|
|
nir_call_instr *call = nir_call_instr_create(b->nb.shader, callee);
|
2015-12-18 23:07:16 +00:00
|
|
|
for (unsigned i = 0; i < call->num_params; i++) {
|
|
|
|
unsigned arg_id = w[4 + i];
|
|
|
|
struct vtn_value *arg = vtn_untyped_value(b, arg_id);
|
2016-01-21 01:11:55 +00:00
|
|
|
if (arg->value_type == vtn_value_type_access_chain) {
|
|
|
|
nir_deref_var *d = vtn_access_chain_to_deref(b, arg->access_chain);
|
|
|
|
call->params[i] = nir_deref_as_var(nir_copy_deref(call, &d->deref));
|
2015-12-18 23:07:16 +00:00
|
|
|
} else {
|
|
|
|
struct vtn_ssa_value *arg_ssa = vtn_ssa_value(b, arg_id);
|
|
|
|
|
|
|
|
/* Make a temporary to store the argument in */
|
|
|
|
nir_variable *tmp =
|
|
|
|
nir_local_variable_create(b->impl, arg_ssa->type, "arg_tmp");
|
|
|
|
call->params[i] = nir_deref_var_create(call, tmp);
|
|
|
|
|
2016-01-21 01:11:55 +00:00
|
|
|
vtn_local_store(b, arg_ssa, call->params[i]);
|
2015-12-18 23:07:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nir_variable *out_tmp = NULL;
|
2015-12-28 18:56:31 +00:00
|
|
|
if (!glsl_type_is_void(callee->return_type)) {
|
|
|
|
out_tmp = nir_local_variable_create(b->impl, callee->return_type,
|
2015-12-18 23:07:16 +00:00
|
|
|
"out_tmp");
|
|
|
|
call->return_deref = nir_deref_var_create(call, out_tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
nir_builder_instr_insert(&b->nb, &call->instr);
|
|
|
|
|
2015-12-28 18:56:31 +00:00
|
|
|
if (glsl_type_is_void(callee->return_type)) {
|
2015-12-18 23:07:16 +00:00
|
|
|
vtn_push_value(b, w[2], vtn_value_type_undef);
|
|
|
|
} else {
|
|
|
|
struct vtn_value *retval = vtn_push_value(b, w[2], vtn_value_type_ssa);
|
2016-01-21 01:11:55 +00:00
|
|
|
retval->ssa = vtn_local_load(b, call->return_deref);
|
2015-12-18 23:07:16 +00:00
|
|
|
}
|
2015-04-30 04:10:20 +01:00
|
|
|
}
|
|
|
|
|
2016-01-08 19:02:17 +00:00
|
|
|
struct vtn_ssa_value *
|
2015-08-31 20:48:04 +01:00
|
|
|
vtn_create_ssa_value(struct vtn_builder *b, const struct glsl_type *type)
|
|
|
|
{
|
|
|
|
struct vtn_ssa_value *val = rzalloc(b, struct vtn_ssa_value);
|
|
|
|
val->type = type;
|
|
|
|
|
|
|
|
if (!glsl_type_is_vector_or_scalar(type)) {
|
|
|
|
unsigned elems = glsl_get_length(type);
|
|
|
|
val->elems = ralloc_array(b, struct vtn_ssa_value *, elems);
|
|
|
|
for (unsigned i = 0; i < elems; i++) {
|
|
|
|
const struct glsl_type *child_type;
|
|
|
|
|
|
|
|
switch (glsl_get_base_type(type)) {
|
|
|
|
case GLSL_TYPE_INT:
|
|
|
|
case GLSL_TYPE_UINT:
|
|
|
|
case GLSL_TYPE_BOOL:
|
|
|
|
case GLSL_TYPE_FLOAT:
|
|
|
|
case GLSL_TYPE_DOUBLE:
|
|
|
|
child_type = glsl_get_column_type(type);
|
|
|
|
break;
|
|
|
|
case GLSL_TYPE_ARRAY:
|
|
|
|
child_type = glsl_get_array_element(type);
|
|
|
|
break;
|
|
|
|
case GLSL_TYPE_STRUCT:
|
|
|
|
child_type = glsl_get_struct_field(type, i);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
unreachable("unkown base type");
|
|
|
|
}
|
|
|
|
|
|
|
|
val->elems[i] = vtn_create_ssa_value(b, child_type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2015-05-16 20:34:15 +01:00
|
|
|
static nir_tex_src
|
|
|
|
vtn_tex_src(struct vtn_builder *b, unsigned index, nir_tex_src_type type)
|
|
|
|
{
|
|
|
|
nir_tex_src src;
|
2015-10-06 23:10:45 +01:00
|
|
|
src.src = nir_src_for_ssa(vtn_ssa_value(b, index)->def);
|
2015-05-16 20:34:15 +01:00
|
|
|
src.src_type = type;
|
|
|
|
return src;
|
|
|
|
}
|
|
|
|
|
2015-04-29 01:43:16 +01:00
|
|
|
static void
|
|
|
|
vtn_handle_texture(struct vtn_builder *b, SpvOp opcode,
|
|
|
|
const uint32_t *w, unsigned count)
|
|
|
|
{
|
2015-11-15 06:32:54 +00:00
|
|
|
if (opcode == SpvOpSampledImage) {
|
|
|
|
struct vtn_value *val =
|
|
|
|
vtn_push_value(b, w[2], vtn_value_type_sampled_image);
|
|
|
|
val->sampled_image = ralloc(b, struct vtn_sampled_image);
|
|
|
|
val->sampled_image->image =
|
2016-01-21 01:11:55 +00:00
|
|
|
vtn_value(b, w[3], vtn_value_type_access_chain)->access_chain;
|
2015-11-15 06:32:54 +00:00
|
|
|
val->sampled_image->sampler =
|
2016-01-21 01:11:55 +00:00
|
|
|
vtn_value(b, w[4], vtn_value_type_access_chain)->access_chain;
|
2015-11-15 06:32:54 +00:00
|
|
|
return;
|
2016-02-01 21:47:13 +00:00
|
|
|
} else if (opcode == SpvOpImage) {
|
|
|
|
struct vtn_value *val =
|
|
|
|
vtn_push_value(b, w[2], vtn_value_type_access_chain);
|
|
|
|
struct vtn_value *src_val = vtn_untyped_value(b, w[3]);
|
|
|
|
if (src_val->value_type == vtn_value_type_sampled_image) {
|
|
|
|
val->access_chain = src_val->sampled_image->image;
|
|
|
|
} else {
|
|
|
|
assert(src_val->value_type == vtn_value_type_access_chain);
|
|
|
|
val->access_chain = src_val->access_chain;
|
|
|
|
}
|
|
|
|
return;
|
2015-11-15 06:32:54 +00:00
|
|
|
}
|
|
|
|
|
2016-01-15 02:40:35 +00:00
|
|
|
struct vtn_type *ret_type = vtn_value(b, w[1], vtn_value_type_type)->type;
|
2015-05-16 20:34:15 +01:00
|
|
|
struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_ssa);
|
2015-11-15 06:32:54 +00:00
|
|
|
|
|
|
|
struct vtn_sampled_image sampled;
|
|
|
|
struct vtn_value *sampled_val = vtn_untyped_value(b, w[3]);
|
|
|
|
if (sampled_val->value_type == vtn_value_type_sampled_image) {
|
|
|
|
sampled = *sampled_val->sampled_image;
|
|
|
|
} else {
|
2016-01-21 01:11:55 +00:00
|
|
|
assert(sampled_val->value_type == vtn_value_type_access_chain);
|
2015-11-15 06:32:54 +00:00
|
|
|
sampled.image = NULL;
|
2016-01-21 01:11:55 +00:00
|
|
|
sampled.sampler = sampled_val->access_chain;
|
2015-11-15 06:32:54 +00:00
|
|
|
}
|
2015-05-16 20:34:15 +01:00
|
|
|
|
2016-02-22 05:42:33 +00:00
|
|
|
const struct glsl_type *image_type;
|
|
|
|
if (sampled.image) {
|
|
|
|
image_type = sampled.image->var->var->interface_type;
|
|
|
|
} else {
|
|
|
|
image_type = sampled.sampler->var->var->interface_type;
|
|
|
|
}
|
2016-07-21 19:56:09 +01:00
|
|
|
const enum glsl_sampler_dim sampler_dim = glsl_get_sampler_dim(image_type);
|
|
|
|
const bool is_array = glsl_sampler_type_is_array(image_type);
|
|
|
|
const bool is_shadow = glsl_sampler_type_is_shadow(image_type);
|
2016-02-22 05:42:33 +00:00
|
|
|
|
2016-07-21 19:47:44 +01:00
|
|
|
/* Figure out the base texture operation */
|
|
|
|
nir_texop texop;
|
|
|
|
switch (opcode) {
|
|
|
|
case SpvOpImageSampleImplicitLod:
|
|
|
|
case SpvOpImageSampleDrefImplicitLod:
|
|
|
|
case SpvOpImageSampleProjImplicitLod:
|
|
|
|
case SpvOpImageSampleProjDrefImplicitLod:
|
|
|
|
texop = nir_texop_tex;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SpvOpImageSampleExplicitLod:
|
|
|
|
case SpvOpImageSampleDrefExplicitLod:
|
|
|
|
case SpvOpImageSampleProjExplicitLod:
|
|
|
|
case SpvOpImageSampleProjDrefExplicitLod:
|
|
|
|
texop = nir_texop_txl;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SpvOpImageFetch:
|
|
|
|
if (glsl_get_sampler_dim(image_type) == GLSL_SAMPLER_DIM_MS) {
|
|
|
|
texop = nir_texop_txf_ms;
|
|
|
|
} else {
|
|
|
|
texop = nir_texop_txf;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SpvOpImageGather:
|
|
|
|
case SpvOpImageDrefGather:
|
|
|
|
texop = nir_texop_tg4;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SpvOpImageQuerySizeLod:
|
|
|
|
case SpvOpImageQuerySize:
|
|
|
|
texop = nir_texop_txs;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SpvOpImageQueryLod:
|
|
|
|
texop = nir_texop_lod;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SpvOpImageQueryLevels:
|
|
|
|
texop = nir_texop_query_levels;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SpvOpImageQuerySamples:
|
2016-07-21 21:15:59 +01:00
|
|
|
texop = nir_texop_texture_samples;
|
|
|
|
break;
|
|
|
|
|
2016-07-21 19:47:44 +01:00
|
|
|
default:
|
|
|
|
unreachable("Unhandled opcode");
|
|
|
|
}
|
|
|
|
|
2015-05-16 20:34:15 +01:00
|
|
|
nir_tex_src srcs[8]; /* 8 should be enough */
|
|
|
|
nir_tex_src *p = srcs;
|
|
|
|
|
2015-08-31 20:48:04 +01:00
|
|
|
unsigned idx = 4;
|
|
|
|
|
2016-07-21 20:01:35 +01:00
|
|
|
struct nir_ssa_def *coord;
|
|
|
|
unsigned coord_components;
|
2015-05-16 20:34:15 +01:00
|
|
|
switch (opcode) {
|
2015-08-31 20:48:04 +01:00
|
|
|
case SpvOpImageSampleImplicitLod:
|
|
|
|
case SpvOpImageSampleExplicitLod:
|
|
|
|
case SpvOpImageSampleDrefImplicitLod:
|
|
|
|
case SpvOpImageSampleDrefExplicitLod:
|
|
|
|
case SpvOpImageSampleProjImplicitLod:
|
|
|
|
case SpvOpImageSampleProjExplicitLod:
|
|
|
|
case SpvOpImageSampleProjDrefImplicitLod:
|
|
|
|
case SpvOpImageSampleProjDrefExplicitLod:
|
|
|
|
case SpvOpImageFetch:
|
|
|
|
case SpvOpImageGather:
|
|
|
|
case SpvOpImageDrefGather:
|
|
|
|
case SpvOpImageQueryLod: {
|
2015-05-16 20:34:15 +01:00
|
|
|
/* All these types have the coordinate as their first real argument */
|
2016-07-21 20:01:35 +01:00
|
|
|
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:
|
2016-08-29 03:13:52 +01:00
|
|
|
unreachable("Invalid sampler type");
|
2016-07-21 20:01:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (is_array && texop != nir_texop_lod)
|
|
|
|
coord_components++;
|
|
|
|
|
|
|
|
coord = vtn_ssa_value(b, w[idx++])->def;
|
|
|
|
p->src = nir_src_for_ssa(coord);
|
2015-05-16 20:34:15 +01:00
|
|
|
p->src_type = nir_tex_src_coord;
|
|
|
|
p++;
|
|
|
|
break;
|
|
|
|
}
|
2015-08-31 20:48:04 +01:00
|
|
|
|
2015-05-16 20:34:15 +01:00
|
|
|
default:
|
2016-07-21 20:01:35 +01:00
|
|
|
coord = NULL;
|
|
|
|
coord_components = 0;
|
2015-05-16 20:34:15 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-07-21 20:01:46 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-07-21 03:56:45 +01:00
|
|
|
unsigned gather_component = 0;
|
2015-05-16 20:34:15 +01:00
|
|
|
switch (opcode) {
|
2015-09-05 22:09:15 +01:00
|
|
|
case SpvOpImageSampleDrefImplicitLod:
|
|
|
|
case SpvOpImageSampleDrefExplicitLod:
|
|
|
|
case SpvOpImageSampleProjDrefImplicitLod:
|
|
|
|
case SpvOpImageSampleProjDrefExplicitLod:
|
2016-07-21 03:56:45 +01:00
|
|
|
case SpvOpImageDrefGather:
|
|
|
|
/* These all have an explicit depth value as their next source */
|
2016-12-12 13:32:38 +00:00
|
|
|
(*p++) = vtn_tex_src(b, w[idx++], nir_tex_src_comparator);
|
2015-05-16 20:34:15 +01:00
|
|
|
break;
|
2016-07-21 03:56:45 +01:00
|
|
|
|
|
|
|
case SpvOpImageGather:
|
|
|
|
/* This has a component as its next source */
|
|
|
|
gather_component =
|
2016-11-30 06:19:28 +00:00
|
|
|
vtn_value(b, w[idx++], vtn_value_type_constant)->constant->values[0].u32[0];
|
2016-07-21 03:56:45 +01:00
|
|
|
break;
|
|
|
|
|
2015-09-05 22:09:15 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2015-05-16 20:34:15 +01:00
|
|
|
|
2016-02-01 21:52:47 +00:00
|
|
|
/* For OpImageQuerySizeLod, we always have an LOD */
|
|
|
|
if (opcode == SpvOpImageQuerySizeLod)
|
|
|
|
(*p++) = vtn_tex_src(b, w[idx++], nir_tex_src_lod);
|
|
|
|
|
2015-09-05 22:09:15 +01:00
|
|
|
/* Now we need to handle some number of optional arguments */
|
2016-11-27 21:09:55 +00:00
|
|
|
const struct vtn_ssa_value *gather_offsets = NULL;
|
2015-08-31 20:48:04 +01:00
|
|
|
if (idx < count) {
|
2015-09-05 22:09:15 +01:00
|
|
|
uint32_t operands = w[idx++];
|
|
|
|
|
|
|
|
if (operands & SpvImageOperandsBiasMask) {
|
|
|
|
assert(texop == nir_texop_tex);
|
|
|
|
texop = nir_texop_txb;
|
|
|
|
(*p++) = vtn_tex_src(b, w[idx++], nir_tex_src_bias);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (operands & SpvImageOperandsLodMask) {
|
2015-10-06 23:10:45 +01:00
|
|
|
assert(texop == nir_texop_txl || texop == nir_texop_txf ||
|
2016-07-21 03:23:17 +01:00
|
|
|
texop == nir_texop_txs);
|
2015-09-05 22:09:15 +01:00
|
|
|
(*p++) = vtn_tex_src(b, w[idx++], nir_tex_src_lod);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (operands & SpvImageOperandsGradMask) {
|
2016-07-21 03:23:17 +01:00
|
|
|
assert(texop == nir_texop_txl);
|
2015-09-05 22:09:15 +01:00
|
|
|
texop = nir_texop_txd;
|
|
|
|
(*p++) = vtn_tex_src(b, w[idx++], nir_tex_src_ddx);
|
|
|
|
(*p++) = vtn_tex_src(b, w[idx++], nir_tex_src_ddy);
|
|
|
|
}
|
2015-08-31 20:48:04 +01:00
|
|
|
|
2016-02-11 01:10:19 +00:00
|
|
|
if (operands & SpvImageOperandsOffsetMask ||
|
|
|
|
operands & SpvImageOperandsConstOffsetMask)
|
2015-09-05 22:09:15 +01:00
|
|
|
(*p++) = vtn_tex_src(b, w[idx++], nir_tex_src_offset);
|
|
|
|
|
2016-11-27 21:09:55 +00:00
|
|
|
if (operands & SpvImageOperandsConstOffsetsMask) {
|
|
|
|
gather_offsets = vtn_ssa_value(b, w[idx++]);
|
|
|
|
(*p++) = (nir_tex_src){};
|
|
|
|
}
|
2015-09-05 22:09:15 +01:00
|
|
|
|
|
|
|
if (operands & SpvImageOperandsSampleMask) {
|
2016-02-22 05:42:33 +00:00
|
|
|
assert(texop == nir_texop_txf_ms);
|
2015-09-05 22:09:15 +01:00
|
|
|
texop = nir_texop_txf_ms;
|
|
|
|
(*p++) = vtn_tex_src(b, w[idx++], nir_tex_src_ms_index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* We should have now consumed exactly all of the arguments */
|
|
|
|
assert(idx == count);
|
2015-08-31 20:48:04 +01:00
|
|
|
|
2015-05-16 20:34:15 +01:00
|
|
|
nir_tex_instr *instr = nir_tex_instr_create(b->shader, p - srcs);
|
2016-01-15 19:10:58 +00:00
|
|
|
instr->op = texop;
|
|
|
|
|
|
|
|
memcpy(instr->src, srcs, instr->num_srcs * sizeof(*instr->src));
|
2015-05-16 20:34:15 +01:00
|
|
|
|
2016-07-21 20:01:35 +01:00
|
|
|
instr->coord_components = coord_components;
|
2016-07-21 19:56:09 +01:00
|
|
|
instr->sampler_dim = sampler_dim;
|
|
|
|
instr->is_array = is_array;
|
|
|
|
instr->is_shadow = is_shadow;
|
|
|
|
instr->is_new_style_shadow =
|
|
|
|
is_shadow && glsl_get_components(ret_type->type) == 1;
|
2016-07-21 03:56:45 +01:00
|
|
|
instr->component = gather_component;
|
2016-01-15 19:10:58 +00:00
|
|
|
|
2016-01-20 19:11:30 +00:00
|
|
|
switch (glsl_get_sampler_result_type(image_type)) {
|
2015-05-16 20:34:15 +01:00
|
|
|
case GLSL_TYPE_FLOAT: instr->dest_type = nir_type_float; break;
|
|
|
|
case GLSL_TYPE_INT: instr->dest_type = nir_type_int; break;
|
2015-11-23 22:03:47 +00:00
|
|
|
case GLSL_TYPE_UINT: instr->dest_type = nir_type_uint; break;
|
2015-05-16 20:34:15 +01:00
|
|
|
case GLSL_TYPE_BOOL: instr->dest_type = nir_type_bool; break;
|
|
|
|
default:
|
|
|
|
unreachable("Invalid base type for sampler result");
|
|
|
|
}
|
|
|
|
|
2016-01-21 01:11:55 +00:00
|
|
|
nir_deref_var *sampler = vtn_access_chain_to_deref(b, sampled.sampler);
|
2016-11-27 21:09:55 +00:00
|
|
|
nir_deref *texture;
|
2015-11-15 06:32:54 +00:00
|
|
|
if (sampled.image) {
|
2016-01-21 01:11:55 +00:00
|
|
|
nir_deref_var *image = vtn_access_chain_to_deref(b, sampled.image);
|
2016-11-27 21:09:55 +00:00
|
|
|
texture = &image->deref;
|
2015-11-15 06:32:54 +00:00
|
|
|
} else {
|
2016-11-27 21:09:55 +00:00
|
|
|
texture = &sampler->deref;
|
2016-02-09 20:13:32 +00:00
|
|
|
}
|
|
|
|
|
2016-11-27 21:09:55 +00:00
|
|
|
instr->texture = nir_deref_as_var(nir_copy_deref(instr, texture));
|
|
|
|
|
2016-02-09 20:13:32 +00:00
|
|
|
switch (instr->op) {
|
|
|
|
case nir_texop_tex:
|
|
|
|
case nir_texop_txb:
|
|
|
|
case nir_texop_txl:
|
|
|
|
case nir_texop_txd:
|
|
|
|
/* These operations require a sampler */
|
|
|
|
instr->sampler = nir_deref_as_var(nir_copy_deref(instr, &sampler->deref));
|
|
|
|
break;
|
|
|
|
case nir_texop_txf:
|
|
|
|
case nir_texop_txf_ms:
|
|
|
|
case nir_texop_txs:
|
|
|
|
case nir_texop_lod:
|
|
|
|
case nir_texop_tg4:
|
|
|
|
case nir_texop_query_levels:
|
|
|
|
case nir_texop_texture_samples:
|
|
|
|
case nir_texop_samples_identical:
|
|
|
|
/* These don't */
|
|
|
|
instr->sampler = NULL;
|
|
|
|
break;
|
2016-05-18 02:28:37 +01:00
|
|
|
case nir_texop_txf_ms_mcs:
|
|
|
|
unreachable("unexpected nir_texop_txf_ms_mcs");
|
2015-11-15 06:32:54 +00:00
|
|
|
}
|
2015-05-16 20:34:15 +01:00
|
|
|
|
2016-01-15 02:40:35 +00:00
|
|
|
nir_ssa_dest_init(&instr->instr, &instr->dest,
|
2016-03-25 00:30:14 +00:00
|
|
|
nir_tex_instr_dest_size(instr), 32, NULL);
|
2016-01-15 02:40:35 +00:00
|
|
|
|
|
|
|
assert(glsl_get_vector_elements(ret_type->type) ==
|
|
|
|
nir_tex_instr_dest_size(instr));
|
|
|
|
|
2016-11-27 21:09:55 +00:00
|
|
|
nir_ssa_def *def;
|
|
|
|
nir_instr *instruction;
|
|
|
|
if (gather_offsets) {
|
|
|
|
assert(glsl_get_base_type(gather_offsets->type) == GLSL_TYPE_ARRAY);
|
|
|
|
assert(glsl_get_length(gather_offsets->type) == 4);
|
|
|
|
nir_tex_instr *instrs[4] = {instr, NULL, NULL, NULL};
|
|
|
|
|
|
|
|
/* Copy the current instruction 4x */
|
|
|
|
for (uint32_t i = 1; i < 4; i++) {
|
|
|
|
instrs[i] = nir_tex_instr_create(b->shader, instr->num_srcs);
|
|
|
|
instrs[i]->op = instr->op;
|
|
|
|
instrs[i]->coord_components = instr->coord_components;
|
|
|
|
instrs[i]->sampler_dim = instr->sampler_dim;
|
|
|
|
instrs[i]->is_array = instr->is_array;
|
|
|
|
instrs[i]->is_shadow = instr->is_shadow;
|
|
|
|
instrs[i]->is_new_style_shadow = instr->is_new_style_shadow;
|
|
|
|
instrs[i]->component = instr->component;
|
|
|
|
instrs[i]->dest_type = instr->dest_type;
|
|
|
|
instrs[i]->texture =
|
|
|
|
nir_deref_as_var(nir_copy_deref(instrs[i], texture));
|
|
|
|
instrs[i]->sampler = NULL;
|
|
|
|
|
|
|
|
memcpy(instrs[i]->src, srcs, instr->num_srcs * sizeof(*instr->src));
|
|
|
|
|
|
|
|
nir_ssa_dest_init(&instrs[i]->instr, &instrs[i]->dest,
|
|
|
|
nir_tex_instr_dest_size(instr), 32, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fill in the last argument with the offset from the passed in offsets
|
|
|
|
* and insert the instruction into the stream.
|
|
|
|
*/
|
|
|
|
for (uint32_t i = 0; i < 4; i++) {
|
|
|
|
nir_tex_src src;
|
|
|
|
src.src = nir_src_for_ssa(gather_offsets->elems[i]->def);
|
|
|
|
src.src_type = nir_tex_src_offset;
|
|
|
|
instrs[i]->src[instrs[i]->num_srcs - 1] = src;
|
|
|
|
nir_builder_instr_insert(&b->nb, &instrs[i]->instr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Combine the results of the 4 instructions by taking their .w
|
|
|
|
* components
|
|
|
|
*/
|
|
|
|
nir_alu_instr *vec4 = nir_alu_instr_create(b->shader, nir_op_vec4);
|
|
|
|
nir_ssa_dest_init(&vec4->instr, &vec4->dest.dest, 4, 32, NULL);
|
|
|
|
vec4->dest.write_mask = 0xf;
|
|
|
|
for (uint32_t i = 0; i < 4; i++) {
|
|
|
|
vec4->src[i].src = nir_src_for_ssa(&instrs[i]->dest.ssa);
|
|
|
|
vec4->src[i].swizzle[0] = 3;
|
|
|
|
}
|
|
|
|
def = &vec4->dest.dest.ssa;
|
|
|
|
instruction = &vec4->instr;
|
|
|
|
} else {
|
|
|
|
def = &instr->dest.ssa;
|
|
|
|
instruction = &instr->instr;
|
|
|
|
}
|
|
|
|
|
2016-01-15 02:40:35 +00:00
|
|
|
val->ssa = vtn_create_ssa_value(b, ret_type->type);
|
2016-11-27 21:09:55 +00:00
|
|
|
val->ssa->def = def;
|
2015-05-16 20:34:15 +01:00
|
|
|
|
2016-11-27 21:09:55 +00:00
|
|
|
nir_builder_instr_insert(&b->nb, instruction);
|
2015-04-29 01:43:16 +01:00
|
|
|
}
|
|
|
|
|
2016-09-06 23:07:57 +01:00
|
|
|
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;
|
|
|
|
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-14 01:26:22 +00:00
|
|
|
static nir_ssa_def *
|
|
|
|
get_image_coord(struct vtn_builder *b, uint32_t value)
|
|
|
|
{
|
|
|
|
struct vtn_ssa_value *coord = vtn_ssa_value(b, value);
|
|
|
|
|
|
|
|
/* The image_load_store intrinsics assume a 4-dim coordinate */
|
|
|
|
unsigned dim = glsl_get_vector_elements(coord->type);
|
|
|
|
unsigned swizzle[4];
|
|
|
|
for (unsigned i = 0; i < 4; i++)
|
|
|
|
swizzle[i] = MIN2(i, dim - 1);
|
|
|
|
|
|
|
|
return nir_swizzle(&b->nb, coord->def, swizzle, 4, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vtn_handle_image(struct vtn_builder *b, SpvOp opcode,
|
|
|
|
const uint32_t *w, unsigned count)
|
|
|
|
{
|
|
|
|
/* Just get this one out of the way */
|
|
|
|
if (opcode == SpvOpImageTexelPointer) {
|
|
|
|
struct vtn_value *val =
|
|
|
|
vtn_push_value(b, w[2], vtn_value_type_image_pointer);
|
|
|
|
val->image = ralloc(b, struct vtn_image_pointer);
|
|
|
|
|
2016-01-21 01:11:55 +00:00
|
|
|
val->image->image =
|
|
|
|
vtn_value(b, w[3], vtn_value_type_access_chain)->access_chain;
|
2015-11-14 01:26:22 +00:00
|
|
|
val->image->coord = get_image_coord(b, w[4]);
|
|
|
|
val->image->sample = vtn_ssa_value(b, w[5])->def;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct vtn_image_pointer image;
|
|
|
|
|
|
|
|
switch (opcode) {
|
|
|
|
case SpvOpAtomicExchange:
|
|
|
|
case SpvOpAtomicCompareExchange:
|
|
|
|
case SpvOpAtomicCompareExchangeWeak:
|
|
|
|
case SpvOpAtomicIIncrement:
|
|
|
|
case SpvOpAtomicIDecrement:
|
|
|
|
case SpvOpAtomicIAdd:
|
|
|
|
case SpvOpAtomicISub:
|
2016-09-19 17:14:18 +01:00
|
|
|
case SpvOpAtomicLoad:
|
2015-11-14 01:26:22 +00:00
|
|
|
case SpvOpAtomicSMin:
|
|
|
|
case SpvOpAtomicUMin:
|
|
|
|
case SpvOpAtomicSMax:
|
|
|
|
case SpvOpAtomicUMax:
|
|
|
|
case SpvOpAtomicAnd:
|
|
|
|
case SpvOpAtomicOr:
|
|
|
|
case SpvOpAtomicXor:
|
|
|
|
image = *vtn_value(b, w[3], vtn_value_type_image_pointer)->image;
|
|
|
|
break;
|
|
|
|
|
2016-09-19 17:14:18 +01:00
|
|
|
case SpvOpAtomicStore:
|
|
|
|
image = *vtn_value(b, w[1], vtn_value_type_image_pointer)->image;
|
2016-09-06 14:26:17 +01:00
|
|
|
break;
|
|
|
|
|
2016-01-05 22:03:58 +00:00
|
|
|
case SpvOpImageQuerySize:
|
2016-01-21 01:11:55 +00:00
|
|
|
image.image =
|
|
|
|
vtn_value(b, w[3], vtn_value_type_access_chain)->access_chain;
|
2016-01-05 22:03:58 +00:00
|
|
|
image.coord = NULL;
|
|
|
|
image.sample = NULL;
|
|
|
|
break;
|
|
|
|
|
2015-11-14 01:26:22 +00:00
|
|
|
case SpvOpImageRead:
|
2016-01-21 01:11:55 +00:00
|
|
|
image.image =
|
|
|
|
vtn_value(b, w[3], vtn_value_type_access_chain)->access_chain;
|
2015-11-14 01:26:22 +00:00
|
|
|
image.coord = get_image_coord(b, w[4]);
|
|
|
|
|
|
|
|
if (count > 5 && (w[5] & SpvImageOperandsSampleMask)) {
|
|
|
|
assert(w[5] == SpvImageOperandsSampleMask);
|
|
|
|
image.sample = vtn_ssa_value(b, w[6])->def;
|
|
|
|
} else {
|
2016-03-25 17:40:24 +00:00
|
|
|
image.sample = nir_ssa_undef(&b->nb, 1, 32);
|
2015-11-14 01:26:22 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SpvOpImageWrite:
|
2016-01-21 01:11:55 +00:00
|
|
|
image.image =
|
|
|
|
vtn_value(b, w[1], vtn_value_type_access_chain)->access_chain;
|
2015-11-14 01:26:22 +00:00
|
|
|
image.coord = get_image_coord(b, w[2]);
|
|
|
|
|
|
|
|
/* texel = w[3] */
|
|
|
|
|
|
|
|
if (count > 4 && (w[4] & SpvImageOperandsSampleMask)) {
|
|
|
|
assert(w[4] == SpvImageOperandsSampleMask);
|
|
|
|
image.sample = vtn_ssa_value(b, w[5])->def;
|
|
|
|
} else {
|
2016-03-25 17:40:24 +00:00
|
|
|
image.sample = nir_ssa_undef(&b->nb, 1, 32);
|
2015-11-14 01:26:22 +00:00
|
|
|
}
|
2015-12-31 05:57:04 +00:00
|
|
|
break;
|
2015-11-14 01:26:22 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
unreachable("Invalid image opcode");
|
|
|
|
}
|
|
|
|
|
|
|
|
nir_intrinsic_op op;
|
|
|
|
switch (opcode) {
|
|
|
|
#define OP(S, N) case SpvOp##S: op = nir_intrinsic_image_##N; break;
|
2016-01-05 22:03:58 +00:00
|
|
|
OP(ImageQuerySize, size)
|
2015-11-14 01:26:22 +00:00
|
|
|
OP(ImageRead, load)
|
|
|
|
OP(ImageWrite, store)
|
2016-09-06 14:26:17 +01:00
|
|
|
OP(AtomicLoad, load)
|
|
|
|
OP(AtomicStore, store)
|
2015-11-14 01:26:22 +00:00
|
|
|
OP(AtomicExchange, atomic_exchange)
|
|
|
|
OP(AtomicCompareExchange, atomic_comp_swap)
|
|
|
|
OP(AtomicIIncrement, atomic_add)
|
|
|
|
OP(AtomicIDecrement, atomic_add)
|
|
|
|
OP(AtomicIAdd, atomic_add)
|
|
|
|
OP(AtomicISub, atomic_add)
|
|
|
|
OP(AtomicSMin, atomic_min)
|
|
|
|
OP(AtomicUMin, atomic_min)
|
|
|
|
OP(AtomicSMax, atomic_max)
|
|
|
|
OP(AtomicUMax, atomic_max)
|
|
|
|
OP(AtomicAnd, atomic_and)
|
|
|
|
OP(AtomicOr, atomic_or)
|
|
|
|
OP(AtomicXor, atomic_xor)
|
|
|
|
#undef OP
|
|
|
|
default:
|
|
|
|
unreachable("Invalid image opcode");
|
|
|
|
}
|
|
|
|
|
|
|
|
nir_intrinsic_instr *intrin = nir_intrinsic_instr_create(b->shader, op);
|
2016-01-21 01:11:55 +00:00
|
|
|
|
|
|
|
nir_deref_var *image_deref = vtn_access_chain_to_deref(b, image.image);
|
2015-11-14 01:26:22 +00:00
|
|
|
intrin->variables[0] =
|
2016-01-21 01:11:55 +00:00
|
|
|
nir_deref_as_var(nir_copy_deref(&intrin->instr, &image_deref->deref));
|
2016-01-18 23:00:01 +00:00
|
|
|
|
2016-01-05 22:03:58 +00:00
|
|
|
/* ImageQuerySize doesn't take any extra parameters */
|
|
|
|
if (opcode != SpvOpImageQuerySize) {
|
|
|
|
/* The image coordinate is always 4 components but we may not have that
|
|
|
|
* many. Swizzle to compensate.
|
|
|
|
*/
|
|
|
|
unsigned swiz[4];
|
|
|
|
for (unsigned i = 0; i < 4; i++)
|
|
|
|
swiz[i] = i < image.coord->num_components ? i : 0;
|
|
|
|
intrin->src[0] = nir_src_for_ssa(nir_swizzle(&b->nb, image.coord,
|
|
|
|
swiz, 4, false));
|
|
|
|
intrin->src[1] = nir_src_for_ssa(image.sample);
|
|
|
|
}
|
2015-11-14 01:26:22 +00:00
|
|
|
|
|
|
|
switch (opcode) {
|
2016-09-06 14:26:17 +01:00
|
|
|
case SpvOpAtomicLoad:
|
2016-01-05 22:03:58 +00:00
|
|
|
case SpvOpImageQuerySize:
|
2015-11-14 01:26:22 +00:00
|
|
|
case SpvOpImageRead:
|
|
|
|
break;
|
2016-09-06 14:26:17 +01:00
|
|
|
case SpvOpAtomicStore:
|
|
|
|
intrin->src[2] = nir_src_for_ssa(vtn_ssa_value(b, w[4])->def);
|
|
|
|
break;
|
2015-11-14 01:26:22 +00:00
|
|
|
case SpvOpImageWrite:
|
|
|
|
intrin->src[2] = nir_src_for_ssa(vtn_ssa_value(b, w[3])->def);
|
|
|
|
break;
|
2016-09-06 23:07:57 +01:00
|
|
|
|
2015-11-14 01:26:22 +00:00
|
|
|
case SpvOpAtomicIIncrement:
|
|
|
|
case SpvOpAtomicIDecrement:
|
|
|
|
case SpvOpAtomicExchange:
|
|
|
|
case SpvOpAtomicIAdd:
|
|
|
|
case SpvOpAtomicSMin:
|
|
|
|
case SpvOpAtomicUMin:
|
|
|
|
case SpvOpAtomicSMax:
|
|
|
|
case SpvOpAtomicUMax:
|
|
|
|
case SpvOpAtomicAnd:
|
|
|
|
case SpvOpAtomicOr:
|
|
|
|
case SpvOpAtomicXor:
|
2016-09-06 23:07:57 +01:00
|
|
|
fill_common_atomic_sources(b, opcode, w, &intrin->src[2]);
|
2015-11-14 01:26:22 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
unreachable("Invalid image opcode");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (opcode != SpvOpImageWrite) {
|
|
|
|
struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_ssa);
|
|
|
|
struct vtn_type *type = vtn_value(b, w[1], vtn_value_type_type)->type;
|
2016-03-25 00:30:14 +00:00
|
|
|
nir_ssa_dest_init(&intrin->instr, &intrin->dest, 4, 32, NULL);
|
2016-01-18 23:00:01 +00:00
|
|
|
|
|
|
|
nir_builder_instr_insert(&b->nb, &intrin->instr);
|
|
|
|
|
|
|
|
/* The image intrinsics always return 4 channels but we may not want
|
|
|
|
* that many. Emit a mov to trim it down.
|
|
|
|
*/
|
|
|
|
unsigned swiz[4] = {0, 1, 2, 3};
|
2015-11-14 01:26:22 +00:00
|
|
|
val->ssa = vtn_create_ssa_value(b, type->type);
|
2016-01-18 23:00:01 +00:00
|
|
|
val->ssa->def = nir_swizzle(&b->nb, &intrin->dest.ssa, swiz,
|
|
|
|
glsl_get_vector_elements(type->type), false);
|
|
|
|
} else {
|
|
|
|
nir_builder_instr_insert(&b->nb, &intrin->instr);
|
2015-11-14 01:26:22 +00:00
|
|
|
}
|
|
|
|
}
|
2015-08-31 20:48:04 +01:00
|
|
|
|
2016-01-10 19:12:17 +00:00
|
|
|
static nir_intrinsic_op
|
|
|
|
get_ssbo_nir_atomic_op(SpvOp opcode)
|
2016-01-08 04:44:04 +00:00
|
|
|
{
|
2016-01-10 19:12:17 +00:00
|
|
|
switch (opcode) {
|
2016-09-06 14:26:17 +01:00
|
|
|
case SpvOpAtomicLoad: return nir_intrinsic_load_ssbo;
|
|
|
|
case SpvOpAtomicStore: return nir_intrinsic_store_ssbo;
|
2016-01-10 19:12:17 +00:00
|
|
|
#define OP(S, N) case SpvOp##S: return nir_intrinsic_ssbo_##N;
|
|
|
|
OP(AtomicExchange, atomic_exchange)
|
|
|
|
OP(AtomicCompareExchange, atomic_comp_swap)
|
|
|
|
OP(AtomicIIncrement, atomic_add)
|
|
|
|
OP(AtomicIDecrement, atomic_add)
|
|
|
|
OP(AtomicIAdd, atomic_add)
|
|
|
|
OP(AtomicISub, atomic_add)
|
|
|
|
OP(AtomicSMin, atomic_imin)
|
|
|
|
OP(AtomicUMin, atomic_umin)
|
|
|
|
OP(AtomicSMax, atomic_imax)
|
|
|
|
OP(AtomicUMax, atomic_umax)
|
|
|
|
OP(AtomicAnd, atomic_and)
|
|
|
|
OP(AtomicOr, atomic_or)
|
|
|
|
OP(AtomicXor, atomic_xor)
|
|
|
|
#undef OP
|
|
|
|
default:
|
|
|
|
unreachable("Invalid SSBO atomic");
|
|
|
|
}
|
|
|
|
}
|
2016-01-08 04:44:04 +00:00
|
|
|
|
2016-01-10 19:12:17 +00:00
|
|
|
static nir_intrinsic_op
|
|
|
|
get_shared_nir_atomic_op(SpvOp opcode)
|
|
|
|
{
|
|
|
|
switch (opcode) {
|
2016-09-06 14:26:17 +01:00
|
|
|
case SpvOpAtomicLoad: return nir_intrinsic_load_var;
|
|
|
|
case SpvOpAtomicStore: return nir_intrinsic_store_var;
|
2016-01-10 19:12:17 +00:00
|
|
|
#define OP(S, N) case SpvOp##S: return nir_intrinsic_var_##N;
|
|
|
|
OP(AtomicExchange, atomic_exchange)
|
|
|
|
OP(AtomicCompareExchange, atomic_comp_swap)
|
|
|
|
OP(AtomicIIncrement, atomic_add)
|
|
|
|
OP(AtomicIDecrement, atomic_add)
|
|
|
|
OP(AtomicIAdd, atomic_add)
|
|
|
|
OP(AtomicISub, atomic_add)
|
|
|
|
OP(AtomicSMin, atomic_imin)
|
|
|
|
OP(AtomicUMin, atomic_umin)
|
|
|
|
OP(AtomicSMax, atomic_imax)
|
|
|
|
OP(AtomicUMax, atomic_umax)
|
|
|
|
OP(AtomicAnd, atomic_and)
|
|
|
|
OP(AtomicOr, atomic_or)
|
|
|
|
OP(AtomicXor, atomic_xor)
|
|
|
|
#undef OP
|
|
|
|
default:
|
|
|
|
unreachable("Invalid shared atomic");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vtn_handle_ssbo_or_shared_atomic(struct vtn_builder *b, SpvOp opcode,
|
|
|
|
const uint32_t *w, unsigned count)
|
|
|
|
{
|
2016-09-06 14:26:17 +01:00
|
|
|
struct vtn_access_chain *chain;
|
2016-01-10 19:12:17 +00:00
|
|
|
nir_intrinsic_instr *atomic;
|
|
|
|
|
2016-09-06 14:26:17 +01:00
|
|
|
switch (opcode) {
|
|
|
|
case SpvOpAtomicLoad:
|
|
|
|
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:
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
2016-01-10 19:12:17 +00:00
|
|
|
/*
|
|
|
|
SpvScope scope = w[4];
|
|
|
|
SpvMemorySemanticsMask semantics = w[5];
|
|
|
|
*/
|
|
|
|
|
2016-01-21 10:09:38 +00:00
|
|
|
if (chain->var->mode == vtn_variable_mode_workgroup) {
|
2016-09-06 22:51:23 +01:00
|
|
|
struct vtn_type *type = chain->var->type;
|
2016-01-21 01:11:55 +00:00
|
|
|
nir_deref *deref = &vtn_access_chain_to_deref(b, chain)->deref;
|
2016-01-10 19:12:17 +00:00
|
|
|
nir_intrinsic_op op = get_shared_nir_atomic_op(opcode);
|
|
|
|
atomic = nir_intrinsic_instr_create(b->nb.shader, op);
|
2016-01-21 01:11:55 +00:00
|
|
|
atomic->variables[0] = nir_deref_as_var(nir_copy_deref(atomic, deref));
|
2016-09-06 22:51:23 +01:00
|
|
|
|
|
|
|
switch (opcode) {
|
|
|
|
case SpvOpAtomicLoad:
|
|
|
|
atomic->num_components = glsl_get_vector_elements(type->type);
|
|
|
|
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);
|
|
|
|
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:
|
|
|
|
fill_common_atomic_sources(b, opcode, w, &atomic->src[0]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
unreachable("Invalid SPIR-V atomic");
|
|
|
|
|
|
|
|
}
|
2016-01-10 19:12:17 +00:00
|
|
|
} else {
|
2016-01-21 10:09:38 +00:00
|
|
|
assert(chain->var->mode == vtn_variable_mode_ssbo);
|
2016-01-21 01:11:55 +00:00
|
|
|
struct vtn_type *type;
|
|
|
|
nir_ssa_def *offset, *index;
|
|
|
|
offset = vtn_access_chain_to_offset(b, chain, &index, &type, NULL, false);
|
|
|
|
|
2016-01-10 19:12:17 +00:00
|
|
|
nir_intrinsic_op op = get_ssbo_nir_atomic_op(opcode);
|
|
|
|
|
|
|
|
atomic = nir_intrinsic_instr_create(b->nb.shader, op);
|
2016-09-06 14:26:17 +01:00
|
|
|
|
|
|
|
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");
|
|
|
|
}
|
2016-01-08 04:44:04 +00:00
|
|
|
}
|
|
|
|
|
2016-09-06 14:26:17 +01:00
|
|
|
if (opcode != SpvOpAtomicStore) {
|
|
|
|
struct vtn_type *type = vtn_value(b, w[1], vtn_value_type_type)->type;
|
|
|
|
|
|
|
|
nir_ssa_dest_init(&atomic->instr, &atomic->dest,
|
|
|
|
glsl_get_vector_elements(type->type),
|
|
|
|
glsl_get_bit_size(type->type), NULL);
|
2016-01-08 04:44:04 +00:00
|
|
|
|
2016-09-06 14:26:17 +01:00
|
|
|
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;
|
|
|
|
}
|
2016-01-08 04:44:04 +00:00
|
|
|
|
|
|
|
nir_builder_instr_insert(&b->nb, &atomic->instr);
|
|
|
|
}
|
|
|
|
|
2015-08-31 20:48:04 +01:00
|
|
|
static nir_alu_instr *
|
2016-03-25 00:30:14 +00:00
|
|
|
create_vec(nir_shader *shader, unsigned num_components, unsigned bit_size)
|
2015-08-31 20:48:04 +01:00
|
|
|
{
|
|
|
|
nir_op op;
|
|
|
|
switch (num_components) {
|
|
|
|
case 1: op = nir_op_fmov; break;
|
|
|
|
case 2: op = nir_op_vec2; break;
|
|
|
|
case 3: op = nir_op_vec3; break;
|
|
|
|
case 4: op = nir_op_vec4; break;
|
|
|
|
default: unreachable("bad vector size");
|
|
|
|
}
|
|
|
|
|
2015-12-23 21:13:54 +00:00
|
|
|
nir_alu_instr *vec = nir_alu_instr_create(shader, op);
|
2016-03-25 00:30:14 +00:00
|
|
|
nir_ssa_dest_init(&vec->instr, &vec->dest.dest, num_components,
|
|
|
|
bit_size, NULL);
|
2015-08-31 20:48:04 +01:00
|
|
|
vec->dest.write_mask = (1 << num_components) - 1;
|
|
|
|
|
|
|
|
return vec;
|
|
|
|
}
|
|
|
|
|
2016-01-08 19:02:17 +00:00
|
|
|
struct vtn_ssa_value *
|
|
|
|
vtn_ssa_transpose(struct vtn_builder *b, struct vtn_ssa_value *src)
|
2015-08-31 20:48:04 +01:00
|
|
|
{
|
|
|
|
if (src->transposed)
|
|
|
|
return src->transposed;
|
|
|
|
|
|
|
|
struct vtn_ssa_value *dest =
|
|
|
|
vtn_create_ssa_value(b, glsl_transposed_type(src->type));
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < glsl_get_matrix_columns(dest->type); i++) {
|
2015-12-23 21:13:54 +00:00
|
|
|
nir_alu_instr *vec = create_vec(b->shader,
|
2016-03-25 00:30:14 +00:00
|
|
|
glsl_get_matrix_columns(src->type),
|
2016-05-11 20:05:09 +01:00
|
|
|
glsl_get_bit_size(src->type));
|
2015-08-31 20:48:04 +01:00
|
|
|
if (glsl_type_is_vector_or_scalar(src->type)) {
|
|
|
|
vec->src[0].src = nir_src_for_ssa(src->def);
|
|
|
|
vec->src[0].swizzle[0] = i;
|
|
|
|
} else {
|
|
|
|
for (unsigned j = 0; j < glsl_get_matrix_columns(src->type); j++) {
|
|
|
|
vec->src[j].src = nir_src_for_ssa(src->elems[j]->def);
|
|
|
|
vec->src[j].swizzle[0] = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
nir_builder_instr_insert(&b->nb, &vec->instr);
|
|
|
|
dest->elems[i]->def = &vec->dest.dest.ssa;
|
|
|
|
}
|
|
|
|
|
|
|
|
dest->transposed = src;
|
|
|
|
|
|
|
|
return dest;
|
|
|
|
}
|
|
|
|
|
2016-01-21 01:40:49 +00:00
|
|
|
nir_ssa_def *
|
2015-08-31 20:48:04 +01:00
|
|
|
vtn_vector_extract(struct vtn_builder *b, nir_ssa_def *src, unsigned index)
|
|
|
|
{
|
|
|
|
unsigned swiz[4] = { index };
|
|
|
|
return nir_swizzle(&b->nb, src, swiz, 1, true);
|
|
|
|
}
|
|
|
|
|
2016-01-21 01:40:49 +00:00
|
|
|
nir_ssa_def *
|
2015-08-31 20:48:04 +01:00
|
|
|
vtn_vector_insert(struct vtn_builder *b, nir_ssa_def *src, nir_ssa_def *insert,
|
|
|
|
unsigned index)
|
|
|
|
{
|
2016-03-25 00:30:14 +00:00
|
|
|
nir_alu_instr *vec = create_vec(b->shader, src->num_components,
|
|
|
|
src->bit_size);
|
2015-08-31 20:48:04 +01:00
|
|
|
|
|
|
|
for (unsigned i = 0; i < src->num_components; i++) {
|
|
|
|
if (i == index) {
|
|
|
|
vec->src[i].src = nir_src_for_ssa(insert);
|
|
|
|
} else {
|
|
|
|
vec->src[i].src = nir_src_for_ssa(src);
|
|
|
|
vec->src[i].swizzle[0] = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nir_builder_instr_insert(&b->nb, &vec->instr);
|
|
|
|
|
|
|
|
return &vec->dest.dest.ssa;
|
|
|
|
}
|
|
|
|
|
2016-01-21 01:40:49 +00:00
|
|
|
nir_ssa_def *
|
2015-08-31 20:48:04 +01:00
|
|
|
vtn_vector_extract_dynamic(struct vtn_builder *b, nir_ssa_def *src,
|
|
|
|
nir_ssa_def *index)
|
|
|
|
{
|
|
|
|
nir_ssa_def *dest = vtn_vector_extract(b, src, 0);
|
|
|
|
for (unsigned i = 1; i < src->num_components; i++)
|
|
|
|
dest = nir_bcsel(&b->nb, nir_ieq(&b->nb, index, nir_imm_int(&b->nb, i)),
|
|
|
|
vtn_vector_extract(b, src, i), dest);
|
|
|
|
|
|
|
|
return dest;
|
|
|
|
}
|
|
|
|
|
2016-01-21 01:40:49 +00:00
|
|
|
nir_ssa_def *
|
2015-08-31 20:48:04 +01:00
|
|
|
vtn_vector_insert_dynamic(struct vtn_builder *b, nir_ssa_def *src,
|
|
|
|
nir_ssa_def *insert, nir_ssa_def *index)
|
|
|
|
{
|
|
|
|
nir_ssa_def *dest = vtn_vector_insert(b, src, insert, 0);
|
|
|
|
for (unsigned i = 1; i < src->num_components; i++)
|
|
|
|
dest = nir_bcsel(&b->nb, nir_ieq(&b->nb, index, nir_imm_int(&b->nb, i)),
|
|
|
|
vtn_vector_insert(b, src, insert, i), dest);
|
|
|
|
|
|
|
|
return dest;
|
|
|
|
}
|
|
|
|
|
|
|
|
static nir_ssa_def *
|
|
|
|
vtn_vector_shuffle(struct vtn_builder *b, unsigned num_components,
|
|
|
|
nir_ssa_def *src0, nir_ssa_def *src1,
|
|
|
|
const uint32_t *indices)
|
|
|
|
{
|
2016-03-25 00:30:14 +00:00
|
|
|
nir_alu_instr *vec = create_vec(b->shader, num_components, src0->bit_size);
|
2015-08-31 20:48:04 +01:00
|
|
|
|
|
|
|
for (unsigned i = 0; i < num_components; i++) {
|
|
|
|
uint32_t index = indices[i];
|
|
|
|
if (index == 0xffffffff) {
|
2016-03-25 17:40:45 +00:00
|
|
|
vec->src[i].src =
|
|
|
|
nir_src_for_ssa(nir_ssa_undef(&b->nb, 1, src0->bit_size));
|
2015-08-31 20:48:04 +01:00
|
|
|
} else if (index < src0->num_components) {
|
|
|
|
vec->src[i].src = nir_src_for_ssa(src0);
|
|
|
|
vec->src[i].swizzle[0] = index;
|
|
|
|
} else {
|
|
|
|
vec->src[i].src = nir_src_for_ssa(src1);
|
|
|
|
vec->src[i].swizzle[0] = index - src0->num_components;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nir_builder_instr_insert(&b->nb, &vec->instr);
|
|
|
|
|
|
|
|
return &vec->dest.dest.ssa;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Concatentates a number of vectors/scalars together to produce a vector
|
|
|
|
*/
|
|
|
|
static nir_ssa_def *
|
|
|
|
vtn_vector_construct(struct vtn_builder *b, unsigned num_components,
|
|
|
|
unsigned num_srcs, nir_ssa_def **srcs)
|
|
|
|
{
|
2016-03-25 00:30:14 +00:00
|
|
|
nir_alu_instr *vec = create_vec(b->shader, num_components,
|
|
|
|
srcs[0]->bit_size);
|
2015-08-31 20:48:04 +01:00
|
|
|
|
|
|
|
unsigned dest_idx = 0;
|
|
|
|
for (unsigned i = 0; i < num_srcs; i++) {
|
|
|
|
nir_ssa_def *src = srcs[i];
|
|
|
|
for (unsigned j = 0; j < src->num_components; j++) {
|
|
|
|
vec->src[dest_idx].src = nir_src_for_ssa(src);
|
|
|
|
vec->src[dest_idx].swizzle[0] = j;
|
|
|
|
dest_idx++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nir_builder_instr_insert(&b->nb, &vec->instr);
|
|
|
|
|
|
|
|
return &vec->dest.dest.ssa;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct vtn_ssa_value *
|
|
|
|
vtn_composite_copy(void *mem_ctx, struct vtn_ssa_value *src)
|
|
|
|
{
|
|
|
|
struct vtn_ssa_value *dest = rzalloc(mem_ctx, struct vtn_ssa_value);
|
|
|
|
dest->type = src->type;
|
|
|
|
|
|
|
|
if (glsl_type_is_vector_or_scalar(src->type)) {
|
|
|
|
dest->def = src->def;
|
|
|
|
} else {
|
|
|
|
unsigned elems = glsl_get_length(src->type);
|
|
|
|
|
|
|
|
dest->elems = ralloc_array(mem_ctx, struct vtn_ssa_value *, elems);
|
|
|
|
for (unsigned i = 0; i < elems; i++)
|
|
|
|
dest->elems[i] = vtn_composite_copy(mem_ctx, src->elems[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return dest;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct vtn_ssa_value *
|
|
|
|
vtn_composite_insert(struct vtn_builder *b, struct vtn_ssa_value *src,
|
|
|
|
struct vtn_ssa_value *insert, const uint32_t *indices,
|
|
|
|
unsigned num_indices)
|
|
|
|
{
|
|
|
|
struct vtn_ssa_value *dest = vtn_composite_copy(b, src);
|
|
|
|
|
|
|
|
struct vtn_ssa_value *cur = dest;
|
|
|
|
unsigned i;
|
|
|
|
for (i = 0; i < num_indices - 1; i++) {
|
|
|
|
cur = cur->elems[indices[i]];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (glsl_type_is_vector_or_scalar(cur->type)) {
|
|
|
|
/* According to the SPIR-V spec, OpCompositeInsert may work down to
|
|
|
|
* the component granularity. In that case, the last index will be
|
|
|
|
* the index to insert the scalar into the vector.
|
|
|
|
*/
|
|
|
|
|
|
|
|
cur->def = vtn_vector_insert(b, cur->def, insert->def, indices[i]);
|
|
|
|
} else {
|
|
|
|
cur->elems[indices[i]] = insert;
|
|
|
|
}
|
|
|
|
|
|
|
|
return dest;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct vtn_ssa_value *
|
|
|
|
vtn_composite_extract(struct vtn_builder *b, struct vtn_ssa_value *src,
|
|
|
|
const uint32_t *indices, unsigned num_indices)
|
|
|
|
{
|
|
|
|
struct vtn_ssa_value *cur = src;
|
|
|
|
for (unsigned i = 0; i < num_indices; i++) {
|
|
|
|
if (glsl_type_is_vector_or_scalar(cur->type)) {
|
|
|
|
assert(i == num_indices - 1);
|
|
|
|
/* According to the SPIR-V spec, OpCompositeExtract may work down to
|
|
|
|
* the component granularity. The last index will be the index of the
|
|
|
|
* vector to extract.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct vtn_ssa_value *ret = rzalloc(b, struct vtn_ssa_value);
|
|
|
|
ret->type = glsl_scalar_type(glsl_get_base_type(cur->type));
|
|
|
|
ret->def = vtn_vector_extract(b, cur->def, indices[i]);
|
|
|
|
return ret;
|
2015-12-22 05:20:50 +00:00
|
|
|
} else {
|
|
|
|
cur = cur->elems[indices[i]];
|
2015-08-31 20:48:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return cur;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vtn_handle_composite(struct vtn_builder *b, SpvOp opcode,
|
|
|
|
const uint32_t *w, unsigned count)
|
|
|
|
{
|
|
|
|
struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_ssa);
|
|
|
|
const struct glsl_type *type =
|
|
|
|
vtn_value(b, w[1], vtn_value_type_type)->type->type;
|
|
|
|
val->ssa = vtn_create_ssa_value(b, type);
|
|
|
|
|
|
|
|
switch (opcode) {
|
|
|
|
case SpvOpVectorExtractDynamic:
|
|
|
|
val->ssa->def = vtn_vector_extract_dynamic(b, vtn_ssa_value(b, w[3])->def,
|
|
|
|
vtn_ssa_value(b, w[4])->def);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SpvOpVectorInsertDynamic:
|
|
|
|
val->ssa->def = vtn_vector_insert_dynamic(b, vtn_ssa_value(b, w[3])->def,
|
|
|
|
vtn_ssa_value(b, w[4])->def,
|
|
|
|
vtn_ssa_value(b, w[5])->def);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SpvOpVectorShuffle:
|
|
|
|
val->ssa->def = vtn_vector_shuffle(b, glsl_get_vector_elements(type),
|
|
|
|
vtn_ssa_value(b, w[3])->def,
|
|
|
|
vtn_ssa_value(b, w[4])->def,
|
|
|
|
w + 5);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SpvOpCompositeConstruct: {
|
|
|
|
unsigned elems = count - 3;
|
|
|
|
if (glsl_type_is_vector_or_scalar(type)) {
|
|
|
|
nir_ssa_def *srcs[4];
|
|
|
|
for (unsigned i = 0; i < elems; i++)
|
|
|
|
srcs[i] = vtn_ssa_value(b, w[3 + i])->def;
|
|
|
|
val->ssa->def =
|
|
|
|
vtn_vector_construct(b, glsl_get_vector_elements(type),
|
|
|
|
elems, srcs);
|
|
|
|
} else {
|
|
|
|
val->ssa->elems = ralloc_array(b, struct vtn_ssa_value *, elems);
|
|
|
|
for (unsigned i = 0; i < elems; i++)
|
|
|
|
val->ssa->elems[i] = vtn_ssa_value(b, w[3 + i]);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SpvOpCompositeExtract:
|
|
|
|
val->ssa = vtn_composite_extract(b, vtn_ssa_value(b, w[3]),
|
|
|
|
w + 4, count - 4);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SpvOpCompositeInsert:
|
|
|
|
val->ssa = vtn_composite_insert(b, vtn_ssa_value(b, w[4]),
|
|
|
|
vtn_ssa_value(b, w[3]),
|
|
|
|
w + 5, count - 5);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SpvOpCopyObject:
|
|
|
|
val->ssa = vtn_composite_copy(b, vtn_ssa_value(b, w[3]));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
unreachable("unknown composite operation");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-22 02:17:11 +01:00
|
|
|
static void
|
|
|
|
vtn_handle_barrier(struct vtn_builder *b, SpvOp opcode,
|
|
|
|
const uint32_t *w, unsigned count)
|
|
|
|
{
|
|
|
|
nir_intrinsic_op intrinsic_op;
|
|
|
|
switch (opcode) {
|
|
|
|
case SpvOpEmitVertex:
|
|
|
|
case SpvOpEmitStreamVertex:
|
|
|
|
intrinsic_op = nir_intrinsic_emit_vertex;
|
|
|
|
break;
|
|
|
|
case SpvOpEndPrimitive:
|
|
|
|
case SpvOpEndStreamPrimitive:
|
|
|
|
intrinsic_op = nir_intrinsic_end_primitive;
|
|
|
|
break;
|
|
|
|
case SpvOpMemoryBarrier:
|
|
|
|
intrinsic_op = nir_intrinsic_memory_barrier;
|
|
|
|
break;
|
|
|
|
case SpvOpControlBarrier:
|
2016-01-05 06:08:24 +00:00
|
|
|
intrinsic_op = nir_intrinsic_barrier;
|
|
|
|
break;
|
2015-10-22 02:17:11 +01:00
|
|
|
default:
|
|
|
|
unreachable("unknown barrier instruction");
|
|
|
|
}
|
|
|
|
|
|
|
|
nir_intrinsic_instr *intrin =
|
|
|
|
nir_intrinsic_instr_create(b->shader, intrinsic_op);
|
|
|
|
|
|
|
|
if (opcode == SpvOpEmitStreamVertex || opcode == SpvOpEndStreamPrimitive)
|
2016-02-09 23:35:51 +00:00
|
|
|
nir_intrinsic_set_stream_id(intrin, w[1]);
|
2015-10-22 02:17:11 +01:00
|
|
|
|
|
|
|
nir_builder_instr_insert(&b->nb, &intrin->instr);
|
|
|
|
}
|
|
|
|
|
2015-10-22 01:58:34 +01:00
|
|
|
static unsigned
|
|
|
|
gl_primitive_from_spv_execution_mode(SpvExecutionMode mode)
|
|
|
|
{
|
|
|
|
switch (mode) {
|
|
|
|
case SpvExecutionModeInputPoints:
|
|
|
|
case SpvExecutionModeOutputPoints:
|
|
|
|
return 0; /* GL_POINTS */
|
|
|
|
case SpvExecutionModeInputLines:
|
|
|
|
return 1; /* GL_LINES */
|
|
|
|
case SpvExecutionModeInputLinesAdjacency:
|
|
|
|
return 0x000A; /* GL_LINE_STRIP_ADJACENCY_ARB */
|
2015-12-04 02:07:58 +00:00
|
|
|
case SpvExecutionModeTriangles:
|
2015-10-22 01:58:34 +01:00
|
|
|
return 4; /* GL_TRIANGLES */
|
|
|
|
case SpvExecutionModeInputTrianglesAdjacency:
|
|
|
|
return 0x000C; /* GL_TRIANGLES_ADJACENCY_ARB */
|
2015-12-04 02:07:58 +00:00
|
|
|
case SpvExecutionModeQuads:
|
2015-10-22 01:58:34 +01:00
|
|
|
return 7; /* GL_QUADS */
|
2015-12-04 02:07:58 +00:00
|
|
|
case SpvExecutionModeIsolines:
|
2015-10-22 01:58:34 +01:00
|
|
|
return 0x8E7A; /* GL_ISOLINES */
|
|
|
|
case SpvExecutionModeOutputLineStrip:
|
|
|
|
return 3; /* GL_LINE_STRIP */
|
|
|
|
case SpvExecutionModeOutputTriangleStrip:
|
|
|
|
return 5; /* GL_TRIANGLE_STRIP */
|
|
|
|
default:
|
|
|
|
assert(!"Invalid primitive type");
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned
|
|
|
|
vertices_in_from_spv_execution_mode(SpvExecutionMode mode)
|
|
|
|
{
|
|
|
|
switch (mode) {
|
|
|
|
case SpvExecutionModeInputPoints:
|
|
|
|
return 1;
|
|
|
|
case SpvExecutionModeInputLines:
|
|
|
|
return 2;
|
|
|
|
case SpvExecutionModeInputLinesAdjacency:
|
|
|
|
return 4;
|
2015-12-04 02:07:58 +00:00
|
|
|
case SpvExecutionModeTriangles:
|
2015-10-22 01:58:34 +01:00
|
|
|
return 3;
|
|
|
|
case SpvExecutionModeInputTrianglesAdjacency:
|
|
|
|
return 6;
|
|
|
|
default:
|
|
|
|
assert(!"Invalid GS input mode");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-11 18:31:25 +00:00
|
|
|
static gl_shader_stage
|
|
|
|
stage_for_execution_model(SpvExecutionModel model)
|
|
|
|
{
|
|
|
|
switch (model) {
|
|
|
|
case SpvExecutionModelVertex:
|
|
|
|
return MESA_SHADER_VERTEX;
|
|
|
|
case SpvExecutionModelTessellationControl:
|
|
|
|
return MESA_SHADER_TESS_CTRL;
|
|
|
|
case SpvExecutionModelTessellationEvaluation:
|
|
|
|
return MESA_SHADER_TESS_EVAL;
|
|
|
|
case SpvExecutionModelGeometry:
|
|
|
|
return MESA_SHADER_GEOMETRY;
|
|
|
|
case SpvExecutionModelFragment:
|
|
|
|
return MESA_SHADER_FRAGMENT;
|
|
|
|
case SpvExecutionModelGLCompute:
|
|
|
|
return MESA_SHADER_COMPUTE;
|
|
|
|
default:
|
|
|
|
unreachable("Unsupported execution model");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-27 23:27:14 +00:00
|
|
|
#define spv_check_supported(name, cap) do { \
|
|
|
|
if (!(b->ext && b->ext->name)) \
|
|
|
|
vtn_warn("Unsupported SPIR-V capability: %s", \
|
|
|
|
spirv_capability_to_string(cap)); \
|
|
|
|
} while(0)
|
|
|
|
|
2015-05-01 22:00:57 +01:00
|
|
|
static bool
|
|
|
|
vtn_handle_preamble_instruction(struct vtn_builder *b, SpvOp opcode,
|
|
|
|
const uint32_t *w, unsigned count)
|
2015-04-29 01:43:16 +01:00
|
|
|
{
|
|
|
|
switch (opcode) {
|
|
|
|
case SpvOpSource:
|
|
|
|
case SpvOpSourceExtension:
|
2016-01-12 00:06:06 +00:00
|
|
|
case SpvOpSourceContinued:
|
2015-04-29 22:32:55 +01:00
|
|
|
case SpvOpExtension:
|
2015-04-29 01:43:16 +01:00
|
|
|
/* Unhandled, but these are for debug so that's ok. */
|
|
|
|
break;
|
|
|
|
|
2016-02-18 01:44:18 +00:00
|
|
|
case SpvOpCapability: {
|
|
|
|
SpvCapability cap = w[1];
|
|
|
|
switch (cap) {
|
2015-10-22 04:36:25 +01:00
|
|
|
case SpvCapabilityMatrix:
|
|
|
|
case SpvCapabilityShader:
|
|
|
|
case SpvCapabilityGeometry:
|
2016-02-24 05:01:00 +00:00
|
|
|
case SpvCapabilityGeometryPointSize:
|
2016-02-18 01:44:18 +00:00
|
|
|
case SpvCapabilityUniformBufferArrayDynamicIndexing:
|
|
|
|
case SpvCapabilitySampledImageArrayDynamicIndexing:
|
|
|
|
case SpvCapabilityStorageBufferArrayDynamicIndexing:
|
|
|
|
case SpvCapabilityStorageImageArrayDynamicIndexing:
|
2016-02-24 05:01:00 +00:00
|
|
|
case SpvCapabilityImageRect:
|
|
|
|
case SpvCapabilitySampledRect:
|
|
|
|
case SpvCapabilitySampled1D:
|
|
|
|
case SpvCapabilityImage1D:
|
|
|
|
case SpvCapabilitySampledCubeArray:
|
|
|
|
case SpvCapabilitySampledBuffer:
|
|
|
|
case SpvCapabilityImageBuffer:
|
2016-02-18 01:44:18 +00:00
|
|
|
case SpvCapabilityImageQuery:
|
2016-06-02 21:43:19 +01:00
|
|
|
case SpvCapabilityDerivativeControl:
|
|
|
|
case SpvCapabilityInterpolationFunction:
|
|
|
|
case SpvCapabilityMultiViewport:
|
2016-09-14 05:09:28 +01:00
|
|
|
case SpvCapabilitySampleRateShading:
|
2016-02-24 06:02:41 +00:00
|
|
|
case SpvCapabilityClipDistance:
|
|
|
|
case SpvCapabilityCullDistance:
|
2016-11-16 00:55:54 +00:00
|
|
|
case SpvCapabilityInputAttachment:
|
2016-11-27 21:09:55 +00:00
|
|
|
case SpvCapabilityImageGatherExtended:
|
2016-12-30 01:59:12 +00:00
|
|
|
case SpvCapabilityStorageImageExtendedFormats:
|
2016-10-04 07:46:37 +01:00
|
|
|
break;
|
|
|
|
|
2016-02-24 06:02:41 +00:00
|
|
|
case SpvCapabilityGeometryStreams:
|
2016-06-02 21:43:19 +01:00
|
|
|
case SpvCapabilityTessellation:
|
|
|
|
case SpvCapabilityTessellationPointSize:
|
|
|
|
case SpvCapabilityLinkage:
|
|
|
|
case SpvCapabilityVector16:
|
|
|
|
case SpvCapabilityFloat16Buffer:
|
|
|
|
case SpvCapabilityFloat16:
|
|
|
|
case SpvCapabilityFloat64:
|
|
|
|
case SpvCapabilityInt64:
|
|
|
|
case SpvCapabilityInt64Atomics:
|
|
|
|
case SpvCapabilityAtomicStorage:
|
|
|
|
case SpvCapabilityInt16:
|
|
|
|
case SpvCapabilityStorageImageMultisample:
|
|
|
|
case SpvCapabilityImageCubeArray:
|
|
|
|
case SpvCapabilityInt8:
|
|
|
|
case SpvCapabilitySparseResidency:
|
|
|
|
case SpvCapabilityMinLod:
|
|
|
|
case SpvCapabilityTransformFeedback:
|
|
|
|
case SpvCapabilityStorageImageReadWithoutFormat:
|
|
|
|
case SpvCapabilityStorageImageWriteWithoutFormat:
|
2016-06-02 22:34:15 +01:00
|
|
|
vtn_warn("Unsupported SPIR-V capability: %s",
|
|
|
|
spirv_capability_to_string(cap));
|
2016-06-02 21:43:19 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SpvCapabilityAddresses:
|
|
|
|
case SpvCapabilityKernel:
|
|
|
|
case SpvCapabilityImageBasic:
|
|
|
|
case SpvCapabilityImageReadWrite:
|
|
|
|
case SpvCapabilityImageMipmap:
|
|
|
|
case SpvCapabilityPipes:
|
|
|
|
case SpvCapabilityGroups:
|
|
|
|
case SpvCapabilityDeviceEnqueue:
|
|
|
|
case SpvCapabilityLiteralSampler:
|
|
|
|
case SpvCapabilityGenericPointer:
|
2016-06-02 22:34:15 +01:00
|
|
|
vtn_warn("Unsupported OpenCL-style SPIR-V capability: %s",
|
|
|
|
spirv_capability_to_string(cap));
|
2016-06-02 21:43:19 +01:00
|
|
|
break;
|
2016-12-27 23:27:14 +00:00
|
|
|
|
|
|
|
case SpvCapabilityImageMSArray:
|
|
|
|
spv_check_supported(image_ms_array, cap);
|
|
|
|
break;
|
2015-10-22 04:36:25 +01:00
|
|
|
}
|
2015-08-31 20:48:04 +01:00
|
|
|
break;
|
2016-02-18 01:44:18 +00:00
|
|
|
}
|
2015-08-31 20:48:04 +01:00
|
|
|
|
2015-05-04 23:17:56 +01:00
|
|
|
case SpvOpExtInstImport:
|
|
|
|
vtn_handle_extension(b, opcode, w, count);
|
|
|
|
break;
|
|
|
|
|
2015-04-29 22:32:55 +01:00
|
|
|
case SpvOpMemoryModel:
|
|
|
|
assert(w[1] == SpvAddressingModelLogical);
|
|
|
|
assert(w[2] == SpvMemoryModelGLSL450);
|
|
|
|
break;
|
|
|
|
|
2016-01-11 18:31:25 +00:00
|
|
|
case SpvOpEntryPoint: {
|
|
|
|
struct vtn_value *entry_point = &b->values[w[2]];
|
2015-12-31 01:31:51 +00:00
|
|
|
/* Let this be a name label regardless */
|
2016-01-11 18:31:25 +00:00
|
|
|
unsigned name_words;
|
|
|
|
entry_point->name = vtn_string_literal(b, &w[3], count - 3, &name_words);
|
2015-12-31 01:31:51 +00:00
|
|
|
|
2016-01-11 18:31:25 +00:00
|
|
|
if (strcmp(entry_point->name, b->entry_point_name) != 0 ||
|
|
|
|
stage_for_execution_model(w[1]) != b->entry_point_stage)
|
2015-12-31 01:17:12 +00:00
|
|
|
break;
|
|
|
|
|
2015-04-29 22:32:55 +01:00
|
|
|
assert(b->entry_point == NULL);
|
2016-01-11 18:31:25 +00:00
|
|
|
b->entry_point = entry_point;
|
2015-04-29 22:32:55 +01:00
|
|
|
break;
|
2016-01-11 18:31:25 +00:00
|
|
|
}
|
2015-04-29 22:32:55 +01:00
|
|
|
|
2015-05-01 22:00:57 +01:00
|
|
|
case SpvOpString:
|
|
|
|
vtn_push_value(b, w[1], vtn_value_type_string)->str =
|
2016-01-11 18:31:25 +00:00
|
|
|
vtn_string_literal(b, &w[2], count - 2, NULL);
|
2015-04-30 04:19:34 +01:00
|
|
|
break;
|
|
|
|
|
2015-05-01 22:00:57 +01:00
|
|
|
case SpvOpName:
|
2016-01-11 18:31:25 +00:00
|
|
|
b->values[w[1]].name = vtn_string_literal(b, &w[2], count - 2, NULL);
|
2015-05-01 22:00:57 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SpvOpMemberName:
|
|
|
|
/* TODO */
|
|
|
|
break;
|
|
|
|
|
2015-12-31 00:38:16 +00:00
|
|
|
case SpvOpExecutionMode:
|
2015-05-01 22:00:57 +01:00
|
|
|
case SpvOpDecorationGroup:
|
|
|
|
case SpvOpDecorate:
|
|
|
|
case SpvOpMemberDecorate:
|
|
|
|
case SpvOpGroupDecorate:
|
|
|
|
case SpvOpGroupMemberDecorate:
|
|
|
|
vtn_handle_decoration(b, opcode, w, count);
|
2015-04-29 22:32:55 +01:00
|
|
|
break;
|
|
|
|
|
2015-12-31 00:35:34 +00:00
|
|
|
default:
|
|
|
|
return false; /* End of preamble */
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-12-31 00:38:16 +00:00
|
|
|
static void
|
|
|
|
vtn_handle_execution_mode(struct vtn_builder *b, struct vtn_value *entry_point,
|
|
|
|
const struct vtn_decoration *mode, void *data)
|
|
|
|
{
|
|
|
|
assert(b->entry_point == entry_point);
|
|
|
|
|
|
|
|
switch(mode->exec_mode) {
|
|
|
|
case SpvExecutionModeOriginUpperLeft:
|
|
|
|
case SpvExecutionModeOriginLowerLeft:
|
|
|
|
b->origin_upper_left =
|
|
|
|
(mode->exec_mode == SpvExecutionModeOriginUpperLeft);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SpvExecutionModeEarlyFragmentTests:
|
|
|
|
assert(b->shader->stage == MESA_SHADER_FRAGMENT);
|
2016-10-13 01:41:23 +01:00
|
|
|
b->shader->info->fs.early_fragment_tests = true;
|
2015-12-31 00:38:16 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SpvExecutionModeInvocations:
|
|
|
|
assert(b->shader->stage == MESA_SHADER_GEOMETRY);
|
2016-10-13 01:41:23 +01:00
|
|
|
b->shader->info->gs.invocations = MAX2(1, mode->literals[0]);
|
2015-12-31 00:38:16 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SpvExecutionModeDepthReplacing:
|
|
|
|
assert(b->shader->stage == MESA_SHADER_FRAGMENT);
|
2016-10-13 01:41:23 +01:00
|
|
|
b->shader->info->fs.depth_layout = FRAG_DEPTH_LAYOUT_ANY;
|
2015-12-31 00:38:16 +00:00
|
|
|
break;
|
|
|
|
case SpvExecutionModeDepthGreater:
|
|
|
|
assert(b->shader->stage == MESA_SHADER_FRAGMENT);
|
2016-10-13 01:41:23 +01:00
|
|
|
b->shader->info->fs.depth_layout = FRAG_DEPTH_LAYOUT_GREATER;
|
2015-12-31 00:38:16 +00:00
|
|
|
break;
|
|
|
|
case SpvExecutionModeDepthLess:
|
|
|
|
assert(b->shader->stage == MESA_SHADER_FRAGMENT);
|
2016-10-13 01:41:23 +01:00
|
|
|
b->shader->info->fs.depth_layout = FRAG_DEPTH_LAYOUT_LESS;
|
2015-12-31 00:38:16 +00:00
|
|
|
break;
|
|
|
|
case SpvExecutionModeDepthUnchanged:
|
|
|
|
assert(b->shader->stage == MESA_SHADER_FRAGMENT);
|
2016-10-13 01:41:23 +01:00
|
|
|
b->shader->info->fs.depth_layout = FRAG_DEPTH_LAYOUT_UNCHANGED;
|
2015-12-31 00:38:16 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SpvExecutionModeLocalSize:
|
|
|
|
assert(b->shader->stage == MESA_SHADER_COMPUTE);
|
2016-10-13 01:41:23 +01:00
|
|
|
b->shader->info->cs.local_size[0] = mode->literals[0];
|
|
|
|
b->shader->info->cs.local_size[1] = mode->literals[1];
|
|
|
|
b->shader->info->cs.local_size[2] = mode->literals[2];
|
2015-12-31 00:38:16 +00:00
|
|
|
break;
|
|
|
|
case SpvExecutionModeLocalSizeHint:
|
Remove wrongly repeated words in comments
Clean up misrepetitions ('if if', 'the the' etc) found throughout the
comments. This has been done manually, after grepping
case-insensitively for duplicate if, is, the, then, do, for, an,
plus a few other typos corrected in fly-by
v2:
* proper commit message and non-joke title;
* replace two 'as is' followed by 'is' to 'as-is'.
v3:
* 'a integer' => 'an integer' and similar (originally spotted by
Jason Ekstrand, I fixed a few other similar ones while at it)
Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
Reviewed-by: Chad Versace <chad.versace@intel.com>
2016-06-23 18:20:18 +01:00
|
|
|
break; /* Nothing to do with this */
|
2015-12-31 00:38:16 +00:00
|
|
|
|
|
|
|
case SpvExecutionModeOutputVertices:
|
|
|
|
assert(b->shader->stage == MESA_SHADER_GEOMETRY);
|
2016-10-13 01:41:23 +01:00
|
|
|
b->shader->info->gs.vertices_out = mode->literals[0];
|
2015-12-31 00:38:16 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SpvExecutionModeInputPoints:
|
|
|
|
case SpvExecutionModeInputLines:
|
|
|
|
case SpvExecutionModeInputLinesAdjacency:
|
|
|
|
case SpvExecutionModeTriangles:
|
|
|
|
case SpvExecutionModeInputTrianglesAdjacency:
|
|
|
|
case SpvExecutionModeQuads:
|
|
|
|
case SpvExecutionModeIsolines:
|
|
|
|
if (b->shader->stage == MESA_SHADER_GEOMETRY) {
|
2016-10-13 01:41:23 +01:00
|
|
|
b->shader->info->gs.vertices_in =
|
2015-12-31 00:38:16 +00:00
|
|
|
vertices_in_from_spv_execution_mode(mode->exec_mode);
|
|
|
|
} else {
|
|
|
|
assert(!"Tesselation shaders not yet supported");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SpvExecutionModeOutputPoints:
|
|
|
|
case SpvExecutionModeOutputLineStrip:
|
|
|
|
case SpvExecutionModeOutputTriangleStrip:
|
|
|
|
assert(b->shader->stage == MESA_SHADER_GEOMETRY);
|
2016-10-13 01:41:23 +01:00
|
|
|
b->shader->info->gs.output_primitive =
|
2015-12-31 00:38:16 +00:00
|
|
|
gl_primitive_from_spv_execution_mode(mode->exec_mode);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SpvExecutionModeSpacingEqual:
|
|
|
|
case SpvExecutionModeSpacingFractionalEven:
|
|
|
|
case SpvExecutionModeSpacingFractionalOdd:
|
|
|
|
case SpvExecutionModeVertexOrderCw:
|
|
|
|
case SpvExecutionModeVertexOrderCcw:
|
|
|
|
case SpvExecutionModePointMode:
|
|
|
|
assert(!"TODO: Add tessellation metadata");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SpvExecutionModePixelCenterInteger:
|
2016-05-18 19:06:08 +01:00
|
|
|
b->pixel_center_integer = true;
|
|
|
|
break;
|
|
|
|
|
2015-12-31 00:38:16 +00:00
|
|
|
case SpvExecutionModeXfb:
|
|
|
|
assert(!"Unhandled execution mode");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SpvExecutionModeVecTypeHint:
|
|
|
|
case SpvExecutionModeContractionOff:
|
|
|
|
break; /* OpenCL */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-31 00:35:34 +00:00
|
|
|
static bool
|
|
|
|
vtn_handle_variable_or_type_instruction(struct vtn_builder *b, SpvOp opcode,
|
|
|
|
const uint32_t *w, unsigned count)
|
|
|
|
{
|
|
|
|
switch (opcode) {
|
|
|
|
case SpvOpSource:
|
2016-01-12 00:06:06 +00:00
|
|
|
case SpvOpSourceContinued:
|
2015-12-31 00:35:34 +00:00
|
|
|
case SpvOpSourceExtension:
|
|
|
|
case SpvOpExtension:
|
|
|
|
case SpvOpCapability:
|
|
|
|
case SpvOpExtInstImport:
|
|
|
|
case SpvOpMemoryModel:
|
|
|
|
case SpvOpEntryPoint:
|
|
|
|
case SpvOpExecutionMode:
|
|
|
|
case SpvOpString:
|
|
|
|
case SpvOpName:
|
|
|
|
case SpvOpMemberName:
|
|
|
|
case SpvOpDecorationGroup:
|
|
|
|
case SpvOpDecorate:
|
|
|
|
case SpvOpMemberDecorate:
|
|
|
|
case SpvOpGroupDecorate:
|
|
|
|
case SpvOpGroupMemberDecorate:
|
|
|
|
assert(!"Invalid opcode types and variables section");
|
|
|
|
break;
|
|
|
|
|
2015-04-29 01:43:16 +01:00
|
|
|
case SpvOpTypeVoid:
|
|
|
|
case SpvOpTypeBool:
|
|
|
|
case SpvOpTypeInt:
|
|
|
|
case SpvOpTypeFloat:
|
|
|
|
case SpvOpTypeVector:
|
|
|
|
case SpvOpTypeMatrix:
|
2015-08-31 20:48:04 +01:00
|
|
|
case SpvOpTypeImage:
|
2015-04-29 01:43:16 +01:00
|
|
|
case SpvOpTypeSampler:
|
2015-08-31 20:48:04 +01:00
|
|
|
case SpvOpTypeSampledImage:
|
2015-04-29 01:43:16 +01:00
|
|
|
case SpvOpTypeArray:
|
|
|
|
case SpvOpTypeRuntimeArray:
|
|
|
|
case SpvOpTypeStruct:
|
|
|
|
case SpvOpTypeOpaque:
|
|
|
|
case SpvOpTypePointer:
|
|
|
|
case SpvOpTypeFunction:
|
|
|
|
case SpvOpTypeEvent:
|
|
|
|
case SpvOpTypeDeviceEvent:
|
|
|
|
case SpvOpTypeReserveId:
|
|
|
|
case SpvOpTypeQueue:
|
|
|
|
case SpvOpTypePipe:
|
2015-08-31 20:48:04 +01:00
|
|
|
vtn_handle_type(b, opcode, w, count);
|
2015-04-29 01:43:16 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SpvOpConstantTrue:
|
|
|
|
case SpvOpConstantFalse:
|
|
|
|
case SpvOpConstant:
|
|
|
|
case SpvOpConstantComposite:
|
|
|
|
case SpvOpConstantSampler:
|
2016-01-11 20:39:32 +00:00
|
|
|
case SpvOpConstantNull:
|
2015-04-29 01:43:16 +01:00
|
|
|
case SpvOpSpecConstantTrue:
|
|
|
|
case SpvOpSpecConstantFalse:
|
|
|
|
case SpvOpSpecConstant:
|
|
|
|
case SpvOpSpecConstantComposite:
|
2016-01-13 04:02:04 +00:00
|
|
|
case SpvOpSpecConstantOp:
|
2015-04-29 01:43:16 +01:00
|
|
|
vtn_handle_constant(b, opcode, w, count);
|
|
|
|
break;
|
|
|
|
|
2015-05-01 22:00:57 +01:00
|
|
|
case SpvOpVariable:
|
|
|
|
vtn_handle_variables(b, opcode, w, count);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false; /* End of preamble */
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
vtn_handle_body_instruction(struct vtn_builder *b, SpvOp opcode,
|
|
|
|
const uint32_t *w, unsigned count)
|
|
|
|
{
|
|
|
|
switch (opcode) {
|
2016-01-05 22:59:40 +00:00
|
|
|
case SpvOpLabel:
|
2015-05-01 22:00:57 +01:00
|
|
|
break;
|
|
|
|
|
2015-05-04 18:23:09 +01:00
|
|
|
case SpvOpLoopMerge:
|
|
|
|
case SpvOpSelectionMerge:
|
2015-05-06 20:37:10 +01:00
|
|
|
/* This is handled by cfg pre-pass and walk_blocks */
|
2015-05-04 18:23:09 +01:00
|
|
|
break;
|
|
|
|
|
2015-12-23 22:14:39 +00:00
|
|
|
case SpvOpUndef: {
|
|
|
|
struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_undef);
|
|
|
|
val->type = vtn_value(b, w[1], vtn_value_type_type)->type;
|
2015-05-01 22:00:57 +01:00
|
|
|
break;
|
2015-12-23 22:14:39 +00:00
|
|
|
}
|
2015-05-01 22:00:57 +01:00
|
|
|
|
|
|
|
case SpvOpExtInst:
|
|
|
|
vtn_handle_extension(b, opcode, w, count);
|
|
|
|
break;
|
|
|
|
|
2015-04-29 01:43:16 +01:00
|
|
|
case SpvOpVariable:
|
|
|
|
case SpvOpLoad:
|
|
|
|
case SpvOpStore:
|
|
|
|
case SpvOpCopyMemory:
|
|
|
|
case SpvOpCopyMemorySized:
|
|
|
|
case SpvOpAccessChain:
|
|
|
|
case SpvOpInBoundsAccessChain:
|
|
|
|
case SpvOpArrayLength:
|
|
|
|
vtn_handle_variables(b, opcode, w, count);
|
|
|
|
break;
|
|
|
|
|
2015-04-30 04:10:20 +01:00
|
|
|
case SpvOpFunctionCall:
|
2015-05-04 18:23:09 +01:00
|
|
|
vtn_handle_function_call(b, opcode, w, count);
|
2015-04-30 04:10:20 +01:00
|
|
|
break;
|
|
|
|
|
2015-11-15 06:32:54 +00:00
|
|
|
case SpvOpSampledImage:
|
2016-02-01 21:47:13 +00:00
|
|
|
case SpvOpImage:
|
2015-08-31 20:48:04 +01:00
|
|
|
case SpvOpImageSampleImplicitLod:
|
|
|
|
case SpvOpImageSampleExplicitLod:
|
|
|
|
case SpvOpImageSampleDrefImplicitLod:
|
|
|
|
case SpvOpImageSampleDrefExplicitLod:
|
|
|
|
case SpvOpImageSampleProjImplicitLod:
|
|
|
|
case SpvOpImageSampleProjExplicitLod:
|
|
|
|
case SpvOpImageSampleProjDrefImplicitLod:
|
|
|
|
case SpvOpImageSampleProjDrefExplicitLod:
|
|
|
|
case SpvOpImageFetch:
|
|
|
|
case SpvOpImageGather:
|
|
|
|
case SpvOpImageDrefGather:
|
|
|
|
case SpvOpImageQuerySizeLod:
|
|
|
|
case SpvOpImageQueryLod:
|
|
|
|
case SpvOpImageQueryLevels:
|
|
|
|
case SpvOpImageQuerySamples:
|
2015-04-29 01:43:16 +01:00
|
|
|
vtn_handle_texture(b, opcode, w, count);
|
|
|
|
break;
|
|
|
|
|
2015-11-14 01:26:22 +00:00
|
|
|
case SpvOpImageRead:
|
|
|
|
case SpvOpImageWrite:
|
|
|
|
case SpvOpImageTexelPointer:
|
|
|
|
vtn_handle_image(b, opcode, w, count);
|
|
|
|
break;
|
|
|
|
|
2016-01-05 22:03:58 +00:00
|
|
|
case SpvOpImageQuerySize: {
|
2016-01-21 01:11:55 +00:00
|
|
|
struct vtn_access_chain *image =
|
|
|
|
vtn_value(b, w[3], vtn_value_type_access_chain)->access_chain;
|
2016-01-21 10:09:38 +00:00
|
|
|
if (glsl_type_is_image(image->var->var->interface_type)) {
|
2016-01-05 22:03:58 +00:00
|
|
|
vtn_handle_image(b, opcode, w, count);
|
|
|
|
} else {
|
|
|
|
vtn_handle_texture(b, opcode, w, count);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-09-06 14:26:17 +01:00
|
|
|
case SpvOpAtomicLoad:
|
2015-11-14 01:26:22 +00:00
|
|
|
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: {
|
|
|
|
struct vtn_value *pointer = vtn_untyped_value(b, w[3]);
|
|
|
|
if (pointer->value_type == vtn_value_type_image_pointer) {
|
|
|
|
vtn_handle_image(b, opcode, w, count);
|
|
|
|
} else {
|
2016-01-21 01:11:55 +00:00
|
|
|
assert(pointer->value_type == vtn_value_type_access_chain);
|
2016-01-10 19:12:17 +00:00
|
|
|
vtn_handle_ssbo_or_shared_atomic(b, opcode, w, count);
|
2015-11-14 01:26:22 +00:00
|
|
|
}
|
2016-01-08 04:44:04 +00:00
|
|
|
break;
|
2015-11-14 01:26:22 +00:00
|
|
|
}
|
|
|
|
|
2016-09-06 14:26:17 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-04-29 01:43:16 +01:00
|
|
|
case SpvOpSNegate:
|
|
|
|
case SpvOpFNegate:
|
|
|
|
case SpvOpNot:
|
|
|
|
case SpvOpAny:
|
|
|
|
case SpvOpAll:
|
|
|
|
case SpvOpConvertFToU:
|
|
|
|
case SpvOpConvertFToS:
|
|
|
|
case SpvOpConvertSToF:
|
|
|
|
case SpvOpConvertUToF:
|
|
|
|
case SpvOpUConvert:
|
|
|
|
case SpvOpSConvert:
|
|
|
|
case SpvOpFConvert:
|
2016-01-12 23:36:38 +00:00
|
|
|
case SpvOpQuantizeToF16:
|
2015-04-29 01:43:16 +01:00
|
|
|
case SpvOpConvertPtrToU:
|
|
|
|
case SpvOpConvertUToPtr:
|
|
|
|
case SpvOpPtrCastToGeneric:
|
|
|
|
case SpvOpGenericCastToPtr:
|
|
|
|
case SpvOpBitcast:
|
|
|
|
case SpvOpIsNan:
|
|
|
|
case SpvOpIsInf:
|
|
|
|
case SpvOpIsFinite:
|
|
|
|
case SpvOpIsNormal:
|
|
|
|
case SpvOpSignBitSet:
|
|
|
|
case SpvOpLessOrGreater:
|
|
|
|
case SpvOpOrdered:
|
|
|
|
case SpvOpUnordered:
|
|
|
|
case SpvOpIAdd:
|
|
|
|
case SpvOpFAdd:
|
|
|
|
case SpvOpISub:
|
|
|
|
case SpvOpFSub:
|
|
|
|
case SpvOpIMul:
|
|
|
|
case SpvOpFMul:
|
|
|
|
case SpvOpUDiv:
|
|
|
|
case SpvOpSDiv:
|
|
|
|
case SpvOpFDiv:
|
|
|
|
case SpvOpUMod:
|
|
|
|
case SpvOpSRem:
|
|
|
|
case SpvOpSMod:
|
|
|
|
case SpvOpFRem:
|
|
|
|
case SpvOpFMod:
|
|
|
|
case SpvOpVectorTimesScalar:
|
|
|
|
case SpvOpDot:
|
2016-01-05 04:59:16 +00:00
|
|
|
case SpvOpIAddCarry:
|
|
|
|
case SpvOpISubBorrow:
|
|
|
|
case SpvOpUMulExtended:
|
|
|
|
case SpvOpSMulExtended:
|
2015-04-29 01:43:16 +01:00
|
|
|
case SpvOpShiftRightLogical:
|
|
|
|
case SpvOpShiftRightArithmetic:
|
|
|
|
case SpvOpShiftLeftLogical:
|
2015-08-31 20:48:04 +01:00
|
|
|
case SpvOpLogicalEqual:
|
|
|
|
case SpvOpLogicalNotEqual:
|
2015-12-23 19:11:58 +00:00
|
|
|
case SpvOpLogicalOr:
|
2015-04-29 01:43:16 +01:00
|
|
|
case SpvOpLogicalAnd:
|
2015-12-23 19:11:58 +00:00
|
|
|
case SpvOpLogicalNot:
|
2015-04-29 01:43:16 +01:00
|
|
|
case SpvOpBitwiseOr:
|
|
|
|
case SpvOpBitwiseXor:
|
|
|
|
case SpvOpBitwiseAnd:
|
|
|
|
case SpvOpSelect:
|
|
|
|
case SpvOpIEqual:
|
|
|
|
case SpvOpFOrdEqual:
|
|
|
|
case SpvOpFUnordEqual:
|
|
|
|
case SpvOpINotEqual:
|
|
|
|
case SpvOpFOrdNotEqual:
|
|
|
|
case SpvOpFUnordNotEqual:
|
|
|
|
case SpvOpULessThan:
|
|
|
|
case SpvOpSLessThan:
|
|
|
|
case SpvOpFOrdLessThan:
|
|
|
|
case SpvOpFUnordLessThan:
|
|
|
|
case SpvOpUGreaterThan:
|
|
|
|
case SpvOpSGreaterThan:
|
|
|
|
case SpvOpFOrdGreaterThan:
|
|
|
|
case SpvOpFUnordGreaterThan:
|
|
|
|
case SpvOpULessThanEqual:
|
|
|
|
case SpvOpSLessThanEqual:
|
|
|
|
case SpvOpFOrdLessThanEqual:
|
|
|
|
case SpvOpFUnordLessThanEqual:
|
|
|
|
case SpvOpUGreaterThanEqual:
|
|
|
|
case SpvOpSGreaterThanEqual:
|
|
|
|
case SpvOpFOrdGreaterThanEqual:
|
|
|
|
case SpvOpFUnordGreaterThanEqual:
|
|
|
|
case SpvOpDPdx:
|
|
|
|
case SpvOpDPdy:
|
|
|
|
case SpvOpFwidth:
|
|
|
|
case SpvOpDPdxFine:
|
|
|
|
case SpvOpDPdyFine:
|
|
|
|
case SpvOpFwidthFine:
|
|
|
|
case SpvOpDPdxCoarse:
|
|
|
|
case SpvOpDPdyCoarse:
|
|
|
|
case SpvOpFwidthCoarse:
|
2016-01-05 01:32:33 +00:00
|
|
|
case SpvOpBitFieldInsert:
|
|
|
|
case SpvOpBitFieldSExtract:
|
|
|
|
case SpvOpBitFieldUExtract:
|
|
|
|
case SpvOpBitReverse:
|
|
|
|
case SpvOpBitCount:
|
2015-05-04 20:04:02 +01:00
|
|
|
case SpvOpTranspose:
|
|
|
|
case SpvOpOuterProduct:
|
|
|
|
case SpvOpMatrixTimesScalar:
|
|
|
|
case SpvOpVectorTimesMatrix:
|
|
|
|
case SpvOpMatrixTimesVector:
|
|
|
|
case SpvOpMatrixTimesMatrix:
|
2016-01-08 19:02:17 +00:00
|
|
|
vtn_handle_alu(b, opcode, w, count);
|
2015-05-04 20:04:02 +01:00
|
|
|
break;
|
|
|
|
|
2015-08-31 20:48:04 +01:00
|
|
|
case SpvOpVectorExtractDynamic:
|
|
|
|
case SpvOpVectorInsertDynamic:
|
|
|
|
case SpvOpVectorShuffle:
|
|
|
|
case SpvOpCompositeConstruct:
|
|
|
|
case SpvOpCompositeExtract:
|
|
|
|
case SpvOpCompositeInsert:
|
|
|
|
case SpvOpCopyObject:
|
|
|
|
vtn_handle_composite(b, opcode, w, count);
|
|
|
|
break;
|
|
|
|
|
2015-10-22 02:17:11 +01:00
|
|
|
case SpvOpEmitVertex:
|
|
|
|
case SpvOpEndPrimitive:
|
|
|
|
case SpvOpEmitStreamVertex:
|
|
|
|
case SpvOpEndStreamPrimitive:
|
|
|
|
case SpvOpControlBarrier:
|
|
|
|
case SpvOpMemoryBarrier:
|
|
|
|
vtn_handle_barrier(b, opcode, w, count);
|
|
|
|
break;
|
|
|
|
|
2015-04-29 01:43:16 +01:00
|
|
|
default:
|
|
|
|
unreachable("Unhandled opcode");
|
|
|
|
}
|
2015-05-01 22:00:57 +01:00
|
|
|
|
|
|
|
return true;
|
2015-04-29 01:43:16 +01:00
|
|
|
}
|
|
|
|
|
2015-12-31 01:17:12 +00:00
|
|
|
nir_function *
|
2015-04-29 01:43:16 +01:00
|
|
|
spirv_to_nir(const uint32_t *words, size_t word_count,
|
2016-01-13 00:28:28 +00:00
|
|
|
struct nir_spirv_specialization *spec, unsigned num_spec,
|
2016-01-11 18:31:25 +00:00
|
|
|
gl_shader_stage stage, const char *entry_point_name,
|
2016-12-27 23:27:14 +00:00
|
|
|
const struct nir_spirv_supported_extensions *ext,
|
2015-04-29 01:43:16 +01:00
|
|
|
const nir_shader_compiler_options *options)
|
|
|
|
{
|
2015-05-04 18:23:09 +01:00
|
|
|
const uint32_t *word_end = words + word_count;
|
|
|
|
|
2015-04-29 01:43:16 +01:00
|
|
|
/* Handle the SPIR-V header (first 4 dwords) */
|
|
|
|
assert(word_count > 5);
|
|
|
|
|
|
|
|
assert(words[0] == SpvMagicNumber);
|
2015-12-04 02:07:58 +00:00
|
|
|
assert(words[1] >= 0x10000);
|
2015-04-29 01:43:16 +01:00
|
|
|
/* words[2] == generator magic */
|
|
|
|
unsigned value_id_bound = words[3];
|
|
|
|
assert(words[4] == 0);
|
|
|
|
|
|
|
|
words+= 5;
|
|
|
|
|
|
|
|
/* Initialize the stn_builder object */
|
|
|
|
struct vtn_builder *b = rzalloc(NULL, struct vtn_builder);
|
|
|
|
b->value_id_bound = value_id_bound;
|
2015-08-31 20:48:04 +01:00
|
|
|
b->values = rzalloc_array(b, struct vtn_value, value_id_bound);
|
2015-05-04 18:23:09 +01:00
|
|
|
exec_list_make_empty(&b->functions);
|
2016-01-11 18:31:25 +00:00
|
|
|
b->entry_point_stage = stage;
|
2015-12-31 01:17:12 +00:00
|
|
|
b->entry_point_name = entry_point_name;
|
2016-12-27 23:27:14 +00:00
|
|
|
b->ext = ext;
|
2015-04-29 01:43:16 +01:00
|
|
|
|
2015-05-01 22:00:57 +01:00
|
|
|
/* Handle all the preamble instructions */
|
|
|
|
words = vtn_foreach_instruction(b, words, word_end,
|
|
|
|
vtn_handle_preamble_instruction);
|
2015-04-29 01:43:16 +01:00
|
|
|
|
2015-12-31 01:17:12 +00:00
|
|
|
if (b->entry_point == NULL) {
|
|
|
|
assert(!"Entry point not found");
|
|
|
|
ralloc_free(b);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-10-13 01:41:23 +01:00
|
|
|
b->shader = nir_shader_create(NULL, stage, options, NULL);
|
2015-12-31 01:00:16 +00:00
|
|
|
|
2016-03-30 04:29:07 +01:00
|
|
|
/* Set shader info defaults */
|
2016-10-13 01:41:23 +01:00
|
|
|
b->shader->info->gs.invocations = 1;
|
2016-03-30 04:29:07 +01:00
|
|
|
|
2015-12-31 00:38:16 +00:00
|
|
|
/* Parse execution modes */
|
|
|
|
vtn_foreach_execution_mode(b, b->entry_point,
|
|
|
|
vtn_handle_execution_mode, NULL);
|
|
|
|
|
2016-01-13 00:28:28 +00:00
|
|
|
b->specializations = spec;
|
|
|
|
b->num_specializations = num_spec;
|
|
|
|
|
2015-12-31 00:35:34 +00:00
|
|
|
/* Handle all variable, type, and constant instructions */
|
|
|
|
words = vtn_foreach_instruction(b, words, word_end,
|
|
|
|
vtn_handle_variable_or_type_instruction);
|
|
|
|
|
2015-12-29 02:19:40 +00:00
|
|
|
vtn_build_cfg(b, words, word_end);
|
2015-05-04 18:23:09 +01:00
|
|
|
|
|
|
|
foreach_list_typed(struct vtn_function, func, node, &b->functions) {
|
2015-12-18 23:07:16 +00:00
|
|
|
b->impl = func->impl;
|
2015-08-31 20:48:04 +01:00
|
|
|
b->const_table = _mesa_hash_table_create(b, _mesa_hash_pointer,
|
|
|
|
_mesa_key_pointer_equal);
|
2016-01-20 02:58:31 +00:00
|
|
|
|
2015-12-29 20:09:32 +00:00
|
|
|
vtn_function_emit(b, func, vtn_handle_body_instruction);
|
2015-05-04 18:23:09 +01:00
|
|
|
}
|
2015-04-29 01:43:16 +01:00
|
|
|
|
2015-12-31 01:17:12 +00:00
|
|
|
assert(b->entry_point->value_type == vtn_value_type_function);
|
|
|
|
nir_function *entry_point = b->entry_point->func->impl->function;
|
|
|
|
assert(entry_point);
|
|
|
|
|
2015-12-31 01:00:16 +00:00
|
|
|
ralloc_free(b);
|
|
|
|
|
2015-12-31 01:17:12 +00:00
|
|
|
return entry_point;
|
2015-04-29 01:43:16 +01:00
|
|
|
}
|