wined3d: Introduce a separate structure for OpenGL shader resource view information.

Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Henri Verbeet 2018-11-13 16:40:17 +03:30 committed by Alexandre Julliard
parent cf6b3f28d7
commit c098173670
3 changed files with 52 additions and 38 deletions

View File

@ -3832,7 +3832,7 @@ static void context_bind_shader_resources(struct wined3d_context *context,
sampler = device->default_sampler;
else if (!(sampler = state->sampler[shader_type][entry->sampler_idx]))
sampler = device->null_sampler;
wined3d_shader_resource_view_bind(view, bind_idx, sampler, context);
wined3d_shader_resource_view_gl_bind(wined3d_shader_resource_view_gl(view), bind_idx, sampler, context);
}
}

View File

@ -672,23 +672,23 @@ ULONG CDECL wined3d_shader_resource_view_incref(struct wined3d_shader_resource_v
return refcount;
}
static void wined3d_shader_resource_view_destroy_object(void *object)
static void wined3d_shader_resource_view_gl_destroy_object(void *object)
{
struct wined3d_shader_resource_view *view = object;
struct wined3d_shader_resource_view_gl *view_gl = object;
if (view->gl_view.name)
if (view_gl->gl_view.name)
{
const struct wined3d_gl_info *gl_info;
struct wined3d_context *context;
context = context_acquire(view->resource->device, NULL, 0);
context = context_acquire(view_gl->v.resource->device, NULL, 0);
gl_info = context->gl_info;
gl_info->gl_ops.gl.p_glDeleteTextures(1, &view->gl_view.name);
gl_info->gl_ops.gl.p_glDeleteTextures(1, &view_gl->gl_view.name);
checkGLcall("glDeleteTextures");
context_release(context);
}
heap_free(view);
heap_free(view_gl);
}
ULONG CDECL wined3d_shader_resource_view_decref(struct wined3d_shader_resource_view *view)
@ -705,7 +705,8 @@ ULONG CDECL wined3d_shader_resource_view_decref(struct wined3d_shader_resource_v
/* Call wined3d_object_destroyed() before releasing the resource,
* since releasing the resource may end up destroying the parent. */
view->parent_ops->wined3d_object_destroyed(view->parent);
wined3d_cs_destroy_object(device->cs, wined3d_shader_resource_view_destroy_object, view);
wined3d_cs_destroy_object(device->cs, wined3d_shader_resource_view_gl_destroy_object,
wined3d_shader_resource_view_gl(view));
wined3d_resource_decref(resource);
}
@ -719,18 +720,18 @@ void * CDECL wined3d_shader_resource_view_get_parent(const struct wined3d_shader
return view->parent;
}
static void wined3d_shader_resource_view_cs_init(void *object)
static void wined3d_shader_resource_view_gl_cs_init(void *object)
{
struct wined3d_shader_resource_view *view = object;
struct wined3d_resource *resource = view->resource;
struct wined3d_shader_resource_view_gl *view_gl = object;
struct wined3d_resource *resource = view_gl->v.resource;
const struct wined3d_format *view_format;
const struct wined3d_gl_info *gl_info;
const struct wined3d_view_desc *desc;
GLenum view_target;
view_format = view->format;
view_format = view_gl->v.format;
gl_info = &resource->device->adapter->gl_info;
desc = &view->desc;
desc = &view_gl->v.desc;
if (resource->type == WINED3D_RTYPE_BUFFER)
{
@ -738,7 +739,7 @@ static void wined3d_shader_resource_view_cs_init(void *object)
struct wined3d_context *context;
context = context_acquire(resource->device, NULL, 0);
create_buffer_view(&view->gl_view, context, desc, buffer, view_format);
create_buffer_view(&view_gl->gl_view, context, desc, buffer, view_format);
context_release(context);
}
else
@ -764,11 +765,11 @@ static void wined3d_shader_resource_view_cs_init(void *object)
else if (resource->format->typeless_id == view_format->typeless_id
&& resource_class == view_class)
{
create_texture_view(&view->gl_view, view_target, desc, texture_gl, view_format);
create_texture_view(&view_gl->gl_view, view_target, desc, texture_gl, view_format);
}
else if (wined3d_format_is_depth_view(resource->format->id, view_format->id))
{
create_texture_view(&view->gl_view, view_target, desc, texture_gl, resource->format);
create_texture_view(&view_gl->gl_view, view_target, desc, texture_gl, resource->format);
}
else
{
@ -792,8 +793,6 @@ static HRESULT wined3d_shader_resource_view_init(struct wined3d_shader_resource_
wined3d_resource_incref(view->resource = resource);
wined3d_cs_init_object(resource->device->cs, wined3d_shader_resource_view_cs_init, view);
return WINED3D_OK;
}
@ -801,7 +800,7 @@ HRESULT CDECL wined3d_shader_resource_view_create(const struct wined3d_view_desc
struct wined3d_resource *resource, void *parent, const struct wined3d_parent_ops *parent_ops,
struct wined3d_shader_resource_view **view)
{
struct wined3d_shader_resource_view *object;
struct wined3d_shader_resource_view_gl *object;
HRESULT hr;
TRACE("desc %s, resource %p, parent %p, parent_ops %p, view %p.\n",
@ -810,20 +809,22 @@ HRESULT CDECL wined3d_shader_resource_view_create(const struct wined3d_view_desc
if (!(object = heap_alloc_zero(sizeof(*object))))
return E_OUTOFMEMORY;
if (FAILED(hr = wined3d_shader_resource_view_init(object, desc, resource, parent, parent_ops)))
if (FAILED(hr = wined3d_shader_resource_view_init(&object->v, desc, resource, parent, parent_ops)))
{
heap_free(object);
WARN("Failed to initialise view, hr %#x.\n", hr);
return hr;
}
wined3d_cs_init_object(resource->device->cs, wined3d_shader_resource_view_gl_cs_init, object);
TRACE("Created shader resource view %p.\n", object);
*view = object;
*view = &object->v;
return WINED3D_OK;
}
void wined3d_shader_resource_view_bind(struct wined3d_shader_resource_view *view,
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 *context)
{
const struct wined3d_gl_info *gl_info = context->gl_info;
@ -831,26 +832,26 @@ void wined3d_shader_resource_view_bind(struct wined3d_shader_resource_view *view
context_active_texture(context, gl_info, unit);
if (view->gl_view.name)
if (view_gl->gl_view.name)
{
context_bind_texture(context, view->gl_view.target, view->gl_view.name);
context_bind_texture(context, view_gl->gl_view.target, view_gl->gl_view.name);
wined3d_sampler_bind(sampler, unit, NULL, context);
return;
}
if (view->resource->type == WINED3D_RTYPE_BUFFER)
if (view_gl->v.resource->type == WINED3D_RTYPE_BUFFER)
{
FIXME("Buffer shader resources not supported.\n");
return;
}
texture_gl = wined3d_texture_gl(wined3d_texture_from_resource(view->resource));
texture_gl = wined3d_texture_gl(wined3d_texture_from_resource(view_gl->v.resource));
wined3d_texture_gl_bind(texture_gl, context, FALSE);
wined3d_sampler_bind(sampler, unit, texture_gl, context);
}
/* Context activation is done by the caller. */
static void shader_resource_view_bind_and_dirtify(struct wined3d_shader_resource_view *view,
static void shader_resource_view_gl_bind_and_dirtify(struct wined3d_shader_resource_view_gl *view_gl,
struct wined3d_context *context)
{
if (context->active_texture < ARRAY_SIZE(context->rev_tex_unit_map))
@ -864,11 +865,12 @@ static void shader_resource_view_bind_and_dirtify(struct wined3d_shader_resource
context_invalidate_compute_state(context, STATE_COMPUTE_SHADER_RESOURCE_BINDING);
context_invalidate_state(context, STATE_GRAPHICS_SHADER_RESOURCE_BINDING);
context_bind_texture(context, view->gl_view.target, view->gl_view.name);
context_bind_texture(context, view_gl->gl_view.target, view_gl->gl_view.name);
}
void shader_resource_view_generate_mipmaps(struct wined3d_shader_resource_view *view)
{
struct wined3d_shader_resource_view_gl *view_gl = wined3d_shader_resource_view_gl(view);
unsigned int i, j, layer_count, level_count, base_level, max_level;
const struct wined3d_gl_info *gl_info;
struct wined3d_texture_gl *texture_gl;
@ -879,22 +881,22 @@ void shader_resource_view_generate_mipmaps(struct wined3d_shader_resource_view *
TRACE("view %p.\n", view);
context = context_acquire(view->resource->device, NULL, 0);
context = context_acquire(view_gl->v.resource->device, NULL, 0);
gl_info = context->gl_info;
layer_count = view->desc.u.texture.layer_count;
level_count = view->desc.u.texture.level_count;
base_level = view->desc.u.texture.level_idx;
layer_count = view_gl->v.desc.u.texture.layer_count;
level_count = view_gl->v.desc.u.texture.level_count;
base_level = view_gl->v.desc.u.texture.level_idx;
max_level = base_level + level_count - 1;
texture_gl = wined3d_texture_gl(texture_from_resource(view->resource));
texture_gl = wined3d_texture_gl(texture_from_resource(view_gl->v.resource));
srgb = !!(texture_gl->t.flags & WINED3D_TEXTURE_IS_SRGB);
location = srgb ? WINED3D_LOCATION_TEXTURE_SRGB : WINED3D_LOCATION_TEXTURE_RGB;
for (i = 0; i < layer_count; ++i)
wined3d_texture_load_location(&texture_gl->t, i * level_count + base_level, context, location);
if (view->gl_view.name)
if (view_gl->gl_view.name)
{
shader_resource_view_bind_and_dirtify(view, context);
shader_resource_view_gl_bind_and_dirtify(view_gl, context);
}
else
{
@ -925,7 +927,7 @@ void shader_resource_view_generate_mipmaps(struct wined3d_shader_resource_view *
}
}
if (!view->gl_view.name)
if (!view_gl->gl_view.name)
{
gl_tex->base_level = base_level;
gl_info->gl_ops.gl.p_glTexParameteri(texture_gl->target,

View File

@ -3872,14 +3872,26 @@ struct wined3d_shader_resource_view
void *parent;
const struct wined3d_parent_ops *parent_ops;
struct wined3d_gl_view gl_view;
const struct wined3d_format *format;
struct wined3d_view_desc desc;
};
void shader_resource_view_generate_mipmaps(struct wined3d_shader_resource_view *view) DECLSPEC_HIDDEN;
void wined3d_shader_resource_view_bind(struct wined3d_shader_resource_view *view, unsigned int unit,
struct wined3d_shader_resource_view_gl
{
struct wined3d_shader_resource_view v;
struct wined3d_gl_view gl_view;
};
static inline struct wined3d_shader_resource_view_gl *wined3d_shader_resource_view_gl(
struct wined3d_shader_resource_view *view)
{
return CONTAINING_RECORD(view, struct wined3d_shader_resource_view_gl, v);
}
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 *context) DECLSPEC_HIDDEN;
struct wined3d_unordered_access_view