i965/gs: Add a case to brwNewProgram() for geometry shaders.
[mesa.git] / src / mesa / drivers / dri / i965 / intel_screen.c
index 41090e8bc59dcb2aec30550f414ae766d7be6f93..9b3c31a5e7196d7f4731befc673852c65bce5843 100644 (file)
@@ -77,8 +77,6 @@ PUBLIC const char __driConfigOptions[] =
    DRI_CONF_SECTION_END
 DRI_CONF_END;
 
-const GLuint __driNConfigOptions = 12;
-
 #include "intel_batchbuffer.h"
 #include "intel_buffers.h"
 #include "intel_bufmgr.h"
@@ -156,13 +154,12 @@ static void
 intelDRI2Flush(__DRIdrawable *drawable)
 {
    GET_CURRENT_CONTEXT(ctx);
-   struct intel_context *intel = intel_context(ctx);
    struct brw_context *brw = brw_context(ctx);
-   if (intel == NULL)
+   if (brw == NULL)
       return;
 
    intel_resolve_for_dri2_flush(brw, drawable);
-   intel->need_throttle = true;
+   brw->need_throttle = true;
 
    if (brw->batch.used)
       intel_batchbuffer_flush(brw);
@@ -232,6 +229,21 @@ static struct intel_image_format intel_image_formats[] = {
        { 0, 1, 0, __DRI_IMAGE_FORMAT_ARGB8888, 4 } } }
 };
 
