mesa/st: make sure we remove dead IO variables before handing NIR to backends
[mesa.git] / src / mesa / state_tracker / st_cb_eglimage.c
index e15b32ff199bef7969d7ab67c81c59901c512bd5..4a58f2f48df055120619751fbdd3776de404eb0d 100644 (file)
 
 static bool
 is_format_supported(struct pipe_screen *screen, enum pipe_format format,
-                    unsigned nr_samples, unsigned usage)
+                    unsigned nr_samples, unsigned nr_storage_samples,
+                    unsigned usage)
 {
    bool supported = screen->is_format_supported(screen, format, PIPE_TEXTURE_2D,
-                                                nr_samples, usage);
+                                                nr_samples, nr_storage_samples,
+                                                usage);
 
    /* for sampling, some formats can be emulated.. it doesn't matter that
     * the surface will have a format that the driver can't cope with because
@@ -52,17 +54,56 @@ is_format_supported(struct pipe_screen *screen, enum pipe_format format,
     * a shader variant that converts.
     */
    if ((usage == PIPE_BIND_SAMPLER_VIEW) && !supported) {
-      if (format == PIPE_FORMAT_IYUV) {
+      switch (format) {
+      case PIPE_FORMAT_IYUV:
          supported = screen->is_format_supported(screen, PIPE_FORMAT_R8_UNORM,
                                                  PIPE_TEXTURE_2D, nr_samples,
-                                                 usage);
-      } else if (format == PIPE_FORMAT_NV12) {
+                                                 nr_storage_samples, usage);
+         break;
+      case PIPE_FORMAT_NV12:
          supported = screen->is_format_supported(screen, PIPE_FORMAT_R8_UNORM,
                                                  PIPE_TEXTURE_2D, nr_samples,
-                                                 usage) &&
+                                                 nr_storage_samples, usage) &&
                      screen->is_format_supported(screen, PIPE_FORMAT_R8G8_UNORM,
                                                  PIPE_TEXTURE_2D, nr_samples,
-                                                 usage);
+                                                 nr_storage_samples, usage);
+         break;
+      case PIPE_FORMAT_P016:
+         supported = screen->is_format_supported(screen, PIPE_FORMAT_R16_UNORM,
+                                                 PIPE_TEXTURE_2D, nr_samples,
+                                                 nr_storage_samples, usage) &&
+                     screen->is_format_supported(screen, PIPE_FORMAT_R16G16_UNORM,
+                                                 PIPE_TEXTURE_2D, nr_samples,
+                                                 nr_storage_samples, usage);
+         break;
+      case PIPE_FORMAT_YUYV:
+         supported = screen->is_format_supported(screen, PIPE_FORMAT_RG88_UNORM,
+                                                 PIPE_TEXTURE_2D, nr_samples,
+                                                 nr_storage_samples, usage) &&
+                     screen->is_format_supported(screen, PIPE_FORMAT_BGRA8888_UNORM,
+                                                 PIPE_TEXTURE_2D, nr_samples,
+                                                 nr_storage_samples, usage);
+         break;
+      case PIPE_FORMAT_UYVY:
+         supported = screen->is_format_supported(screen, PIPE_FORMAT_RG88_UNORM,
+                                                 PIPE_TEXTURE_2D, nr_samples,
+                                                 nr_storage_samples, usage) &&
+                     screen->is_format_supported(screen, PIPE_FORMAT_RGBA8888_UNORM,
+                                                 PIPE_TEXTURE_2D, nr_samples,
+                                                 nr_storage_samples, usage);
+         break;
+      case PIPE_FORMAT_AYUV:
+         supported = screen->is_format_supported(screen, PIPE_FORMAT_RGBA8888_UNORM,
+                                                 PIPE_TEXTURE_2D, nr_samples,
+                                                 nr_storage_samples, usage);
+         break;
+      case PIPE_FORMAT_XYUV:
+         supported = screen->is_format_supported(screen, PIPE_FORMAT_RGBX8888_UNORM,
+                                                 PIPE_TEXTURE_2D, nr_samples,
+                                                 nr_storage_samples, usage);
+         break;
+       default:
+         break;
       }
    }
 
@@ -91,7 +132,8 @@ st_get_egl_image(struct gl_context *ctx, GLeglImageOES image_handle,
       return false;
    }
 
