From f1c2db43dcf35d2cf4715390bd2391c28e42a8c2 Mon Sep 17 00:00:00 2001 From: marha Date: Sun, 22 Feb 2015 14:31:16 +0100 Subject: xwininfo fontconfig libX11 libXdmcp libfontenc libxcb libxcb/xcb-proto mesalib xserver xkeyboard-config mkfontscale git update 22 Feb 2015 xserver commit 3a06faf3fcdb7451125a46181f9152e8e59e9770 libxcb commit e3ec1f74637237ce500dfd0ca59f2e422da4e019 libxcb/xcb-proto commit 4c550465934164aab2449a125f75f4ca07816233 xkeyboard-config commit 26f344c93f8c6141e9233eb68088ba4fd56bc9ef libX11 commit c8e19b393defd53f046ddc2da3a16881221b3c34 libXdmcp commit 9f4cac7656b221ce2a8f97e7bd31e5e23126d001 libfontenc commit de1843aaf76015c9d99416f3122d169fe331b849 mkfontscale commit 87d628f8eec170ec13bb9feefb1ce05aed07d1d6 xwininfo commit 0c49f8f2bd56b1e77721e81030ea948386dcdf4e fontconfig commit d6d5adeb7940c0d0beb86489c2a1c2ce59e5c044 mesa commit 4359954d842caa2a9f8d4b50d70ecc789884b68b --- mesalib/src/glsl/nir/nir_lower_samplers.cpp | 184 ++++++++++++++++++++++++++++ 1 file changed, 184 insertions(+) create mode 100644 mesalib/src/glsl/nir/nir_lower_samplers.cpp (limited to 'mesalib/src/glsl/nir/nir_lower_samplers.cpp') diff --git a/mesalib/src/glsl/nir/nir_lower_samplers.cpp b/mesalib/src/glsl/nir/nir_lower_samplers.cpp new file mode 100644 index 000000000..3015dbd09 --- /dev/null +++ b/mesalib/src/glsl/nir/nir_lower_samplers.cpp @@ -0,0 +1,184 @@ +/* + * Copyright (C) 2005-2007 Brian Paul All Rights Reserved. + * Copyright (C) 2008 VMware, Inc. All Rights Reserved. + * Copyright © 2014 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 "nir.h" +#include "../program.h" +#include "program/hash_table.h" +#include "ir_uniform.h" + +extern "C" { +#include "main/compiler.h" +#include "main/mtypes.h" +#include "program/prog_parameter.h" +#include "program/program.h" +} + +static unsigned +get_sampler_index(struct gl_shader_program *shader_program, const char *name, + const struct gl_program *prog) +{ + GLuint shader = _mesa_program_enum_to_shader_stage(prog->Target); + + unsigned location; + if (!shader_program->UniformHash->get(location, name)) { + linker_error(shader_program, + "failed to find sampler named %s.\n", name); + return 0; + } + + if (!shader_program->UniformStorage[location].sampler[shader].active) { + assert(0 && "cannot return a sampler"); + linker_error(shader_program, + "cannot return a sampler named %s, because it is not " + "used in this shader stage. This is a driver bug.\n", + name); + return 0; + } + + return shader_program->UniformStorage[location].sampler[shader].index; +} + +static void +lower_sampler(nir_tex_instr *instr, struct gl_shader_program *shader_program, + const struct gl_program *prog, void *mem_ctx) +{ + if (instr->sampler == NULL) + return; + + /* Get the name and the offset */ + instr->sampler_index = 0; + char *name = ralloc_strdup(mem_ctx, instr->sampler->var->name); + + for (nir_deref *deref = &instr->sampler->deref; + deref->child; deref = deref->child) { + switch (deref->child->deref_type) { + case nir_deref_type_array: { + nir_deref_array *deref_array = nir_deref_as_array(deref->child); + + /* XXX: We're assuming here that the indirect is the last array + * thing we have. This should be ok for now as we don't support + * arrays_of_arrays yet. + */ + + instr->sampler_index *= glsl_get_length(deref->type); + switch (deref_array->deref_array_type) { + case nir_deref_array_type_direct: + instr->sampler_index += deref_array->base_offset; + if (deref_array->deref.child) + ralloc_asprintf_append(&name, "[%u]", deref_array->base_offset); + break; + case nir_deref_array_type_indirect: { + instr->src = reralloc(mem_ctx, instr->src, nir_tex_src, + instr->num_srcs + 1); + memset(&instr->src[instr->num_srcs], 0, sizeof *instr->src); + instr->src[instr->num_srcs].src_type = nir_tex_src_sampler_offset; + instr->num_srcs++; + + nir_instr_rewrite_src(&instr->instr, + &instr->src[instr->num_srcs - 1].src, + deref_array->indirect); + + instr->sampler_array_size = glsl_get_length(deref->type); + + nir_src empty; + memset(&empty, 0, sizeof empty); + nir_instr_rewrite_src(&instr->instr, &deref_array->indirect, empty); + + if (deref_array->deref.child) + ralloc_strcat(&name, "[0]"); + break; + } + + case nir_deref_array_type_wildcard: + unreachable("Cannot copy samplers"); + default: + unreachable("Invalid deref array type"); + } + break; + } + + case nir_deref_type_struct: { + nir_deref_struct *deref_struct = nir_deref_as_struct(deref->child); + const char *field = glsl_get_struct_elem_name(deref->type, + deref_struct->index); + ralloc_asprintf_append(&name, ".%s", field); + break; + } + + default: + unreachable("Invalid deref type"); + break; + } + } + + instr->sampler_index += get_sampler_index(shader_program, name, prog); + + instr->sampler = NULL; +} + +typedef struct { + void *mem_ctx; + struct gl_shader_program *shader_program; + struct gl_program *prog; +} lower_state; + +static bool +lower_block_cb(nir_block *block, void *_state) +{ + lower_state *state = (lower_state *) _state; + + nir_foreach_instr(block, instr) { + if (instr->type == nir_instr_type_tex) { + nir_tex_instr *tex_instr = nir_instr_as_tex(instr); + lower_sampler(tex_instr, state->shader_program, state->prog, + state->mem_ctx); + } + } + + return true; +} + +static void +lower_impl(nir_function_impl *impl, struct gl_shader_program *shader_program, + struct gl_program *prog) +{ + lower_state state; + + state.mem_ctx = ralloc_parent(impl); + state.shader_program = shader_program; + state.prog = prog; + + nir_foreach_block(impl, lower_block_cb, &state); +} + +extern "C" void +nir_lower_samplers(nir_shader *shader, struct gl_shader_program *shader_program, + struct gl_program *prog) +{ + nir_foreach_overload(shader, overload) { + if (overload->impl) + lower_impl(overload->impl, shader_program, prog); + } +} -- cgit v1.2.3