=?UTF-8?Q?J=C3=B3zef=20Kucia=20?=: wined3d: Add support for NULL sampler.

Alexandre Julliard julliard at winehq.org
Thu Jun 2 10:50:00 CDT 2016


Module: wine
Branch: master
Commit: 3bac75c040eb1391eb567e52dd56256350dc1371
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=3bac75c040eb1391eb567e52dd56256350dc1371

Author: Józef Kucia <jkucia at codeweavers.com>
Date:   Thu Jun  2 11:14:12 2016 +0200

wined3d: Add support for NULL sampler.

Signed-off-by: Józef Kucia <jkucia at codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/d3d10core/tests/device.c  |  2 +-
 dlls/d3d11/tests/d3d11.c       |  2 +-
 dlls/wined3d/context.c         |  9 +--------
 dlls/wined3d/device.c          | 39 ++++++++++++++++++++++++---------------
 dlls/wined3d/wined3d_private.h |  1 +
 5 files changed, 28 insertions(+), 25 deletions(-)

diff --git a/dlls/d3d10core/tests/device.c b/dlls/d3d10core/tests/device.c
index 46c437a..8a00952 100644
--- a/dlls/d3d10core/tests/device.c
+++ b/dlls/d3d10core/tests/device.c
@@ -6251,7 +6251,7 @@ static void test_swapchain_flip(void)
     color = get_texture_color(offscreen, 120, 240); /* blue, buf 0 */
     todo_wine ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
     color = get_texture_color(offscreen, 360, 240); /* red, buf 1 */
-    todo_wine ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
+    ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
 
     color = get_texture_color(backbuffer_0, 320, 240); /* blue */
     ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
diff --git a/dlls/d3d11/tests/d3d11.c b/dlls/d3d11/tests/d3d11.c
index 61d02ab..74feaa2 100644
--- a/dlls/d3d11/tests/d3d11.c
+++ b/dlls/d3d11/tests/d3d11.c
@@ -6173,7 +6173,7 @@ static void test_swapchain_flip(void)
     color = get_texture_color(offscreen, 120, 240); /* blue, buf 0 */
     todo_wine ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
     color = get_texture_color(offscreen, 360, 240); /* red, buf 1 */
-    todo_wine ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
+    ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
 
     color = get_texture_color(backbuffer_0, 320, 240); /* blue */
     ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
diff --git a/dlls/wined3d/context.c b/dlls/wined3d/context.c
index f07b3ab..845ca1d 100644
--- a/dlls/wined3d/context.c
+++ b/dlls/wined3d/context.c
@@ -3339,18 +3339,11 @@ static void context_bind_shader_resources(struct wined3d_context *context, const
             }
 
             if (entry->sampler_idx == WINED3D_SAMPLER_DEFAULT)
-            {
                 sampler_name = device->default_sampler;
-            }
             else if ((sampler = state->sampler[shader_types[i].type][entry->sampler_idx]))
-            {
                 sampler_name = sampler->name;
-            }
             else
-            {
-                WARN("No sampler object bound at index %u, %u.\n", shader_types[i].type, entry->sampler_idx);
-                continue;
-            }
+                sampler_name = device->null_sampler;
 
             texture = texture_from_resource(view->resource);
             context_active_texture(context, gl_info, shader_types[i].base_idx + entry->bind_idx);
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index ddfc715..88ca8fb 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -814,43 +814,52 @@ static void destroy_dummy_textures(struct wined3d_device *device, const struct w
 }
 
 /* Context activation is done by the caller. */
