mesa: Flip the script on SPIR-V extension enabling

Instead of populating SPIR-V capabilities from st_extensions.c and then
deriving extensios from caps, we populate SPIR-V extensions from
st_extensions.c and populate caps from a combination of GL extensions,
SPIR-V extensions, and GL limits.  This means that the stuff we store in
the context is the actual stuff exposed to the client.  This is also
more like how we do things in Vulkan.

Most importantly, however, this means we're no longer storing a struct
spirv_supported_capabilities in the context.  Since we're about to
replace it with the auto-generated spirv_capabilities struct, that would
mean mtypes.h is dependent on codegen and mtypes.h is included
everywhere.

Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28905>
This commit is contained in:
Faith Ekstrand 2024-05-08 13:14:51 -05:00 committed by Marge Bot
parent d5f3233a06
commit 4203d7339c
8 changed files with 137 additions and 70 deletions

View file

@ -982,9 +982,6 @@ struct gl_constants
*/
bool PrimitiveRestartFixedIndex;
/** GL_ARB_gl_spirv */
struct spirv_supported_capabilities SpirVCapabilities;
/** GL_ARB_spirv_extensions */
struct spirv_supported_extensions *SpirVExtensions;

View file

@ -24,6 +24,7 @@
#include "glspirv.h"
#include "errors.h"
#include "shaderobj.h"
#include "spirv_capabilities.h"
#include "mtypes.h"
#include "compiler/nir/nir.h"
@ -260,10 +261,14 @@ _mesa_spirv_to_nir(struct gl_context *ctx,
spec_entries[i].defined_on_module = false;
}
const struct spirv_to_nir_options spirv_options = {
struct spirv_supported_capabilities spirv_caps;
_mesa_fill_supported_spirv_capabilities(&spirv_caps, &ctx->Const,
&ctx->Extensions);
struct spirv_to_nir_options spirv_options = {
.environment = NIR_SPIRV_OPENGL,
.caps = spirv_caps,
.subgroup_size = SUBGROUP_SIZE_UNIFORM,
.caps = ctx->Const.SpirVCapabilities,
.ubo_addr_format = nir_address_format_32bit_index_offset,
.ssbo_addr_format = nir_address_format_32bit_index_offset,

View file

@ -0,0 +1,69 @@
/*
* Copyright 2017 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
* on the rights to use, copy, modify, merge, publish, distribute, sub
* license, 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 NON-INFRINGEMENT. IN NO EVENT SHALL
* THE AUTHOR(S) AND/OR THEIR SUPPLIERS 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.
*/
/**
* \file
* \brief SPIRV-V capability handling.
*/
#include "spirv_capabilities.h"
#include "compiler/shader_info.h"
void
_mesa_fill_supported_spirv_capabilities(struct spirv_supported_capabilities *caps,
struct gl_constants *consts,
const struct gl_extensions *gl_exts)
{
const struct spirv_supported_extensions *spirv_exts = consts->SpirVExtensions;
*caps = (struct spirv_supported_capabilities) {
.atomic_storage = gl_exts->ARB_shader_atomic_counters,
.demote_to_helper_invocation = gl_exts->EXT_demote_to_helper_invocation,
.draw_parameters =
gl_exts->ARB_shader_draw_parameters &&
spirv_exts->supported[SPV_KHR_shader_draw_parameters],
.derivative_group = gl_exts->NV_compute_shader_derivatives,
.float64 = gl_exts->ARB_gpu_shader_fp64,
.geometry_streams = gl_exts->ARB_gpu_shader5,
.image_ms_array = gl_exts->ARB_shader_image_load_store &&
consts->MaxImageSamples > 1,
.image_read_without_format = gl_exts->EXT_shader_image_load_formatted,
.image_write_without_format = gl_exts->ARB_shader_image_load_store,
.int64 = gl_exts->ARB_gpu_shader_int64,
.int64_atomics = gl_exts->NV_shader_atomic_int64,
.post_depth_coverage = gl_exts->ARB_post_depth_coverage,
.shader_clock = gl_exts->ARB_shader_clock,
.shader_viewport_index_layer = gl_exts->ARB_shader_viewport_layer_array,
.stencil_export = gl_exts->ARB_shader_stencil_export,
.storage_image_ms = gl_exts->ARB_shader_image_load_store &&
consts->MaxImageSamples > 1,
.subgroup_ballot =
gl_exts->ARB_shader_ballot && spirv_exts->supported[SPV_KHR_shader_ballot],
.subgroup_vote =
gl_exts->ARB_shader_group_vote && spirv_exts->supported[SPV_KHR_subgroup_vote],
.tessellation = gl_exts->ARB_tessellation_shader,
.transform_feedback = gl_exts->ARB_transform_feedback3,
.variable_pointers = spirv_exts->supported[SPV_KHR_variable_pointers],
.integer_functions2 = gl_exts->INTEL_shader_integer_functions2,
};
}

View file

@ -0,0 +1,50 @@
/*
* Copyright 2017 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
* on the rights to use, copy, modify, merge, publish, distribute, sub
* license, 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 NON-INFRINGEMENT. IN NO EVENT SHALL
* THE AUTHOR(S) AND/OR THEIR SUPPLIERS 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.
*/
/**
* \file
* \brief SPIRV-V capability handling.
*/
#ifndef _SPIRVCAPABILITIES_H_
#define _SPIRVCAPABILITIES_H_
#include "mtypes.h"
#include "spirv_extensions.h"
#ifdef __cplusplus
extern "C" {
#endif
struct spirv_supported_capabilities;
void _mesa_fill_supported_spirv_capabilities(struct spirv_supported_capabilities *caps,
struct gl_constants *consts,
const struct gl_extensions *gl_exts);
#ifdef __cplusplus
}
#endif
#endif /* SPIRVCAPABILITIES_H */

View file

@ -80,36 +80,3 @@ _mesa_spirv_extensions_to_string(enum SpvExtension ext)
return "unknown";
}
/**
* Sets the supported flags for known SPIR-V extensions based on the
* capabilites supported (spirv capabilities based on the spirv to nir
* support).
*
* One could argue that makes more sense in the other way around, as from the
* spec pov capabilities are enable for a given extension. But from our pov,
* we support or not (depending on the driver) some given capability, and
* spirv_to_nir check for capabilities not extensions. Also we usually fill
* first the supported capabilities, that are not always related to an
* extension.
*/
void
_mesa_fill_supported_spirv_extensions(struct spirv_supported_extensions *ext,
const struct spirv_supported_capabilities *cap)
{
memset(ext->supported, 0, sizeof(ext->supported));
ext->count = 0;
ext->supported[SPV_KHR_shader_draw_parameters] = cap->draw_parameters;
ext->supported[SPV_KHR_multiview] = cap->multiview;
ext->supported[SPV_KHR_storage_buffer_storage_class] = true;
ext->supported[SPV_KHR_variable_pointers] = cap->variable_pointers;
ext->supported[SPV_KHR_shader_ballot] = cap->subgroup_ballot;
ext->supported[SPV_KHR_subgroup_vote] = cap->subgroup_vote;
for (unsigned i = 0; i < SPV_EXTENSIONS_COUNT; i++) {
if (ext->supported[i])
ext->count++;
}
}

View file

@ -65,9 +65,6 @@ _mesa_get_enabled_spirv_extension(struct gl_context *ctx,
const char *_mesa_spirv_extensions_to_string(enum SpvExtension ext);
void _mesa_fill_supported_spirv_extensions(struct spirv_supported_extensions *ext,
const struct spirv_supported_capabilities *cap);
#ifdef __cplusplus
}
#endif

View file

@ -195,6 +195,8 @@ files_libmesa = files(
'main/shaderobj.h',
'main/shared.c',
'main/shared.h',
'main/spirv_capabilities.c',
'main/spirv_capabilities.h',
'main/spirv_extensions.c',
'main/spirv_extensions.h',
'main/state.c',

View file

@ -1802,36 +1802,16 @@ void st_init_extensions(struct pipe_screen *screen,
}
if (extensions->ARB_gl_spirv) {
struct spirv_supported_capabilities *spirv_caps = &consts->SpirVCapabilities;
spirv_caps->atomic_storage = extensions->ARB_shader_atomic_counters;
spirv_caps->demote_to_helper_invocation = extensions->EXT_demote_to_helper_invocation;
spirv_caps->draw_parameters = extensions->ARB_shader_draw_parameters;
spirv_caps->derivative_group = extensions->NV_compute_shader_derivatives;
spirv_caps->float64 = extensions->ARB_gpu_shader_fp64;
spirv_caps->geometry_streams = extensions->ARB_gpu_shader5;
spirv_caps->image_ms_array = extensions->ARB_shader_image_load_store &&
consts->MaxImageSamples > 1;
spirv_caps->image_read_without_format = extensions->EXT_shader_image_load_formatted;
spirv_caps->image_write_without_format = extensions->ARB_shader_image_load_store;
spirv_caps->int64 = extensions->ARB_gpu_shader_int64;
spirv_caps->int64_atomics = extensions->NV_shader_atomic_int64;
spirv_caps->post_depth_coverage = extensions->ARB_post_depth_coverage;
spirv_caps->shader_clock = extensions->ARB_shader_clock;
spirv_caps->shader_viewport_index_layer = extensions->ARB_shader_viewport_layer_array;
spirv_caps->stencil_export = extensions->ARB_shader_stencil_export;
spirv_caps->storage_image_ms = extensions->ARB_shader_image_load_store &&
consts->MaxImageSamples > 1;
spirv_caps->subgroup_ballot = extensions->ARB_shader_ballot;
spirv_caps->subgroup_vote = extensions->ARB_shader_group_vote;
spirv_caps->tessellation = extensions->ARB_tessellation_shader;
spirv_caps->transform_feedback = extensions->ARB_transform_feedback3;
spirv_caps->variable_pointers =
screen->get_param(screen, PIPE_CAP_GL_SPIRV_VARIABLE_POINTERS);
spirv_caps->integer_functions2 = extensions->INTEL_shader_integer_functions2;
consts->SpirVExtensions = CALLOC_STRUCT(spirv_supported_extensions);
_mesa_fill_supported_spirv_extensions(consts->SpirVExtensions, spirv_caps);
consts->SpirVExtensions->supported[SPV_KHR_shader_draw_parameters] =
extensions->ARB_shader_draw_parameters;
consts->SpirVExtensions->supported[SPV_KHR_storage_buffer_storage_class] = true;
consts->SpirVExtensions->supported[SPV_KHR_variable_pointers] =
screen->get_param(screen, PIPE_CAP_GL_SPIRV_VARIABLE_POINTERS);
consts->SpirVExtensions->supported[SPV_KHR_shader_ballot] =
extensions->ARB_shader_ballot;
consts->SpirVExtensions->supported[SPV_KHR_subgroup_vote] =
extensions->ARB_shader_group_vote;
}
consts->AllowDrawOutOfOrder =