mesa/main: introduce MAX_SAMPLES define

We're hard-coding the max to 16 in several places, but this value needs
to be consistent. Let's introduce a define here, that we can use instead
of hard-coding 16 more places.

Reviewed-by: Eric R. Smith <eric.smith@collabora.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34455>
This commit is contained in:
Erik Faye-Lund 2025-04-10 11:22:03 +02:00 committed by Marge Bot
parent 02457ee29e
commit 8ffce0e49b
8 changed files with 17 additions and 12 deletions

View file

@ -302,6 +302,10 @@
*/
#define MAX_CLIPPED_VERTICES ((2 * (6 + MAX_CLIP_PLANES))+1)
/**
* Maximum number of MSAA samples
*/
#define MAX_SAMPLES 16
/** For GL_ARB_sample_locations - maximum of SAMPLE_LOCATION_PIXEL_GRID_*_ARB */
#define MAX_SAMPLE_LOCATION_GRID_SIZE 4

View file

@ -909,7 +909,7 @@ void GLAPIENTRY
_mesa_GetInternalformativ(GLenum target, GLenum internalformat, GLenum pname,
GLsizei bufSize, GLint *params)
{
GLint buffer[16];
GLint buffer[MAX_SAMPLES];
GET_CURRENT_CONTEXT(ctx);
ASSERT_OUTSIDE_BEGIN_END(ctx);
@ -925,7 +925,7 @@ _mesa_GetInternalformativ(GLenum target, GLenum internalformat, GLenum pname,
return;
/* initialize the contents of the temporary buffer */
memcpy(buffer, params, MIN2(bufSize, 16) * sizeof(GLint));
memcpy(buffer, params, MIN2(bufSize, MAX_SAMPLES) * sizeof(GLint));
/* Use the 'unsupported' response defined by the spec for every pname
* as the default answer.

View file

@ -25,6 +25,7 @@
#define FORMATQUERY_H
#include "util/glheader.h"
#include "config.h"
void
_mesa_query_internal_format_default(struct gl_context *ctx, GLenum target,

View file

@ -310,7 +310,7 @@ _mesa_check_sample_count(struct gl_context *ctx, GLenum target,
* for <internalformat> then the error INVALID_OPERATION is generated."
*/
if (ctx->Extensions.ARB_internalformat_query) {
GLint buffer[16] = {-1};
GLint buffer[MAX_SAMPLES] = {-1};
GLint limit;
st_QueryInternalFormat(ctx, target, internalFormat,

View file

@ -1089,7 +1089,7 @@ _mesa_get_fallback_texture(struct gl_context *ctx, gl_texture_index tex, bool is
GLenum internalFormat = is_depth ? GL_DEPTH_COMPONENT : GL_RGBA;
if (tex == TEXTURE_2D_MULTISAMPLE_INDEX ||
tex == TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX) {
int samples[16];
int samples[MAX_SAMPLES];
st_QueryInternalFormat(ctx, 0, internalFormat, GL_SAMPLES, samples);
_mesa_init_teximage_fields_ms(ctx, texImage,
width,

View file

@ -1144,7 +1144,7 @@ guess_and_alloc_texture(struct st_context *st,
unsigned nr_samples = 0;
if (stObj->TargetIndex == TEXTURE_2D_MULTISAMPLE_INDEX ||
stObj->TargetIndex == TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX) {
int samples[16];
int samples[MAX_SAMPLES];
st_QueryInternalFormat(st->ctx, 0, stImage->InternalFormat, GL_SAMPLES, samples);
nr_samples = samples[0];
}

View file

@ -1373,12 +1373,12 @@ void st_init_extensions(struct pipe_screen *screen,
consts->MaxSamples =
get_max_samples_for_formats(screen, ARRAY_SIZE(color_formats),
color_formats, 16,
color_formats, MAX_SAMPLES,
PIPE_BIND_RENDER_TARGET);
consts->MaxImageSamples =
get_max_samples_for_formats(screen, ARRAY_SIZE(color_formats),
color_formats, 16,
color_formats, MAX_SAMPLES,
PIPE_BIND_SHADER_IMAGE);
consts->MaxColorTextureSamples =
@ -1408,7 +1408,7 @@ void st_init_extensions(struct pipe_screen *screen,
consts->MaxColorFramebufferSamples =
get_max_samples_for_formats_advanced(screen,
ARRAY_SIZE(color_formats),
color_formats, 16,
color_formats, MAX_SAMPLES,
consts->MaxSamples,
PIPE_BIND_RENDER_TARGET);

View file

@ -1483,7 +1483,7 @@ st_ChooseTextureFormat(struct gl_context *ctx, GLenum target,
*/
static size_t
st_QuerySamplesForFormat(struct gl_context *ctx, GLenum target,
GLenum internalFormat, int samples[16])
GLenum internalFormat, int samples[MAX_SAMPLES])
{
struct st_context *st = st_context(ctx);
enum pipe_format format;
@ -1512,7 +1512,7 @@ st_QuerySamplesForFormat(struct gl_context *ctx, GLenum target,
}
/* Set sample counts in descending order. */
for (i = 16; i > 1; i--) {
for (i = MAX_SAMPLES; i > 1; i--) {
format = st_choose_format(st, internalFormat, GL_NONE, GL_NONE,
PIPE_TEXTURE_2D, i, i, bind,
false, false);
@ -1545,7 +1545,7 @@ st_QueryTextureFormatSupport(struct gl_context *ctx, GLenum target, GLenum inter
/* multisample textures need >= 2 samples */
unsigned min_samples = target == GL_TEXTURE_2D_MULTISAMPLE ||
target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY ? 1 : 0;
unsigned max_samples = min_samples ? 16 : 1;
unsigned max_samples = min_samples ? MAX_SAMPLES : 1;
/* compressed textures will be allocated as e.g., RGBA8, so check that instead */
enum pipe_format pf = st_choose_format(st, internalFormat, GL_NONE, GL_NONE,
@ -1628,7 +1628,7 @@ st_QueryInternalFormat(struct gl_context *ctx, GLenum target,
break;
case GL_NUM_SAMPLE_COUNTS: {
int samples[16];
int samples[MAX_SAMPLES];
size_t num_samples;
num_samples = st_QuerySamplesForFormat(ctx, target, internalFormat,
samples);