Merge remote-tracking branch 'fdo-personal/nir-spirv' into vulkan

From now on, the majority of SPIR-V improvements should happen on the spirv
branch which will also be public.  It will be frequently merged into the
vulkan driver.
This commit is contained in:
Jason Ekstrand 2015-08-31 17:14:47 -07:00
commit 6350c97412
11 changed files with 78 additions and 65 deletions

View File

@ -1131,6 +1131,7 @@ glsl_type::component_slots() const
return 1;
case GLSL_TYPE_SUBROUTINE:
return 1;
case GLSL_TYPE_FUNCTION:
case GLSL_TYPE_SAMPLER:
case GLSL_TYPE_ATOMIC_UINT:

View File

@ -265,16 +265,17 @@ struct glsl_type {
enum glsl_interface_packing packing,
const char *block_name);
/**
* Get the instance of an subroutine type
*/
static const glsl_type *get_subroutine_instance(const char *subroutine_name);
/**
* Get the instance of a function type
*/
static const glsl_type *get_function_instance(const struct glsl_type *return_type,
const glsl_function_param *parameters,
unsigned num_params);
/**
* Get the instance of an subroutine type
*/
static const glsl_type *get_subroutine_instance(const char *subroutine_name);
/**
* Get the type resulting from a multiplication of \p type_a * \p type_b
@ -715,12 +716,12 @@ private:
/** Hash table containing the known interface types. */
static struct hash_table *interface_types;
/** Hash table containing the known function types. */
static struct hash_table *function_types;
/** Hash table containing the known subroutine types. */
static struct hash_table *subroutine_types;
/** Hash table containing the known function types. */
static struct hash_table *function_types;
static bool record_key_compare(const void *a, const void *b);
static unsigned record_key_hash(const void *key);

View File

@ -296,12 +296,16 @@ typedef struct {
*/
int index;
/**
* Descriptor set binding for sampler or UBO.
*/
int descriptor_set;
/**
* Initial binding point for a sampler or UBO.
*
* For array types, this represents the binding point for the first element.
*/
int descriptor_set;
int binding;
/**

View File

@ -49,8 +49,7 @@ nir_builder_instr_insert(nir_builder *build, nir_instr *instr)
nir_instr_insert(build->cursor, instr);
/* Move the cursor forward. */
if (build->cursor.option == nir_cursor_after_instr)
build->cursor.instr = instr;
build->cursor = nir_after_instr(instr);
}
static inline void

View File

@ -249,12 +249,7 @@ add_parallel_copy_to_end_of_block(nir_block *block, void *void_state)
nir_parallel_copy_instr *pcopy =
nir_parallel_copy_instr_create(state->dead_ctx);
nir_instr *last_instr = nir_block_last_instr(block);
if (last_instr && last_instr->type == nir_instr_type_jump) {
nir_instr_insert_before(last_instr, &pcopy->instr);
} else {
nir_instr_insert_after_block(block, &pcopy->instr);
}
nir_instr_insert(nir_after_block_before_jump(block), &pcopy->instr);
}
return true;

View File

@ -53,11 +53,7 @@ emit_output_copies(nir_shader *shader, nir_variable *temp, nir_variable *output)
copy->variables[0] = nir_deref_var_create(copy, output);
copy->variables[1] = nir_deref_var_create(copy, temp);
nir_instr *last_instr = nir_block_last_instr(block);
if (last_instr && last_instr->type == nir_instr_type_jump)
nir_instr_insert_before(last_instr, &copy->instr);
else
nir_instr_insert_after_block(block, &copy->instr);
nir_instr_insert(nir_after_block_before_jump(block), &copy->instr);
}
}
}
@ -83,8 +79,8 @@ nir_lower_outputs_to_temporaries(nir_shader *shader)
if (output->name)
ralloc_steal(output, output->name);
/* Give the temporary a new name with @out-temp appended */
temp->name = ralloc_asprintf(temp, "%s@out-temp", output->name);
/* Give the output a new name with @out-temp appended */
temp->name = ralloc_asprintf(var, "%s@out-temp", output->name);
temp->data.mode = nir_var_global;
temp->constant_initializer = NULL;
@ -93,5 +89,5 @@ nir_lower_outputs_to_temporaries(nir_shader *shader)
emit_output_copies(shader, temp, output);
}
exec_list_append(&shader->globals, &old_outputs);
exec_list_append(&shader->globals, &old_outputs);
}

View File

@ -252,7 +252,7 @@ glsl_vector_type(enum glsl_base_type base_type, unsigned components)
const glsl_type *
glsl_matrix_type(enum glsl_base_type base_type, unsigned rows, unsigned columns)
{
assert(rows >= 1 && rows <= 4 && columns >= 1 && columns <= 4);
assert(rows > 1 && rows <= 4 && columns > 1 && columns <= 4);
return glsl_type::get_instance(base_type, rows, columns);
}

