diff --git a/src/gallium/auxiliary/meson.build b/src/gallium/auxiliary/meson.build index 9da93185b91..d0b3fabb5c1 100644 --- a/src/gallium/auxiliary/meson.build +++ b/src/gallium/auxiliary/meson.build @@ -327,6 +327,8 @@ files_libgallium = files( 'nir/nir_to_tgsi.h', 'nir/nir_draw_helpers.c', 'nir/nir_draw_helpers.h', + 'nir/nir_helpers.c', + 'nir/nir_helpers.h', ) if dep_libdrm.found() diff --git a/src/gallium/auxiliary/nir/nir_helpers.c b/src/gallium/auxiliary/nir/nir_helpers.c new file mode 100644 index 00000000000..1b5b7968ef5 --- /dev/null +++ b/src/gallium/auxiliary/nir/nir_helpers.c @@ -0,0 +1,56 @@ +/************************************************************************** + * + * Copyright 2021 Advanced Micro Devices, Inc. + * All Rights Reserved. + * + * 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 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_helpers.h" +#include "nir_xfb_info.h" + +void +nir_gather_stream_output_info(nir_shader *nir, + struct pipe_stream_output_info *so) +{ + int slot_to_register[NUM_TOTAL_VARYING_SLOTS]; + nir_xfb_info *info = nir_gather_xfb_info_from_intrinsics(nir, slot_to_register); + + memset(so, 0, sizeof(*so)); + + if (!info) + return; + + so->num_outputs = info->output_count; + + for (unsigned i = 0; i < info->output_count; i++) { + so->output[i].start_component = info->outputs[i].component_offset; + so->output[i].num_components = util_bitcount(info->outputs[i].component_mask); + so->output[i].output_buffer = info->outputs[i].buffer; + so->output[i].dst_offset = info->outputs[i].offset / 4; + so->output[i].stream = info->buffer_to_stream[info->outputs[i].buffer]; + so->output[i].register_index = slot_to_register[info->outputs[i].location]; + } + + for (unsigned i = 0; i < MAX_XFB_BUFFERS; i++) + so->stride[i] = info->buffers[i].stride; + + free(info); +} diff --git a/src/gallium/auxiliary/nir/nir_helpers.h b/src/gallium/auxiliary/nir/nir_helpers.h new file mode 100644 index 00000000000..08761b0455a --- /dev/null +++ b/src/gallium/auxiliary/nir/nir_helpers.h @@ -0,0 +1,36 @@ +/************************************************************************** + * + * Copyright 2021 Advanced Micro Devices, Inc. + * All Rights Reserved. + * + * 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 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 GALLIUM_NIR_HELPERS +#define GALLIUM_NIR_HELPERS + +#include "nir.h" +#include "pipe/p_state.h" + +void +nir_gather_stream_output_info(nir_shader *nir, + struct pipe_stream_output_info *so); + +#endif