[v2 1/4] wined3d: Implement buffer shader resource views.

Andrew Wesie awesie at gmail.com
Sun Nov 20 11:16:29 CST 2016


Signed-off-by: Andrew Wesie <awesie at gmail.com>
---
 dlls/wined3d/buffer.c     |  3 +++
 dlls/wined3d/context.c    |  4 ++++
 dlls/wined3d/directx.c    |  3 +++
 dlls/wined3d/utils.c      |  2 +-
 dlls/wined3d/view.c       | 28 +++++++++++++++++++++++++++-
 dlls/wined3d/wined3d_gl.h |  1 +
 6 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/dlls/wined3d/buffer.c b/dlls/wined3d/buffer.c
index 58c273c..96d6e22 100644
--- a/dlls/wined3d/buffer.c
+++ b/dlls/wined3d/buffer.c
@@ -1432,6 +1432,9 @@ static GLenum buffer_type_hint_from_bind_flags(unsigned int bind_flags)
     if (bind_flags == WINED3D_BIND_INDEX_BUFFER)
         return GL_ELEMENT_ARRAY_BUFFER;
 
+    if (bind_flags == WINED3D_BIND_SHADER_RESOURCE)
+        return GL_TEXTURE_BUFFER;
+
     if (bind_flags & WINED3D_BIND_CONSTANT_BUFFER)
         return GL_UNIFORM_BUFFER;
 
diff --git a/dlls/wined3d/context.c b/dlls/wined3d/context.c
index 88d34e6..415d284 100644
--- a/dlls/wined3d/context.c
+++ b/dlls/wined3d/context.c
@@ -2426,6 +2426,10 @@ void context_bind_texture(struct wined3d_context *context, GLenum target, GLuint
                 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_3D, device->dummy_textures.tex_3d);
                 checkGLcall("glBindTexture");
                 break;
+            case GL_TEXTURE_BUFFER:
+                gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_BUFFER, 0);
+                checkGLcall("glBindTexture");
+                break;
             default:
                 ERR("Unexpected texture target %#x.\n", old_texture_type);
         }
diff --git a/dlls/wined3d/directx.c b/dlls/wined3d/directx.c
index 6588d1c..b4f2846 100644
--- a/dlls/wined3d/directx.c
+++ b/dlls/wined3d/directx.c
@@ -150,6 +150,7 @@ static const struct wined3d_extension_map gl_extension_map[] =
     {"GL_ARB_shadow",                       ARB_SHADOW                    },
     {"GL_ARB_sync",                         ARB_SYNC                      },
     {"GL_ARB_texture_border_clamp",         ARB_TEXTURE_BORDER_CLAMP      },
+    {"GL_ARB_texture_buffer_range",         ARB_TEXTURE_BUFFER_RANGE      },
     {"GL_ARB_texture_compression",          ARB_TEXTURE_COMPRESSION       },
     {"GL_ARB_texture_compression_bptc",     ARB_TEXTURE_COMPRESSION_BPTC  },
     {"GL_ARB_texture_compression_rgtc",     ARB_TEXTURE_COMPRESSION_RGTC  },
@@ -2763,6 +2764,8 @@ static void load_gl_funcs(struct wined3d_gl_info *gl_info)
     USE_GL_FUNC(glGetSynciv)
     USE_GL_FUNC(glIsSync)
     USE_GL_FUNC(glWaitSync)
+    /* GL_ARB_texture_buffer_range */
+    USE_GL_FUNC(glTexBufferRange)
     /* GL_ARB_texture_compression */
     USE_GL_FUNC(glCompressedTexImage2DARB)
     USE_GL_FUNC(glCompressedTexImage3DARB)
diff --git a/dlls/wined3d/utils.c b/dlls/wined3d/utils.c
index 1255a9a..a7a9603 100644
--- a/dlls/wined3d/utils.c
+++ b/dlls/wined3d/utils.c
@@ -1877,7 +1877,7 @@ static GLenum wined3d_gl_type_to_enum(enum wined3d_gl_resource_type type)
         case WINED3D_GL_RES_TYPE_TEX_RECT:
             return GL_TEXTURE_RECTANGLE_ARB;
         case WINED3D_GL_RES_TYPE_BUFFER:
-            return GL_TEXTURE_2D; /* TODO: GL_TEXTURE_BUFFER. */
+            return GL_TEXTURE_BUFFER;
         case WINED3D_GL_RES_TYPE_RB:
             return GL_RENDERBUFFER;
         case WINED3D_GL_RES_TYPE_COUNT:
diff --git a/dlls/wined3d/view.c b/dlls/wined3d/view.c
index a67c506..75d49ef 100644
--- a/dlls/wined3d/view.c
+++ b/dlls/wined3d/view.c
@@ -293,6 +293,29 @@ void * CDECL wined3d_shader_resource_view_get_parent(const struct wined3d_shader
     return view->parent;
 }
 
+static void wined3d_shader_resource_view_create_buffer_view(struct wined3d_shader_resource_view *view,
+        const struct wined3d_shader_resource_view_desc *desc, struct wined3d_buffer *buffer,
+        const struct wined3d_format *view_format)
+{
+    const struct wined3d_gl_info *gl_info;
+    struct wined3d_context *context;
+
+    context = context_acquire(buffer->resource.device, NULL);
+    gl_info = context->gl_info;
+
+    wined3d_buffer_load_location(buffer, context, WINED3D_LOCATION_BUFFER);
+
+    gl_info->gl_ops.gl.p_glGenTextures(1, &view->object);
+    gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_BUFFER, view->object);
+
+    GL_EXTCALL(glTexBufferRange(GL_TEXTURE_BUFFER, view_format->glInternal, buffer->buffer_object,
+            desc->u.buffer.start_idx * view_format->byte_count, desc->u.buffer.count * view_format->byte_count));
+    checkGLcall("Create buffer view");
+
+    gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_BUFFER, 0);
+    context_release(context);
+}
+
 static void wined3d_shader_resource_view_create_texture_view(struct wined3d_shader_resource_view *view,
         const struct wined3d_shader_resource_view_desc *desc, struct wined3d_texture *texture,
         const struct wined3d_format *view_format)
@@ -362,7 +385,10 @@ static HRESULT wined3d_shader_resource_view_init(struct wined3d_shader_resource_
 
     if (resource->type == WINED3D_RTYPE_BUFFER)
     {
-        FIXME("Buffer shader resource views not supported.\n");
+        struct wined3d_buffer *buffer = buffer_from_resource(resource);
+
+        view->target = GL_TEXTURE_BUFFER;
+        wined3d_shader_resource_view_create_buffer_view(view, desc, buffer, view_format);
     }
     else
     {
diff --git a/dlls/wined3d/wined3d_gl.h b/dlls/wined3d/wined3d_gl.h
index b71190d..d59785c 100644
--- a/dlls/wined3d/wined3d_gl.h
+++ b/dlls/wined3d/wined3d_gl.h
@@ -83,6 +83,7 @@ enum wined3d_gl_extension
     ARB_SHADOW,
     ARB_SYNC,
     ARB_TEXTURE_BORDER_CLAMP,
+    ARB_TEXTURE_BUFFER_RANGE,
     ARB_TEXTURE_COMPRESSION,
     ARB_TEXTURE_COMPRESSION_BPTC,
     ARB_TEXTURE_COMPRESSION_RGTC,
-- 
2.7.4




More information about the wine-patches mailing list