i965/vec4: Make with_writemask() non-static.
[mesa.git] / src / mesa / drivers / dri / i965 / intel_context.c
index 626eab723d21bb656e169e55479ba29dd40684fe..4f969898e05486b8fefe16732e897de49c8bd8bf 100644 (file)
@@ -94,8 +94,7 @@ void
 intel_resolve_for_dri2_flush(struct brw_context *brw,
                              __DRIdrawable *drawable)
 {
-   struct intel_context *intel = &brw->intel;
-   if (intel->gen < 6) {
+   if (brw->gen < 6) {
       /* MSAA and fast color clear are not supported, so don't waste time
        * checking whether a resolve is needed.
        */
@@ -145,6 +144,7 @@ intel_flush_front(struct gl_context *ctx)
           * performance.
           */
          intel_resolve_for_dri2_flush(brw, driDrawable);
+         intel_batchbuffer_flush(brw);
 
          screen->dri2.loader->flushFrontBuffer(driDrawable,
                                                driDrawable->loaderPrivate);
@@ -182,7 +182,6 @@ intel_update_renderbuffers(__DRIcontext *context, __DRIdrawable *drawable)
    struct gl_framebuffer *fb = drawable->driverPrivate;
    struct intel_renderbuffer *rb;
    struct brw_context *brw = context->driverPrivate;
-   struct intel_context *intel = &brw->intel;
    __DRIbuffer *buffers = NULL;
    int i, count;
    const char *region_name;
@@ -232,7 +231,7 @@ intel_update_renderbuffers(__DRIcontext *context, __DRIdrawable *drawable)
        intel_process_dri2_buffer(brw, drawable, &buffers[i], rb, region_name);
    }
 
-   driUpdateFramebufferSize(&intel->ctx, drawable);
+   driUpdateFramebufferSize(&brw->ctx, drawable);
 }
 
 /**
@@ -290,6 +289,21 @@ intel_prepare_render(struct brw_context *brw)
    }
 }
 
+static void
+intel_viewport(struct gl_context *ctx, GLint x, GLint y, GLsizei w, GLsizei h)
+{
+    struct brw_context *brw = brw_context(ctx);
+    __DRIcontext *driContext = brw->driContext;
+
+    if (brw->saved_viewport)
+       brw->saved_viewport(ctx, x, y, w, h);
+
+    if (_mesa_is_winsys_fbo(ctx->DrawBuffer)) {
+       dri2InvalidateDrawable(driContext->driDrawablePriv);
+       dri2InvalidateDrawable(driContext->driReadablePriv);
+    }
+}
+
 static const struct dri_debug_control debug_control[] = {
    { "tex",   DEBUG_TEXTURE},
    { "state", DEBUG_STATE},
@@ -319,6 +333,7 @@ static const struct dri_debug_control debug_control[] = {
    { "shader_time", DEBUG_SHADER_TIME },
    { "no16",  DEBUG_NO16 },
    { "blorp", DEBUG_BLORP },
+   { "vue",   DEBUG_VUE },
    { NULL,    0 }
 };
 
@@ -335,21 +350,12 @@ intelInvalidateState(struct gl_context * ctx, GLuint new_state)
    brw->NewGLState |= new_state;
 }
 
-void
-_intel_flush(struct gl_context *ctx, const char *file, int line)
-{
-   struct brw_context *brw = brw_context(ctx);
-
-   if (brw->batch.used)
-      _intel_batchbuffer_flush(brw, file, line);
-}
-
 static void
 intel_glFlush(struct gl_context *ctx)
 {
    struct brw_context *brw = brw_context(ctx);
 
-   intel_flush(ctx);
+   intel_batchbuffer_flush(brw);
    intel_flush_front(ctx);
    if (brw->is_front_buffer_rendering)
       brw->need_throttle = true;
@@ -360,8 +366,7 @@ intelFinish(struct gl_context * ctx)
 {
    struct brw_context *brw = brw_context(ctx);
 
-   intel_flush(ctx);
-   intel_flush_front(ctx);
+   intel_glFlush(ctx);
 
    if (brw->batch.last_bo)
       drm_intel_bo_wait_rendering(brw->batch.last_bo);
@@ -386,6 +391,7 @@ intelInitDriverFunctions(struct dd_function_table *functions)
    intelInitPixelFuncs(functions);
    intelInitBufferObjectFuncs(functions);
    intel_init_syncobj_functions(functions);
+   brw_init_object_purgeable_functions(functions);
 }
 
 static bool
@@ -438,8 +444,7 @@ intelInitContext(struct brw_context *brw,
                  struct dd_function_table *functions,
                  unsigned *dri_ctx_error)
 {
-   struct intel_context *intel = &brw->intel;
-   struct gl_context *ctx = &intel->ctx;
+   struct gl_context *ctx = &brw->ctx;
    struct gl_context *shareCtx = (struct gl_context *) sharedContextPrivate;
    __DRIscreen *sPriv = driContextPriv->driScreenPriv;
    struct intel_screen *intelScreen = sPriv->driverPrivate;
@@ -457,14 +462,21 @@ intelInitContext(struct brw_context *brw,
                                  dri_ctx_error))
       return false;
 
+   /* Can't rely on invalidate events, fall back to glViewport hack */
+   if (!driContextPriv->driScreenPriv->dri2.useInvalidate) {
+      brw->saved_viewport = functions->Viewport;
+      functions->Viewport = intel_viewport;
+   }
+
    if (mesaVis == NULL) {
       memset(&visual, 0, sizeof visual);
       mesaVis = &visual;
    }
 
    brw->intelScreen = intelScreen;
+   brw->bufmgr = intelScreen->bufmgr;
 
-   if (!_mesa_initialize_context(&intel->ctx, api, mesaVis, shareCtx,
+   if (!_mesa_initialize_context(&brw->ctx, api, mesaVis, shareCtx,
                                  functions)) {
       *dri_ctx_error = __DRI_CTX_ERROR_NO_MEMORY;
       printf("%s: failed to init mesa context\n", __FUNCTION__);
@@ -474,32 +486,32 @@ intelInitContext(struct brw_context *brw,
    driContextPriv->driverPrivate = brw;
    brw->driContext = driContextPriv;
 
-   intel->gen = intelScreen->gen;
+   brw->gen = intelScreen->gen;
 
    const int devID = intelScreen->deviceID;
    if (IS_SNB_GT1(devID) || IS_IVB_GT1(devID) || IS_HSW_GT1(devID))
-      intel->gt = 1;
+      brw->gt = 1;
    else if (IS_SNB_GT2(devID) || IS_IVB_GT2(devID) || IS_HSW_GT2(devID))
-      intel->gt = 2;
+      brw->gt = 2;
    else if (IS_HSW_GT3(devID))
-      intel->gt = 3;
+      brw->gt = 3;
    else
-      intel->gt = 0;
+      brw->gt = 0;
 
    if (IS_HASWELL(devID)) {
-      intel->is_haswell = true;
+      brw->is_haswell = true;
    } else if (IS_BAYTRAIL(devID)) {
-      intel->is_baytrail = true;
-      intel->gt = 1;
+      brw->is_baytrail = true;
+      brw->gt = 1;
    } else if (IS_G4X(devID)) {
-      intel->is_g4x = true;
+      brw->is_g4x = true;
    }
 
-   intel->has_separate_stencil = brw->intelScreen->hw_has_separate_stencil;
-   intel->must_use_separate_stencil = brw->intelScreen->hw_must_use_separate_stencil;
-   intel->has_hiz = intel->gen >= 6;
-   intel->has_llc = brw->intelScreen->hw_has_llc;
-   intel->has_swizzling = brw->intelScreen->hw_has_swizzling;
+   brw->has_separate_stencil = brw->intelScreen->hw_has_separate_stencil;
+   brw->must_use_separate_stencil = brw->intelScreen->hw_must_use_separate_stencil;
+   brw->has_hiz = brw->gen >= 6;
+   brw->has_llc = brw->intelScreen->hw_has_llc;
+   brw->has_swizzling = brw->intelScreen->hw_has_swizzling;
 
    memset(&ctx->TextureFormatSupported,
          0, sizeof(ctx->TextureFormatSupported));
@@ -522,8 +534,6 @@ intelInitContext(struct brw_context *brw,
     */
    brw->max_gtt_map_object_size = gtt_size / 4;
 
-   brw->bufmgr = intelScreen->bufmgr;
-
    bo_reuse_mode = driQueryOptioni(&brw->optionCache, "bo_reuse");
    switch (bo_reuse_mode) {
    case DRI_CONF_BO_REUSE_DISABLED:
@@ -539,7 +549,7 @@ intelInitContext(struct brw_context *brw,
     * software fallbacks (which we have to support on legacy GL to do weird
     * glDrawPixels(), glBitmap(), and other functions).
     */
-   if (api != API_OPENGL_CORE) {
+   if (api != API_OPENGL_CORE && api != API_OPENGLES2) {
       _swrast_CreateContext(ctx);
    }
 
@@ -560,7 +570,7 @@ intelInitContext(struct brw_context *brw,
    INTEL_DEBUG = driParseDebugString(getenv("INTEL_DEBUG"), debug_control);
    if (INTEL_DEBUG & DEBUG_BUFMGR)
       dri_bufmgr_set_debug(brw->bufmgr, true);
-   if ((INTEL_DEBUG & DEBUG_SHADER_TIME) && intel->gen < 7) {
+   if ((INTEL_DEBUG & DEBUG_SHADER_TIME) && brw->gen < 7) {
       fprintf(stderr,
               "shader_time debugging requires gen7 (Ivybridge) or better.\n");
       INTEL_DEBUG &= ~DEBUG_SHADER_TIME;
@@ -576,10 +586,10 @@ intelInitContext(struct brw_context *brw,
    intel_fbo_init(brw);
 
    if (!driQueryOptionb(&brw->optionCache, "hiz")) {
-       intel->has_hiz = false;
+       brw->has_hiz = false;
        /* On gen6, you can only do separate stencil with HIZ. */
-       if (intel->gen == 6)
-         intel->has_separate_stencil = false;
+       if (brw->gen == 6)
+         brw->has_separate_stencil = false;
    }
 
    if (driQueryOptionb(&brw->optionCache, "always_flush_batch")) {
@@ -605,29 +615,28 @@ intelDestroyContext(__DRIcontext * driContextPriv)
 {
    struct brw_context *brw =
       (struct brw_context *) driContextPriv->driverPrivate;
-   struct intel_context *intel = &brw->intel;
-   struct gl_context *ctx = &intel->ctx;
+   struct gl_context *ctx = &brw->ctx;
 
-   assert(intel);               /* should never be null */
-   if (intel) {
+   assert(brw); /* should never be null */
+   if (brw) {
       /* Dump a final BMP in case the application doesn't call SwapBuffers */
       if (INTEL_DEBUG & DEBUG_AUB) {
          intel_batchbuffer_flush(brw);
-        aub_dump_bmp(&intel->ctx);
+        aub_dump_bmp(&brw->ctx);
       }
 
-      _mesa_meta_free(&intel->ctx);
+      _mesa_meta_free(&brw->ctx);
 
       brw->vtbl.destroy(brw);
 
       if (ctx->swrast_context) {
-         _swsetup_DestroyContext(&intel->ctx);
-         _tnl_DestroyContext(&intel->ctx);
+         _swsetup_DestroyContext(&brw->ctx);
+         _tnl_DestroyContext(&brw->ctx);
       }
-      _vbo_DestroyContext(&intel->ctx);
+      _vbo_DestroyContext(&brw->ctx);
 
       if (ctx->swrast_context)
-         _swrast_DestroyContext(&intel->ctx);
+         _swrast_DestroyContext(&brw->ctx);
 
       intel_batchbuffer_free(brw);
 
@@ -637,9 +646,9 @@ intelDestroyContext(__DRIcontext * driContextPriv)
       driDestroyOptionCache(&brw->optionCache);
 
       /* free the Mesa context */
-      _mesa_free_context_data(&intel->ctx);
+      _mesa_free_context_data(&brw->ctx);
 
-      ralloc_free(intel);
+      ralloc_free(brw);
       driContextPriv->driverPrivate = NULL;
    }
 }
@@ -685,8 +694,7 @@ static void
 intel_gles3_srgb_workaround(struct brw_context *brw,
                             struct gl_framebuffer *fb)
 {
-   struct intel_context *intel = &brw->intel;
-   struct gl_context *ctx = &intel->ctx;
+   struct gl_context *ctx = &brw->ctx;
 
    if (_mesa_is_desktop_gl(ctx) || !fb->Visual.sRGBCapable)
       return;
@@ -724,10 +732,8 @@ intelMakeCurrent(__DRIcontext * driContextPriv,
       _mesa_flush(curCtx);
    }
 
-   struct intel_context *intel = &brw->intel;
-
    if (driContextPriv) {
-      struct gl_context *ctx = &intel->ctx;
+      struct gl_context *ctx = &brw->ctx;
       struct gl_framebuffer *fb, *readFb;
       
       if (driDrawPriv == NULL && driReadPriv == NULL) {
@@ -740,11 +746,15 @@ intelMakeCurrent(__DRIcontext * driContextPriv,
         driContextPriv->dri2.read_stamp = driReadPriv->dri2.stamp - 1;
       }
 
+      /* The sRGB workaround changes the renderbuffer's format. We must change
+       * the format before the renderbuffer's miptree get's allocated, otherwise
+       * the formats of the renderbuffer and its miptree will differ.
+       */
+      intel_gles3_srgb_workaround(brw, fb);
+      intel_gles3_srgb_workaround(brw, readFb);
+
       intel_prepare_render(brw);
       _mesa_make_current(ctx, fb, readFb);
-
-      intel_gles3_srgb_workaround(brw, ctx->WinSysDrawBuffer);
-      intel_gles3_srgb_workaround(brw, ctx->WinSysReadBuffer);
    }
    else {
       _mesa_make_current(NULL, NULL, NULL);
@@ -776,7 +786,6 @@ intel_query_dri2_buffers(struct brw_context *brw,
                         __DRIbuffer **buffers,
                         int *buffer_count)
 {
-   struct intel_context *intel = &brw->intel;
    __DRIscreen *screen = brw->intelScreen->driScrnPriv;
    struct gl_framebuffer *fb = drawable->driverPrivate;
    int i = 0;
@@ -798,8 +807,8 @@ intel_query_dri2_buffers(struct brw_context *brw,
        * query, we need to make sure all the pending drawing has landed in the
        * real front buffer.
        */
-      intel_flush(&intel->ctx);
-      intel_flush_front(&intel->ctx);
+      intel_batchbuffer_flush(brw);
+      intel_flush_front(&brw->ctx);
 
       attachments[i++] = __DRI_BUFFER_FRONT_LEFT;
       attachments[i++] = intel_bits_per_pixel(front_rb);
@@ -810,8 +819,8 @@ intel_query_dri2_buffers(struct brw_context *brw,
        * So before doing the query, make sure all the pending drawing has
        * landed in the real front buffer.
        */
-      intel_flush(&intel->ctx);
-      intel_flush_front(&intel->ctx);
+      intel_batchbuffer_flush(brw);
+      intel_flush_front(&brw->ctx);
    }
 
    if (back_rb) {