"Fossies" - the Fresh Open Source Software Archive

Member "mesa-20.1.8/src/gallium/drivers/r600/sfn/sfn_shader_vertex.cpp" (16 Sep 2020, 6929 Bytes) of package /linux/misc/mesa-20.1.8.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "sfn_shader_vertex.cpp" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 20.1.5_vs_20.2.0-rc1.

    1 /* -*- mesa-c++  -*-
    2  *
    3  * Copyright (c) 2018 Collabora LTD
    4  *
    5  * Author: Gert Wollny <gert.wollny@collabora.com>
    6  *
    7  * Permission is hereby granted, free of charge, to any person obtaining a
    8  * copy of this software and associated documentation files (the "Software"),
    9  * to deal in the Software without restriction, including without limitation
   10  * on the rights to use, copy, modify, merge, publish, distribute, sub
   11  * license, and/or sell copies of the Software, and to permit persons to whom
   12  * the Software is furnished to do so, subject to the following conditions:
   13  *
   14  * The above copyright notice and this permission notice (including the next
   15  * paragraph) shall be included in all copies or substantial portions of the
   16  * Software.
   17  *
   18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   20  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
   21  * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
   22  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
   23  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
   24  * USE OR OTHER DEALINGS IN THE SOFTWARE.
   25  */
   26 
   27 
   28 #include "pipe/p_defines.h"
   29 #include "tgsi/tgsi_from_mesa.h"
   30 #include "sfn_shader_vertex.h"
   31 #include "sfn_instruction_lds.h"
   32 
   33 #include <queue>
   34 
   35 
   36 namespace r600 {
   37 
   38 using std::priority_queue;
   39 
   40 VertexShaderFromNir::VertexShaderFromNir(r600_pipe_shader *sh,
   41                                          r600_pipe_shader_selector& sel,
   42                                          const r600_shader_key& key,
   43                                          struct r600_shader* gs_shader):
   44    VertexStage(PIPE_SHADER_VERTEX, sel, sh->shader,
   45                sh->scratch_space_needed),
   46    m_num_clip_dist(0),
   47    m_last_param_export(nullptr),
   48    m_last_pos_export(nullptr),
   49    m_pipe_shader(sh),
   50    m_enabled_stream_buffers_mask(0),
   51    m_so_info(&sel.so),
   52    m_vertex_id(),
   53    m_key(key)
   54 {
   55    // reg 0 is used in the fetch shader
   56    increment_reserved_registers();
   57 
   58    sh_info().atomic_base = key.vs.first_atomic_counter;
   59    sh_info().vs_as_gs_a = m_key.vs.as_gs_a;
   60 
   61    if (key.vs.as_es) {
   62       sh->shader.vs_as_es = true;
   63       m_export_processor.reset(new VertexStageExportForGS(*this, gs_shader));
   64    } else if (key.vs.as_ls) {
   65       sh->shader.vs_as_ls = true;
   66       sfn_log << SfnLog::trans << "Start VS for GS\n";
   67       m_export_processor.reset(new VertexStageExportForES(*this));
   68    } else {
   69       m_export_processor.reset(new VertexStageExportForFS(*this, &sel.so, sh, key));
   70    }
   71 }
   72 
   73 bool VertexShaderFromNir::do_process_inputs(nir_variable *input)
   74 {
   75    ++sh_info().ninput;
   76 
   77    if (input->data.location < VERT_ATTRIB_MAX) {
   78       increment_reserved_registers();
   79       return true;
   80    }
   81    fprintf(stderr, "r600-NIR-VS: Unimplemented process_inputs for %d\n", input->data.location);
   82    return false;
   83 }
   84 
   85 bool VertexShaderFromNir::allocate_reserved_registers()
   86 {
   87    /* Since the vertex ID is nearly always used, we add it here as an input so
   88     * that the registers used for vertex attributes don't get clobbered by the
   89     * register merge step */
   90    auto R0x = new GPRValue(0,0);
   91    R0x->set_as_input();
   92    m_vertex_id.reset(R0x);
   93    inject_register(0, 0, m_vertex_id, false);
   94 
   95    if (m_key.vs.as_gs_a || m_sv_values.test(es_primitive_id)) {
   96       auto R0z = new GPRValue(0,2);
   97       R0x->set_as_input();
   98       m_primitive_id.reset(R0z);
   99       inject_register(0, 2, m_primitive_id, false);
  100    }
  101 
  102    if (m_sv_values.test(es_instanceid)) {
  103       auto R0w = new GPRValue(0,3);
  104       R0w->set_as_input();
  105       m_instance_id.reset(R0w);
  106       inject_register(0, 3, m_instance_id, false);
  107    }
  108 
  109 
  110    if (m_sv_values.test(es_rel_patch_id)) {
  111       auto R0y = new GPRValue(0,1);
  112       R0y->set_as_input();
  113       m_rel_vertex_id.reset(R0y);
  114       inject_register(0, 1, m_rel_vertex_id, false);
  115    }
  116 
  117    return true;
  118 }
  119 
  120 void VertexShaderFromNir::emit_shader_start()
  121 {
  122    m_export_processor->setup_paramn_map();
  123 }
  124 
  125 bool VertexShaderFromNir::scan_sysvalue_access(nir_instr *instr)
  126 {
  127    switch (instr->type) {
  128    case nir_instr_type_intrinsic: {
  129       nir_intrinsic_instr *ii =  nir_instr_as_intrinsic(instr);
  130       switch (ii->intrinsic) {
  131       case nir_intrinsic_load_vertex_id:
  132          m_sv_values.set(es_vertexid);
  133          break;
  134       case nir_intrinsic_load_instance_id:
  135          m_sv_values.set(es_instanceid);
  136          break;
  137       case nir_intrinsic_load_tcs_rel_patch_id_r600:
  138          m_sv_values.set(es_rel_patch_id);
  139          break;
  140       default:
  141          ;
  142       }
  143    }
  144    default:
  145       ;
  146    }
  147    return true;
  148 }
  149 
  150 bool VertexShaderFromNir::emit_intrinsic_instruction_override(nir_intrinsic_instr* instr)
  151 {
  152    switch (instr->intrinsic) {
  153    case nir_intrinsic_load_vertex_id:
  154       return load_preloaded_value(instr->dest, 0, m_vertex_id);
  155    case nir_intrinsic_load_tcs_rel_patch_id_r600:
  156       return load_preloaded_value(instr->dest, 0, m_rel_vertex_id);
  157    case nir_intrinsic_load_instance_id:
  158       return load_preloaded_value(instr->dest, 0, m_instance_id);
  159    case nir_intrinsic_store_local_shared_r600:
  160       return emit_store_local_shared(instr);
  161    default:
  162       return false;
  163    }
  164 }
  165 
  166 bool VertexShaderFromNir::emit_store_local_shared(nir_intrinsic_instr* instr)
  167 {
  168    unsigned write_mask = nir_intrinsic_write_mask(instr);
  169 
  170    auto address = from_nir(instr->src[1], 0);
  171    int swizzle_base = (write_mask & 0x3) ? 0 : 2;
  172    write_mask |= write_mask >> 2;
  173 
  174    auto value =  from_nir(instr->src[0], swizzle_base);
  175    if (!(write_mask & 2)) {
  176       emit_instruction(new LDSWriteInstruction(address, 1, value));
  177    } else {
  178       auto value1 =  from_nir(instr->src[0], swizzle_base + 1);
  179       emit_instruction(new LDSWriteInstruction(address, 1, value, value1));
  180    }
  181 
  182    return true;
  183 }
  184 
  185 bool VertexShaderFromNir::do_process_outputs(nir_variable *output)
  186 {
  187    return m_export_processor->do_process_outputs(output);
  188 }
  189 
  190 bool VertexShaderFromNir::do_emit_load_deref(const nir_variable *in_var, nir_intrinsic_instr* instr)
  191 {
  192    if (in_var->data.location < VERT_ATTRIB_MAX) {
  193       for (int i = 0; i < instr->num_components ; ++i) {
  194          auto s = new GPRValue(in_var->data.driver_location + 1, i);
  195          s->set_as_input();
  196          auto src = PValue(s);
  197          inject_register(in_var->data.driver_location + 1, i, src, false);
  198 
  199          if (i == 0)
  200             set_input(in_var->data.driver_location, src);
  201 
  202          load_preloaded_value(instr->dest, i, src, i == instr->num_components - 1);
  203       }
  204       return true;
  205    }
  206    fprintf(stderr, "r600-NIR: Unimplemented load_deref for %d\n", in_var->data.location);
  207    return false;
  208 }
  209 
  210 void VertexShaderFromNir::do_finalize()
  211 {
  212    m_export_processor->finalize_exports();
  213 }
  214 
  215 bool VertexShaderFromNir::do_emit_store_deref(const nir_variable *out_var, nir_intrinsic_instr* instr)
  216 {
  217    return m_export_processor->store_deref(out_var, instr);
  218 }
  219 
  220 }