- struct pipe_resource *resource = strb->rtt->pt;
- int rtt_width = strb->Base.Width;
- int rtt_height = strb->Base.Height;
-
- if (!strb->surface ||
- strb->surface->texture != resource ||
- strb->surface->width != rtt_width ||
- strb->surface->height != rtt_height) {
- GLuint level;
- /* find matching mipmap level size */
- for (level = 0; level <= resource->last_level; level++) {
- if (u_minify(resource->width0, level) == rtt_width &&
- u_minify(resource->height0, level) == rtt_height) {
-
- pipe_surface_reference(&strb->surface, NULL);
-
- strb->surface = screen->get_tex_surface(screen,
- resource,
- strb->rtt_face,
- level,
- strb->rtt_slice,
- PIPE_BIND_RENDER_TARGET |
- PIPE_BIND_BLIT_SOURCE |
- PIPE_BIND_BLIT_DESTINATION );
-#if 0
- printf("-- alloc new surface %d x %d into tex %p\n",
- strb->surface->width, strb->surface->height,
- texture);
-#endif
- break;
- }
- }
+ int quantized_samples = 0;
+ unsigned msaa_mode;
+
+ if (!num_samples)
+ return 0;
+
+ /* Assumes the highest supported MSAA is a power of 2 */
+ msaa_mode = util_next_power_of_two(st->ctx->Const.MaxFramebufferSamples);
+ assert(!(num_samples > msaa_mode)); /* be safe from infinite loops */
+
+ /**
+ * Check if the MSAA mode that is higher than the requested
+ * num_samples is supported, and if so returning it.
+ */
+ for (; msaa_mode >= num_samples; msaa_mode = msaa_mode / 2) {
+ /**
+ * For ARB_framebuffer_no_attachment, A format of
+ * PIPE_FORMAT_NONE implies what number of samples is
+ * supported for a framebuffer with no attachment. Thus the
+ * drivers callback must be adjusted for this.
+ */
+ if (screen->is_format_supported(screen, PIPE_FORMAT_NONE,
+ PIPE_TEXTURE_2D, msaa_mode, msaa_mode,
+ PIPE_BIND_RENDER_TARGET))
+ quantized_samples = msaa_mode;