st/nine: Return D3DERR_INVALIDCALL when trying to create a texture of bad format
authorAxel Davy <axel.davy@ens.fr>
Sun, 7 Dec 2014 15:51:49 +0000 (16:51 +0100)
committerEmil Velikov <emil.l.velikov@gmail.com>
Thu, 22 Jan 2015 22:16:18 +0000 (22:16 +0000)
Reviewed-by: Ilia Mirkin <imirkin@alum.mit.edu>
Reviewed-by: David Heidelberg <david@ixit.cz>
Signed-off-by: Axel Davy <axel.davy@ens.fr>
src/gallium/state_trackers/nine/cubetexture9.c
src/gallium/state_trackers/nine/texture9.c
src/gallium/state_trackers/nine/volumetexture9.c

index 2c607c067999763f96abc9bf9316b59e58dc9c49..bb1219aa88fa260b4219aa814c8622562ee7f52c 100644 (file)
@@ -38,6 +38,8 @@ NineCubeTexture9_ctor( struct NineCubeTexture9 *This,
                        HANDLE *pSharedHandle )
 {
     struct pipe_resource *info = &This->base.base.info;
+    struct pipe_screen *screen = pParams->device->screen;
+    enum pipe_format pf;
     unsigned i;
     D3DSURFACE_DESC sfdesc;
     HRESULT hr;
@@ -55,9 +57,15 @@ NineCubeTexture9_ctor( struct NineCubeTexture9 *This,
     if (Usage & D3DUSAGE_AUTOGENMIPMAP)
         Levels = 0;
 
+    pf = d3d9_to_pipe_format(Format);
+    if (pf == PIPE_FORMAT_NONE ||
+        !screen->is_format_supported(screen, pf, PIPE_TEXTURE_CUBE, 0, PIPE_BIND_SAMPLER_VIEW)) {
+        return D3DERR_INVALIDCALL;
+    }
+
     info->screen = pParams->device->screen;
     info->target = PIPE_TEXTURE_CUBE;
-    info->format = d3d9_to_pipe_format(Format);
+    info->format = pf;
     info->width0 = EdgeLength;
     info->height0 = EdgeLength;
     info->depth0 = 1;
index 8852142c8e7125b0c0eb74457e95c893c7c686aa..4d7e950e2cad634567c738c6f70896a9f8cc9bbd 100644 (file)
@@ -47,6 +47,7 @@ NineTexture9_ctor( struct NineTexture9 *This,
     struct pipe_screen *screen = pParams->device->screen;
     struct pipe_resource *info = &This->base.base.info;
     struct pipe_resource *resource;
+    enum pipe_format pf;
     unsigned l;
     D3DSURFACE_DESC sfdesc;
     HRESULT hr;
@@ -92,9 +93,15 @@ NineTexture9_ctor( struct NineTexture9 *This,
     if (Usage & D3DUSAGE_AUTOGENMIPMAP)
         Levels = 0;
 
+    pf = d3d9_to_pipe_format(Format);
+    if (Format != D3DFMT_NULL && (pf == PIPE_FORMAT_NONE ||
+        !screen->is_format_supported(screen, pf, PIPE_TEXTURE_2D, 0, PIPE_BIND_SAMPLER_VIEW))) {
+        return D3DERR_INVALIDCALL;
+    }
+
     info->screen = screen;
     info->target = PIPE_TEXTURE_2D;
-    info->format = d3d9_to_pipe_format(Format);
+    info->format = pf;
     info->width0 = Width;
     info->height0 = Height;
     info->depth0 = 1;
index 9366dc95a1410f51adb81d8e22ba5ffc0ed8e939..f116899bcef3199e216c6b8505a0e2be3a39e433 100644 (file)
@@ -37,6 +37,8 @@ NineVolumeTexture9_ctor( struct NineVolumeTexture9 *This,
                          HANDLE *pSharedHandle )
 {
     struct pipe_resource *info = &This->base.base.info;
+    struct pipe_screen *screen = pParams->device->screen;
+    enum pipe_format pf;
     unsigned l;
     D3DVOLUME_DESC voldesc;
     HRESULT hr;
@@ -57,9 +59,15 @@ NineVolumeTexture9_ctor( struct NineVolumeTexture9 *This,
     if (Usage & D3DUSAGE_AUTOGENMIPMAP)
         Levels = 0;
 
+    pf = d3d9_to_pipe_format(Format);
+    if (pf == PIPE_FORMAT_NONE ||
+        !screen->is_format_supported(screen, pf, PIPE_TEXTURE_3D, 0, PIPE_BIND_SAMPLER_VIEW)) {
+        return D3DERR_INVALIDCALL;
+    }
+
     info->screen = pParams->device->screen;
     info->target = PIPE_TEXTURE_3D;
-    info->format = d3d9_to_pipe_format(Format);
+    info->format = pf;
     info->width0 = Width;
     info->height0 = Height;
     info->depth0 = Depth;