mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-09 04:38:03 +02:00
gallium: Add u_default_get_sample_position
ctx->get_sample_position doesn't change what it returns based on the programmed
positions, it's just supposed to return the defaults. For most (all?) hardware,
those are the Vulkan standard sample positions. In bf9a1e0a4b ("zink: add a
pipe_context::get_sample_position hook"), Mike wondered why there wasn't a
common implementation. So here's one to fix that :~)
Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Reviewed-by: Emma Anholt <emma@anholt.net>
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22383>
This commit is contained in:
parent
6124f8f371
commit
6b211e9b43
3 changed files with 113 additions and 0 deletions
|
|
@ -251,6 +251,8 @@ files_libgallium = files(
|
|||
'util/u_rect.h',
|
||||
'util/u_resource.c',
|
||||
'util/u_resource.h',
|
||||
'util/u_sample_positions.c',
|
||||
'util/u_sample_positions.h',
|
||||
'util/u_sampler.c',
|
||||
'util/u_sampler.h',
|
||||
'util/u_screen.c',
|
||||
|
|
|
|||
86
src/gallium/auxiliary/util/u_sample_positions.c
Normal file
86
src/gallium/auxiliary/util/u_sample_positions.c
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
/*
|
||||
* Copyright 2023 Alyssa Rosenzweig
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#include "u_sample_positions.h"
|
||||
|
||||
/*
|
||||
* This file implement a default version of get_sample_position that returns the
|
||||
* standard sample positions, as standardized in both Vulkan and Direct3D and
|
||||
* hence almost everyone's hardware.
|
||||
*/
|
||||
|
||||
static const float u_default_sample_positions_1x[][2] = {
|
||||
{0.5, 0.5}
|
||||
};
|
||||
|
||||
static const float u_default_sample_positions_2x[][2] = {
|
||||
{0.75, 0.75},
|
||||
{0.25, 0.25}
|
||||
};
|
||||
|
||||
static const float u_default_sample_positions_4x[][4] = {
|
||||
{0.375, 0.125},
|
||||
{0.875, 0.375},
|
||||
{0.125, 0.625},
|
||||
{0.625, 0.875},
|
||||
};
|
||||
|
||||
static const float u_default_sample_positions_8x[][4] = {
|
||||
{0.5625, 0.3125},
|
||||
{0.4375, 0.6875},
|
||||
{0.8125, 0.5625},
|
||||
{0.3125, 0.1875},
|
||||
{0.1875, 0.8125},
|
||||
{0.0625, 0.4375},
|
||||
{0.6875, 0.9375},
|
||||
{0.9375, 0.0625},
|
||||
|
||||
};
|
||||
|
||||
static const float u_default_sample_positions_16x[][4] = {
|
||||
{0.5625, 0.5625},
|
||||
{0.4375, 0.3125},
|
||||
{0.3125, 0.625},
|
||||
{0.75, 0.4375},
|
||||
{0.1875, 0.375},
|
||||
{0.625, 0.8125},
|
||||
{0.8125, 0.6875},
|
||||
{0.6875, 0.1875},
|
||||
{0.375, 0.875},
|
||||
{0.5, 0.0625},
|
||||
{0.25, 0.125},
|
||||
{0.125, 0.75},
|
||||
{0.0, 0.5},
|
||||
{0.9375, 0.25},
|
||||
{0.875, 0.9375},
|
||||
{0.0625, 0.0},
|
||||
};
|
||||
|
||||
static const float *
|
||||
u_default_sample_position(unsigned sample_count, unsigned sample_index)
|
||||
{
|
||||
switch (sample_count) {
|
||||
case 0:
|
||||
case 1: return u_default_sample_positions_1x[sample_index];
|
||||
case 2: return u_default_sample_positions_2x[sample_index];
|
||||
case 4: return u_default_sample_positions_4x[sample_index];
|
||||
case 8: return u_default_sample_positions_8x[sample_index];
|
||||
case 16: return u_default_sample_positions_16x[sample_index];
|
||||
default: unreachable("Invalid sample count");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
u_default_get_sample_position(struct pipe_context *ctx,
|
||||
unsigned sample_count,
|
||||
unsigned sample_index,
|
||||
float *out_value)
|
||||
{
|
||||
const float *positions =
|
||||
u_default_sample_position(sample_count, sample_index);
|
||||
|
||||
out_value[0] = positions[0];
|
||||
out_value[1] = positions[1];
|
||||
}
|
||||
25
src/gallium/auxiliary/util/u_sample_positions.h
Normal file
25
src/gallium/auxiliary/util/u_sample_positions.h
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* Copyright 2023 Alyssa Rosenzweig
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#ifndef U_SAMPLE_POSITIONS_H
|
||||
#define U_SAMPLE_POSITIONS_H
|
||||
|
||||
#include "pipe/p_context.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void
|
||||
u_default_get_sample_position(struct pipe_context *ctx,
|
||||
unsigned sample_count,
|
||||
unsigned sample_index,
|
||||
float *out_value);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Reference in a new issue