+static struct intel_image_format *
+intel_image_format_lookup(int fourcc)
+{
+   struct intel_image_format *f = NULL;
+
+   for (unsigned i = 0; i < ARRAY_SIZE(intel_image_formats); i++) {
+      if (intel_image_formats[i].fourcc == fourcc) {
+        f = &intel_image_formats[i];
+        break;
+      }
+   }
+
+   return f;
+}
+
 static __DRIimage *
 intel_allocate_image(int dri_format, void *loaderPrivate)
 {
@@ -378,7 +390,7 @@ intel_create_image_from_renderbuffer(__DRIcontext *context,
 {
    __DRIimage *image;
    struct brw_context *brw = context->driverPrivate;
-   struct gl_context *ctx = &brw->intel.ctx;
+   struct gl_context *ctx = &brw->ctx;
    struct gl_renderbuffer *rb;
    struct intel_renderbuffer *irb;
 
@@ -416,12 +428,11 @@ intel_create_image_from_texture(__DRIcontext *context, int target,
 {
    __DRIimage *image;
    struct brw_context *brw = context->driverPrivate;
-   struct intel_context *intel = &brw->intel;
    struct gl_texture_object *obj;
    struct intel_texture_object *iobj;
    GLuint face = 0;
 
-   obj = _mesa_lookup_texture(&intel->ctx, texture);
+   obj = _mesa_lookup_texture(&brw->ctx, texture);
    if (!obj || obj->Target != target) {
       *error = __DRI_IMAGE_ERROR_BAD_PARAMETER;
       return NULL;
@@ -430,7 +441,7 @@ intel_create_image_from_texture(__DRIcontext *context, int target,
    if (target == GL_TEXTURE_CUBE_MAP)
       face = zoffset;
 
-   _mesa_test_texobj_completeness(&intel->ctx, obj);
+   _mesa_test_texobj_completeness(&brw->ctx, obj);
    iobj = intel_texture_object(obj);
    if (!obj->_BaseComplete || (level > 0 && !obj->_MipmapComplete)) {
       *error = __DRI_IMAGE_ERROR_BAD_PARAMETER;
@@ -603,12 +614,7 @@ intel_create_image_from_names(__DRIscreen *screen,
     if (screen == NULL || names == NULL || num_names != 1)
         return NULL;
 
-    for (i = 0; i < ARRAY_SIZE(intel_image_formats); i++) {
-        if (intel_image_formats[i].fourcc == fourcc) {
-           f = &intel_image_formats[i];
-        }
-    }
-
+    f = intel_image_format_lookup(fourcc);
     if (f == NULL)
         return NULL;
 
@@ -637,23 +643,22 @@ intel_create_image_from_fds(__DRIscreen *screen,
                             void *loaderPrivate)
 {
    struct intel_screen *intelScreen = screen->driverPrivate;
-   struct intel_image_format *f = NULL;
+   struct intel_image_format *f;
    __DRIimage *image;
    int i, index;
 
    if (fds == NULL || num_fds != 1)
       return NULL;
 
-   for (i = 0; i < ARRAY_SIZE(intel_image_formats); i++) {
-      if (intel_image_formats[i].fourcc == fourcc) {
-         f = &intel_image_formats[i];
-      }
-   }
-
+   f = intel_image_format_lookup(fourcc);
    if (f == NULL)
       return NULL;
 
-   image = intel_allocate_image(__DRI_IMAGE_FORMAT_NONE, loaderPrivate);
+   if (f->nplanes == 1)
+      image = intel_allocate_image(f->planes[0].dri_format, loaderPrivate);
+   else
+      image = intel_allocate_image(__DRI_IMAGE_FORMAT_NONE, loaderPrivate);
+
    if (image == NULL)
       return NULL;
 
@@ -672,9 +677,55 @@ intel_create_image_from_fds(__DRIscreen *screen,
       image->strides[index] = strides[index];
    }
 
+   intel_setup_image_from_dimensions(image);
+
    return image;
 }
 
+static __DRIimage *
+intel_create_image_from_dma_bufs(__DRIscreen *screen,
+                                 int width, int height, int fourcc,
+                                 int *fds, int num_fds,
+                                 int *strides, int *offsets,
+                                 enum __DRIYUVColorSpace yuv_color_space,
+                                 enum __DRISampleRange sample_range,
+                                 enum __DRIChromaSiting horizontal_siting,
+                                 enum __DRIChromaSiting vertical_siting,
+                                 unsigned *error,
+                                 void *loaderPrivate)
+{
+   __DRIimage *image;
+   struct intel_image_format *f = intel_image_format_lookup(fourcc);
+
+   /* For now only packed formats that have native sampling are supported. */
+   if (!f || f->nplanes != 1) {
+      *error = __DRI_IMAGE_ERROR_BAD_MATCH;
+      return NULL;
+   }
+
+   image = intel_create_image_from_fds(screen, width, height, fourcc, fds,
+                                       num_fds, strides, offsets,
+                                       loaderPrivate);
+
+   /*
+    * Invalid parameters and any inconsistencies between are assumed to be
+    * checked by the caller. Therefore besides unsupported formats one can fail
+    * only in allocation.
+    */
+   if (!image) {
+      *error = __DRI_IMAGE_ERROR_BAD_ALLOC;
+      return NULL;
+   }
+
+   image->dma_buf_imported = true;
+   image->yuv_color_space = yuv_color_space;
+   image->sample_range = sample_range;
+   image->horizontal_siting = horizontal_siting;
+   image->vertical_siting = vertical_siting;
+
+   *error = __DRI_IMAGE_ERROR_SUCCESS;
+   return image;
+}
 
 static __DRIimage *
 intel_from_planar(__DRIimage *parent, int plane, void *loaderPrivate)
@@ -735,7 +786,7 @@ intel_from_planar(__DRIimage *parent, int plane, void *loaderPrivate)
 }
 
 static struct __DRIimageExtensionRec intelImageExtension = {
-    .base = { __DRI_IMAGE, 7 },
+    .base = { __DRI_IMAGE, 8 },
 
     .createImageFromName                = intel_create_image_from_name,
     .createImageFromRenderbuffer        = intel_create_image_from_renderbuffer,
@@ -747,7 +798,8 @@ static struct __DRIimageExtensionRec intelImageExtension = {
     .createImageFromNames               = intel_create_image_from_names,
     .fromPlanar                         = intel_from_planar,
     .createImageFromTexture             = intel_create_image_from_texture,
-    .createImageFromFds                 = intel_create_image_from_fds
+    .createImageFromFds                 = intel_create_image_from_fds,
+    .createImageFromDmaBufs             = intel_create_image_from_dma_bufs
 };
 
 static const __DRIextension *intelScreenExtensions[] = {
@@ -1205,8 +1257,7 @@ __DRIconfig **intelInitScreen2(__DRIscreen *psp)
       return false;
    }
    /* parse information in __driConfigOptions */
-   driParseOptionInfo(&intelScreen->optionCache,
-                      __driConfigOptions, __driNConfigOptions);
+   driParseOptionInfo(&intelScreen->optionCache, __driConfigOptions);
 
    intelScreen->driScrnPriv = psp;
    psp->driverPrivate = (void *) intelScreen;