-   if (!is_format_supported(screen, out->format, out->texture->nr_samples, usage)) {
+   if (!is_format_supported(screen, out->format, out->texture->nr_samples,
+                            out->texture->nr_storage_samples, usage)) {
       /* unable to specify a texture object using the specified EGL image */
       pipe_resource_reference(&out->texture, NULL);
       _mesa_error(ctx, GL_INVALID_OPERATION, "%s(format not supported)", error);
@@ -156,20 +198,11 @@ st_egl_image_target_renderbuffer_storage(struct gl_context *ctx,
       if (!ps)
          return;
 
-      strb->Base.Width = ps->width;
-      strb->Base.Height = ps->height;
       strb->Base.Format = st_pipe_format_to_mesa_format(ps->format);
       strb->Base._BaseFormat = st_pipe_format_to_base_format(ps->format);
       strb->Base.InternalFormat = strb->Base._BaseFormat;
 
-      struct pipe_surface **psurf =
-         util_format_is_srgb(ps->format) ? &strb->surface_srgb :
-                                           &strb->surface_linear;
-
-      pipe_surface_reference(psurf, ps);
-      strb->surface = *psurf;
-      pipe_resource_reference(&strb->texture, ps->texture);
-
+      st_set_ws_renderbuffer_surface(strb, ps);
       pipe_surface_reference(&ps, NULL);
    }
 }
@@ -202,36 +235,58 @@ st_bind_egl_image(struct gl_context *ctx,
       stObj->surface_based = GL_TRUE;
    }
 
-   texFormat = st_pipe_format_to_mesa_format(stimg->format);
-
    /* TODO RequiredTextureImageUnits should probably be reset back
     * to 1 somewhere if different texture is bound??
     */
-   if (texFormat == MESA_FORMAT_NONE) {
-      switch (stimg->format) {
-      case PIPE_FORMAT_NV12:
-         texFormat = MESA_FORMAT_R_UNORM8;
-         texObj->RequiredTextureImageUnits = 2;
-         break;
-      case PIPE_FORMAT_IYUV:
-         texFormat = MESA_FORMAT_R_UNORM8;
-         texObj->RequiredTextureImageUnits = 3;
-         break;
-      default:
-         unreachable("bad YUV format!");
-      }
+   switch (stimg->format) {
+   case PIPE_FORMAT_NV12:
+      texFormat = MESA_FORMAT_R_UNORM8;
+      texObj->RequiredTextureImageUnits = 2;
+      break;
+   case PIPE_FORMAT_P016:
+      texFormat = MESA_FORMAT_R_UNORM16;
+      texObj->RequiredTextureImageUnits = 2;
+      break;
+   case PIPE_FORMAT_IYUV:
+      texFormat = MESA_FORMAT_R_UNORM8;
+      texObj->RequiredTextureImageUnits = 3;
+      break;
+   case PIPE_FORMAT_YUYV:
+   case PIPE_FORMAT_UYVY:
+      texFormat = MESA_FORMAT_RG_UNORM8;
+      texObj->RequiredTextureImageUnits = 2;
+      break;
+   case PIPE_FORMAT_AYUV:
+      texFormat = MESA_FORMAT_R8G8B8A8_UNORM;
+      internalFormat = GL_RGBA;
+      texObj->RequiredTextureImageUnits = 1;
+      break;
+   case PIPE_FORMAT_XYUV:
+      texFormat = MESA_FORMAT_R8G8B8X8_UNORM;
+      texObj->RequiredTextureImageUnits = 1;
+      break;
+   default:
+      texFormat = st_pipe_format_to_mesa_format(stimg->format);
+      break;
    }
+   assert(texFormat != MESA_FORMAT_NONE);
+
+   /* Minify texture size based on level set on the EGLImage. */
+   uint32_t width = u_minify(stimg->texture->width0, stimg->level);
+   uint32_t height = u_minify(stimg->texture->height0, stimg->level);
 
-   _mesa_init_teximage_fields(ctx, texImage,
-                              stimg->texture->width0, stimg->texture->height0,
+   _mesa_init_teximage_fields(ctx, texImage, width, height,
                               1, 0, internalFormat, texFormat);
 
-   /* FIXME create a non-default sampler view from the stimg? */
    pipe_resource_reference(&stObj->pt, stimg->texture);
    st_texture_release_all_sampler_views(st, stObj);
    pipe_resource_reference(&stImage->pt, stObj->pt);
+   if (st->pipe->screen->resource_changed)
+      st->pipe->screen->resource_changed(st->pipe->screen, stImage->pt);
 
    stObj->surface_format = stimg->format;
+   stObj->level_override = stimg->level;
+   stObj->layer_override = stimg->layer;
 
    _mesa_dirty_texobj(ctx, texObj);
 }