[Mesa-dev] [PATCH 4/8] mesa: add gl_renderbuffer::NumStorageSamples
Marek Olšák
maraeo at gmail.com
Wed Aug 1 23:26:00 UTC 2018
From: Marek Olšák <marek.olsak at amd.com>
---
src/mesa/drivers/dri/i965/intel_fbo.c | 2 ++
src/mesa/main/fbobject.c | 25 +++++++++++++++++--------
src/mesa/main/mtypes.h | 1 +
src/mesa/state_tracker/st_cb_fbo.c | 4 +++-
4 files changed, 23 insertions(+), 9 deletions(-)
diff --git a/src/mesa/drivers/dri/i965/intel_fbo.c b/src/mesa/drivers/dri/i965/intel_fbo.c
index e6825955b0e..4ad27474100 100644
--- a/src/mesa/drivers/dri/i965/intel_fbo.c
+++ b/src/mesa/drivers/dri/i965/intel_fbo.c
@@ -283,20 +283,21 @@ intel_alloc_private_renderbuffer_storage(struct gl_context * ctx, struct gl_rend
GLenum internalFormat,
GLuint width, GLuint height)
{
struct brw_context *brw = brw_context(ctx);
struct intel_screen *screen = brw->screen;
struct intel_renderbuffer *irb = intel_renderbuffer(rb);
assert(rb->Format != MESA_FORMAT_NONE);
rb->NumSamples = intel_quantize_num_samples(screen, rb->NumSamples);
+ rb->NumStorageSamples = rb->NumSamples;
rb->Width = width;
rb->Height = height;
rb->_BaseFormat = _mesa_get_format_base_format(rb->Format);
intel_miptree_release(&irb->mt);
DBG("%s: %s: %s (%dx%d)\n", __func__,
_mesa_enum_to_string(internalFormat),
_mesa_get_format_name(rb->Format), width, height);
@@ -426,20 +427,21 @@ intel_create_winsys_renderbuffer(struct intel_screen *screen,
struct intel_renderbuffer *irb = CALLOC_STRUCT(intel_renderbuffer);
if (!irb)
return NULL;
struct gl_renderbuffer *rb = &irb->Base.Base;
irb->layer_count = 1;
_mesa_init_renderbuffer(rb, 0);
rb->ClassID = INTEL_RB_CLASS;
rb->NumSamples = num_samples;
+ rb->NumStorageSamples = num_samples;
/* The base format and internal format must be derived from the user-visible
* format (that is, the gl_config's format), even if we internally use
* choose a different format for the renderbuffer. Otherwise, rendering may
* use incorrect channel write masks.
*/
rb->_BaseFormat = _mesa_get_format_base_format(format);
rb->InternalFormat = rb->_BaseFormat;
rb->Format = format;
diff --git a/src/mesa/main/fbobject.c b/src/mesa/main/fbobject.c
index f63902c9dd4..3ed303b51ab 100644
--- a/src/mesa/main/fbobject.c
+++ b/src/mesa/main/fbobject.c
@@ -474,20 +474,21 @@ _mesa_update_texture_renderbuffer(struct gl_context *ctx,
if (!texImage)
return;
rb->_BaseFormat = texImage->_BaseFormat;
rb->Format = texImage->TexFormat;
rb->InternalFormat = texImage->InternalFormat;
rb->Width = texImage->Width2;
rb->Height = texImage->Height2;
rb->Depth = texImage->Depth2;
rb->NumSamples = texImage->NumSamples;
+ rb->NumStorageSamples = texImage->NumSamples;
rb->TexImage = texImage;
if (driver_RenderTexture_is_safe(att))
ctx->Driver.RenderTexture(ctx, fb, att);
}
/**
* Bind a texture object to an attachment point.
* The previous binding, if any, will be removed first.
*/
@@ -2230,48 +2231,51 @@ _mesa_renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
assert(_mesa_check_sample_count(ctx, GL_RENDERBUFFER,
internalFormat, samples,
storageSamples) == GL_NO_ERROR);
}
FLUSH_VERTICES(ctx, _NEW_BUFFERS);
if (rb->InternalFormat == internalFormat &&
rb->Width == (GLuint) width &&
rb->Height == (GLuint) height &&
- rb->NumSamples == samples) {
+ rb->NumSamples == samples &&
+ rb->NumStorageSamples == storageSamples) {
/* no change in allocation needed */
return;
}
/* These MUST get set by the AllocStorage func */
rb->Format = MESA_FORMAT_NONE;
rb->NumSamples = samples;
+ rb->NumStorageSamples = storageSamples;
/* Now allocate the storage */
assert(rb->AllocStorage);
if (rb->AllocStorage(ctx, rb, internalFormat, width, height)) {
/* No error - check/set fields now */
/* If rb->Format == MESA_FORMAT_NONE, the format is unsupported. */
assert(rb->Width == (GLuint) width);
assert(rb->Height == (GLuint) height);
rb->InternalFormat = internalFormat;
rb->_BaseFormat = baseFormat;
assert(rb->_BaseFormat != 0);
}
else {
/* Probably ran out of memory - clear the fields */
rb->Width = 0;
rb->Height = 0;
rb->Format = MESA_FORMAT_NONE;
rb->InternalFormat = GL_NONE;
rb->_BaseFormat = GL_NONE;
rb->NumSamples = 0;
+ rb->NumStorageSamples = 0;
}
/* Invalidate the framebuffers the renderbuffer is attached in. */
if (rb->AttachedAnytime) {
_mesa_HashWalk(ctx->Shared->FrameBuffers, invalidate_rb, rb);
}
}
/**
* Helper function used by renderbuffer_storage_direct() and
@@ -2577,33 +2581,38 @@ get_render_buffer_parameteriv(struct gl_context *ctx,
case GL_RENDERBUFFER_INTERNAL_FORMAT_EXT:
*params = rb->InternalFormat;
return;
case GL_RENDERBUFFER_RED_SIZE_EXT:
case GL_RENDERBUFFER_GREEN_SIZE_EXT:
case GL_RENDERBUFFER_BLUE_SIZE_EXT:
case GL_RENDERBUFFER_ALPHA_SIZE_EXT:
case GL_RENDERBUFFER_DEPTH_SIZE_EXT:
case GL_RENDERBUFFER_STENCIL_SIZE_EXT:
*params = get_component_bits(pname, rb->_BaseFormat, rb->Format);
- break;
+ return;
case GL_RENDERBUFFER_SAMPLES:
if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_framebuffer_object)
|| _mesa_is_gles3(ctx)) {
*params = rb->NumSamples;
- break;
+ return;
}
- /* fallthrough */
- default:
- _mesa_error(ctx, GL_INVALID_ENUM, "%s(invalid pname=%s)", func,
- _mesa_enum_to_string(pname));
- return;
+ break;
+ case GL_RENDERBUFFER_STORAGE_SAMPLES_AMD:
+ if (ctx->Extensions.AMD_framebuffer_multisample_advanced) {
+ *params = rb->NumStorageSamples;
+ return;
+ }
+ break;
}
+
+ _mesa_error(ctx, GL_INVALID_ENUM, "%s(invalid pname=%s)", func,
+ _mesa_enum_to_string(pname));
}
void GLAPIENTRY
_mesa_GetRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
{
GET_CURRENT_CONTEXT(ctx);
if (target != GL_RENDERBUFFER_EXT) {
_mesa_error(ctx, GL_INVALID_ENUM,
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index f707e1629a5..202268e710b 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -3329,20 +3329,21 @@ struct gl_renderbuffer
/**
* True for renderbuffers that wrap textures, giving the driver a chance to
* flush render caches through the FinishRenderTexture hook.
*
* Drivers may also set this on renderbuffers other than those generated by
* glFramebufferTexture(), though it means FinishRenderTexture() would be
* called without a rb->TexImage.
*/
GLboolean NeedsFinishRenderTexture;
GLubyte NumSamples; /**< zero means not multisampled */
+ GLubyte NumStorageSamples; /**< for AMD_framebuffer_multisample_advanced */
GLenum16 InternalFormat; /**< The user-specified format */
GLenum16 _BaseFormat; /**< Either GL_RGB, GL_RGBA, GL_DEPTH_COMPONENT or
GL_STENCIL_INDEX. */
mesa_format Format; /**< The actual renderbuffer memory format */
/**
* Pointer to the texture image if this renderbuffer wraps a texture,
* otherwise NULL.
*
* Note that the reference on the gl_texture_object containing this
* TexImage is held by the gl_renderbuffer_attachment.
diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c
index 73414fdfa15..2bb910fcecd 100644
--- a/src/mesa/state_tracker/st_cb_fbo.c
+++ b/src/mesa/state_tracker/st_cb_fbo.c
@@ -166,20 +166,21 @@ st_renderbuffer_alloc_storage(struct gl_context * ctx,
start = 2;
} else {
start = rb->NumSamples;
}
for (i = start; i <= ctx->Const.MaxSamples; i++) {
format = st_choose_renderbuffer_format(st, internalFormat, i);
if (format != PIPE_FORMAT_NONE) {
rb->NumSamples = i;
+ rb->NumStorageSamples = i;
break;
}
}
} else {
format = st_choose_renderbuffer_format(st, internalFormat, 0);
}
/* Not setting gl_renderbuffer::Format here will cause
* FRAMEBUFFER_UNSUPPORTED and ValidateFramebuffer will not be called.
*/
@@ -197,21 +198,21 @@ st_renderbuffer_alloc_storage(struct gl_context * ctx,
/* Setup new texture template.
*/
memset(&templ, 0, sizeof(templ));
templ.target = st->internal_target;
templ.format = format;
templ.width0 = width;
templ.height0 = height;
templ.depth0 = 1;
templ.array_size = 1;
templ.nr_samples = rb->NumSamples;
- templ.nr_storage_samples = rb->NumSamples;
+ templ.nr_storage_samples = rb->NumStorageSamples;
if (util_format_is_depth_or_stencil(format)) {
templ.bind = PIPE_BIND_DEPTH_STENCIL;
}
else if (strb->Base.Name != 0) {
/* this is a user-created renderbuffer */
templ.bind = PIPE_BIND_RENDER_TARGET;
}
else {
/* this is a window-system buffer */
@@ -277,20 +278,21 @@ st_new_renderbuffer_fb(enum pipe_format format, unsigned samples, boolean sw)
strb = ST_CALLOC_STRUCT(st_renderbuffer);
if (!strb) {
_mesa_error(NULL, GL_OUT_OF_MEMORY, "creating renderbuffer");
return NULL;
}
_mesa_init_renderbuffer(&strb->Base, 0);
strb->Base.ClassID = 0x4242; /* just a unique value */
strb->Base.NumSamples = samples;
+ strb->Base.NumStorageSamples = samples;
strb->Base.Format = st_pipe_format_to_mesa_format(format);
strb->Base._BaseFormat = _mesa_get_format_base_format(strb->Base.Format);
strb->software = sw;
switch (format) {
case PIPE_FORMAT_B10G10R10A2_UNORM:
case PIPE_FORMAT_R10G10B10A2_UNORM:
strb->Base.InternalFormat = GL_RGB10_A2;
break;
case PIPE_FORMAT_R10G10B10X2_UNORM:
--
2.17.1
More information about the mesa-dev
mailing list