i965: Put '_default_' in the name of functions that set default state.
[mesa.git] / src / mesa / drivers / dri / i965 / brw_meta_updownsample.c
index de25bf4f7aaa476c85fa7221c4025fdc8e3540cf..21507b1ad2a879c9d41e3bd75784f255d521b8fe 100644 (file)
@@ -27,6 +27,7 @@
 
 #include "main/blit.h"
 #include "main/buffers.h"
+#include "main/enums.h"
 #include "main/fbobject.h"
 
 #include "drivers/common/meta.h"
  *
  * Clobbers the current renderbuffer binding (ctx->CurrentRenderbuffer).
  */
-static GLuint
-brw_get_rb_for_first_slice(struct brw_context *brw, struct intel_mipmap_tree *mt)
+GLuint
+brw_get_rb_for_slice(struct brw_context *brw,
+                     struct intel_mipmap_tree *mt,
+                     unsigned level, unsigned layer, bool flat)
 {
    struct gl_context *ctx = &brw->ctx;
    GLuint rbo;
@@ -62,11 +65,27 @@ brw_get_rb_for_first_slice(struct brw_context *brw, struct intel_mipmap_tree *mt
    irb = intel_renderbuffer(rb);
 
    rb->Format = mt->format;
-   rb->_BaseFormat = _mesa_base_fbo_format(ctx, mt->format);
+   rb->_BaseFormat = _mesa_get_format_base_format(mt->format);
 
-   rb->NumSamples = mt->num_samples;
-   rb->Width = mt->logical_width0;
-   rb->Height = mt->logical_height0;
+   /* Program takes care of msaa and mip-level access manually for stencil.
+    * The surface is also treated as Y-tiled instead of as W-tiled calling for
+    * twice the width and half the height in dimensions.
+    */
+   if (flat) {
+      const unsigned halign_stencil = 8;
+
+      rb->NumSamples = 0;
+      rb->Width = ALIGN(mt->total_width, halign_stencil) * 2;
+      rb->Height = (mt->total_height / mt->physical_depth0) / 2;
+      irb->mt_level = 0;
+   } else {
+      rb->NumSamples = mt->num_samples;
+      rb->Width = mt->logical_width0;
+      rb->Height = mt->logical_height0;
+      irb->mt_level = level;
+   }
+
+   irb->mt_layer = layer;
 
    intel_miptree_reference(&irb->mt, mt);
 
@@ -101,8 +120,8 @@ brw_meta_updownsample(struct brw_context *brw,
 
    _mesa_meta_begin(ctx, MESA_META_ALL);
    _mesa_GenFramebuffers(2, fbos);
-   src_rbo = brw_get_rb_for_first_slice(brw, src_mt);
-   dst_rbo = brw_get_rb_for_first_slice(brw, dst_mt);
+   src_rbo = brw_get_rb_for_slice(brw, src_mt, 0, 0, false);
+   dst_rbo = brw_get_rb_for_slice(brw, dst_mt, 0, 0, false);
    src_fbo = fbos[0];
    dst_fbo = fbos[1];