From 73bc99a081af878150b2093f211239d44aab5444 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20D=C3=B6singer?= <stefan@codeweavers.com>
Date: Thu, 19 Sep 2013 12:13:31 +0200
Subject: wined3d: Handle WINED3D_LOCATION_DISCARDED for sysmem loads.

---
 dlls/wined3d/resource.c | 12 ++++++++++++
 dlls/wined3d/volume.c   | 14 ++------------
 2 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/dlls/wined3d/resource.c b/dlls/wined3d/resource.c
index d5ec71f..051297c 100644
--- a/dlls/wined3d/resource.c
+++ b/dlls/wined3d/resource.c
@@ -397,6 +397,8 @@ void wined3d_resource_load_location(struct wined3d_resource *resource,
         struct wined3d_context *context, DWORD location)
 {
     DWORD required_access = wined3d_resource_access_from_location(location);
+    DWORD simple_locations = WINED3D_LOCATION_SYSMEM | WINED3D_LOCATION_USER_MEMORY
+            | WINED3D_LOCATION_DIB | WINED3D_LOCATION_BUFFER;
 
     if ((resource->locations & location) == location)
     {
@@ -409,6 +411,16 @@ void wined3d_resource_load_location(struct wined3d_resource *resource,
         WARN("Operation requires %#x access, but resource only has %#x.\n",
                 required_access, resource->access_flags);
 
+    if (location & simple_locations)
+    {
+        if (resource->locations & WINED3D_LOCATION_DISCARDED)
+        {
+            TRACE("Resource was discarded, nothing to do.\n");
+            resource->locations |= location;
+            return;
+        }
+    }
+
     /* Context is NULL in ddraw-only operation without OpenGL. */
     if (!context)
         ERR("A context is required for non-sysmem operation.\n");
diff --git a/dlls/wined3d/volume.c b/dlls/wined3d/volume.c
index a40d9f0..9ad7d75 100644
--- a/dlls/wined3d/volume.c
+++ b/dlls/wined3d/volume.c
@@ -229,12 +229,7 @@ static void wined3d_volume_load_location(struct wined3d_resource *resource,
             if (!volume->resource.heap_memory)
                 ERR("Trying to load WINED3D_LOCATION_SYSMEM without setting it up first.\n");
 
-            if (volume->resource.locations & WINED3D_LOCATION_DISCARDED)
-            {
-                TRACE("Volume previously discarded, nothing to do.\n");
-                wined3d_resource_invalidate_location(&volume->resource, WINED3D_LOCATION_DISCARDED);
-            }
-            else if (volume->resource.locations & (WINED3D_LOCATION_TEXTURE_RGB | WINED3D_LOCATION_TEXTURE_SRGB))
+            if (volume->resource.locations & (WINED3D_LOCATION_TEXTURE_RGB | WINED3D_LOCATION_TEXTURE_SRGB))
             {
                 struct wined3d_bo_address data = {0, volume->resource.heap_memory};
 
@@ -259,12 +254,7 @@ static void wined3d_volume_load_location(struct wined3d_resource *resource,
             if (!volume->resource.buffer_object)
                 ERR("Trying to load WINED3D_LOCATION_BUFFER without setting it up first.\n");
 
-            if (volume->resource.locations & WINED3D_LOCATION_DISCARDED)
-            {
-                TRACE("Volume previously discarded, nothing to do.\n");
-                wined3d_resource_invalidate_location(&volume->resource, WINED3D_LOCATION_DISCARDED);
-            }
-            else if (volume->resource.locations & (WINED3D_LOCATION_TEXTURE_RGB | WINED3D_LOCATION_TEXTURE_SRGB))
+            if (volume->resource.locations & (WINED3D_LOCATION_TEXTURE_RGB | WINED3D_LOCATION_TEXTURE_SRGB))
             {
                 struct wined3d_bo_address data = {volume->resource.buffer_object, NULL};
 
-- 
2.1.3