View File

@ -1,12 +1,17 @@
/*
** Copyright (c) 2014-2015 The Khronos Group Inc.
<<<<<<< HEAD
**
=======
**
>>>>>>> fdo-personal/nir-spirv
** Permission is hereby granted, free of charge, to any person obtaining a copy
** of this software and/or associated documentation files (the "Materials"),
** to deal in the Materials without restriction, including without limitation
** the rights to use, copy, modify, merge, publish, distribute, sublicense,
** and/or sell copies of the Materials, and to permit persons to whom the
** Materials are furnished to do so, subject to the following conditions:
<<<<<<< HEAD
**
** The above copyright notice and this permission notice shall be included in
** all copies or substantial portions of the Materials.
@ -15,6 +20,16 @@
** STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS SPECIFICATIONS AND
** HEADER INFORMATION ARE LOCATED AT https://www.khronos.org/registry/
**
=======
**
** The above copyright notice and this permission notice shall be included in
** all copies or substantial portions of the Materials.
**
** MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS KHRONOS
** STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS SPECIFICATIONS AND
** HEADER INFORMATION ARE LOCATED AT https://www.khronos.org/registry/
**
>>>>>>> fdo-personal/nir-spirv
** THE MATERIALS ARE 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
@ -33,13 +48,21 @@
** Specification revision 31.
** Enumeration tokens for SPIR-V, in various styles:
** C, C++, C++11, JSON, Lua, Python
<<<<<<< HEAD
**
=======
**
>>>>>>> fdo-personal/nir-spirv
** - C will have tokens with a "Spv" prefix, e.g.: SpvSourceLanguageGLSL
** - C++ will have tokens in the "spv" name space, e.g.: spv::SourceLanguageGLSL
** - C++11 will use enum classes in the spv namespace, e.g.: spv::SourceLanguage::GLSL
** - Lua will use tables, e.g.: spv.SourceLanguage.GLSL
** - Python will use dictionaries, e.g.: spv['SourceLanguage']['GLSL']
<<<<<<< HEAD
**
=======
**
>>>>>>> fdo-personal/nir-spirv
** Some tokens act like mask values, which can be OR'd together,
** while others are mutually exclusive. The mask-like ones have
** "Mask" in their name, and a parallel enum that has the shift
@ -818,4 +841,3 @@ typedef enum SpvOp_ {
} SpvOp;
#endif // #ifndef spirv_H

View File

@ -49,6 +49,7 @@ int main(int argc, char **argv)
const void *map = mmap(NULL, len, PROT_READ, MAP_PRIVATE, fd, 0);
assert(map != NULL);
nir_shader *shader = spirv_to_nir(map, word_count, MESA_SHADER_FRAGMENT, NULL);
nir_shader *shader = spirv_to_nir(map, MESA_SHADER_FRAGMENT,
word_count, NULL);
nir_print_shader(shader, stderr);
}

View File

@ -556,7 +556,7 @@ vtn_handle_type(struct vtn_builder *b, SpvOp opcode,
default:
unreachable("Unhandled opcode");
}
vtn_foreach_decoration(b, val, type_decoration_cb, NULL);
}
@ -644,10 +644,7 @@ vtn_get_builtin_location(SpvBuiltIn builtin, int *location,
/* XXX figure this out */
unreachable("unhandled builtin");
case SpvBuiltInVertexId:
/* Vulkan defines VertexID to be zero-based and reserves the new
* builtin keyword VertexIndex to indicate the non-zero-based value.
*/
*location = SYSTEM_VALUE_VERTEX_ID_ZERO_BASE;
*location = SYSTEM_VALUE_VERTEX_ID;
*mode = nir_var_system_value;
break;
case SpvBuiltInInstanceId:
@ -825,7 +822,7 @@ get_builtin_variable(struct vtn_builder *b,
if (!var) {
var = ralloc(b->shader, nir_variable);
var->type = type;
nir_variable_mode mode;
vtn_get_builtin_location(builtin, &var->data.location, &mode);
var->data.mode = mode;
@ -1060,10 +1057,10 @@ vtn_block_load(struct vtn_builder *b, nir_deref_var *src,
struct vtn_type *type, nir_deref *src_tail)
{
unsigned set = src->var->data.descriptor_set;
nir_ssa_def *binding = nir_imm_int(&b->nb, src->var->data.binding);
nir_deref *deref = &src->deref;
/* The block variable may be an array, in which case the array index adds
* an offset to the binding. Figure out that index now.
*/
@ -1097,7 +1094,7 @@ vtn_block_load(struct vtn_builder *b, nir_deref_var *src,
type = type->array_element;
break;
}
case nir_deref_type_struct: {
nir_deref_struct *deref_struct = nir_deref_as_struct(deref);
offset += type->offsets[deref_struct->index];
@ -1461,7 +1458,7 @@ 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);
@ -1517,16 +1514,16 @@ vtn_handle_texture(struct vtn_builder *b, SpvOp opcode,
unsigned coord_components = 0;
switch (opcode) {
case SpvOpImageSampleImplicitLod:
case SpvOpImageSampleExplicitLod:
case SpvOpImageSampleDrefImplicitLod:
case SpvOpImageSampleDrefExplicitLod:
case SpvOpImageSampleExplicitLod:
case SpvOpImageSampleDrefImplicitLod:
case SpvOpImageSampleDrefExplicitLod:
case SpvOpImageSampleProjImplicitLod:
case SpvOpImageSampleProjExplicitLod:
case SpvOpImageSampleProjDrefImplicitLod:
case SpvOpImageSampleProjDrefExplicitLod:
case SpvOpImageSampleProjExplicitLod:
case SpvOpImageSampleProjDrefImplicitLod:
case SpvOpImageSampleProjDrefExplicitLod:
case SpvOpImageFetch:
case SpvOpImageGather:
case SpvOpImageDrefGather:
case SpvOpImageDrefGather:
case SpvOpImageQueryLod: {
/* All these types have the coordinate as their first real argument */
struct vtn_ssa_value *coord = vtn_ssa_value(b, w[idx++]);
@ -1547,16 +1544,16 @@ vtn_handle_texture(struct vtn_builder *b, SpvOp opcode,
texop = nir_texop_tex;
break;
case SpvOpImageSampleExplicitLod:
case SpvOpImageSampleDrefImplicitLod:
case SpvOpImageSampleDrefExplicitLod:
case SpvOpImageSampleExplicitLod:
case SpvOpImageSampleDrefImplicitLod:
case SpvOpImageSampleDrefExplicitLod:
case SpvOpImageSampleProjImplicitLod:
case SpvOpImageSampleProjExplicitLod:
case SpvOpImageSampleProjDrefImplicitLod:
case SpvOpImageSampleProjDrefExplicitLod:
case SpvOpImageSampleProjExplicitLod:
case SpvOpImageSampleProjDrefImplicitLod:
case SpvOpImageSampleProjDrefExplicitLod:
case SpvOpImageFetch:
case SpvOpImageGather:
case SpvOpImageDrefGather:
case SpvOpImageDrefGather:
case SpvOpImageQuerySizeLod:
case SpvOpImageQuerySize:
case SpvOpImageQueryLod:
@ -1753,7 +1750,7 @@ vtn_matrix_multiply(struct vtn_builder *b,
}
}
}
dest = vtn_unwrap_matrix(dest);
if (transpose_result)
@ -2386,10 +2383,7 @@ vtn_handle_preamble_instruction(struct vtn_builder *b, SpvOp opcode,
break;
case SpvOpExecutionMode:
/*
* TODO handle these - for Vulkan OriginUpperLeft is always set for
* fragment shaders, so we can ignore this for now
*/
/* TODO */
break;
case SpvOpString:
@ -2603,16 +2597,16 @@ vtn_handle_body_instruction(struct vtn_builder *b, SpvOp opcode,
break;
case SpvOpImageSampleImplicitLod:
case SpvOpImageSampleExplicitLod:
case SpvOpImageSampleDrefImplicitLod:
case SpvOpImageSampleDrefExplicitLod:
case SpvOpImageSampleExplicitLod:
case SpvOpImageSampleDrefImplicitLod:
case SpvOpImageSampleDrefExplicitLod:
case SpvOpImageSampleProjImplicitLod:
case SpvOpImageSampleProjExplicitLod:
case SpvOpImageSampleProjDrefImplicitLod:
case SpvOpImageSampleProjDrefExplicitLod:
case SpvOpImageSampleProjExplicitLod:
case SpvOpImageSampleProjDrefImplicitLod:
case SpvOpImageSampleProjDrefExplicitLod:
case SpvOpImageFetch:
case SpvOpImageGather:
case SpvOpImageDrefGather:
case SpvOpImageDrefGather:
case SpvOpImageQuerySizeLod:
case SpvOpImageQuerySize:
case SpvOpImageQueryLod:

View File

@ -23,8 +23,6 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "main/config.h"
#ifndef SHADER_ENUMS_H
#define SHADER_ENUMS_H
@ -47,6 +45,7 @@ typedef enum
#define MESA_SHADER_STAGES (MESA_SHADER_COMPUTE + 1)
/**
* Indexes for vertex program attributes.
* GL_NV_vertex_program aliases generic attributes over the conventional
@ -153,6 +152,7 @@ typedef enum
BITFIELD64_RANGE(VERT_ATTRIB_GENERIC(0), VERT_ATTRIB_GENERIC_MAX)
/*@}*/
/**
* Indexes for vertex shader outputs, geometry shader inputs/outputs, and
* fragment shader inputs.