-static void create_default_sampler(struct wined3d_device *device)
+static void create_default_samplers(struct wined3d_device *device)
 {
     const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
 
-    /*
-     * In SM4+ shaders there is a separation between resources and samplers. Some shader
-     * instructions allow access to resources without using samplers.
-     * In GLSL, resources are always accessed through sampler or image variables. The default
-     * sampler object is used to emulate the direct resource access when there is no sampler state
-     * to use.
-     */
     if (gl_info->supported[ARB_SAMPLER_OBJECTS])
     {
+        /* In SM4+ shaders there is a separation between resources and samplers. Some shader
+         * instructions allow access to resources without using samplers.
+         * In GLSL, resources are always accessed through sampler or image variables. The default
+         * sampler object is used to emulate the direct resource access when there is no sampler state
+         * to use.
+         */
         GL_EXTCALL(glGenSamplers(1, &device->default_sampler));
-        checkGLcall("glGenSamplers");
         GL_EXTCALL(glSamplerParameteri(device->default_sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST));
         GL_EXTCALL(glSamplerParameteri(device->default_sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST));
-        checkGLcall("glSamplerParameteri");
+        checkGLcall("Create default sampler");
+
+        /* In D3D10+, a NULL sampler maps to the default sampler state. */
+        GL_EXTCALL(glGenSamplers(1, &device->null_sampler));
+        GL_EXTCALL(glSamplerParameteri(device->null_sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR));
+        GL_EXTCALL(glSamplerParameteri(device->null_sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
+        GL_EXTCALL(glSamplerParameteri(device->null_sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
+        GL_EXTCALL(glSamplerParameteri(device->null_sampler, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE));
+        checkGLcall("Create null sampler");
     }
     else
     {
         device->default_sampler = 0;
+        device->null_sampler = 0;
     }
 }
 
 /* Context activation is done by the caller. */
-static void destroy_default_sampler(struct wined3d_device *device)
+static void destroy_default_samplers(struct wined3d_device *device)
 {
     const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
 
     if (gl_info->supported[ARB_SAMPLER_OBJECTS])
     {
         GL_EXTCALL(glDeleteSamplers(1, &device->default_sampler));
+        GL_EXTCALL(glDeleteSamplers(1, &device->null_sampler));
         checkGLcall("glDeleteSamplers");
     }
 
     device->default_sampler = 0;
+    device->null_sampler = 0;
 }
 
 static LONG fullscreen_style(LONG style)
@@ -1058,7 +1067,7 @@ HRESULT CDECL wined3d_device_init_3d(struct wined3d_device *device,
     context = context_acquire(device, swapchain->front_buffer->sub_resources[0].u.surface);
 
     create_dummy_textures(device, context);
-    create_default_sampler(device);
+    create_default_samplers(device);
 
     device->contexts[0]->last_was_rhw = 0;
 
@@ -1183,7 +1192,7 @@ HRESULT CDECL wined3d_device_uninit_3d(struct wined3d_device *device)
     device->blitter->free_private(device);
     device->shader_backend->shader_free_private(device);
     destroy_dummy_textures(device, gl_info);
-    destroy_default_sampler(device);
+    destroy_default_samplers(device);
 
     /* Release the context again as soon as possible. In particular,
      * releasing the render target views below may release the last reference
@@ -4548,7 +4557,7 @@ static void delete_opengl_contexts(struct wined3d_device *device, struct wined3d
     device->blitter->free_private(device);
     device->shader_backend->shader_free_private(device);
     destroy_dummy_textures(device, gl_info);
-    destroy_default_sampler(device);
+    destroy_default_samplers(device);
 
     context_release(context);
 
@@ -4604,7 +4613,7 @@ static HRESULT create_primary_opengl_context(struct wined3d_device *device, stru
     swapchain->context[0] = context;
     swapchain->num_contexts = 1;
     create_dummy_textures(device, context);
-    create_default_sampler(device);
+    create_default_samplers(device);
     context_release(context);
 
     return WINED3D_OK;
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 1a5e2a0..5879aed 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -2351,6 +2351,7 @@ struct wined3d_device
 
     /* Default sampler used to emulate the direct resource access without using wined3d_sampler */
     GLuint default_sampler;
+    GLuint null_sampler;
 
     /* Command stream */
     struct wined3d_cs *cs;




More information about the wine-cvs mailing list