[virglrenderer-devel] [PATCH] virgl: Add method to query supported MSAA samples and positions
Jakob Bornecrantz
jakob at collabora.com
Wed Jun 27 17:14:57 UTC 2018
On 2018-06-25 15:57, Gert Wollny wrote:
> Query the number of supported samples and the sample position and
> store these to the caps.v2 structure. We support only up to 16 samples.
> This implementation requires a GL host backend.
>
This patch uses functions that are not available in GLES causing qemu to
crash on startup with this patch applied.
vrend_formats also seems to have two space as indentations instead of
the rest of the files 3, not sure what is the way forward here.
Cheers, Jakob.
> Signed-off-by: Gert Wollny <gert.wollny at collabora.com>
> ---
> This patch needs another patch against mesa/virgl.
>
> src/virgl_hw.h | 1 +
> src/vrend_formats.c | 48 +++++++++++++++++++++++++++++++++++++++++++-
> src/vrend_renderer.c | 2 +-
> src/vrend_renderer.h | 3 +++
> 4 files changed, 52 insertions(+), 2 deletions(-)
>
> diff --git a/src/virgl_hw.h b/src/virgl_hw.h
> index 27b1a25..84bdfaa 100644
> --- a/src/virgl_hw.h
> +++ b/src/virgl_hw.h
> @@ -312,6 +312,7 @@ struct virgl_caps_v2 {
> uint32_t uniform_buffer_offset_alignment;
> uint32_t shader_buffer_offset_alignment;
> uint32_t capability_bits;
> + uint32_t sample_locations[8];
> };
>
> union virgl_caps {
> diff --git a/src/vrend_formats.c b/src/vrend_formats.c
> index 0bb23c4..d1e18a6 100644
> --- a/src/vrend_formats.c
> +++ b/src/vrend_formats.c
> @@ -467,4 +467,50 @@ bool vrend_is_canonical_format(enum pipe_format format)
> default:
> return false;
> }
> -}
> \ No newline at end of file
> +}
> +
> +unsigned vrend_renderer_query_multisample_caps(unsigned max_samples, struct virgl_caps_v2 *caps)
> +{
> + GLuint tex;
> + GLuint fbo;
> + GLenum status;
> +
> + uint i;
> + uint max_samples_confirmed = 1;
> + uint test_num_samples[4] = {2,4,8,16};
> + int offsets[4] = {0,1,2,4};
> +
> + glGenTextures( 1, &tex );
> + glGenFramebuffers( 1, &fbo );
> +
> + memset(caps->sample_locations, 0, 8 * sizeof(uint32_t));
> +
> + for (int i = 0; i < 4 && test_num_samples[i] <= max_samples; ++i) {
> +
> + glBindTexture( GL_TEXTURE_2D_MULTISAMPLE, tex );
> + glTexImage2DMultisample( GL_TEXTURE_2D_MULTISAMPLE, test_num_samples[i], GL_RGBA32F, 10, 10, GL_TRUE);
> + status = glGetError();
> +
> + if (status == GL_NO_ERROR) {
> + glBindFramebuffer( GL_FRAMEBUFFER, fbo );
> + glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, tex, 0 );
> + status = glCheckFramebufferStatus( GL_FRAMEBUFFER );
> + if (status == GL_FRAMEBUFFER_COMPLETE) {
> + max_samples_confirmed = test_num_samples[i];
> +
> + for (uint k = 0; k < test_num_samples[i]; ++k) {
> + float msp[2];
> + uint32_t compressed;
> + glGetMultisamplefv(GL_SAMPLE_POSITION, k, msp);
> + compressed = ((unsigned)(floor(msp[0] * 16.0f)) & 0xf) << 4;
> + compressed |= ((unsigned)(floor(msp[1] * 16.0f)) & 0xf);
> + caps->sample_locations[offsets[i] + (k >> 2)] |= compressed << (8 * (k & 3));
> + }
> + }
> + }
> + }
> +
> + glDeleteFramebuffers( 1, &fbo );
> + glDeleteTextures( 1, &tex );
> + return max_samples_confirmed;
> +}
> diff --git a/src/vrend_renderer.c b/src/vrend_renderer.c
> index 8690eb2..7074cad 100644
> --- a/src/vrend_renderer.c
> +++ b/src/vrend_renderer.c
> @@ -7142,7 +7142,7 @@ static bool vrend_renderer_fill_caps_common(uint32_t set, UNUSED uint32_t versio
> caps->v1.max_render_targets = vrend_state.max_draw_buffers;
>
> glGetIntegerv(GL_MAX_SAMPLES, &max);
> - caps->v1.max_samples = max;
> + caps->v1.max_samples = vrend_renderer_query_multisample_caps(max, &caps->v2);
>
>
> /* All of the formats are common. */
> diff --git a/src/vrend_renderer.h b/src/vrend_renderer.h
> index badf2b1..254edc7 100644
> --- a/src/vrend_renderer.h
> +++ b/src/vrend_renderer.h
> @@ -390,6 +390,9 @@ void vrend_renderer_reset(void);
> int vrend_renderer_get_poll_fd(void);
> void vrend_decode_reset(bool ctx_0_only);
>
> +unsigned vrend_renderer_query_multisample_caps(unsigned max_samples,
> + struct virgl_caps_v2 *caps);
> +
> struct gl_version {
> uint32_t major;
> uint32_t minor;
>
More information about the virglrenderer-devel
mailing list