mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-08 09:08:10 +02:00
mesa: checkpoint: GLSL 1.20 array constructors
(cherry picked from commit ade777ea1b)
This commit is contained in:
parent
0d293f6687
commit
593073a3b3
7 changed files with 92 additions and 24 deletions
|
|
@ -1754,18 +1754,12 @@ _slang_find_function_by_max_argc(slang_function_scope *scope,
|
|||
* struct type.
|
||||
*/
|
||||
static slang_function *
|
||||
_slang_make_constructor(slang_assemble_ctx *A, slang_struct *str)
|
||||
_slang_make_struct_constructor(slang_assemble_ctx *A, slang_struct *str)
|
||||
{
|
||||
const GLint numFields = str->fields->num_variables;
|
||||
|
||||
slang_function *fun = (slang_function *) _mesa_malloc(sizeof(slang_function));
|
||||
if (!fun)
|
||||
return NULL;
|
||||
|
||||
slang_function_construct(fun);
|
||||
slang_function *fun = slang_new_function(SLANG_FUNC_CONSTRUCTOR);
|
||||
|
||||
/* function header (name, return type) */
|
||||
fun->kind = SLANG_FUNC_CONSTRUCTOR;
|
||||
fun->header.a_name = str->a_name;
|
||||
fun->header.type.qualifier = SLANG_QUAL_NONE;
|
||||
fun->header.type.specifier.type = SLANG_SPEC_STRUCT;
|
||||
|
|
@ -1884,7 +1878,6 @@ _slang_make_constructor(slang_assemble_ctx *A, slang_struct *str)
|
|||
ret->children[0].type = SLANG_OPER_IDENTIFIER;
|
||||
ret->children[0].a_id = var->a_name;
|
||||
ret->children[0].locals = _slang_variable_scope_new(scope);
|
||||
|
||||
}
|
||||
}
|
||||
/*
|
||||
|
|
@ -1907,7 +1900,7 @@ _slang_locate_struct_constructor(slang_assemble_ctx *A, const char *name)
|
|||
/* found a structure type that matches the function name */
|
||||
if (!str->constructor) {
|
||||
/* create the constructor function now */
|
||||
str->constructor = _slang_make_constructor(A, str);
|
||||
str->constructor = _slang_make_struct_constructor(A, str);
|
||||
}
|
||||
return str->constructor;
|
||||
}
|
||||
|
|
@ -1916,6 +1909,29 @@ _slang_locate_struct_constructor(slang_assemble_ctx *A, const char *name)
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate a new slang_function to satisfy a call to an array constructor.
|
||||
* Ex: float[3](1., 2., 3.)
|
||||
*/
|
||||
static slang_function *
|
||||
_slang_make_array_constructor(slang_assemble_ctx *A, slang_operation *oper)
|
||||
{
|
||||
slang_function *fun = slang_new_function(SLANG_FUNC_CONSTRUCTOR);
|
||||
if (fun) {
|
||||
slang_type_specifier_type baseType =
|
||||
slang_type_specifier_type_from_string((char *) oper->a_id);
|
||||
|
||||
fun->header.a_name = oper->a_id;
|
||||
fun->header.type.qualifier = SLANG_QUAL_NONE;
|
||||
fun->header.type.specifier.type = SLANG_SPEC_ARRAY;
|
||||
fun->header.type.specifier._array =
|
||||
slang_type_specifier_new(baseType, NULL, NULL);
|
||||
|
||||
|
||||
}
|
||||
return fun;
|
||||
}
|
||||
|
||||
|
||||
static GLboolean
|
||||
_slang_is_vec_mat_type(const char *name)
|
||||
|
|
@ -1956,11 +1972,15 @@ _slang_gen_function_call_name(slang_assemble_ctx *A, const char *name,
|
|||
if (atom == SLANG_ATOM_NULL)
|
||||
return NULL;
|
||||
|
||||
/*
|
||||
* First, try to find function by name and exact argument type matching.
|
||||
*/
|
||||
fun = _slang_locate_function(A->space.funcs, atom, params, param_count,
|
||||
&A->space, A->atoms, A->log, &error);
|
||||
if (oper->array_constructor) {
|
||||
/* this needs special handling */
|
||||
fun = _slang_make_array_constructor(A, oper);
|
||||
}
|
||||
else {
|
||||
/* Try to find function by name and exact argument type matching */
|
||||
fun = _slang_locate_function(A->space.funcs, atom, params, param_count,
|
||||
&A->space, A->atoms, A->log, &error);
|
||||
}
|
||||
|
||||
if (error) {
|
||||
slang_info_log_error(A->log,
|
||||
|
|
|
|||
|
|
@ -2181,8 +2181,8 @@ parse_function(slang_parse_ctx * C, slang_output_ctx * O, int definition,
|
|||
/* destroy the existing function declaration and replace it
|
||||
* with the new one, remember to save the fixup table
|
||||
*/
|
||||
parsed_func.fixups = found_func->fixups;
|
||||
slang_fixup_table_init(&found_func->fixups);
|
||||
//parsed_func.fixups = found_func->fixups;
|
||||
//slang_fixup_table_init(&found_func->fixups);
|
||||
slang_function_destruct(found_func);
|
||||
*found_func = parsed_func;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,8 +86,8 @@ slang_function_construct(slang_function * func)
|
|||
_slang_variable_scope_ctr(func->parameters);
|
||||
func->param_count = 0;
|
||||
func->body = NULL;
|
||||
func->address = ~0;
|
||||
slang_fixup_table_init(&func->fixups);
|
||||
//func->address = ~0;
|
||||
//slang_fixup_table_init(&func->fixups);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
@ -101,9 +101,23 @@ slang_function_destruct(slang_function * func)
|
|||
slang_operation_destruct(func->body);
|
||||
_slang_free(func->body);
|
||||
}
|
||||
slang_fixup_table_free(&func->fixups);
|
||||
//slang_fixup_table_free(&func->fixups);
|
||||
}
|
||||
|
||||
|
||||
slang_function *
|
||||
slang_new_function(slang_function_kind kind)
|
||||
{
|
||||
slang_function *fun = (slang_function *)
|
||||
_mesa_malloc(sizeof(slang_function));
|
||||
if (fun) {
|
||||
slang_function_construct(fun);
|
||||
fun->kind = kind;
|
||||
}
|
||||
return fun;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* slang_function_scope
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -64,12 +64,15 @@ typedef struct slang_function_
|
|||
slang_variable_scope *parameters; /**< formal parameters AND local vars */
|
||||
unsigned int param_count; /**< number of formal params (no locals) */
|
||||
slang_operation *body; /**< The instruction tree */
|
||||
#if 0
|
||||
unsigned int address; /**< Address of this func in memory */
|
||||
slang_fixup_table fixups; /**< Mem locations which need func's address */
|
||||
#endif
|
||||
} slang_function;
|
||||
|
||||
extern int slang_function_construct(slang_function *);
|
||||
extern void slang_function_destruct(slang_function *);
|
||||
extern slang_function *slang_new_function(slang_function_kind kind);
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@
|
|||
#define SLANG_STORAGE_H
|
||||
|
||||
#include "slang_compile.h"
|
||||
#include "slang_typeinfo.h"
|
||||
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -187,6 +187,21 @@ slang_type_specifier_dtr(slang_type_specifier * self)
|
|||
}
|
||||
}
|
||||
|
||||
slang_type_specifier *
|
||||
slang_type_specifier_new(slang_type_specifier_type type,
|
||||
struct slang_struct_ *_struct,
|
||||
struct slang_type_specifier_ *_array)
|
||||
{
|
||||
slang_type_specifier *spec =
|
||||
(slang_type_specifier *) _mesa_malloc(sizeof(slang_type_specifier));
|
||||
if (spec) {
|
||||
spec->type = type;
|
||||
spec->_struct = _struct;
|
||||
spec->_array = _array;
|
||||
}
|
||||
return spec;
|
||||
}
|
||||
|
||||
GLboolean
|
||||
slang_type_specifier_copy(slang_type_specifier * x,
|
||||
const slang_type_specifier * y)
|
||||
|
|
@ -583,7 +598,18 @@ _slang_typeof_operation_(slang_operation * op,
|
|||
}
|
||||
break;
|
||||
case SLANG_OPER_CALL:
|
||||
if (op->fun) {
|
||||
if (op->array_constructor) {
|
||||
/* build array typeinfo */
|
||||
ti->spec.type = SLANG_SPEC_ARRAY;
|
||||
ti->spec._array = (slang_type_specifier *)
|
||||
_slang_alloc(sizeof(slang_type_specifier));
|
||||
slang_type_specifier_ctr(ti->spec._array);
|
||||
|
||||
ti->spec._array->type =
|
||||
slang_type_specifier_type_from_string((char *) op->a_id);
|
||||
ti->array_len = op->num_children;
|
||||
}
|
||||
else if (op->fun) {
|
||||
/* we've resolved this call before */
|
||||
slang_type_specifier_copy(&ti->spec, &op->fun->header.type.specifier);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -134,8 +134,8 @@ typedef enum slang_type_specifier_type_
|
|||
typedef struct slang_type_specifier_
|
||||
{
|
||||
slang_type_specifier_type type;
|
||||
struct slang_struct_ *_struct; /**< used if type == spec_struct */
|
||||
struct slang_type_specifier_ *_array; /**< used if type == spec_array */
|
||||
struct slang_struct_ *_struct; /**< if type == SLANG_SPEC_STRUCT */
|
||||
struct slang_type_specifier_ *_array; /**< if type == SLANG_SPEC_ARRAY */
|
||||
} slang_type_specifier;
|
||||
|
||||
|
||||
|
|
@ -145,6 +145,12 @@ slang_type_specifier_ctr(slang_type_specifier *);
|
|||
extern GLvoid
|
||||
slang_type_specifier_dtr(slang_type_specifier *);
|
||||
|
||||
extern slang_type_specifier *
|
||||
slang_type_specifier_new(slang_type_specifier_type type,
|
||||
struct slang_struct_ *_struct,
|
||||
struct slang_type_specifier_ *_array);
|
||||
|
||||
|
||||
extern GLboolean
|
||||
slang_type_specifier_copy(slang_type_specifier *, const slang_type_specifier *);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue