"Fossies" - the Fresh Open Source Software Archive

Member "mesa-20.1.9/src/gallium/drivers/r600/sfn/sfn_shader_tess_eval.cpp" (30 Sep 2020, 5058 Bytes) of package /linux/misc/mesa-20.1.9.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. See also the last Fossies "Diffs" side-by-side code changes report for "sfn_shader_tess_eval.cpp": 20.1.5_vs_20.2.0-rc1.

    1 #include "sfn_shader_tess_eval.h"
    2 #include "tgsi/tgsi_from_mesa.h"
    3 
    4 namespace r600 {
    5 
    6 TEvalShaderFromNir::TEvalShaderFromNir(r600_pipe_shader *sh, r600_pipe_shader_selector& sel,
    7                                        const r600_shader_key& key, r600_shader *gs_shader):
    8    VertexStage(PIPE_SHADER_TESS_EVAL, sel, sh->shader,
    9                sh->scratch_space_needed),
   10    m_reserved_registers(0),
   11    m_key(key)
   12 
   13 {
   14    sh->shader.tes_as_es = key.tes.as_es;
   15    if (key.tes.as_es)
   16       m_export_processor.reset(new VertexStageExportForGS(*this, gs_shader));
   17    else
   18       m_export_processor.reset(new VertexStageExportForFS(*this, &sel.so, sh, key));
   19 }
   20 
   21 bool TEvalShaderFromNir::do_process_inputs(nir_variable *input)
   22 {
   23    if (input->data.location == VARYING_SLOT_POS ||
   24        input->data.location == VARYING_SLOT_PSIZ ||
   25        input->data.location == VARYING_SLOT_CLIP_DIST0 ||
   26        input->data.location == VARYING_SLOT_CLIP_DIST1 ||
   27        (input->data.location >= VARYING_SLOT_VAR0 &&
   28        input->data.location <= VARYING_SLOT_VAR31) ||
   29        (input->data.location >= VARYING_SLOT_TEX0 &&
   30        input->data.location <= VARYING_SLOT_TEX7) ||
   31         (input->data.location >= VARYING_SLOT_PATCH0 &&
   32          input->data.location <= VARYING_SLOT_TESS_MAX)) {
   33 
   34       r600_shader_io& io = sh_info().input[input->data.driver_location];
   35       tgsi_get_gl_varying_semantic(static_cast<gl_varying_slot>( input->data.location),
   36                                    true, &io.name, &io.sid);
   37       ++sh_info().ninput;
   38       return true;
   39    }
   40 
   41    return false;
   42 
   43 }
   44 
   45 bool TEvalShaderFromNir::scan_sysvalue_access(nir_instr *instr)
   46 {
   47    if (instr->type != nir_instr_type_intrinsic)
   48       return true;
   49 
   50    auto ir = nir_instr_as_intrinsic(instr);
   51 
   52    switch (ir->intrinsic) {
   53    case nir_intrinsic_load_tess_coord:
   54       m_sv_values.set(es_tess_coord);
   55       break;
   56    case nir_intrinsic_load_primitive_id:
   57       m_sv_values.set(es_primitive_id);
   58       break;
   59    case nir_intrinsic_load_tcs_rel_patch_id_r600:
   60       m_sv_values.set(es_rel_patch_id);
   61       break;
   62    default:
   63       ;
   64    }
   65    return true;
   66 }
   67 
   68 bool TEvalShaderFromNir::allocate_reserved_registers()
   69 {
   70    if (m_sv_values.test(es_tess_coord)) {
   71       m_reserved_registers = 1;
   72       auto gpr = new GPRValue(0,0);
   73       gpr->set_as_input();
   74       m_tess_coord[0].reset(gpr);
   75       gpr = new GPRValue(0,1);
   76       gpr->set_as_input();
   77       m_tess_coord[1].reset(gpr);
   78    }
   79 
   80    if (m_sv_values.test(es_rel_patch_id)) {
   81       m_reserved_registers = 1;
   82       auto gpr = new GPRValue(0,2);
   83       gpr->set_as_input();
   84       m_rel_patch_id.reset(gpr);
   85    }
   86 
   87    if (m_sv_values.test(es_primitive_id) ||
   88        m_key.vs.as_gs_a) {
   89       m_reserved_registers = 1;
   90       auto gpr = new GPRValue(0,3);
   91       gpr->set_as_input();
   92       m_primitive_id.reset(gpr);
   93       if (m_key.vs.as_gs_a)
   94          inject_register(0, 3, m_primitive_id, false);
   95    }
   96    set_reserved_registers(m_reserved_registers);
   97    return true;
   98 }
   99 
  100 bool TEvalShaderFromNir::load_tess_z_coord(nir_intrinsic_instr* instr)
  101 {
  102    if (m_tess_coord[2])
  103       return load_preloaded_value(instr->dest, 2, m_tess_coord[2]);
  104 
  105    m_tess_coord[2] = from_nir(instr->dest, 2);
  106    emit_instruction(new AluInstruction(op2_add, m_tess_coord[2], Value::one_f, m_tess_coord[0], {alu_last_instr, alu_write, alu_src1_neg}));
  107    emit_instruction(new AluInstruction(op2_add, m_tess_coord[2], m_tess_coord[2], m_tess_coord[1], {alu_last_instr, alu_write, alu_src1_neg}));
  108    return true;
  109 }
  110 
  111 bool TEvalShaderFromNir::emit_intrinsic_instruction_override(nir_intrinsic_instr* instr)
  112 {
  113    switch (instr->intrinsic) {
  114    case nir_intrinsic_load_tess_coord:
  115       return load_preloaded_value(instr->dest, 0, m_tess_coord[0]) &&
  116             load_preloaded_value(instr->dest, 1, m_tess_coord[1]) &&
  117             load_tess_z_coord(instr);
  118    case nir_intrinsic_load_primitive_id:
  119       return load_preloaded_value(instr->dest, 0, m_primitive_id);
  120    case nir_intrinsic_load_tcs_rel_patch_id_r600:
  121       return load_preloaded_value(instr->dest, 0, m_rel_patch_id);
  122    default:
  123       return false;
  124    }
  125 }
  126 
  127 
  128 bool TEvalShaderFromNir::do_process_outputs(nir_variable *output)
  129 {
  130    return m_export_processor->do_process_outputs(output);
  131 }
  132 
  133 bool TEvalShaderFromNir::do_emit_store_deref(const nir_variable *out_var, nir_intrinsic_instr* instr)
  134 {
  135    return m_export_processor->store_deref(out_var, instr);
  136 }
  137 
  138 void TEvalShaderFromNir::do_finalize()
  139 {
  140    m_export_processor->finalize_exports();
  141 }
  142 
  143 
  144 bool TEvalShaderFromNir::emit_load_tess_coord(nir_intrinsic_instr* instr)
  145 {
  146    bool result = load_preloaded_value(instr->dest, 0, m_tess_coord[0]) &&
  147                load_preloaded_value(instr->dest, 1, m_tess_coord[1]);
  148 
  149    m_tess_coord[2] = from_nir(instr->dest, 2);
  150 
  151 
  152    emit_instruction(new AluInstruction(op2_add, m_tess_coord[2], m_tess_coord[2],
  153          m_tess_coord[0], {alu_last_instr, alu_write, alu_src0_neg}));
  154    emit_instruction(new AluInstruction(op2_add, m_tess_coord[2], m_tess_coord[2],
  155          m_tess_coord[1], {alu_last_instr, alu_write, alu_src0_neg}));
  156    return result;
  157 }
  158 
  159 }