[PATCH 1/5] wined3d: Introduce a separate structure for OpenGL sampler information.

Henri Verbeet hverbeet at codeweavers.com
Thu Aug 15 04:49:59 CDT 2019


Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
---
 dlls/wined3d/adapter_gl.c      | 14 +++++++-----
 dlls/wined3d/context.c         |  3 ++-
 dlls/wined3d/sampler.c         | 50 ++++++++++++++++++++++--------------------
 dlls/wined3d/state.c           |  2 +-
 dlls/wined3d/view.c            |  6 ++---
 dlls/wined3d/wined3d_private.h | 20 ++++++++++++-----
 6 files changed, 55 insertions(+), 40 deletions(-)

diff --git a/dlls/wined3d/adapter_gl.c b/dlls/wined3d/adapter_gl.c
index 7c645aebfd6..f8030bb3574 100644
--- a/dlls/wined3d/adapter_gl.c
+++ b/dlls/wined3d/adapter_gl.c
@@ -5027,7 +5027,7 @@ static void adapter_gl_destroy_unordered_access_view(struct wined3d_unordered_ac
 static HRESULT adapter_gl_create_sampler(struct wined3d_device *device, const struct wined3d_sampler_desc *desc,
         void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_sampler **sampler)
 {
-    struct wined3d_sampler *sampler_gl;
+    struct wined3d_sampler_gl *sampler_gl;
 
     TRACE("device %p, desc %p, parent %p, parent_ops %p, sampler %p.\n",
             device, desc, parent, parent_ops, sampler);
@@ -5038,20 +5038,20 @@ static HRESULT adapter_gl_create_sampler(struct wined3d_device *device, const st
     wined3d_sampler_gl_init(sampler_gl, device, desc, parent, parent_ops);
 
     TRACE("Created sampler %p.\n", sampler_gl);
-    *sampler = sampler_gl;
+    *sampler = &sampler_gl->s;
 
     return WINED3D_OK;
 }
 
 static void wined3d_sampler_gl_destroy_object(void *object)
 {
-    struct wined3d_sampler *sampler_gl = object;
+    struct wined3d_sampler_gl *sampler_gl = object;
     const struct wined3d_gl_info *gl_info;
     struct wined3d_context *context;
 
     if (sampler_gl->name)
     {
-        context = context_acquire(sampler_gl->device, NULL, 0);
+        context = context_acquire(sampler_gl->s.device, NULL, 0);
         gl_info = wined3d_context_gl(context)->gl_info;
         GL_EXTCALL(glDeleteSamplers(1, &sampler_gl->name));
         context_release(context);
@@ -5062,9 +5062,11 @@ static void wined3d_sampler_gl_destroy_object(void *object)
 
 static void adapter_gl_destroy_sampler(struct wined3d_sampler *sampler)
 {
-    TRACE("sampler %p.\n", sampler);
+    struct wined3d_sampler_gl *sampler_gl = wined3d_sampler_gl(sampler);
 
-    wined3d_cs_destroy_object(sampler->device->cs, wined3d_sampler_gl_destroy_object, sampler);
+    TRACE("sampler_gl %p.\n", sampler_gl);
+
+    wined3d_cs_destroy_object(sampler->device->cs, wined3d_sampler_gl_destroy_object, sampler_gl);
 }
 
 static const struct wined3d_adapter_ops wined3d_adapter_gl_ops =
diff --git a/dlls/wined3d/context.c b/dlls/wined3d/context.c
index 2d22409d50b..672efa7aef2 100644
--- a/dlls/wined3d/context.c
+++ b/dlls/wined3d/context.c
@@ -3797,7 +3797,8 @@ static void wined3d_context_gl_bind_shader_resources(struct wined3d_context_gl *
             sampler = device->default_sampler;
         else if (!(sampler = state->sampler[shader_type][entry->sampler_idx]))
             sampler = device->null_sampler;
-        wined3d_shader_resource_view_gl_bind(wined3d_shader_resource_view_gl(view), bind_idx, sampler, context_gl);
+        wined3d_shader_resource_view_gl_bind(wined3d_shader_resource_view_gl(view),
+                bind_idx, wined3d_sampler_gl(sampler), context_gl);
     }
 }
 
diff --git a/dlls/wined3d/sampler.c b/dlls/wined3d/sampler.c
index 5a9170b6d4d..c4f4d3eec30 100644
--- a/dlls/wined3d/sampler.c
+++ b/dlls/wined3d/sampler.c
@@ -70,53 +70,55 @@ static void wined3d_sampler_init(struct wined3d_sampler *sampler, struct wined3d
 
 static void wined3d_sampler_gl_cs_init(void *object)
 {
-    struct wined3d_sampler *sampler = object;
+    struct wined3d_sampler_gl *sampler_gl = object;
     const struct wined3d_sampler_desc *desc;
     const struct wined3d_gl_info *gl_info;
     struct wined3d_context *context;
+    GLuint name;
 
-    context = context_acquire(sampler->device, NULL, 0);
+    context = context_acquire(sampler_gl->s.device, NULL, 0);
     gl_info = wined3d_context_gl(context)->gl_info;
 
-    desc = &sampler->desc;
-    GL_EXTCALL(glGenSamplers(1, &sampler->name));
-    GL_EXTCALL(glSamplerParameteri(sampler->name, GL_TEXTURE_WRAP_S,
+    desc = &sampler_gl->s.desc;
+    GL_EXTCALL(glGenSamplers(1, &name));
+    GL_EXTCALL(glSamplerParameteri(name, GL_TEXTURE_WRAP_S,
             gl_info->wrap_lookup[desc->address_u - WINED3D_TADDRESS_WRAP]));
-    GL_EXTCALL(glSamplerParameteri(sampler->name, GL_TEXTURE_WRAP_T,
+    GL_EXTCALL(glSamplerParameteri(name, GL_TEXTURE_WRAP_T,
             gl_info->wrap_lookup[desc->address_v - WINED3D_TADDRESS_WRAP]));
-    GL_EXTCALL(glSamplerParameteri(sampler->name, GL_TEXTURE_WRAP_R,
+    GL_EXTCALL(glSamplerParameteri(name, GL_TEXTURE_WRAP_R,
             gl_info->wrap_lookup[desc->address_w - WINED3D_TADDRESS_WRAP]));
-    GL_EXTCALL(glSamplerParameterfv(sampler->name, GL_TEXTURE_BORDER_COLOR, &desc->border_color[0]));
-    GL_EXTCALL(glSamplerParameteri(sampler->name, GL_TEXTURE_MAG_FILTER,
+    GL_EXTCALL(glSamplerParameterfv(name, GL_TEXTURE_BORDER_COLOR, &desc->border_color[0]));
+    GL_EXTCALL(glSamplerParameteri(name, GL_TEXTURE_MAG_FILTER,
             wined3d_gl_mag_filter(desc->mag_filter)));
-    GL_EXTCALL(glSamplerParameteri(sampler->name, GL_TEXTURE_MIN_FILTER,
+    GL_EXTCALL(glSamplerParameteri(name, GL_TEXTURE_MIN_FILTER,
             wined3d_gl_min_mip_filter(desc->min_filter, desc->mip_filter)));
-    GL_EXTCALL(glSamplerParameterf(sampler->name, GL_TEXTURE_LOD_BIAS, desc->lod_bias));
-    GL_EXTCALL(glSamplerParameterf(sampler->name, GL_TEXTURE_MIN_LOD, desc->min_lod));
-    GL_EXTCALL(glSamplerParameterf(sampler->name, GL_TEXTURE_MAX_LOD, desc->max_lod));
+    GL_EXTCALL(glSamplerParameterf(name, GL_TEXTURE_LOD_BIAS, desc->lod_bias));
+    GL_EXTCALL(glSamplerParameterf(name, GL_TEXTURE_MIN_LOD, desc->min_lod));
+    GL_EXTCALL(glSamplerParameterf(name, GL_TEXTURE_MAX_LOD, desc->max_lod));
     if (gl_info->supported[ARB_TEXTURE_FILTER_ANISOTROPIC])
-        GL_EXTCALL(glSamplerParameteri(sampler->name, GL_TEXTURE_MAX_ANISOTROPY, desc->max_anisotropy));
+        GL_EXTCALL(glSamplerParameteri(name, GL_TEXTURE_MAX_ANISOTROPY, desc->max_anisotropy));
     if (desc->compare)
-        GL_EXTCALL(glSamplerParameteri(sampler->name, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE));
-    GL_EXTCALL(glSamplerParameteri(sampler->name, GL_TEXTURE_COMPARE_FUNC,
+        GL_EXTCALL(glSamplerParameteri(name, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE));
+    GL_EXTCALL(glSamplerParameteri(name, GL_TEXTURE_COMPARE_FUNC,
             wined3d_gl_compare_func(desc->comparison_func)));
     if ((context->d3d_info->wined3d_creation_flags & WINED3D_SRGB_READ_WRITE_CONTROL)
             && gl_info->supported[EXT_TEXTURE_SRGB_DECODE] && !desc->srgb_decode)
-        GL_EXTCALL(glSamplerParameteri(sampler->name, GL_TEXTURE_SRGB_DECODE_EXT, GL_SKIP_DECODE_EXT));
+        GL_EXTCALL(glSamplerParameteri(name, GL_TEXTURE_SRGB_DECODE_EXT, GL_SKIP_DECODE_EXT));
     checkGLcall("sampler creation");
 
-    TRACE("Created sampler %u.\n", sampler->name);
+    TRACE("Created sampler %u.\n", name);
+    sampler_gl->name = name;
 
     context_release(context);
 }
 
-void wined3d_sampler_gl_init(struct wined3d_sampler *sampler_gl, struct wined3d_device *device,
+void wined3d_sampler_gl_init(struct wined3d_sampler_gl *sampler_gl, struct wined3d_device *device,
         const struct wined3d_sampler_desc *desc, void *parent, const struct wined3d_parent_ops *parent_ops)
 {
     TRACE("sampler_gl %p, device %p, desc %p, parent %p, parent_ops %p.\n",
             sampler_gl, device, desc, parent, parent_ops);
 
-    wined3d_sampler_init(sampler_gl, device, desc, parent, parent_ops);
+    wined3d_sampler_init(&sampler_gl->s, device, desc, parent, parent_ops);
 
     if (device->adapter->gl_info.supported[ARB_SAMPLER_OBJECTS])
         wined3d_cs_init_object(device->cs, wined3d_sampler_gl_cs_init, sampler_gl);
@@ -176,19 +178,19 @@ static void texture_gl_apply_base_level(struct wined3d_texture_gl *texture_gl,
 }
 
 /* This function relies on the correct texture being bound and loaded. */
-void wined3d_sampler_bind(struct wined3d_sampler *sampler, unsigned int unit,
+void wined3d_sampler_gl_bind(struct wined3d_sampler_gl *sampler_gl, unsigned int unit,
         struct wined3d_texture_gl *texture_gl, const struct wined3d_context_gl *context_gl)
 {
     const struct wined3d_gl_info *gl_info = context_gl->gl_info;
 
     if (gl_info->supported[ARB_SAMPLER_OBJECTS])
     {
-        GL_EXTCALL(glBindSampler(unit, sampler->name));
+        GL_EXTCALL(glBindSampler(unit, sampler_gl->name));
         checkGLcall("bind sampler");
     }
     else if (texture_gl)
     {
-        wined3d_texture_gl_apply_sampler_desc(texture_gl, &sampler->desc, context_gl);
+        wined3d_texture_gl_apply_sampler_desc(texture_gl, &sampler_gl->s.desc, context_gl);
     }
     else
     {
@@ -196,5 +198,5 @@ void wined3d_sampler_bind(struct wined3d_sampler *sampler, unsigned int unit,
     }
 
     if (texture_gl)
-        texture_gl_apply_base_level(texture_gl, &sampler->desc, gl_info);
+        texture_gl_apply_base_level(texture_gl, &sampler_gl->s.desc, gl_info);
 }
diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c
index 6df5a6d0190..4cdca277f63 100644
--- a/dlls/wined3d/state.c
+++ b/dlls/wined3d/state.c
@@ -3639,7 +3639,7 @@ static void sampler(struct wined3d_context *context, const struct wined3d_state
             }
         }
 
-        wined3d_sampler_bind(sampler, mapped_stage, texture_gl, context_gl);
+        wined3d_sampler_gl_bind(wined3d_sampler_gl(sampler), mapped_stage, texture_gl, context_gl);
 
         /* Trigger shader constant reloading (for NP2 texcoord fixup) */
         if (!(texture_gl->t.flags & WINED3D_TEXTURE_POW2_MAT_IDENT))
diff --git a/dlls/wined3d/view.c b/dlls/wined3d/view.c
index 43b4ac58f17..45ec39fbd21 100644
--- a/dlls/wined3d/view.c
+++ b/dlls/wined3d/view.c
@@ -818,7 +818,7 @@ HRESULT CDECL wined3d_shader_resource_view_create(const struct wined3d_view_desc
 }
 
 void wined3d_shader_resource_view_gl_bind(struct wined3d_shader_resource_view_gl *view_gl,
-        unsigned int unit, struct wined3d_sampler *sampler, struct wined3d_context_gl *context_gl)
+        unsigned int unit, struct wined3d_sampler_gl *sampler_gl, struct wined3d_context_gl *context_gl)
 {
     const struct wined3d_gl_info *gl_info = context_gl->gl_info;
     struct wined3d_texture_gl *texture_gl;
@@ -828,7 +828,7 @@ void wined3d_shader_resource_view_gl_bind(struct wined3d_shader_resource_view_gl
     if (view_gl->gl_view.name)
     {
         wined3d_context_gl_bind_texture(context_gl, view_gl->gl_view.target, view_gl->gl_view.name);
-        wined3d_sampler_bind(sampler, unit, NULL, context_gl);
+        wined3d_sampler_gl_bind(sampler_gl, unit, NULL, context_gl);
         return;
     }
 
@@ -840,7 +840,7 @@ void wined3d_shader_resource_view_gl_bind(struct wined3d_shader_resource_view_gl
 
     texture_gl = wined3d_texture_gl(wined3d_texture_from_resource(view_gl->v.resource));
     wined3d_texture_gl_bind(texture_gl, context_gl, FALSE);
-    wined3d_sampler_bind(sampler, unit, texture_gl, context_gl);
+    wined3d_sampler_gl_bind(sampler_gl, unit, texture_gl, context_gl);
 }
 
 /* Context activation is done by the caller. */
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 05657764e61..04379247378 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -3793,17 +3793,27 @@ struct wined3d_sampler
 {
     struct wine_rb_entry entry;
     LONG refcount;
-    GLuint name;
     struct wined3d_device *device;
     void *parent;
     const struct wined3d_parent_ops *parent_ops;
     struct wined3d_sampler_desc desc;
 };
 
-void wined3d_sampler_bind(struct wined3d_sampler *sampler, unsigned int unit,
-        struct wined3d_texture_gl *texture_gl, const struct wined3d_context_gl *context_gl) DECLSPEC_HIDDEN;
+struct wined3d_sampler_gl
+{
+    struct wined3d_sampler s;
+
+    GLuint name;
+};
 
-void wined3d_sampler_gl_init(struct wined3d_sampler *sampler_gl,
+static inline struct wined3d_sampler_gl *wined3d_sampler_gl(struct wined3d_sampler *sampler)
+{
+    return CONTAINING_RECORD(sampler, struct wined3d_sampler_gl, s);
+}
+
+void wined3d_sampler_gl_bind(struct wined3d_sampler_gl *sampler_gl, unsigned int unit,
+        struct wined3d_texture_gl *texture_gl, const struct wined3d_context_gl *context_gl) DECLSPEC_HIDDEN;
+void wined3d_sampler_gl_init(struct wined3d_sampler_gl *sampler_gl,
         struct wined3d_device *device, const struct wined3d_sampler_desc *desc,
         void *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
 
@@ -4291,7 +4301,7 @@ static inline struct wined3d_shader_resource_view_gl *wined3d_shader_resource_vi
 }
 
 void wined3d_shader_resource_view_gl_bind(struct wined3d_shader_resource_view_gl *view_gl, unsigned int unit,
-        struct wined3d_sampler *sampler, struct wined3d_context_gl *context_gl) DECLSPEC_HIDDEN;
+        struct wined3d_sampler_gl *sampler_gl, struct wined3d_context_gl *context_gl) DECLSPEC_HIDDEN;
 HRESULT wined3d_shader_resource_view_gl_init(struct wined3d_shader_resource_view_gl *view_gl,
         const struct wined3d_view_desc *desc, struct wined3d_resource *resource,
         void *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
-- 
2.11.0




More information about the wine-devel mailing list