This is a rewrite of the GLSL IR atomic counter intrinsics translation code based on the recently introduced surface builder. The new implementation is considerably cleaner and back-end-independent. --- src/mesa/drivers/dri/i965/Makefile.sources | 1 + src/mesa/drivers/dri/i965/brw_ir_glsl_intrinsics.h | 100 +++++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 src/mesa/drivers/dri/i965/brw_ir_glsl_intrinsics.h
diff --git a/src/mesa/drivers/dri/i965/Makefile.sources b/src/mesa/drivers/dri/i965/Makefile.sources index 4e8b25c..fd6d840 100644 --- a/src/mesa/drivers/dri/i965/Makefile.sources +++ b/src/mesa/drivers/dri/i965/Makefile.sources @@ -67,6 +67,7 @@ i965_FILES = \ brw_interpolation_map.c \ brw_ir_allocator.h \ brw_ir_fs.h \ + brw_ir_glsl_intrinsics.h \ brw_ir_surface_builder.h \ brw_ir_svec4.h \ brw_ir_vec4.h \ diff --git a/src/mesa/drivers/dri/i965/brw_ir_glsl_intrinsics.h b/src/mesa/drivers/dri/i965/brw_ir_glsl_intrinsics.h new file mode 100644 index 0000000..cc838e9 --- /dev/null +++ b/src/mesa/drivers/dri/i965/brw_ir_glsl_intrinsics.h @@ -0,0 +1,100 @@ +/* -*- c++ -*- */ +/* + * Copyright © 2013-2015 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#ifndef BRW_IR_GLSL_INTRINSICS_H +#define BRW_IR_GLSL_INTRINSICS_H + +#include "brw_ir_surface_builder.h" +#include "main/shaderimage.h" + +namespace brw { + namespace detail { + /** + * Process the i-th parameter passed to an intrinsic call. + */ + template<typename S, typename V> + S + visit_argument(V *v, ir_call *ir, unsigned i) + { + unsigned j = 0; + + foreach_in_list(ir_dereference, arg, &ir->actual_parameters) { + if (j++ == i) { + const unsigned n = + (arg->type->is_scalar() || arg->type->is_vector() || + arg->type->is_matrix() ? arg->type->vector_elements : 4); + return src_vector(v->visit_result(arg), n); + } + } + + return S(); + } + } + + /** + * Entry point for translating GLSL IR atomic counter intrinsics. + */ + template<typename V, typename B> + void + visit_atomic_counter_intrinsic(V *v, const B &bld, ir_call *ir) + { + using namespace detail; + using namespace surface_access; + typedef typename B::vector_builder::src_reg src_reg; + typedef typename B::vector_builder::dst_reg dst_reg; + typename B::vector_builder vbld = bld.vector(); + + /* Get the referenced atomic counter variable. */ + const ir_variable *var = static_cast<ir_dereference *>( + ir->actual_parameters.get_head())->variable_referenced(); + + /* Visit the arguments of the atomic intrinsic. */ + const src_reg offset = visit_argument<src_reg>(v, ir, 0); + const src_reg surface(v->stage_prog_data->binding_table.abo_start + + var->data.binding); + + /* Get some metadata from the atomic intrinsic. */ + const char *callee = ir->callee->function_name(); + const unsigned rsize = (ir->return_deref ? 1 : 0); + src_reg tmp; + + /* Emit a surface read or atomic op. */ + if (!strcmp("__intrinsic_atomic_read", callee)) + tmp = emit_untyped_read(vbld, surface, offset, 1, 1); + + else if (!strcmp("__intrinsic_atomic_increment", callee)) + tmp = emit_untyped_atomic(vbld, surface, offset, src_reg(), src_reg(), + 1, rsize, BRW_AOP_INC); + + else if (!strcmp("__intrinsic_atomic_predecrement", callee)) + tmp = emit_untyped_atomic(vbld, surface, offset, src_reg(), src_reg(), + 1, rsize, BRW_AOP_PREDEC); + + /* Assign the result. */ + if (ir->return_deref) + vbld.MOV(dst_reg(v->visit_result(ir->return_deref)), tmp); + } +} + +#endif -- 2.3.5 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev