mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-23 22:00:13 +01:00
glsl: Retire the non-NIR GLSL linking paths.
Now that we have only GLSL->NIR as a path in the frontend, we can rely on the NIR linking support. Reviewed-by: Marek Olšák <marek.olsak@amd.com> Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8044>
This commit is contained in:
parent
7221cc7657
commit
9617184bc2
13 changed files with 0 additions and 3616 deletions
|
|
@ -1,354 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright © 2013 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "glsl_parser_extras.h"
|
|
||||||
#include "ir.h"
|
|
||||||
#include "ir_uniform.h"
|
|
||||||
#include "linker.h"
|
|
||||||
#include "main/errors.h"
|
|
||||||
#include "main/macros.h"
|
|
||||||
#include "main/consts_exts.h"
|
|
||||||
#include "main/shader_types.h"
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
/*
|
|
||||||
* Atomic counter uniform as seen by the program.
|
|
||||||
*/
|
|
||||||
struct active_atomic_counter_uniform {
|
|
||||||
unsigned uniform_loc;
|
|
||||||
ir_variable *var;
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Atomic counter buffer referenced by the program. There is a one
|
|
||||||
* to one correspondence between these and the objects that can be
|
|
||||||
* queried using glGetActiveAtomicCounterBufferiv().
|
|
||||||
*/
|
|
||||||
struct active_atomic_buffer {
|
|
||||||
active_atomic_buffer()
|
|
||||||
: uniforms(0), num_uniforms(0), stage_counter_references(), size(0)
|
|
||||||
{}
|
|
||||||
|
|
||||||
~active_atomic_buffer()
|
|
||||||
{
|
|
||||||
free(uniforms);
|
|
||||||
}
|
|
||||||
|
|
||||||
void push_back(unsigned uniform_loc, ir_variable *var)
|
|
||||||
{
|
|
||||||
active_atomic_counter_uniform *new_uniforms;
|
|
||||||
|
|
||||||
new_uniforms = (active_atomic_counter_uniform *)
|
|
||||||
realloc(uniforms, sizeof(active_atomic_counter_uniform) *
|
|
||||||
(num_uniforms + 1));
|
|
||||||
|
|
||||||
if (new_uniforms == NULL) {
|
|
||||||
_mesa_error_no_memory(__func__);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
uniforms = new_uniforms;
|
|
||||||
uniforms[num_uniforms].uniform_loc = uniform_loc;
|
|
||||||
uniforms[num_uniforms].var = var;
|
|
||||||
num_uniforms++;
|
|
||||||
}
|
|
||||||
|
|
||||||
active_atomic_counter_uniform *uniforms;
|
|
||||||
unsigned num_uniforms;
|
|
||||||
unsigned stage_counter_references[MESA_SHADER_STAGES];
|
|
||||||
unsigned size;
|
|
||||||
};
|
|
||||||
|
|
||||||
int
|
|
||||||
cmp_actives(const void *a, const void *b)
|
|
||||||
{
|
|
||||||
const active_atomic_counter_uniform *const first = (active_atomic_counter_uniform *) a;
|
|
||||||
const active_atomic_counter_uniform *const second = (active_atomic_counter_uniform *) b;
|
|
||||||
|
|
||||||
return int(first->var->data.offset) - int(second->var->data.offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
check_atomic_counters_overlap(const ir_variable *x, const ir_variable *y)
|
|
||||||
{
|
|
||||||
return ((x->data.offset >= y->data.offset &&
|
|
||||||
x->data.offset < y->data.offset + y->type->atomic_size()) ||
|
|
||||||
(y->data.offset >= x->data.offset &&
|
|
||||||
y->data.offset < x->data.offset + x->type->atomic_size()));
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
process_atomic_variable(const glsl_type *t, struct gl_shader_program *prog,
|
|
||||||
unsigned *uniform_loc, ir_variable *var,
|
|
||||||
active_atomic_buffer *const buffers,
|
|
||||||
unsigned *num_buffers, int *offset,
|
|
||||||
const unsigned shader_stage)
|
|
||||||
{
|
|
||||||
/* FIXME: Arrays of arrays get counted separately. For example:
|
|
||||||
* x1[3][3][2] = 9 uniforms, 18 atomic counters
|
|
||||||
* x2[3][2] = 3 uniforms, 6 atomic counters
|
|
||||||
* x3[2] = 1 uniform, 2 atomic counters
|
|
||||||
*
|
|
||||||
* However this code marks all the counters as active even when they
|
|
||||||
* might not be used.
|
|
||||||
*/
|
|
||||||
if (t->is_array() && t->fields.array->is_array()) {
|
|
||||||
for (unsigned i = 0; i < t->length; i++) {
|
|
||||||
process_atomic_variable(t->fields.array, prog, uniform_loc,
|
|
||||||
var, buffers, num_buffers, offset,
|
|
||||||
shader_stage);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
active_atomic_buffer *buf = &buffers[var->data.binding];
|
|
||||||
gl_uniform_storage *const storage =
|
|
||||||
&prog->data->UniformStorage[*uniform_loc];
|
|
||||||
|
|
||||||
/* If this is the first time the buffer is used, increment
|
|
||||||
* the counter of buffers used.
|
|
||||||
*/
|
|
||||||
if (buf->size == 0)
|
|
||||||
(*num_buffers)++;
|
|
||||||
|
|
||||||
buf->push_back(*uniform_loc, var);
|
|
||||||
|
|
||||||
/* When checking for atomic counters we should count every member in
|
|
||||||
* an array as an atomic counter reference.
|
|
||||||
*/
|
|
||||||
if (t->is_array())
|
|
||||||
buf->stage_counter_references[shader_stage] += t->length;
|
|
||||||
else
|
|
||||||
buf->stage_counter_references[shader_stage]++;
|
|
||||||
buf->size = MAX2(buf->size, *offset + t->atomic_size());
|
|
||||||
|
|
||||||
storage->offset = *offset;
|
|
||||||
*offset += t->atomic_size();
|
|
||||||
|
|
||||||
(*uniform_loc)++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
active_atomic_buffer *
|
|
||||||
find_active_atomic_counters(const struct gl_constants *consts,
|
|
||||||
struct gl_shader_program *prog,
|
|
||||||
unsigned *num_buffers)
|
|
||||||
{
|
|
||||||
active_atomic_buffer *const buffers =
|
|
||||||
new active_atomic_buffer[consts->MaxAtomicBufferBindings];
|
|
||||||
|
|
||||||
*num_buffers = 0;
|
|
||||||
|
|
||||||
for (unsigned i = 0; i < MESA_SHADER_STAGES; ++i) {
|
|
||||||
struct gl_linked_shader *sh = prog->_LinkedShaders[i];
|
|
||||||
if (sh == NULL)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
foreach_in_list(ir_instruction, node, sh->ir) {
|
|
||||||
ir_variable *var = node->as_variable();
|
|
||||||
|
|
||||||
if (var && var->type->contains_atomic()) {
|
|
||||||
int offset = var->data.offset;
|
|
||||||
unsigned uniform_loc = var->data.location;
|
|
||||||
process_atomic_variable(var->type, prog, &uniform_loc,
|
|
||||||
var, buffers, num_buffers, &offset, i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (unsigned i = 0; i < consts->MaxAtomicBufferBindings; i++) {
|
|
||||||
if (buffers[i].size == 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
qsort(buffers[i].uniforms, buffers[i].num_uniforms,
|
|
||||||
sizeof(active_atomic_counter_uniform),
|
|
||||||
cmp_actives);
|
|
||||||
|
|
||||||
for (unsigned j = 1; j < buffers[i].num_uniforms; j++) {
|
|
||||||
/* If an overlapping counter found, it must be a reference to the
|
|
||||||
* same counter from a different shader stage.
|
|
||||||
*/
|
|
||||||
if (check_atomic_counters_overlap(buffers[i].uniforms[j-1].var,
|
|
||||||
buffers[i].uniforms[j].var)
|
|
||||||
&& strcmp(buffers[i].uniforms[j-1].var->name,
|
|
||||||
buffers[i].uniforms[j].var->name) != 0) {
|
|
||||||
linker_error(prog, "Atomic counter %s declared at offset %d "
|
|
||||||
"which is already in use.",
|
|
||||||
buffers[i].uniforms[j].var->name,
|
|
||||||
buffers[i].uniforms[j].var->data.offset);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return buffers;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
link_assign_atomic_counter_resources(const struct gl_constants *consts,
|
|
||||||
struct gl_shader_program *prog)
|
|
||||||
{
|
|
||||||
unsigned num_buffers;
|
|
||||||
unsigned num_atomic_buffers[MESA_SHADER_STAGES] = {};
|
|
||||||
active_atomic_buffer *abs =
|
|
||||||
find_active_atomic_counters(consts, prog, &num_buffers);
|
|
||||||
|
|
||||||
prog->data->AtomicBuffers = rzalloc_array(prog->data, gl_active_atomic_buffer,
|
|
||||||
num_buffers);
|
|
||||||
prog->data->NumAtomicBuffers = num_buffers;
|
|
||||||
|
|
||||||
unsigned i = 0;
|
|
||||||
for (unsigned binding = 0;
|
|
||||||
binding < consts->MaxAtomicBufferBindings;
|
|
||||||
binding++) {
|
|
||||||
|
|
||||||
/* If the binding was not used, skip.
|
|
||||||
*/
|
|
||||||
if (abs[binding].size == 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
active_atomic_buffer &ab = abs[binding];
|
|
||||||
gl_active_atomic_buffer &mab = prog->data->AtomicBuffers[i];
|
|
||||||
|
|
||||||
/* Assign buffer-specific fields. */
|
|
||||||
mab.Binding = binding;
|
|
||||||
mab.MinimumSize = ab.size;
|
|
||||||
mab.Uniforms = rzalloc_array(prog->data->AtomicBuffers, GLuint,
|
|
||||||
ab.num_uniforms);
|
|
||||||
mab.NumUniforms = ab.num_uniforms;
|
|
||||||
|
|
||||||
/* Assign counter-specific fields. */
|
|
||||||
for (unsigned j = 0; j < ab.num_uniforms; j++) {
|
|
||||||
ir_variable *const var = ab.uniforms[j].var;
|
|
||||||
gl_uniform_storage *const storage =
|
|
||||||
&prog->data->UniformStorage[ab.uniforms[j].uniform_loc];
|
|
||||||
|
|
||||||
mab.Uniforms[j] = ab.uniforms[j].uniform_loc;
|
|
||||||
if (!var->data.explicit_binding)
|
|
||||||
var->data.binding = i;
|
|
||||||
|
|
||||||
storage->atomic_buffer_index = i;
|
|
||||||
storage->offset = var->data.offset;
|
|
||||||
storage->array_stride = (var->type->is_array() ?
|
|
||||||
var->type->without_array()->atomic_size() : 0);
|
|
||||||
if (!var->type->is_matrix())
|
|
||||||
storage->matrix_stride = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Assign stage-specific fields. */
|
|
||||||
for (unsigned j = 0; j < MESA_SHADER_STAGES; ++j) {
|
|
||||||
if (ab.stage_counter_references[j]) {
|
|
||||||
mab.StageReferences[j] = GL_TRUE;
|
|
||||||
num_atomic_buffers[j]++;
|
|
||||||
} else {
|
|
||||||
mab.StageReferences[j] = GL_FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Store a list pointers to atomic buffers per stage and store the index
|
|
||||||
* to the intra-stage buffer list in uniform storage.
|
|
||||||
*/
|
|
||||||
for (unsigned j = 0; j < MESA_SHADER_STAGES; ++j) {
|
|
||||||
if (prog->_LinkedShaders[j] && num_atomic_buffers[j] > 0) {
|
|
||||||
struct gl_program *gl_prog = prog->_LinkedShaders[j]->Program;
|
|
||||||
gl_prog->info.num_abos = num_atomic_buffers[j];
|
|
||||||
gl_prog->sh.AtomicBuffers =
|
|
||||||
rzalloc_array(gl_prog, gl_active_atomic_buffer *,
|
|
||||||
num_atomic_buffers[j]);
|
|
||||||
|
|
||||||
unsigned intra_stage_idx = 0;
|
|
||||||
for (unsigned i = 0; i < num_buffers; i++) {
|
|
||||||
struct gl_active_atomic_buffer *atomic_buffer =
|
|
||||||
&prog->data->AtomicBuffers[i];
|
|
||||||
if (atomic_buffer->StageReferences[j]) {
|
|
||||||
gl_prog->sh.AtomicBuffers[intra_stage_idx] = atomic_buffer;
|
|
||||||
|
|
||||||
for (unsigned u = 0; u < atomic_buffer->NumUniforms; u++) {
|
|
||||||
prog->data->UniformStorage[atomic_buffer->Uniforms[u]].opaque[j].index =
|
|
||||||
intra_stage_idx;
|
|
||||||
prog->data->UniformStorage[atomic_buffer->Uniforms[u]].opaque[j].active =
|
|
||||||
true;
|
|
||||||
}
|
|
||||||
|
|
||||||
intra_stage_idx++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
delete [] abs;
|
|
||||||
assert(i == num_buffers);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
link_check_atomic_counter_resources(const struct gl_constants *consts,
|
|
||||||
struct gl_shader_program *prog)
|
|
||||||
{
|
|
||||||
unsigned num_buffers;
|
|
||||||
active_atomic_buffer *const abs =
|
|
||||||
find_active_atomic_counters(consts, prog, &num_buffers);
|
|
||||||
unsigned atomic_counters[MESA_SHADER_STAGES] = {};
|
|
||||||
unsigned atomic_buffers[MESA_SHADER_STAGES] = {};
|
|
||||||
unsigned total_atomic_counters = 0;
|
|
||||||
unsigned total_atomic_buffers = 0;
|
|
||||||
|
|
||||||
/* Sum the required resources. Note that this counts buffers and
|
|
||||||
* counters referenced by several shader stages multiple times
|
|
||||||
* against the combined limit -- That's the behavior the spec
|
|
||||||
* requires.
|
|
||||||
*/
|
|
||||||
for (unsigned i = 0; i < consts->MaxAtomicBufferBindings; i++) {
|
|
||||||
if (abs[i].size == 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
for (unsigned j = 0; j < MESA_SHADER_STAGES; ++j) {
|
|
||||||
const unsigned n = abs[i].stage_counter_references[j];
|
|
||||||
|
|
||||||
if (n) {
|
|
||||||
atomic_counters[j] += n;
|
|
||||||
total_atomic_counters += n;
|
|
||||||
atomic_buffers[j]++;
|
|
||||||
total_atomic_buffers++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check that they are within the supported limits. */
|
|
||||||
for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
|
|
||||||
if (atomic_counters[i] > consts->Program[i].MaxAtomicCounters)
|
|
||||||
linker_error(prog, "Too many %s shader atomic counters",
|
|
||||||
_mesa_shader_stage_to_string(i));
|
|
||||||
|
|
||||||
if (atomic_buffers[i] > consts->Program[i].MaxAtomicBuffers)
|
|
||||||
linker_error(prog, "Too many %s shader atomic counter buffers",
|
|
||||||
_mesa_shader_stage_to_string(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (total_atomic_counters > consts->MaxCombinedAtomicCounters)
|
|
||||||
linker_error(prog, "Too many combined atomic counters");
|
|
||||||
|
|
||||||
if (total_atomic_buffers > consts->MaxCombinedAtomicBuffers)
|
|
||||||
linker_error(prog, "Too many combined atomic buffers");
|
|
||||||
|
|
||||||
delete [] abs;
|
|
||||||
}
|
|
||||||
|
|
@ -1,312 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright © 2012 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "ir.h"
|
|
||||||
#include "linker.h"
|
|
||||||
#include "ir_uniform.h"
|
|
||||||
#include "string_to_uint_map.h"
|
|
||||||
#include "main/shader_types.h"
|
|
||||||
|
|
||||||
/* These functions are put in a "private" namespace instead of being marked
|
|
||||||
* static so that the unit tests can access them. See
|
|
||||||
* http://code.google.com/p/googletest/wiki/AdvancedGuide#Testing_Private_Code
|
|
||||||
*/
|
|
||||||
namespace linker {
|
|
||||||
|
|
||||||
static gl_uniform_storage *
|
|
||||||
get_storage(struct gl_shader_program *prog, const char *name)
|
|
||||||
{
|
|
||||||
unsigned id;
|
|
||||||
if (prog->UniformHash->get(id, name))
|
|
||||||
return &prog->data->UniformStorage[id];
|
|
||||||
|
|
||||||
assert(!"No uniform storage found!");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
copy_constant_to_storage(union gl_constant_value *storage,
|
|
||||||
const ir_constant *val,
|
|
||||||
const enum glsl_base_type base_type,
|
|
||||||
const unsigned int elements,
|
|
||||||
unsigned int boolean_true)
|
|
||||||
{
|
|
||||||
for (unsigned int i = 0; i < elements; i++) {
|
|
||||||
switch (base_type) {
|
|
||||||
case GLSL_TYPE_UINT:
|
|
||||||
storage[i].u = val->value.u[i];
|
|
||||||
break;
|
|
||||||
case GLSL_TYPE_INT:
|
|
||||||
case GLSL_TYPE_SAMPLER:
|
|
||||||
storage[i].i = val->value.i[i];
|
|
||||||
break;
|
|
||||||
case GLSL_TYPE_FLOAT:
|
|
||||||
storage[i].f = val->value.f[i];
|
|
||||||
break;
|
|
||||||
case GLSL_TYPE_DOUBLE:
|
|
||||||
case GLSL_TYPE_UINT64:
|
|
||||||
case GLSL_TYPE_INT64:
|
|
||||||
/* XXX need to check on big-endian */
|
|
||||||
memcpy(&storage[i * 2].u, &val->value.d[i], sizeof(double));
|
|
||||||
break;
|
|
||||||
case GLSL_TYPE_BOOL:
|
|
||||||
storage[i].b = val->value.b[i] ? boolean_true : 0;
|
|
||||||
break;
|
|
||||||
case GLSL_TYPE_ARRAY:
|
|
||||||
case GLSL_TYPE_STRUCT:
|
|
||||||
case GLSL_TYPE_TEXTURE:
|
|
||||||
case GLSL_TYPE_IMAGE:
|
|
||||||
case GLSL_TYPE_ATOMIC_UINT:
|
|
||||||
case GLSL_TYPE_INTERFACE:
|
|
||||||
case GLSL_TYPE_VOID:
|
|
||||||
case GLSL_TYPE_SUBROUTINE:
|
|
||||||
case GLSL_TYPE_FUNCTION:
|
|
||||||
case GLSL_TYPE_ERROR:
|
|
||||||
case GLSL_TYPE_UINT16:
|
|
||||||
case GLSL_TYPE_INT16:
|
|
||||||
case GLSL_TYPE_UINT8:
|
|
||||||
case GLSL_TYPE_INT8:
|
|
||||||
case GLSL_TYPE_FLOAT16:
|
|
||||||
/* All other types should have already been filtered by other
|
|
||||||
* paths in the caller.
|
|
||||||
*/
|
|
||||||
assert(!"Should not get here.");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialize an opaque uniform from the value of an explicit binding
|
|
||||||
* qualifier specified in the shader. Atomic counters are different because
|
|
||||||
* they have no storage and should be handled elsewhere.
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
set_opaque_binding(void *mem_ctx, gl_shader_program *prog,
|
|
||||||
const ir_variable *var, const glsl_type *type,
|
|
||||||
const char *name, int *binding)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (type->is_array() && type->fields.array->is_array()) {
|
|
||||||
const glsl_type *const element_type = type->fields.array;
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < type->length; i++) {
|
|
||||||
const char *element_name = ralloc_asprintf(mem_ctx, "%s[%d]", name, i);
|
|
||||||
|
|
||||||
set_opaque_binding(mem_ctx, prog, var, element_type,
|
|
||||||
element_name, binding);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
struct gl_uniform_storage *const storage = get_storage(prog, name);
|
|
||||||
|
|
||||||
if (!storage)
|
|
||||||
return;
|
|
||||||
|
|
||||||
const unsigned elements = MAX2(storage->array_elements, 1);
|
|
||||||
|
|
||||||
/* Section 4.4.6 (Opaque-Uniform Layout Qualifiers) of the GLSL 4.50 spec
|
|
||||||
* says:
|
|
||||||
*
|
|
||||||
* "If the binding identifier is used with an array, the first element
|
|
||||||
* of the array takes the specified unit and each subsequent element
|
|
||||||
* takes the next consecutive unit."
|
|
||||||
*/
|
|
||||||
for (unsigned int i = 0; i < elements; i++) {
|
|
||||||
storage->storage[i].i = (*binding)++;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int sh = 0; sh < MESA_SHADER_STAGES; sh++) {
|
|
||||||
gl_linked_shader *shader = prog->_LinkedShaders[sh];
|
|
||||||
|
|
||||||
if (!shader)
|
|
||||||
continue;
|
|
||||||
if (!storage->opaque[sh].active)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (storage->type->is_sampler()) {
|
|
||||||
for (unsigned i = 0; i < elements; i++) {
|
|
||||||
const unsigned index = storage->opaque[sh].index + i;
|
|
||||||
|
|
||||||
if (var->data.bindless) {
|
|
||||||
if (index >= shader->Program->sh.NumBindlessSamplers)
|
|
||||||
break;
|
|
||||||
shader->Program->sh.BindlessSamplers[index].unit =
|
|
||||||
storage->storage[i].i;
|
|
||||||
shader->Program->sh.BindlessSamplers[index].bound = true;
|
|
||||||
shader->Program->sh.HasBoundBindlessSampler = true;
|
|
||||||
} else {
|
|
||||||
if (index >= ARRAY_SIZE(shader->Program->SamplerUnits))
|
|
||||||
break;
|
|
||||||
shader->Program->SamplerUnits[index] =
|
|
||||||
storage->storage[i].i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (storage->type->is_image()) {
|
|
||||||
for (unsigned i = 0; i < elements; i++) {
|
|
||||||
const unsigned index = storage->opaque[sh].index + i;
|
|
||||||
|
|
||||||
|
|
||||||
if (var->data.bindless) {
|
|
||||||
if (index >= shader->Program->sh.NumBindlessImages)
|
|
||||||
break;
|
|
||||||
shader->Program->sh.BindlessImages[index].unit =
|
|
||||||
storage->storage[i].i;
|
|
||||||
shader->Program->sh.BindlessImages[index].bound = true;
|
|
||||||
shader->Program->sh.HasBoundBindlessImage = true;
|
|
||||||
} else {
|
|
||||||
if (index >= ARRAY_SIZE(shader->Program->sh.ImageUnits))
|
|
||||||
break;
|
|
||||||
shader->Program->sh.ImageUnits[index] =
|
|
||||||
storage->storage[i].i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
set_uniform_initializer(void *mem_ctx, gl_shader_program *prog,
|
|
||||||
const char *name, const glsl_type *type,
|
|
||||||
ir_constant *val, unsigned int boolean_true)
|
|
||||||
{
|
|
||||||
const glsl_type *t_without_array = type->without_array();
|
|
||||||
if (type->is_struct()) {
|
|
||||||
for (unsigned int i = 0; i < type->length; i++) {
|
|
||||||
const glsl_type *field_type = type->fields.structure[i].type;
|
|
||||||
const char *field_name = ralloc_asprintf(mem_ctx, "%s.%s", name,
|
|
||||||
type->fields.structure[i].name);
|
|
||||||
set_uniform_initializer(mem_ctx, prog, field_name,
|
|
||||||
field_type, val->get_record_field(i),
|
|
||||||
boolean_true);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
} else if (t_without_array->is_struct() ||
|
|
||||||
(type->is_array() && type->fields.array->is_array())) {
|
|
||||||
const glsl_type *const element_type = type->fields.array;
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < type->length; i++) {
|
|
||||||
const char *element_name = ralloc_asprintf(mem_ctx, "%s[%d]", name, i);
|
|
||||||
|
|
||||||
set_uniform_initializer(mem_ctx, prog, element_name,
|
|
||||||
element_type, val->const_elements[i],
|
|
||||||
boolean_true);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct gl_uniform_storage *const storage = get_storage(prog, name);
|
|
||||||
|
|
||||||
if (!storage)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (val->type->is_array()) {
|
|
||||||
const enum glsl_base_type base_type =
|
|
||||||
val->const_elements[0]->type->base_type;
|
|
||||||
const unsigned int elements = val->const_elements[0]->type->components();
|
|
||||||
unsigned int idx = 0;
|
|
||||||
unsigned dmul = glsl_base_type_is_64bit(base_type) ? 2 : 1;
|
|
||||||
|
|
||||||
assert(val->type->length >= storage->array_elements);
|
|
||||||
for (unsigned int i = 0; i < storage->array_elements; i++) {
|
|
||||||
copy_constant_to_storage(& storage->storage[idx],
|
|
||||||
val->const_elements[i],
|
|
||||||
base_type,
|
|
||||||
elements,
|
|
||||||
boolean_true);
|
|
||||||
|
|
||||||
idx += elements * dmul;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
copy_constant_to_storage(storage->storage,
|
|
||||||
val,
|
|
||||||
val->type->base_type,
|
|
||||||
val->type->components(),
|
|
||||||
boolean_true);
|
|
||||||
|
|
||||||
if (storage->type->is_sampler()) {
|
|
||||||
for (int sh = 0; sh < MESA_SHADER_STAGES; sh++) {
|
|
||||||
gl_linked_shader *shader = prog->_LinkedShaders[sh];
|
|
||||||
|
|
||||||
if (shader && storage->opaque[sh].active) {
|
|
||||||
unsigned index = storage->opaque[sh].index;
|
|
||||||
|
|
||||||
shader->Program->SamplerUnits[index] = storage->storage[0].i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
link_set_uniform_initializers(struct gl_shader_program *prog,
|
|
||||||
unsigned int boolean_true)
|
|
||||||
{
|
|
||||||
void *mem_ctx = NULL;
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < MESA_SHADER_STAGES; i++) {
|
|
||||||
struct gl_linked_shader *shader = prog->_LinkedShaders[i];
|
|
||||||
|
|
||||||
if (shader == NULL)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
foreach_in_list(ir_instruction, node, shader->ir) {
|
|
||||||
ir_variable *const var = node->as_variable();
|
|
||||||
|
|
||||||
if (!var || (var->data.mode != ir_var_uniform &&
|
|
||||||
var->data.mode != ir_var_shader_storage))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!mem_ctx)
|
|
||||||
mem_ctx = ralloc_context(NULL);
|
|
||||||
|
|
||||||
if (var->data.explicit_binding) {
|
|
||||||
const glsl_type *const type = var->type;
|
|
||||||
|
|
||||||
if (var->is_in_buffer_block()) {
|
|
||||||
/* This case is handled by link_uniform_blocks (at
|
|
||||||
* process_block_array_leaf)
|
|
||||||
*/
|
|
||||||
} else if (type->without_array()->is_sampler() ||
|
|
||||||
type->without_array()->is_image()) {
|
|
||||||
int binding = var->data.binding;
|
|
||||||
linker::set_opaque_binding(mem_ctx, prog, var, var->type,
|
|
||||||
var->name, &binding);
|
|
||||||
} else if (type->contains_atomic()) {
|
|
||||||
/* we don't actually need to do anything. */
|
|
||||||
} else {
|
|
||||||
assert(!"Explicit binding not on a sampler, UBO or atomic.");
|
|
||||||
}
|
|
||||||
} else if (var->constant_initializer) {
|
|
||||||
linker::set_uniform_initializer(mem_ctx, prog, var->name,
|
|
||||||
var->type, var->constant_initializer,
|
|
||||||
boolean_true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
memcpy(prog->data->UniformDataDefaults, prog->data->UniformDataSlots,
|
|
||||||
sizeof(union gl_constant_value) * prog->data->NumUniformDataSlots);
|
|
||||||
ralloc_free(mem_ctx);
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -2676,97 +2676,6 @@ link_intrastage_shaders(void *mem_ctx,
|
||||||
return linked;
|
return linked;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Update the sizes of linked shader uniform arrays to the maximum
|
|
||||||
* array index used.
|
|
||||||
*
|
|
||||||
* From page 81 (page 95 of the PDF) of the OpenGL 2.1 spec:
|
|
||||||
*
|
|
||||||
* If one or more elements of an array are active,
|
|
||||||
* GetActiveUniform will return the name of the array in name,
|
|
||||||
* subject to the restrictions listed above. The type of the array
|
|
||||||
* is returned in type. The size parameter contains the highest
|
|
||||||
* array element index used, plus one. The compiler or linker
|
|
||||||
* determines the highest index used. There will be only one
|
|
||||||
* active uniform reported by the GL per uniform array.
|
|
||||||
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
update_array_sizes(struct gl_shader_program *prog)
|
|
||||||
{
|
|
||||||
for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
|
|
||||||
if (prog->_LinkedShaders[i] == NULL)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
bool types_were_updated = false;
|
|
||||||
|
|
||||||
foreach_in_list(ir_instruction, node, prog->_LinkedShaders[i]->ir) {
|
|
||||||
ir_variable *const var = node->as_variable();
|
|
||||||
|
|
||||||
if ((var == NULL) || (var->data.mode != ir_var_uniform) ||
|
|
||||||
!var->type->is_array())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
/* GL_ARB_uniform_buffer_object says that std140 uniforms
|
|
||||||
* will not be eliminated. Since we always do std140, just
|
|
||||||
* don't resize arrays in UBOs.
|
|
||||||
*
|
|
||||||
* Atomic counters are supposed to get deterministic
|
|
||||||
* locations assigned based on the declaration ordering and
|
|
||||||
* sizes, array compaction would mess that up.
|
|
||||||
*
|
|
||||||
* Subroutine uniforms are not removed.
|
|
||||||
*/
|
|
||||||
if (var->is_in_buffer_block() || var->type->contains_atomic() ||
|
|
||||||
var->type->contains_subroutine() || var->constant_initializer)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
int size = var->data.max_array_access;
|
|
||||||
for (unsigned j = 0; j < MESA_SHADER_STAGES; j++) {
|
|
||||||
if (prog->_LinkedShaders[j] == NULL)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
foreach_in_list(ir_instruction, node2, prog->_LinkedShaders[j]->ir) {
|
|
||||||
ir_variable *other_var = node2->as_variable();
|
|
||||||
if (!other_var)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (strcmp(var->name, other_var->name) == 0 &&
|
|
||||||
other_var->data.max_array_access > size) {
|
|
||||||
size = other_var->data.max_array_access;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (size + 1 != (int)var->type->length) {
|
|
||||||
/* If this is a built-in uniform (i.e., it's backed by some
|
|
||||||
* fixed-function state), adjust the number of state slots to
|
|
||||||
* match the new array size. The number of slots per array entry
|
|
||||||
* is not known. It seems safe to assume that the total number of
|
|
||||||
* slots is an integer multiple of the number of array elements.
|
|
||||||
* Determine the number of slots per array element by dividing by
|
|
||||||
* the old (total) size.
|
|
||||||
*/
|
|
||||||
const unsigned num_slots = var->get_num_state_slots();
|
|
||||||
if (num_slots > 0) {
|
|
||||||
var->set_num_state_slots((size + 1)
|
|
||||||
* (num_slots / var->type->length));
|
|
||||||
}
|
|
||||||
|
|
||||||
var->type = glsl_type::get_array_instance(var->type->fields.array,
|
|
||||||
size + 1);
|
|
||||||
types_were_updated = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Update the types of dereferences in case we changed any. */
|
|
||||||
if (types_were_updated) {
|
|
||||||
deref_type_updater v;
|
|
||||||
v.run(prog->_LinkedShaders[i]->ir);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resize tessellation evaluation per-vertex inputs to the size of
|
* Resize tessellation evaluation per-vertex inputs to the size of
|
||||||
* tessellation control per-vertex outputs.
|
* tessellation control per-vertex outputs.
|
||||||
|
|
@ -3421,49 +3330,6 @@ store_fragdepth_layout(struct gl_shader_program *prog)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Validate shader image resources.
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
check_image_resources(const struct gl_constants *consts,
|
|
||||||
const struct gl_extensions *exts,
|
|
||||||
struct gl_shader_program *prog)
|
|
||||||
{
|
|
||||||
unsigned total_image_units = 0;
|
|
||||||
unsigned fragment_outputs = 0;
|
|
||||||
unsigned total_shader_storage_blocks = 0;
|
|
||||||
|
|
||||||
if (!consts->MaxCombinedImageUniforms &&
|
|
||||||
!consts->MaxCombinedShaderStorageBlocks)
|
|
||||||
return;
|
|
||||||
|
|
||||||
for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
|
|
||||||
struct gl_linked_shader *sh = prog->_LinkedShaders[i];
|
|
||||||
|
|
||||||
if (sh) {
|
|
||||||
total_image_units += sh->Program->info.num_images;
|
|
||||||
total_shader_storage_blocks += sh->Program->info.num_ssbos;
|
|
||||||
|
|
||||||
if (i == MESA_SHADER_FRAGMENT) {
|
|
||||||
foreach_in_list(ir_instruction, node, sh->ir) {
|
|
||||||
ir_variable *var = node->as_variable();
|
|
||||||
if (var && var->data.mode == ir_var_shader_out)
|
|
||||||
/* since there are no double fs outputs - pass false */
|
|
||||||
fragment_outputs += var->type->count_attribute_slots(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (total_image_units > consts->MaxCombinedImageUniforms)
|
|
||||||
linker_error(prog, "Too many combined image uniforms\n");
|
|
||||||
|
|
||||||
if (total_image_units + fragment_outputs + total_shader_storage_blocks >
|
|
||||||
consts->MaxCombinedShaderOutputResources)
|
|
||||||
linker_error(prog, "Too many combined image uniforms, shader storage "
|
|
||||||
" buffers and fragment outputs\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes explicit location slots to INACTIVE_UNIFORM_EXPLICIT_LOCATION
|
* Initializes explicit location slots to INACTIVE_UNIFORM_EXPLICIT_LOCATION
|
||||||
|
|
@ -4498,27 +4364,6 @@ disable_varying_optimizations_for_sso(struct gl_shader_program *prog)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
link_and_validate_uniforms(const struct gl_constants *consts,
|
|
||||||
const struct gl_extensions *exts,
|
|
||||||
struct gl_shader_program *prog)
|
|
||||||
{
|
|
||||||
assert(!consts->UseNIRGLSLLinker);
|
|
||||||
|
|
||||||
update_array_sizes(prog);
|
|
||||||
link_assign_uniform_locations(prog, consts);
|
|
||||||
|
|
||||||
if (prog->data->LinkStatus == LINKING_FAILURE)
|
|
||||||
return;
|
|
||||||
|
|
||||||
link_util_calculate_subroutine_compat(prog);
|
|
||||||
link_util_check_uniform_resources(consts, prog);
|
|
||||||
link_util_check_subroutine_resources(prog);
|
|
||||||
check_image_resources(consts, exts, prog);
|
|
||||||
link_assign_atomic_counter_resources(consts, prog);
|
|
||||||
link_check_atomic_counter_resources(consts, prog);
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
link_varyings_and_uniforms(unsigned first, unsigned last,
|
link_varyings_and_uniforms(unsigned first, unsigned last,
|
||||||
const struct gl_constants *consts,
|
const struct gl_constants *consts,
|
||||||
|
|
@ -4566,9 +4411,6 @@ link_varyings_and_uniforms(unsigned first, unsigned last,
|
||||||
api, mem_ctx))
|
api, mem_ctx))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!consts->UseNIRGLSLLinker)
|
|
||||||
link_and_validate_uniforms(consts, exts, prog);
|
|
||||||
|
|
||||||
if (!prog->data->LinkStatus)
|
if (!prog->data->LinkStatus)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,14 +38,6 @@ link_function_calls(gl_shader_program *prog, gl_linked_shader *main,
|
||||||
extern void
|
extern void
|
||||||
link_invalidate_variable_locations(exec_list *ir);
|
link_invalidate_variable_locations(exec_list *ir);
|
||||||
|
|
||||||
extern void
|
|
||||||
link_assign_uniform_locations(struct gl_shader_program *prog,
|
|
||||||
const struct gl_constants *consts);
|
|
||||||
|
|
||||||
extern void
|
|
||||||
link_set_uniform_initializers(struct gl_shader_program *prog,
|
|
||||||
unsigned int boolean_true);
|
|
||||||
|
|
||||||
extern int
|
extern int
|
||||||
link_cross_validate_uniform_block(void *mem_ctx,
|
link_cross_validate_uniform_block(void *mem_ctx,
|
||||||
struct gl_uniform_block **linked_blocks,
|
struct gl_uniform_block **linked_blocks,
|
||||||
|
|
@ -82,15 +74,6 @@ void
|
||||||
validate_interstage_uniform_blocks(struct gl_shader_program *prog,
|
validate_interstage_uniform_blocks(struct gl_shader_program *prog,
|
||||||
gl_linked_shader **stages);
|
gl_linked_shader **stages);
|
||||||
|
|
||||||
extern void
|
|
||||||
link_assign_atomic_counter_resources(const struct gl_constants *consts,
|
|
||||||
struct gl_shader_program *prog);
|
|
||||||
|
|
||||||
extern void
|
|
||||||
link_check_atomic_counter_resources(const struct gl_constants *consts,
|
|
||||||
struct gl_shader_program *prog);
|
|
||||||
|
|
||||||
|
|
||||||
extern struct gl_linked_shader *
|
extern struct gl_linked_shader *
|
||||||
link_intrastage_shaders(void *mem_ctx,
|
link_intrastage_shaders(void *mem_ctx,
|
||||||
struct gl_context *ctx,
|
struct gl_context *ctx,
|
||||||
|
|
|
||||||
|
|
@ -140,11 +140,9 @@ files_libglsl = files(
|
||||||
'linker.h',
|
'linker.h',
|
||||||
'linker_util.h',
|
'linker_util.h',
|
||||||
'linker_util.cpp',
|
'linker_util.cpp',
|
||||||
'link_atomics.cpp',
|
|
||||||
'link_functions.cpp',
|
'link_functions.cpp',
|
||||||
'link_interface_blocks.cpp',
|
'link_interface_blocks.cpp',
|
||||||
'link_uniforms.cpp',
|
'link_uniforms.cpp',
|
||||||
'link_uniform_initializers.cpp',
|
|
||||||
'link_uniform_block_active_visitor.cpp',
|
'link_uniform_block_active_visitor.cpp',
|
||||||
'link_uniform_block_active_visitor.h',
|
'link_uniform_block_active_visitor.h',
|
||||||
'link_uniform_blocks.cpp',
|
'link_uniform_blocks.cpp',
|
||||||
|
|
|
||||||
|
|
@ -1,303 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright © 2012 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.
|
|
||||||
*/
|
|
||||||
#include <gtest/gtest.h>
|
|
||||||
#include "util/compiler.h"
|
|
||||||
#include "main/macros.h"
|
|
||||||
#include "util/ralloc.h"
|
|
||||||
#include "uniform_initializer_utils.h"
|
|
||||||
|
|
||||||
namespace linker {
|
|
||||||
extern void
|
|
||||||
copy_constant_to_storage(union gl_constant_value *storage,
|
|
||||||
const ir_constant *val,
|
|
||||||
const enum glsl_base_type base_type,
|
|
||||||
const unsigned int elements,
|
|
||||||
unsigned int boolean_true);
|
|
||||||
}
|
|
||||||
|
|
||||||
class copy_constant_to_storage : public ::testing::Test {
|
|
||||||
public:
|
|
||||||
void int_test(unsigned rows);
|
|
||||||
void uint_test(unsigned rows);
|
|
||||||
void bool_test(unsigned rows);
|
|
||||||
void sampler_test();
|
|
||||||
void float_test(unsigned columns, unsigned rows);
|
|
||||||
|
|
||||||
virtual void SetUp();
|
|
||||||
virtual void TearDown();
|
|
||||||
|
|
||||||
gl_constant_value storage[17];
|
|
||||||
void *mem_ctx;
|
|
||||||
};
|
|
||||||
|
|
||||||
void
|
|
||||||
copy_constant_to_storage::SetUp()
|
|
||||||
{
|
|
||||||
glsl_type_singleton_init_or_ref();
|
|
||||||
|
|
||||||
this->mem_ctx = ralloc_context(NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
copy_constant_to_storage::TearDown()
|
|
||||||
{
|
|
||||||
ralloc_free(this->mem_ctx);
|
|
||||||
this->mem_ctx = NULL;
|
|
||||||
|
|
||||||
glsl_type_singleton_decref();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
copy_constant_to_storage::int_test(unsigned rows)
|
|
||||||
{
|
|
||||||
ir_constant *val;
|
|
||||||
generate_data(mem_ctx, GLSL_TYPE_INT, 1, rows, val);
|
|
||||||
|
|
||||||
const unsigned red_zone_size = ARRAY_SIZE(storage) - val->type->components();
|
|
||||||
fill_storage_array_with_sentinels(storage,
|
|
||||||
val->type->components(),
|
|
||||||
red_zone_size);
|
|
||||||
|
|
||||||
linker::copy_constant_to_storage(storage,
|
|
||||||
val,
|
|
||||||
val->type->base_type,
|
|
||||||
val->type->components(),
|
|
||||||
0xF00F);
|
|
||||||
|
|
||||||
verify_data(storage, 0, val, red_zone_size, 0xF00F);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
copy_constant_to_storage::uint_test(unsigned rows)
|
|
||||||
{
|
|
||||||
ir_constant *val;
|
|
||||||
generate_data(mem_ctx, GLSL_TYPE_UINT, 1, rows, val);
|
|
||||||
|
|
||||||
const unsigned red_zone_size = ARRAY_SIZE(storage) - val->type->components();
|
|
||||||
fill_storage_array_with_sentinels(storage,
|
|
||||||
val->type->components(),
|
|
||||||
red_zone_size);
|
|
||||||
|
|
||||||
linker::copy_constant_to_storage(storage,
|
|
||||||
val,
|
|
||||||
val->type->base_type,
|
|
||||||
val->type->components(),
|
|
||||||
0xF00F);
|
|
||||||
|
|
||||||
verify_data(storage, 0, val, red_zone_size, 0xF00F);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
copy_constant_to_storage::float_test(unsigned columns, unsigned rows)
|
|
||||||
{
|
|
||||||
ir_constant *val;
|
|
||||||
generate_data(mem_ctx, GLSL_TYPE_FLOAT, columns, rows, val);
|
|
||||||
|
|
||||||
const unsigned red_zone_size = ARRAY_SIZE(storage) - val->type->components();
|
|
||||||
fill_storage_array_with_sentinels(storage,
|
|
||||||
val->type->components(),
|
|
||||||
red_zone_size);
|
|
||||||
|
|
||||||
linker::copy_constant_to_storage(storage,
|
|
||||||
val,
|
|
||||||
val->type->base_type,
|
|
||||||
val->type->components(),
|
|
||||||
0xF00F);
|
|
||||||
|
|
||||||
verify_data(storage, 0, val, red_zone_size, 0xF00F);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
copy_constant_to_storage::bool_test(unsigned rows)
|
|
||||||
{
|
|
||||||
ir_constant *val;
|
|
||||||
generate_data(mem_ctx, GLSL_TYPE_BOOL, 1, rows, val);
|
|
||||||
|
|
||||||
const unsigned red_zone_size = ARRAY_SIZE(storage) - val->type->components();
|
|
||||||
fill_storage_array_with_sentinels(storage,
|
|
||||||
val->type->components(),
|
|
||||||
red_zone_size);
|
|
||||||
|
|
||||||
linker::copy_constant_to_storage(storage,
|
|
||||||
val,
|
|
||||||
val->type->base_type,
|
|
||||||
val->type->components(),
|
|
||||||
0xF00F);
|
|
||||||
|
|
||||||
verify_data(storage, 0, val, red_zone_size, 0xF00F);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The only difference between this test and int_test is that the base type
|
|
||||||
* passed to \c linker::copy_constant_to_storage is hard-coded to \c
|
|
||||||
* GLSL_TYPE_SAMPLER instead of using the base type from the constant.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
copy_constant_to_storage::sampler_test(void)
|
|
||||||
{
|
|
||||||
ir_constant *val;
|
|
||||||
generate_data(mem_ctx, GLSL_TYPE_INT, 1, 1, val);
|
|
||||||
|
|
||||||
const unsigned red_zone_size = ARRAY_SIZE(storage) - val->type->components();
|
|
||||||
fill_storage_array_with_sentinels(storage,
|
|
||||||
val->type->components(),
|
|
||||||
red_zone_size);
|
|
||||||
|
|
||||||
linker::copy_constant_to_storage(storage,
|
|
||||||
val,
|
|
||||||
GLSL_TYPE_SAMPLER,
|
|
||||||
val->type->components(),
|
|
||||||
0xF00F);
|
|
||||||
|
|
||||||
verify_data(storage, 0, val, red_zone_size, 0xF00F);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(copy_constant_to_storage, bool_uniform)
|
|
||||||
{
|
|
||||||
bool_test(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(copy_constant_to_storage, bvec2_uniform)
|
|
||||||
{
|
|
||||||
bool_test(2);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(copy_constant_to_storage, bvec3_uniform)
|
|
||||||
{
|
|
||||||
bool_test(3);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(copy_constant_to_storage, bvec4_uniform)
|
|
||||||
{
|
|
||||||
bool_test(4);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(copy_constant_to_storage, int_uniform)
|
|
||||||
{
|
|
||||||
int_test(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(copy_constant_to_storage, ivec2_uniform)
|
|
||||||
{
|
|
||||||
int_test(2);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(copy_constant_to_storage, ivec3_uniform)
|
|
||||||
{
|
|
||||||
int_test(3);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(copy_constant_to_storage, ivec4_uniform)
|
|
||||||
{
|
|
||||||
int_test(4);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(copy_constant_to_storage, uint_uniform)
|
|
||||||
{
|
|
||||||
uint_test(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(copy_constant_to_storage, uvec2_uniform)
|
|
||||||
{
|
|
||||||
uint_test(2);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(copy_constant_to_storage, uvec3_uniform)
|
|
||||||
{
|
|
||||||
uint_test(3);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(copy_constant_to_storage, uvec4_uniform)
|
|
||||||
{
|
|
||||||
uint_test(4);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(copy_constant_to_storage, float_uniform)
|
|
||||||
{
|
|
||||||
float_test(1, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(copy_constant_to_storage, vec2_uniform)
|
|
||||||
{
|
|
||||||
float_test(1, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(copy_constant_to_storage, vec3_uniform)
|
|
||||||
{
|
|
||||||
float_test(1, 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(copy_constant_to_storage, vec4_uniform)
|
|
||||||
{
|
|
||||||
float_test(1, 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(copy_constant_to_storage, mat2x2_uniform)
|
|
||||||
{
|
|
||||||
float_test(2, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(copy_constant_to_storage, mat2x3_uniform)
|
|
||||||
{
|
|
||||||
float_test(2, 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(copy_constant_to_storage, mat2x4_uniform)
|
|
||||||
{
|
|
||||||
float_test(2, 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(copy_constant_to_storage, mat3x2_uniform)
|
|
||||||
{
|
|
||||||
float_test(3, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(copy_constant_to_storage, mat3x3_uniform)
|
|
||||||
{
|
|
||||||
float_test(3, 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(copy_constant_to_storage, mat3x4_uniform)
|
|
||||||
{
|
|
||||||
float_test(3, 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(copy_constant_to_storage, mat4x2_uniform)
|
|
||||||
{
|
|
||||||
float_test(4, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(copy_constant_to_storage, mat4x3_uniform)
|
|
||||||
{
|
|
||||||
float_test(4, 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(copy_constant_to_storage, mat4x4_uniform)
|
|
||||||
{
|
|
||||||
float_test(4, 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(copy_constant_to_storage, sampler_uniform)
|
|
||||||
{
|
|
||||||
sampler_test();
|
|
||||||
}
|
|
||||||
|
|
@ -36,23 +36,6 @@ test(
|
||||||
protocol : gtest_test_protocol,
|
protocol : gtest_test_protocol,
|
||||||
)
|
)
|
||||||
|
|
||||||
test(
|
|
||||||
'uniform_initializer_test',
|
|
||||||
executable(
|
|
||||||
'uniform_initializer_test',
|
|
||||||
['copy_constant_to_storage_tests.cpp', 'set_uniform_initializer_tests.cpp',
|
|
||||||
'uniform_initializer_utils.cpp', 'uniform_initializer_utils.h',
|
|
||||||
ir_expression_operation_h],
|
|
||||||
cpp_args : [cpp_msvc_compat_args],
|
|
||||||
gnu_symbol_visibility : 'hidden',
|
|
||||||
include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux, inc_glsl],
|
|
||||||
link_with : [libglsl, libglsl_util],
|
|
||||||
dependencies : [dep_thread, idep_gtest, idep_mesautil],
|
|
||||||
),
|
|
||||||
suite : ['compiler', 'glsl'],
|
|
||||||
protocol : gtest_test_protocol,
|
|
||||||
)
|
|
||||||
|
|
||||||
test(
|
test(
|
||||||
'sampler_types_test',
|
'sampler_types_test',
|
||||||
executable(
|
executable(
|
||||||
|
|
|
||||||
|
|
@ -1,588 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright © 2012 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.
|
|
||||||
*/
|
|
||||||
#include <gtest/gtest.h>
|
|
||||||
#include "util/compiler.h"
|
|
||||||
#include "main/shader_types.h"
|
|
||||||
#include "main/macros.h"
|
|
||||||
#include "util/ralloc.h"
|
|
||||||
#include "string_to_uint_map.h"
|
|
||||||
#include "uniform_initializer_utils.h"
|
|
||||||
|
|
||||||
namespace linker {
|
|
||||||
extern void
|
|
||||||
set_uniform_initializer(void *mem_ctx, gl_shader_program *prog,
|
|
||||||
const char *name, const glsl_type *type,
|
|
||||||
ir_constant *val, unsigned int boolean_true);
|
|
||||||
}
|
|
||||||
|
|
||||||
class set_uniform_initializer : public ::testing::Test {
|
|
||||||
public:
|
|
||||||
virtual void SetUp();
|
|
||||||
virtual void TearDown();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Index of the uniform to be tested.
|
|
||||||
*
|
|
||||||
* All of the \c set_uniform_initializer tests create several slots for
|
|
||||||
* unifroms. All but one of the slots is fake. This field holds the index
|
|
||||||
* of the slot for the uniform being tested.
|
|
||||||
*/
|
|
||||||
unsigned actual_index;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Name of the uniform to be tested.
|
|
||||||
*/
|
|
||||||
const char *name;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Shader program used in the test.
|
|
||||||
*/
|
|
||||||
struct gl_shader_program *prog;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Ralloc memory context used for all temporary allocations.
|
|
||||||
*/
|
|
||||||
void *mem_ctx;
|
|
||||||
};
|
|
||||||
|
|
||||||
void
|
|
||||||
set_uniform_initializer::SetUp()
|
|
||||||
{
|
|
||||||
glsl_type_singleton_init_or_ref();
|
|
||||||
|
|
||||||
this->mem_ctx = ralloc_context(NULL);
|
|
||||||
this->prog = rzalloc(NULL, struct gl_shader_program);
|
|
||||||
this->prog->data = rzalloc(this->prog, struct gl_shader_program_data);
|
|
||||||
|
|
||||||
/* Set default values used by the test cases.
|
|
||||||
*/
|
|
||||||
this->actual_index = 1;
|
|
||||||
this->name = "i";
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
set_uniform_initializer::TearDown()
|
|
||||||
{
|
|
||||||
ralloc_free(this->mem_ctx);
|
|
||||||
this->mem_ctx = NULL;
|
|
||||||
|
|
||||||
if (this->prog->UniformHash)
|
|
||||||
string_to_uint_map_dtor(this->prog->UniformHash);
|
|
||||||
|
|
||||||
ralloc_free(this->prog);
|
|
||||||
this->prog = NULL;
|
|
||||||
|
|
||||||
glsl_type_singleton_decref();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create some uniform storage for a program.
|
|
||||||
*
|
|
||||||
* \param prog Program to get some storage
|
|
||||||
* \param num_storage Total number of storage slots
|
|
||||||
* \param index_to_set Storage slot that will actually get a value
|
|
||||||
* \param name Name for the actual storage slot
|
|
||||||
* \param type Type for the elements of the actual storage slot
|
|
||||||
* \param array_size Size for the array of the actual storage slot. This
|
|
||||||
* should be zero for non-arrays.
|
|
||||||
*/
|
|
||||||
static unsigned
|
|
||||||
establish_uniform_storage(struct gl_shader_program *prog, unsigned num_storage,
|
|
||||||
unsigned index_to_set, const char *name,
|
|
||||||
const glsl_type *type, unsigned array_size)
|
|
||||||
{
|
|
||||||
const unsigned elements = MAX2(1, array_size);
|
|
||||||
const unsigned data_components = elements * type->components();
|
|
||||||
const unsigned total_components = MAX2(17, (data_components
|
|
||||||
+ type->components()));
|
|
||||||
const unsigned red_zone_components = total_components - data_components;
|
|
||||||
|
|
||||||
prog->UniformHash = new string_to_uint_map;
|
|
||||||
prog->data->UniformStorage = rzalloc_array(prog, struct gl_uniform_storage,
|
|
||||||
num_storage);
|
|
||||||
prog->data->NumUniformStorage = num_storage;
|
|
||||||
|
|
||||||
prog->data->UniformStorage[index_to_set].name.string = (char *) name;
|
|
||||||
prog->data->UniformStorage[index_to_set].type = type;
|
|
||||||
prog->data->UniformStorage[index_to_set].array_elements = array_size;
|
|
||||||
for (int sh = 0; sh < MESA_SHADER_STAGES; sh++) {
|
|
||||||
prog->data->UniformStorage[index_to_set].opaque[sh].index = ~0;
|
|
||||||
prog->data->UniformStorage[index_to_set].opaque[sh].active = false;
|
|
||||||
}
|
|
||||||
prog->data->UniformStorage[index_to_set].num_driver_storage = 0;
|
|
||||||
prog->data->UniformStorage[index_to_set].driver_storage = NULL;
|
|
||||||
prog->data->UniformStorage[index_to_set].storage =
|
|
||||||
rzalloc_array(prog, union gl_constant_value, total_components);
|
|
||||||
|
|
||||||
fill_storage_array_with_sentinels(prog->data->UniformStorage[index_to_set].storage,
|
|
||||||
data_components,
|
|
||||||
red_zone_components);
|
|
||||||
|
|
||||||
prog->UniformHash->put(index_to_set,
|
|
||||||
prog->data->UniformStorage[index_to_set].name.string);
|
|
||||||
|
|
||||||
for (unsigned i = 0; i < num_storage; i++) {
|
|
||||||
if (i == index_to_set)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
prog->data->UniformStorage[i].name.string = (char *) "invalid slot";
|
|
||||||
prog->data->UniformStorage[i].type = glsl_type::void_type;
|
|
||||||
prog->data->UniformStorage[i].array_elements = 0;
|
|
||||||
for (int sh = 0; sh < MESA_SHADER_STAGES; sh++) {
|
|
||||||
prog->data->UniformStorage[i].opaque[sh].index = ~0;
|
|
||||||
prog->data->UniformStorage[i].opaque[sh].active = false;
|
|
||||||
}
|
|
||||||
prog->data->UniformStorage[i].num_driver_storage = 0;
|
|
||||||
prog->data->UniformStorage[i].driver_storage = NULL;
|
|
||||||
prog->data->UniformStorage[i].storage = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return red_zone_components;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
non_array_test(void *mem_ctx, struct gl_shader_program *prog,
|
|
||||||
unsigned actual_index, const char *name,
|
|
||||||
enum glsl_base_type base_type,
|
|
||||||
unsigned columns, unsigned rows)
|
|
||||||
{
|
|
||||||
const glsl_type *const type =
|
|
||||||
glsl_type::get_instance(base_type, rows, columns);
|
|
||||||
|
|
||||||
unsigned red_zone_components =
|
|
||||||
establish_uniform_storage(prog, 3, actual_index, name, type, 0);
|
|
||||||
|
|
||||||
ir_constant *val;
|
|
||||||
generate_data(mem_ctx, base_type, columns, rows, val);
|
|
||||||
|
|
||||||
linker::set_uniform_initializer(mem_ctx, prog, name, type, val, 0xF00F);
|
|
||||||
|
|
||||||
verify_data(prog->data->UniformStorage[actual_index].storage, 0, val,
|
|
||||||
red_zone_components, 0xF00F);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, int_uniform)
|
|
||||||
{
|
|
||||||
non_array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_INT, 1, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, ivec2_uniform)
|
|
||||||
{
|
|
||||||
non_array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_INT, 1, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, ivec3_uniform)
|
|
||||||
{
|
|
||||||
non_array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_INT, 1, 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, ivec4_uniform)
|
|
||||||
{
|
|
||||||
non_array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_INT, 1, 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, uint_uniform)
|
|
||||||
{
|
|
||||||
non_array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_UINT, 1, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, uvec2_uniform)
|
|
||||||
{
|
|
||||||
non_array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_UINT, 1, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, uvec3_uniform)
|
|
||||||
{
|
|
||||||
non_array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_UINT, 1, 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, uvec4_uniform)
|
|
||||||
{
|
|
||||||
non_array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_UINT, 1, 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, bool_uniform)
|
|
||||||
{
|
|
||||||
non_array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_BOOL, 1, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, bvec2_uniform)
|
|
||||||
{
|
|
||||||
non_array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_BOOL, 1, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, bvec3_uniform)
|
|
||||||
{
|
|
||||||
non_array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_BOOL, 1, 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, bvec4_uniform)
|
|
||||||
{
|
|
||||||
non_array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_BOOL, 1, 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, float_uniform)
|
|
||||||
{
|
|
||||||
non_array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_FLOAT, 1, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, vec2_uniform)
|
|
||||||
{
|
|
||||||
non_array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_FLOAT, 1, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, vec3_uniform)
|
|
||||||
{
|
|
||||||
non_array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_FLOAT, 1, 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, vec4_uniform)
|
|
||||||
{
|
|
||||||
non_array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_FLOAT, 1, 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, mat2x2_uniform)
|
|
||||||
{
|
|
||||||
non_array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_FLOAT, 2, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, mat2x3_uniform)
|
|
||||||
{
|
|
||||||
non_array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_FLOAT, 2, 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, mat2x4_uniform)
|
|
||||||
{
|
|
||||||
non_array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_FLOAT, 2, 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, mat3x2_uniform)
|
|
||||||
{
|
|
||||||
non_array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_FLOAT, 3, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, mat3x3_uniform)
|
|
||||||
{
|
|
||||||
non_array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_FLOAT, 3, 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, mat3x4_uniform)
|
|
||||||
{
|
|
||||||
non_array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_FLOAT, 3, 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, mat4x2_uniform)
|
|
||||||
{
|
|
||||||
non_array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_FLOAT, 4, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, mat4x3_uniform)
|
|
||||||
{
|
|
||||||
non_array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_FLOAT, 4, 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, mat4x4_uniform)
|
|
||||||
{
|
|
||||||
non_array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_FLOAT, 4, 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
array_test(void *mem_ctx, struct gl_shader_program *prog,
|
|
||||||
unsigned actual_index, const char *name,
|
|
||||||
enum glsl_base_type base_type,
|
|
||||||
unsigned columns, unsigned rows, unsigned array_size,
|
|
||||||
unsigned excess_data_size)
|
|
||||||
{
|
|
||||||
const glsl_type *const element_type =
|
|
||||||
glsl_type::get_instance(base_type, rows, columns);
|
|
||||||
|
|
||||||
const unsigned red_zone_components =
|
|
||||||
establish_uniform_storage(prog, 3, actual_index, name, element_type,
|
|
||||||
array_size);
|
|
||||||
|
|
||||||
/* The constant value generated may have more array elements than the
|
|
||||||
* uniform that it initializes. In the real compiler and linker this can
|
|
||||||
* happen when a uniform array is compacted because some of the tail
|
|
||||||
* elements are not used. In this case, the type of the uniform will be
|
|
||||||
* modified, but the initializer will not.
|
|
||||||
*/
|
|
||||||
ir_constant *val;
|
|
||||||
generate_array_data(mem_ctx, base_type, columns, rows,
|
|
||||||
array_size + excess_data_size, val);
|
|
||||||
|
|
||||||
linker::set_uniform_initializer(mem_ctx, prog, name, element_type, val,
|
|
||||||
0xF00F);
|
|
||||||
|
|
||||||
verify_data(prog->data->UniformStorage[actual_index].storage, array_size,
|
|
||||||
val, red_zone_components, 0xF00F);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, int_array_uniform)
|
|
||||||
{
|
|
||||||
array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_INT, 1, 1, 4, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, ivec2_array_uniform)
|
|
||||||
{
|
|
||||||
array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_INT, 1, 2, 4, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, ivec3_array_uniform)
|
|
||||||
{
|
|
||||||
array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_INT, 1, 3, 4, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, ivec4_array_uniform)
|
|
||||||
{
|
|
||||||
array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_INT, 1, 4, 4, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, uint_array_uniform)
|
|
||||||
{
|
|
||||||
array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_UINT, 1, 1, 4, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, uvec2_array_uniform)
|
|
||||||
{
|
|
||||||
array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_UINT, 1, 2, 4, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, uvec3_array_uniform)
|
|
||||||
{
|
|
||||||
array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_UINT, 1, 3, 4, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, uvec4_array_uniform)
|
|
||||||
{
|
|
||||||
array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_UINT, 1, 4, 4, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, bool_array_uniform)
|
|
||||||
{
|
|
||||||
array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_BOOL, 1, 1, 4, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, bvec2_array_uniform)
|
|
||||||
{
|
|
||||||
array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_BOOL, 1, 2, 4, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, bvec3_array_uniform)
|
|
||||||
{
|
|
||||||
array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_BOOL, 1, 3, 4, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, bvec4_array_uniform)
|
|
||||||
{
|
|
||||||
array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_BOOL, 1, 4, 4, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, float_array_uniform)
|
|
||||||
{
|
|
||||||
array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_FLOAT, 1, 1, 4, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, vec2_array_uniform)
|
|
||||||
{
|
|
||||||
array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_FLOAT, 1, 2, 4, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, vec3_array_uniform)
|
|
||||||
{
|
|
||||||
array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_FLOAT, 1, 3, 4, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, vec4_array_uniform)
|
|
||||||
{
|
|
||||||
array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_FLOAT, 1, 4, 4, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, mat2x2_array_uniform)
|
|
||||||
{
|
|
||||||
array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_FLOAT, 2, 2, 4, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, mat2x3_array_uniform)
|
|
||||||
{
|
|
||||||
array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_FLOAT, 2, 3, 4, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, mat2x4_array_uniform)
|
|
||||||
{
|
|
||||||
array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_FLOAT, 2, 4, 4, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, mat3x2_array_uniform)
|
|
||||||
{
|
|
||||||
array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_FLOAT, 3, 2, 4, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, mat3x3_array_uniform)
|
|
||||||
{
|
|
||||||
array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_FLOAT, 3, 3, 4, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, mat3x4_array_uniform)
|
|
||||||
{
|
|
||||||
array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_FLOAT, 3, 4, 4, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, mat4x2_array_uniform)
|
|
||||||
{
|
|
||||||
array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_FLOAT, 4, 2, 4, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, mat4x3_array_uniform)
|
|
||||||
{
|
|
||||||
array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_FLOAT, 4, 3, 4, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, mat4x4_array_uniform)
|
|
||||||
{
|
|
||||||
array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_FLOAT, 4, 4, 4, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, int_array_uniform_excess_initializer)
|
|
||||||
{
|
|
||||||
array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_INT, 1, 1, 4, 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, ivec2_array_uniform_excess_initializer)
|
|
||||||
{
|
|
||||||
array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_INT, 1, 2, 4, 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, ivec3_array_uniform_excess_initializer)
|
|
||||||
{
|
|
||||||
array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_INT, 1, 3, 4, 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, ivec4_array_uniform_excess_initializer)
|
|
||||||
{
|
|
||||||
array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_INT, 1, 4, 4, 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, uint_array_uniform_excess_initializer)
|
|
||||||
{
|
|
||||||
array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_UINT, 1, 1, 4, 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, uvec2_array_uniform_excess_initializer)
|
|
||||||
{
|
|
||||||
array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_UINT, 1, 2, 4, 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, uvec3_array_uniform_excess_initializer)
|
|
||||||
{
|
|
||||||
array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_UINT, 1, 3, 4, 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, uvec4_array_uniform_excess_initializer)
|
|
||||||
{
|
|
||||||
array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_UINT, 1, 4, 4, 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, bool_array_uniform_excess_initializer)
|
|
||||||
{
|
|
||||||
array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_BOOL, 1, 1, 4, 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, bvec2_array_uniform_excess_initializer)
|
|
||||||
{
|
|
||||||
array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_BOOL, 1, 2, 4, 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, bvec3_array_uniform_excess_initializer)
|
|
||||||
{
|
|
||||||
array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_BOOL, 1, 3, 4, 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, bvec4_array_uniform_excess_initializer)
|
|
||||||
{
|
|
||||||
array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_BOOL, 1, 4, 4, 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, float_array_uniform_excess_initializer)
|
|
||||||
{
|
|
||||||
array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_FLOAT, 1, 1, 4, 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, vec2_array_uniform_excess_initializer)
|
|
||||||
{
|
|
||||||
array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_FLOAT, 1, 2, 4, 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, vec3_array_uniform_excess_initializer)
|
|
||||||
{
|
|
||||||
array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_FLOAT, 1, 3, 4, 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, vec4_array_uniform_excess_initializer)
|
|
||||||
{
|
|
||||||
array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_FLOAT, 1, 4, 4, 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, mat2x2_array_uniform_excess_initializer)
|
|
||||||
{
|
|
||||||
array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_FLOAT, 2, 2, 4, 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, mat2x3_array_uniform_excess_initializer)
|
|
||||||
{
|
|
||||||
array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_FLOAT, 2, 3, 4, 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, mat2x4_array_uniform_excess_initializer)
|
|
||||||
{
|
|
||||||
array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_FLOAT, 2, 4, 4, 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, mat3x2_array_uniform_excess_initializer)
|
|
||||||
{
|
|
||||||
array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_FLOAT, 3, 2, 4, 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, mat3x3_array_uniform_excess_initializer)
|
|
||||||
{
|
|
||||||
array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_FLOAT, 3, 3, 4, 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, mat3x4_array_uniform_excess_initializer)
|
|
||||||
{
|
|
||||||
array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_FLOAT, 3, 4, 4, 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, mat4x2_array_uniform_excess_initializer)
|
|
||||||
{
|
|
||||||
array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_FLOAT, 4, 2, 4, 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, mat4x3_array_uniform_excess_initializer)
|
|
||||||
{
|
|
||||||
array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_FLOAT, 4, 3, 4, 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(set_uniform_initializer, mat4x4_array_uniform_excess_initializer)
|
|
||||||
{
|
|
||||||
array_test(mem_ctx, prog, actual_index, name, GLSL_TYPE_FLOAT, 4, 4, 4, 5);
|
|
||||||
}
|
|
||||||
|
|
@ -1,309 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright © 2012 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.
|
|
||||||
*/
|
|
||||||
#include <gtest/gtest.h>
|
|
||||||
#include "main/macros.h"
|
|
||||||
#include "util/ralloc.h"
|
|
||||||
#include "uniform_initializer_utils.h"
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
void
|
|
||||||
fill_storage_array_with_sentinels(gl_constant_value *storage,
|
|
||||||
unsigned data_size,
|
|
||||||
unsigned red_zone_size)
|
|
||||||
{
|
|
||||||
for (unsigned i = 0; i < data_size; i++)
|
|
||||||
storage[i].u = 0xDEADBEEF;
|
|
||||||
|
|
||||||
for (unsigned i = 0; i < red_zone_size; i++)
|
|
||||||
storage[data_size + i].u = 0xBADDC0DE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Verfiy that markers past the end of the real uniform are unmodified
|
|
||||||
*/
|
|
||||||
static ::testing::AssertionResult
|
|
||||||
red_zone_is_intact(gl_constant_value *storage,
|
|
||||||
unsigned data_size,
|
|
||||||
unsigned red_zone_size)
|
|
||||||
{
|
|
||||||
for (unsigned i = 0; i < red_zone_size; i++) {
|
|
||||||
const unsigned idx = data_size + i;
|
|
||||||
|
|
||||||
if (storage[idx].u != 0xBADDC0DE)
|
|
||||||
return ::testing::AssertionFailure()
|
|
||||||
<< "storage[" << idx << "].u = " << storage[idx].u
|
|
||||||
<< ", exepected data values = " << data_size
|
|
||||||
<< ", red-zone size = " << red_zone_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ::testing::AssertionSuccess();
|
|
||||||
}
|
|
||||||
|
|
||||||
static const int values[] = {
|
|
||||||
2, 0, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate a single data element.
|
|
||||||
*
|
|
||||||
* This is by both \c generate_data and \c generate_array_data to create the
|
|
||||||
* data.
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
generate_data_element(void *mem_ctx, const glsl_type *type,
|
|
||||||
ir_constant *&val, unsigned data_index_base)
|
|
||||||
{
|
|
||||||
/* Set the initial data values for the generated constant.
|
|
||||||
*/
|
|
||||||
ir_constant_data data;
|
|
||||||
memset(&data, 0, sizeof(data));
|
|
||||||
for (unsigned i = 0; i < type->components(); i++) {
|
|
||||||
const unsigned idx = (i + data_index_base) % ARRAY_SIZE(values);
|
|
||||||
switch (type->base_type) {
|
|
||||||
case GLSL_TYPE_UINT:
|
|
||||||
case GLSL_TYPE_INT:
|
|
||||||
case GLSL_TYPE_SAMPLER:
|
|
||||||
case GLSL_TYPE_TEXTURE:
|
|
||||||
case GLSL_TYPE_IMAGE:
|
|
||||||
data.i[i] = values[idx];
|
|
||||||
break;
|
|
||||||
case GLSL_TYPE_FLOAT:
|
|
||||||
data.f[i] = float(values[idx]);
|
|
||||||
break;
|
|
||||||
case GLSL_TYPE_BOOL:
|
|
||||||
data.b[i] = bool(values[idx]);
|
|
||||||
break;
|
|
||||||
case GLSL_TYPE_DOUBLE:
|
|
||||||
data.d[i] = double(values[idx]);
|
|
||||||
break;
|
|
||||||
case GLSL_TYPE_UINT64:
|
|
||||||
data.u64[i] = (uint64_t) values[idx];
|
|
||||||
break;
|
|
||||||
case GLSL_TYPE_INT64:
|
|
||||||
data.i64[i] = (int64_t) values[idx];
|
|
||||||
break;
|
|
||||||
case GLSL_TYPE_ATOMIC_UINT:
|
|
||||||
case GLSL_TYPE_STRUCT:
|
|
||||||
case GLSL_TYPE_ARRAY:
|
|
||||||
case GLSL_TYPE_VOID:
|
|
||||||
case GLSL_TYPE_ERROR:
|
|
||||||
case GLSL_TYPE_INTERFACE:
|
|
||||||
case GLSL_TYPE_SUBROUTINE:
|
|
||||||
case GLSL_TYPE_FUNCTION:
|
|
||||||
case GLSL_TYPE_FLOAT16:
|
|
||||||
case GLSL_TYPE_UINT16:
|
|
||||||
case GLSL_TYPE_INT16:
|
|
||||||
case GLSL_TYPE_UINT8:
|
|
||||||
case GLSL_TYPE_INT8:
|
|
||||||
ASSERT_TRUE(false);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Generate and verify the constant.
|
|
||||||
*/
|
|
||||||
val = new(mem_ctx) ir_constant(type, &data);
|
|
||||||
|
|
||||||
for (unsigned i = 0; i < type->components(); i++) {
|
|
||||||
switch (type->base_type) {
|
|
||||||
case GLSL_TYPE_UINT:
|
|
||||||
case GLSL_TYPE_INT:
|
|
||||||
case GLSL_TYPE_SAMPLER:
|
|
||||||
case GLSL_TYPE_TEXTURE:
|
|
||||||
case GLSL_TYPE_IMAGE:
|
|
||||||
ASSERT_EQ(data.i[i], val->value.i[i]);
|
|
||||||
break;
|
|
||||||
case GLSL_TYPE_FLOAT:
|
|
||||||
ASSERT_EQ(data.f[i], val->value.f[i]);
|
|
||||||
break;
|
|
||||||
case GLSL_TYPE_BOOL:
|
|
||||||
ASSERT_EQ(data.b[i], val->value.b[i]);
|
|
||||||
break;
|
|
||||||
case GLSL_TYPE_DOUBLE:
|
|
||||||
ASSERT_EQ(data.d[i], val->value.d[i]);
|
|
||||||
break;
|
|
||||||
case GLSL_TYPE_UINT64:
|
|
||||||
ASSERT_EQ(data.u64[i], val->value.u64[i]);
|
|
||||||
break;
|
|
||||||
case GLSL_TYPE_INT64:
|
|
||||||
ASSERT_EQ(data.i64[i], val->value.i64[i]);
|
|
||||||
break;
|
|
||||||
case GLSL_TYPE_ATOMIC_UINT:
|
|
||||||
case GLSL_TYPE_STRUCT:
|
|
||||||
case GLSL_TYPE_ARRAY:
|
|
||||||
case GLSL_TYPE_VOID:
|
|
||||||
case GLSL_TYPE_ERROR:
|
|
||||||
case GLSL_TYPE_INTERFACE:
|
|
||||||
case GLSL_TYPE_SUBROUTINE:
|
|
||||||
case GLSL_TYPE_FUNCTION:
|
|
||||||
case GLSL_TYPE_FLOAT16:
|
|
||||||
case GLSL_TYPE_UINT16:
|
|
||||||
case GLSL_TYPE_INT16:
|
|
||||||
case GLSL_TYPE_UINT8:
|
|
||||||
case GLSL_TYPE_INT8:
|
|
||||||
ASSERT_TRUE(false);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
generate_data(void *mem_ctx, enum glsl_base_type base_type,
|
|
||||||
unsigned columns, unsigned rows,
|
|
||||||
ir_constant *&val)
|
|
||||||
{
|
|
||||||
/* Determine what the type of the generated constant should be.
|
|
||||||
*/
|
|
||||||
const glsl_type *const type =
|
|
||||||
glsl_type::get_instance(base_type, rows, columns);
|
|
||||||
ASSERT_FALSE(type->is_error());
|
|
||||||
|
|
||||||
generate_data_element(mem_ctx, type, val, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
generate_array_data(void *mem_ctx, enum glsl_base_type base_type,
|
|
||||||
unsigned columns, unsigned rows, unsigned array_size,
|
|
||||||
ir_constant *&val)
|
|
||||||
{
|
|
||||||
/* Determine what the type of the generated constant should be.
|
|
||||||
*/
|
|
||||||
const glsl_type *const element_type =
|
|
||||||
glsl_type::get_instance(base_type, rows, columns);
|
|
||||||
ASSERT_FALSE(element_type->is_error());
|
|
||||||
|
|
||||||
const glsl_type *const array_type =
|
|
||||||
glsl_type::get_array_instance(element_type, array_size);
|
|
||||||
ASSERT_FALSE(array_type->is_error());
|
|
||||||
|
|
||||||
/* Set the initial data values for the generated constant.
|
|
||||||
*/
|
|
||||||
exec_list values_for_array;
|
|
||||||
for (unsigned i = 0; i < array_size; i++) {
|
|
||||||
ir_constant *element;
|
|
||||||
|
|
||||||
generate_data_element(mem_ctx, element_type, element, i);
|
|
||||||
values_for_array.push_tail(element);
|
|
||||||
}
|
|
||||||
|
|
||||||
val = new(mem_ctx) ir_constant(array_type, &values_for_array);
|
|
||||||
}
|
|
||||||
|
|
||||||
static uint64_t
|
|
||||||
uint64_storage(union gl_constant_value *storage)
|
|
||||||
{
|
|
||||||
uint64_t val;
|
|
||||||
memcpy(&val, &storage->i, sizeof(uint64_t));
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
|
|
||||||
static uint64_t
|
|
||||||
double_storage(union gl_constant_value *storage)
|
|
||||||
{
|
|
||||||
double val;
|
|
||||||
memcpy(&val, &storage->i, sizeof(double));
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Verify that the data stored for the uniform matches the initializer
|
|
||||||
*
|
|
||||||
* \param storage Backing storage for the uniform
|
|
||||||
* \param storage_array_size Array size of the backing storage. This must be
|
|
||||||
* less than or equal to the array size of the type
|
|
||||||
* of \c val. If \c val is not an array, this must
|
|
||||||
* be zero.
|
|
||||||
* \param val Value of the initializer for the unifrom.
|
|
||||||
* \param red_zone
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
verify_data(gl_constant_value *storage, unsigned storage_array_size,
|
|
||||||
ir_constant *val, unsigned red_zone_size,
|
|
||||||
unsigned int boolean_true)
|
|
||||||
{
|
|
||||||
if (val->type->is_array()) {
|
|
||||||
const glsl_type *const element_type = val->const_elements[0]->type;
|
|
||||||
|
|
||||||
for (unsigned i = 0; i < storage_array_size; i++) {
|
|
||||||
verify_data(storage + (i * element_type->components()), 0,
|
|
||||||
val->const_elements[i], 0, boolean_true);
|
|
||||||
}
|
|
||||||
|
|
||||||
const unsigned components = element_type->components();
|
|
||||||
|
|
||||||
if (red_zone_size > 0) {
|
|
||||||
EXPECT_TRUE(red_zone_is_intact(storage,
|
|
||||||
storage_array_size * components,
|
|
||||||
red_zone_size));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ASSERT_EQ(0u, storage_array_size);
|
|
||||||
for (unsigned i = 0; i < val->type->components(); i++) {
|
|
||||||
switch (val->type->base_type) {
|
|
||||||
case GLSL_TYPE_UINT:
|
|
||||||
case GLSL_TYPE_INT:
|
|
||||||
case GLSL_TYPE_SAMPLER:
|
|
||||||
case GLSL_TYPE_TEXTURE:
|
|
||||||
case GLSL_TYPE_IMAGE:
|
|
||||||
EXPECT_EQ(val->value.i[i], storage[i].i);
|
|
||||||
break;
|
|
||||||
case GLSL_TYPE_FLOAT:
|
|
||||||
EXPECT_EQ(val->value.f[i], storage[i].f);
|
|
||||||
break;
|
|
||||||
case GLSL_TYPE_BOOL:
|
|
||||||
EXPECT_EQ(val->value.b[i] ? boolean_true : 0, storage[i].i);
|
|
||||||
break;
|
|
||||||
case GLSL_TYPE_DOUBLE:
|
|
||||||
EXPECT_EQ(val->value.d[i], double_storage(&storage[i*2]));
|
|
||||||
break;
|
|
||||||
case GLSL_TYPE_UINT64:
|
|
||||||
EXPECT_EQ(val->value.u64[i], uint64_storage(&storage[i*2]));
|
|
||||||
break;
|
|
||||||
case GLSL_TYPE_INT64:
|
|
||||||
EXPECT_EQ(val->value.i64[i], uint64_storage(&storage[i*2]));
|
|
||||||
break;
|
|
||||||
case GLSL_TYPE_ATOMIC_UINT:
|
|
||||||
case GLSL_TYPE_STRUCT:
|
|
||||||
case GLSL_TYPE_ARRAY:
|
|
||||||
case GLSL_TYPE_VOID:
|
|
||||||
case GLSL_TYPE_ERROR:
|
|
||||||
case GLSL_TYPE_INTERFACE:
|
|
||||||
case GLSL_TYPE_SUBROUTINE:
|
|
||||||
case GLSL_TYPE_FUNCTION:
|
|
||||||
case GLSL_TYPE_FLOAT16:
|
|
||||||
case GLSL_TYPE_UINT16:
|
|
||||||
case GLSL_TYPE_INT16:
|
|
||||||
case GLSL_TYPE_UINT8:
|
|
||||||
case GLSL_TYPE_INT8:
|
|
||||||
ASSERT_TRUE(false);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (red_zone_size > 0) {
|
|
||||||
EXPECT_TRUE(red_zone_is_intact(storage,
|
|
||||||
val->type->components(),
|
|
||||||
red_zone_size));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,51 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright © 2012 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef GLSL_UNIFORM_INITIALIZER_UTILS_H
|
|
||||||
#define GLSL_UNIFORM_INITIALIZER_UTILS_H
|
|
||||||
|
|
||||||
#include "program/prog_parameter.h"
|
|
||||||
#include "ir.h"
|
|
||||||
#include "ir_uniform.h"
|
|
||||||
|
|
||||||
extern void
|
|
||||||
fill_storage_array_with_sentinels(gl_constant_value *storage,
|
|
||||||
unsigned data_size,
|
|
||||||
unsigned red_zone_size);
|
|
||||||
|
|
||||||
extern void
|
|
||||||
generate_data(void *mem_ctx, enum glsl_base_type base_type,
|
|
||||||
unsigned columns, unsigned rows,
|
|
||||||
ir_constant *&val);
|
|
||||||
|
|
||||||
extern void
|
|
||||||
generate_array_data(void *mem_ctx, enum glsl_base_type base_type,
|
|
||||||
unsigned columns, unsigned rows, unsigned array_size,
|
|
||||||
ir_constant *&val);
|
|
||||||
|
|
||||||
extern void
|
|
||||||
verify_data(gl_constant_value *storage, unsigned storage_array_size,
|
|
||||||
ir_constant *val, unsigned red_zone_size,
|
|
||||||
unsigned int boolean_true);
|
|
||||||
|
|
||||||
#endif /* GLSL_UNIFORM_INITIALIZER_UTILS_H */
|
|
||||||
|
|
@ -953,9 +953,6 @@ struct gl_constants
|
||||||
/** Is the drivers uniform storage packed or padded to 16 bytes. */
|
/** Is the drivers uniform storage packed or padded to 16 bytes. */
|
||||||
bool PackedDriverUniformStorage;
|
bool PackedDriverUniformStorage;
|
||||||
|
|
||||||
/** Does the driver make use of the NIR based GLSL linker */
|
|
||||||
bool UseNIRGLSLLinker;
|
|
||||||
|
|
||||||
/** Wether or not glBitmap uses red textures rather than alpha */
|
/** Wether or not glBitmap uses red textures rather than alpha */
|
||||||
bool BitmapUsesRed;
|
bool BitmapUsesRed;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -699,14 +699,11 @@ st_create_context_priv(struct gl_context *ctx, struct pipe_context *pipe,
|
||||||
|
|
||||||
ctx->Const.ShaderCompilerOptions[MESA_SHADER_TESS_EVAL].PositionAlwaysPrecise = options->vs_position_always_precise;
|
ctx->Const.ShaderCompilerOptions[MESA_SHADER_TESS_EVAL].PositionAlwaysPrecise = options->vs_position_always_precise;
|
||||||
|
|
||||||
ctx->Const.UseNIRGLSLLinker = true;
|
|
||||||
|
|
||||||
/* NIR drivers that support tess shaders and compact arrays need to use
|
/* NIR drivers that support tess shaders and compact arrays need to use
|
||||||
* GLSLTessLevelsAsInputs / PIPE_CAP_GLSL_TESS_LEVELS_AS_INPUTS. The NIR
|
* GLSLTessLevelsAsInputs / PIPE_CAP_GLSL_TESS_LEVELS_AS_INPUTS. The NIR
|
||||||
* linker doesn't support linking these as compat arrays of sysvals.
|
* linker doesn't support linking these as compat arrays of sysvals.
|
||||||
*/
|
*/
|
||||||
assert(ctx->Const.GLSLTessLevelsAsInputs ||
|
assert(ctx->Const.GLSLTessLevelsAsInputs ||
|
||||||
!ctx->Const.UseNIRGLSLLinker ||
|
|
||||||
!screen->get_param(screen, PIPE_CAP_NIR_COMPACT_ARRAYS) ||
|
!screen->get_param(screen, PIPE_CAP_NIR_COMPACT_ARRAYS) ||
|
||||||
!ctx->Extensions.ARB_tessellation_shader);
|
!ctx->Extensions.ARB_tessellation_shader);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue