1/**************************************************************************
2 *
3 * Copyright 2021 Advanced Micro Devices, Inc.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 *
24 **************************************************************************/
25
26#include "nir_helpers.h"
27#include "nir_xfb_info.h"
28
29void
30nir_gather_stream_output_info(nir_shader *nir,
31                              struct pipe_stream_output_info *so)
32{
33   int slot_to_register[NUM_TOTAL_VARYING_SLOTS];
34   nir_xfb_info *info = nir_gather_xfb_info_from_intrinsics(nir, slot_to_register);
35
36   memset(so, 0, sizeof(*so));
37
38   if (!info)
39      return;
40
41   so->num_outputs = info->output_count;
42
43   for (unsigned i = 0; i < info->output_count; i++) {
44      so->output[i].start_component = info->outputs[i].component_offset;
45      so->output[i].num_components = util_bitcount(info->outputs[i].component_mask);
46      so->output[i].output_buffer = info->outputs[i].buffer;
47      so->output[i].dst_offset = info->outputs[i].offset / 4;
48      so->output[i].stream = info->buffer_to_stream[info->outputs[i].buffer];
49      so->output[i].register_index = slot_to_register[info->outputs[i].location];
50   }
51
52   for (unsigned i = 0; i < MAX_XFB_BUFFERS; i++)
53      so->stride[i] = info->buffers[i].stride;
54
55   free(info);
56}
57