2009-02-24 07:43:02 +01:00
|
|
|
/*
|
2011-04-05 19:01:32 +02:00
|
|
|
* Copyright 2009, 2011 Henri Verbeet for CodeWeavers
|
2009-02-24 07:43:02 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
|
|
|
#include "wined3d_private.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d3d);
|
|
|
|
|
2017-02-10 12:26:54 +01:00
|
|
|
#define WINED3D_VIEW_CUBE_ARRAY (WINED3D_VIEW_TEXTURE_CUBE | WINED3D_VIEW_TEXTURE_ARRAY)
|
|
|
|
|
2016-12-01 13:56:34 +01:00
|
|
|
static BOOL is_stencil_view_format(const struct wined3d_format *format)
|
|
|
|
{
|
|
|
|
return format->id == WINED3DFMT_X24_TYPELESS_G8_UINT
|
|
|
|
|| format->id == WINED3DFMT_X32_TYPELESS_G8X24_UINT;
|
|
|
|
}
|
|
|
|
|
2017-02-10 12:26:54 +01:00
|
|
|
static GLenum get_texture_view_target(const struct wined3d_gl_info *gl_info,
|
|
|
|
const struct wined3d_view_desc *desc, const struct wined3d_texture *texture)
|
2016-12-09 11:30:43 +01:00
|
|
|
{
|
|
|
|
static const struct
|
|
|
|
{
|
|
|
|
GLenum texture_target;
|
|
|
|
unsigned int view_flags;
|
|
|
|
GLenum view_target;
|
2017-02-10 12:26:54 +01:00
|
|
|
enum wined3d_gl_extension extension;
|
2016-12-09 11:30:43 +01:00
|
|
|
}
|
|
|
|
view_types[] =
|
|
|
|
{
|
|
|
|
{GL_TEXTURE_2D, 0, GL_TEXTURE_2D},
|
|
|
|
{GL_TEXTURE_2D, WINED3D_VIEW_TEXTURE_ARRAY, GL_TEXTURE_2D_ARRAY},
|
|
|
|
{GL_TEXTURE_2D_ARRAY, 0, GL_TEXTURE_2D},
|
|
|
|
{GL_TEXTURE_2D_ARRAY, WINED3D_VIEW_TEXTURE_ARRAY, GL_TEXTURE_2D_ARRAY},
|
|
|
|
{GL_TEXTURE_2D_ARRAY, WINED3D_VIEW_TEXTURE_CUBE, GL_TEXTURE_CUBE_MAP},
|
2017-02-10 12:26:54 +01:00
|
|
|
{GL_TEXTURE_2D_ARRAY, WINED3D_VIEW_CUBE_ARRAY, GL_TEXTURE_CUBE_MAP_ARRAY, ARB_TEXTURE_CUBE_MAP_ARRAY},
|
2016-12-09 11:30:43 +01:00
|
|
|
{GL_TEXTURE_3D, 0, GL_TEXTURE_3D},
|
|
|
|
};
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(view_types); ++i)
|
|
|
|
{
|
2017-02-10 12:26:54 +01:00
|
|
|
if (view_types[i].texture_target != texture->target || view_types[i].view_flags != desc->flags)
|
|
|
|
continue;
|
|
|
|
if (gl_info->supported[view_types[i].extension])
|
2016-12-09 11:30:43 +01:00
|
|
|
return view_types[i].view_target;
|
2017-02-10 12:26:54 +01:00
|
|
|
|
|
|
|
FIXME("Extension %#x not supported.\n", view_types[i].extension);
|
2016-12-09 11:30:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
FIXME("Unhandled view flags %#x for texture target %#x.\n", desc->flags, texture->target);
|
|
|
|
return texture->target;
|
|
|
|
}
|
|
|
|
|
2017-02-24 12:27:35 +01:00
|
|
|
static const struct wined3d_format *validate_shader_resource_view(const struct wined3d_view_desc *desc,
|
|
|
|
struct wined3d_resource *resource, BOOL mip_slice)
|
|
|
|
{
|
|
|
|
const struct wined3d_gl_info *gl_info = &resource->device->adapter->gl_info;
|
|
|
|
const struct wined3d_format *format;
|
|
|
|
|
|
|
|
format = wined3d_get_format(gl_info, desc->format_id, resource->usage);
|
|
|
|
if (resource->type == WINED3D_RTYPE_BUFFER && (desc->flags & WINED3D_VIEW_BUFFER_RAW))
|
|
|
|
{
|
|
|
|
if (format->id != WINED3DFMT_R32_TYPELESS)
|
|
|
|
{
|
|
|
|
WARN("Invalid format %s for raw buffer view.\n", debug_d3dformat(format->id));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
format = wined3d_get_format(gl_info, WINED3DFMT_R32_UINT, resource->usage);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wined3d_format_is_typeless(format))
|
|
|
|
{
|
|
|
|
WARN("Trying to create view for typeless format %s.\n", debug_d3dformat(format->id));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (resource->type == WINED3D_RTYPE_BUFFER)
|
|
|
|
{
|
|
|
|
struct wined3d_buffer *buffer = buffer_from_resource(resource);
|
|
|
|
unsigned int buffer_size, element_size;
|
|
|
|
|
|
|
|
if (buffer->desc.structure_byte_stride)
|
|
|
|
{
|
|
|
|
if (desc->format_id != WINED3DFMT_UNKNOWN)
|
|
|
|
{
|
|
|
|
WARN("Invalid format %s for structured buffer view.\n", debug_d3dformat(desc->format_id));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
format = wined3d_get_format(gl_info, WINED3DFMT_R32_UINT, resource->usage);
|
|
|
|
element_size = buffer->desc.structure_byte_stride;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
element_size = format->byte_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!element_size)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
buffer_size = buffer->resource.size / element_size;
|
|
|
|
if (desc->u.buffer.start_idx >= buffer_size
|
|
|
|
|| desc->u.buffer.count > buffer_size - desc->u.buffer.start_idx)
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
struct wined3d_texture *texture = texture_from_resource(resource);
|
|
|
|
unsigned int depth_or_layer_count;
|
|
|
|
|
|
|
|
if (mip_slice && resource->type == WINED3D_RTYPE_TEXTURE_3D)
|
|
|
|
depth_or_layer_count = wined3d_texture_get_level_depth(texture, desc->u.texture.level_idx);
|
|
|
|
else
|
|
|
|
depth_or_layer_count = texture->layer_count;
|
|
|
|
|
|
|
|
if (!desc->u.texture.level_count
|
|
|
|
|| (mip_slice && desc->u.texture.level_count != 1)
|
|
|
|
|| desc->u.texture.level_idx >= texture->level_count
|
|
|
|
|| desc->u.texture.level_count > texture->level_count - desc->u.texture.level_idx
|
|
|
|
|| !desc->u.texture.layer_count
|
|
|
|
|| desc->u.texture.layer_idx >= depth_or_layer_count
|
|
|
|
|| desc->u.texture.layer_count > depth_or_layer_count - desc->u.texture.layer_idx)
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return format;
|
|
|
|
}
|
|
|
|
|
2016-12-09 11:30:41 +01:00
|
|
|
static void create_texture_view(struct wined3d_gl_view *view, GLenum view_target,
|
|
|
|
const struct wined3d_view_desc *desc, struct wined3d_texture *texture,
|
|
|
|
const struct wined3d_format *view_format)
|
|
|
|
{
|
|
|
|
const struct wined3d_gl_info *gl_info;
|
2016-12-09 11:30:44 +01:00
|
|
|
unsigned int layer_idx, layer_count;
|
2016-12-09 11:30:41 +01:00
|
|
|
struct wined3d_context *context;
|
|
|
|
struct gl_texture *gl_texture;
|
|
|
|
|
|
|
|
view->target = view_target;
|
|
|
|
|
2017-02-15 14:17:15 +01:00
|
|
|
context = context_acquire(texture->resource.device, NULL, 0);
|
2016-12-09 11:30:41 +01:00
|
|
|
gl_info = context->gl_info;
|
|
|
|
|
|
|
|
if (!gl_info->supported[ARB_TEXTURE_VIEW])
|
|
|
|
{
|
|
|
|
context_release(context);
|
|
|
|
FIXME("OpenGL implementation does not support texture views.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wined3d_texture_prepare_texture(texture, context, FALSE);
|
|
|
|
gl_texture = wined3d_texture_get_gl_texture(texture, FALSE);
|
|
|
|
|
2016-12-09 11:30:44 +01:00
|
|
|
layer_idx = desc->u.texture.layer_idx;
|
|
|
|
layer_count = desc->u.texture.layer_count;
|
|
|
|
if (view_target == GL_TEXTURE_3D && (layer_idx || layer_count != 1))
|
|
|
|
{
|
|
|
|
FIXME("Depth slice (%u-%u) not supported.\n", layer_idx, layer_count);
|
|
|
|
layer_idx = 0;
|
|
|
|
layer_count = 1;
|
|
|
|
}
|
|
|
|
|
2016-12-09 11:30:41 +01:00
|
|
|
gl_info->gl_ops.gl.p_glGenTextures(1, &view->name);
|
|
|
|
GL_EXTCALL(glTextureView(view->name, view->target, gl_texture->name, view_format->glInternal,
|
|
|
|
desc->u.texture.level_idx, desc->u.texture.level_count,
|
2016-12-09 11:30:44 +01:00
|
|
|
layer_idx, layer_count));
|
2016-12-09 11:30:41 +01:00
|
|
|
checkGLcall("Create texture view");
|
|
|
|
|
|
|
|
if (is_stencil_view_format(view_format))
|
|
|
|
{
|
|
|
|
static const GLint swizzle[] = {GL_ZERO, GL_RED, GL_ZERO, GL_ZERO};
|
|
|
|
|
|
|
|
if (!gl_info->supported[ARB_STENCIL_TEXTURING])
|
|
|
|
{
|
|
|
|
context_release(context);
|
|
|
|
FIXME("OpenGL implementation does not support stencil texturing.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
context_bind_texture(context, view->target, view->name);
|
|
|
|
gl_info->gl_ops.gl.p_glTexParameteriv(view->target, GL_TEXTURE_SWIZZLE_RGBA, swizzle);
|
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(view->target, GL_DEPTH_STENCIL_TEXTURE_MODE, GL_STENCIL_INDEX);
|
|
|
|
checkGLcall("Initialize stencil view");
|
|
|
|
|
2017-02-22 13:19:30 +01:00
|
|
|
context_invalidate_compute_state(context, STATE_COMPUTE_SHADER_RESOURCE_BINDING);
|
|
|
|
context_invalidate_state(context, STATE_GRAPHICS_SHADER_RESOURCE_BINDING);
|
2016-12-09 11:30:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
context_release(context);
|
|
|
|
}
|
|
|
|
|
2017-03-03 01:30:32 +01:00
|
|
|
static void create_buffer_texture(struct wined3d_gl_view *view, struct wined3d_context *context,
|
2017-02-14 13:15:07 +01:00
|
|
|
struct wined3d_buffer *buffer, const struct wined3d_format *view_format,
|
|
|
|
unsigned int offset, unsigned int size)
|
2017-01-26 13:07:31 +01:00
|
|
|
{
|
2017-03-03 01:30:32 +01:00
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
2017-01-26 13:07:31 +01:00
|
|
|
|
|
|
|
if (!gl_info->supported[ARB_TEXTURE_BUFFER_OBJECT])
|
|
|
|
{
|
|
|
|
FIXME("OpenGL implementation does not support buffer textures.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-02-14 13:15:07 +01:00
|
|
|
if ((offset & (gl_info->limits.texture_buffer_offset_alignment - 1)))
|
|
|
|
{
|
|
|
|
FIXME("Buffer offset %u is not %u byte aligned.\n",
|
|
|
|
offset, gl_info->limits.texture_buffer_offset_alignment);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-26 13:07:31 +01:00
|
|
|
wined3d_buffer_load_location(buffer, context, WINED3D_LOCATION_BUFFER);
|
|
|
|
|
|
|
|
view->target = GL_TEXTURE_BUFFER;
|
|
|
|
gl_info->gl_ops.gl.p_glGenTextures(1, &view->name);
|
|
|
|
|
|
|
|
context_bind_texture(context, GL_TEXTURE_BUFFER, view->name);
|
2017-02-14 13:15:07 +01:00
|
|
|
if (gl_info->supported[ARB_TEXTURE_BUFFER_RANGE])
|
|
|
|
{
|
|
|
|
GL_EXTCALL(glTexBufferRange(GL_TEXTURE_BUFFER, view_format->glInternal,
|
|
|
|
buffer->buffer_object, offset, size));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-02-15 14:27:30 +01:00
|
|
|
if (offset || size != buffer->resource.size)
|
2017-02-14 13:15:07 +01:00
|
|
|
FIXME("OpenGL implementation does not support ARB_texture_buffer_range.\n");
|
|
|
|
GL_EXTCALL(glTexBuffer(GL_TEXTURE_BUFFER, view_format->glInternal, buffer->buffer_object));
|
|
|
|
}
|
2017-01-26 13:07:31 +01:00
|
|
|
checkGLcall("Create buffer texture");
|
|
|
|
|
2017-02-22 13:19:30 +01:00
|
|
|
context_invalidate_compute_state(context, STATE_COMPUTE_SHADER_RESOURCE_BINDING);
|
|
|
|
context_invalidate_state(context, STATE_GRAPHICS_SHADER_RESOURCE_BINDING);
|
2017-01-26 13:07:31 +01:00
|
|
|
}
|
|
|
|
|
2017-03-03 01:30:32 +01:00
|
|
|
static void create_buffer_view(struct wined3d_gl_view *view, struct wined3d_context *context,
|
2017-02-14 13:15:10 +01:00
|
|
|
const struct wined3d_view_desc *desc, struct wined3d_buffer *buffer,
|
|
|
|
const struct wined3d_format *view_format)
|
|
|
|
{
|
|
|
|
unsigned int offset, size;
|
|
|
|
|
|
|
|
if (desc->format_id == WINED3DFMT_UNKNOWN)
|
|
|
|
{
|
2017-02-23 15:00:57 +01:00
|
|
|
offset = desc->u.buffer.start_idx * buffer->desc.structure_byte_stride;
|
|
|
|
size = desc->u.buffer.count * buffer->desc.structure_byte_stride;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
offset = desc->u.buffer.start_idx * view_format->byte_count;
|
|
|
|
size = desc->u.buffer.count * view_format->byte_count;
|
2017-02-14 13:15:10 +01:00
|
|
|
}
|
|
|
|
|
2017-03-03 01:30:32 +01:00
|
|
|
create_buffer_texture(view, context, buffer, view_format, offset, size);
|
2017-02-14 13:15:10 +01:00
|
|
|
}
|
|
|
|
|
2011-04-05 19:01:32 +02:00
|
|
|
ULONG CDECL wined3d_rendertarget_view_incref(struct wined3d_rendertarget_view *view)
|
2009-02-24 07:43:02 +01:00
|
|
|
{
|
2011-04-05 19:01:32 +02:00
|
|
|
ULONG refcount = InterlockedIncrement(&view->refcount);
|
2009-02-24 07:43:02 +01:00
|
|
|
|
2011-04-05 19:01:32 +02:00
|
|
|
TRACE("%p increasing refcount to %u.\n", view, refcount);
|
2009-02-24 07:43:02 +01:00
|
|
|
|
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
2016-06-21 10:32:47 +02:00
|
|
|
static void wined3d_rendertarget_view_destroy_object(void *object)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, object);
|
|
|
|
}
|
|
|
|
|
2011-04-05 19:01:32 +02:00
|
|
|
ULONG CDECL wined3d_rendertarget_view_decref(struct wined3d_rendertarget_view *view)
|
2009-02-24 07:43:02 +01:00
|
|
|
{
|
2011-04-05 19:01:32 +02:00
|
|
|
ULONG refcount = InterlockedDecrement(&view->refcount);
|
2009-02-24 07:43:02 +01:00
|
|
|
|
2011-04-05 19:01:32 +02:00
|
|
|
TRACE("%p decreasing refcount to %u.\n", view, refcount);
|
2009-02-24 07:43:02 +01:00
|
|
|
|
|
|
|
if (!refcount)
|
2014-08-21 09:55:52 +02:00
|
|
|
{
|
2016-07-03 17:49:35 +02:00
|
|
|
struct wined3d_resource *resource = view->resource;
|
|
|
|
struct wined3d_device *device = resource->device;
|
2016-06-21 10:32:47 +02:00
|
|
|
|
2014-08-21 09:55:55 +02:00
|
|
|
/* 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);
|
2017-02-16 00:58:53 +01:00
|
|
|
wined3d_cs_destroy_object(device->cs, wined3d_rendertarget_view_destroy_object, view);
|
2016-07-03 17:49:35 +02:00
|
|
|
wined3d_resource_decref(resource);
|
2014-08-21 09:55:52 +02:00
|
|
|
}
|
2009-02-24 07:43:02 +01:00
|
|
|
|
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
2011-04-05 19:01:32 +02:00
|
|
|
void * CDECL wined3d_rendertarget_view_get_parent(const struct wined3d_rendertarget_view *view)
|
2009-02-24 07:43:02 +01:00
|
|
|
{
|
2011-04-05 19:01:32 +02:00
|
|
|
TRACE("view %p.\n", view);
|
2009-02-24 07:43:02 +01:00
|
|
|
|
2011-04-05 19:01:32 +02:00
|
|
|
return view->parent;
|
2009-02-24 07:43:02 +01:00
|
|
|
}
|
|
|
|
|
2014-08-21 09:55:55 +02:00
|
|
|
void * CDECL wined3d_rendertarget_view_get_sub_resource_parent(const struct wined3d_rendertarget_view *view)
|
|
|
|
{
|
2016-03-29 16:45:34 +02:00
|
|
|
struct wined3d_texture *texture;
|
2014-08-21 09:55:55 +02:00
|
|
|
|
|
|
|
TRACE("view %p.\n", view);
|
|
|
|
|
|
|
|
if (view->resource->type == WINED3D_RTYPE_BUFFER)
|
|
|
|
return wined3d_buffer_get_parent(buffer_from_resource(view->resource));
|
|
|
|
|
2016-04-20 19:29:13 +02:00
|
|
|
texture = texture_from_resource(view->resource);
|
2014-08-21 09:55:55 +02:00
|
|
|
|
2016-04-20 19:29:14 +02:00
|
|
|
return texture->sub_resources[view->sub_resource_idx].parent;
|
2014-08-21 09:55:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CDECL wined3d_rendertarget_view_set_parent(struct wined3d_rendertarget_view *view, void *parent)
|
|
|
|
{
|
|
|
|
TRACE("view %p, parent %p.\n", view, parent);
|
|
|
|
|
|
|
|
view->parent = parent;
|
|
|
|
}
|
|
|
|
|
2011-04-05 19:01:32 +02:00
|
|
|
struct wined3d_resource * CDECL wined3d_rendertarget_view_get_resource(const struct wined3d_rendertarget_view *view)
|
2009-02-24 07:43:02 +01:00
|
|
|
{
|
2011-04-05 19:01:32 +02:00
|
|
|
TRACE("view %p.\n", view);
|
2009-02-24 07:43:02 +01:00
|
|
|
|
2011-04-05 19:01:32 +02:00
|
|
|
return view->resource;
|
2009-02-24 07:43:02 +01:00
|
|
|
}
|
|
|
|
|
2016-11-04 13:43:44 +01:00
|
|
|
void wined3d_rendertarget_view_get_drawable_size(const struct wined3d_rendertarget_view *view,
|
|
|
|
const struct wined3d_context *context, unsigned int *width, unsigned int *height)
|
2016-11-04 13:43:43 +01:00
|
|
|
{
|
2016-11-04 13:43:44 +01:00
|
|
|
const struct wined3d_texture *texture;
|
|
|
|
|
|
|
|
if (view->resource->type != WINED3D_RTYPE_TEXTURE_2D)
|
|
|
|
{
|
|
|
|
FIXME("Not implemented for %s resources.\n", debug_d3dresourcetype(view->resource->type));
|
|
|
|
*width = 0;
|
|
|
|
*height = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
texture = texture_from_resource(view->resource);
|
|
|
|
if (texture->swapchain)
|
2016-11-04 13:43:43 +01:00
|
|
|
{
|
|
|
|
/* The drawable size of an onscreen drawable is the surface size.
|
|
|
|
* (Actually: The window size, but the surface is created in window
|
|
|
|
* size.) */
|
|
|
|
*width = context->current_rt.texture->resource.width;
|
|
|
|
*height = context->current_rt.texture->resource.height;
|
|
|
|
}
|
|
|
|
else if (wined3d_settings.offscreen_rendering_mode == ORM_BACKBUFFER)
|
|
|
|
{
|
|
|
|
const struct wined3d_swapchain *swapchain = context->swapchain;
|
|
|
|
|
|
|
|
/* The drawable size of a backbuffer / aux buffer offscreen target is
|
|
|
|
* the size of the current context's drawable, which is the size of
|
|
|
|
* the back buffer of the swapchain the active context belongs to. */
|
|
|
|
*width = swapchain->desc.backbuffer_width;
|
|
|
|
*height = swapchain->desc.backbuffer_height;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
struct wined3d_surface *rt;
|
|
|
|
|
|
|
|
/* The drawable size of an FBO target is the OpenGL texture size,
|
|
|
|
* which is the power of two size. */
|
|
|
|
rt = context->current_rt.texture->sub_resources[context->current_rt.sub_resource_idx].u.surface;
|
|
|
|
*width = wined3d_texture_get_level_pow2_width(rt->container, rt->texture_level);
|
|
|
|
*height = wined3d_texture_get_level_pow2_height(rt->container, rt->texture_level);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-29 16:45:34 +02:00
|
|
|
static HRESULT wined3d_rendertarget_view_init(struct wined3d_rendertarget_view *view,
|
2016-12-05 12:04:41 +01:00
|
|
|
const struct wined3d_view_desc *desc, struct wined3d_resource *resource,
|
2014-08-21 09:55:55 +02:00
|
|
|
void *parent, const struct wined3d_parent_ops *parent_ops)
|
2010-04-13 20:46:24 +02:00
|
|
|
{
|
2014-08-21 09:55:53 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = &resource->device->adapter->gl_info;
|
|
|
|
|
2010-04-13 20:46:24 +02:00
|
|
|
view->refcount = 1;
|
|
|
|
view->parent = parent;
|
2014-08-21 09:55:55 +02:00
|
|
|
view->parent_ops = parent_ops;
|
2014-08-21 09:55:53 +02:00
|
|
|
|
2016-12-09 11:30:48 +01:00
|
|
|
view->format = wined3d_get_format(gl_info, desc->format_id, resource->usage);
|
2015-04-24 10:33:47 +02:00
|
|
|
view->format_flags = view->format->flags[resource->gl_type];
|
2016-06-16 11:59:37 +02:00
|
|
|
|
|
|
|
if (wined3d_format_is_typeless(view->format))
|
|
|
|
{
|
|
|
|
WARN("Trying to create view for typeless format %s.\n", debug_d3dformat(view->format->id));
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2014-08-21 09:55:53 +02:00
|
|
|
if (resource->type == WINED3D_RTYPE_BUFFER)
|
|
|
|
{
|
|
|
|
view->sub_resource_idx = 0;
|
|
|
|
view->buffer_offset = desc->u.buffer.start_idx;
|
|
|
|
view->width = desc->u.buffer.count;
|
|
|
|
view->height = 1;
|
|
|
|
view->depth = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-04-20 19:29:13 +02:00
|
|
|
struct wined3d_texture *texture = texture_from_resource(resource);
|
2016-06-08 14:54:58 +02:00
|
|
|
unsigned int depth_or_layer_count;
|
|
|
|
|
|
|
|
if (resource->type == WINED3D_RTYPE_TEXTURE_3D)
|
|
|
|
depth_or_layer_count = wined3d_texture_get_level_depth(texture, desc->u.texture.level_idx);
|
|
|
|
else
|
|
|
|
depth_or_layer_count = texture->layer_count;
|
2014-08-21 09:55:53 +02:00
|
|
|
|
2016-03-29 16:45:34 +02:00
|
|
|
if (desc->u.texture.level_idx >= texture->level_count
|
2016-12-05 12:04:41 +01:00
|
|
|
|| desc->u.texture.level_count != 1
|
2016-06-08 14:54:58 +02:00
|
|
|
|| desc->u.texture.layer_idx >= depth_or_layer_count
|
2016-06-16 11:59:35 +02:00
|
|
|
|| !desc->u.texture.layer_count
|
2016-06-08 14:54:58 +02:00
|
|
|
|| desc->u.texture.layer_count > depth_or_layer_count - desc->u.texture.layer_idx)
|
2016-06-16 11:59:36 +02:00
|
|
|
return E_INVALIDARG;
|
2016-06-08 14:54:58 +02:00
|
|
|
|
|
|
|
view->sub_resource_idx = desc->u.texture.level_idx;
|
|
|
|
if (resource->type != WINED3D_RTYPE_TEXTURE_3D)
|
|
|
|
view->sub_resource_idx += desc->u.texture.layer_idx * texture->level_count;
|
2014-08-21 09:55:53 +02:00
|
|
|
view->buffer_offset = 0;
|
2016-03-29 16:45:34 +02:00
|
|
|
view->width = wined3d_texture_get_level_width(texture, desc->u.texture.level_idx);
|
|
|
|
view->height = wined3d_texture_get_level_height(texture, desc->u.texture.level_idx);
|
2014-08-21 09:55:53 +02:00
|
|
|
view->depth = desc->u.texture.layer_count;
|
|
|
|
}
|
2016-03-29 16:45:34 +02:00
|
|
|
wined3d_resource_incref(view->resource = resource);
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
2010-04-13 20:46:24 +02:00
|
|
|
}
|
2011-05-10 21:18:47 +02:00
|
|
|
|
2016-12-05 12:04:41 +01:00
|
|
|
HRESULT CDECL wined3d_rendertarget_view_create(const struct wined3d_view_desc *desc,
|
2014-08-21 09:55:55 +02:00
|
|
|
struct wined3d_resource *resource, void *parent, const struct wined3d_parent_ops *parent_ops,
|
|
|
|
struct wined3d_rendertarget_view **view)
|
2011-05-10 21:18:47 +02:00
|
|
|
{
|
|
|
|
struct wined3d_rendertarget_view *object;
|
2016-03-29 16:45:34 +02:00
|
|
|
HRESULT hr;
|
2011-05-10 21:18:47 +02:00
|
|
|
|
2015-09-18 15:54:41 +02:00
|
|
|
TRACE("desc %p, resource %p, parent %p, parent_ops %p, view %p.\n",
|
|
|
|
desc, resource, parent, parent_ops, view);
|
2011-05-10 21:18:47 +02:00
|
|
|
|
2014-08-21 09:55:53 +02:00
|
|
|
if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
|
2011-05-10 21:18:47 +02:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2016-03-29 16:45:34 +02:00
|
|
|
if (FAILED(hr = wined3d_rendertarget_view_init(object, desc, resource, parent, parent_ops)))
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, object);
|
|
|
|
WARN("Failed to initialise view, hr %#x.\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
2011-05-10 21:18:47 +02:00
|
|
|
|
|
|
|
TRACE("Created render target view %p.\n", object);
|
2014-08-21 09:55:53 +02:00
|
|
|
*view = object;
|
2011-05-10 21:18:47 +02:00
|
|
|
|
2016-03-29 16:45:34 +02:00
|
|
|
return hr;
|
2011-05-10 21:18:47 +02:00
|
|
|
}
|
2014-08-21 09:55:55 +02:00
|
|
|
|
2015-10-28 14:02:10 +01:00
|
|
|
HRESULT CDECL wined3d_rendertarget_view_create_from_sub_resource(struct wined3d_texture *texture,
|
|
|
|
unsigned int sub_resource_idx, void *parent, const struct wined3d_parent_ops *parent_ops,
|
|
|
|
struct wined3d_rendertarget_view **view)
|
|
|
|
{
|
2016-12-05 12:04:41 +01:00
|
|
|
struct wined3d_view_desc desc;
|
2015-10-28 14:02:10 +01:00
|
|
|
|
|
|
|
TRACE("texture %p, sub_resource_idx %u, parent %p, parent_ops %p, view %p.\n",
|
|
|
|
texture, sub_resource_idx, parent, parent_ops, view);
|
|
|
|
|
2016-02-02 19:23:31 +01:00
|
|
|
desc.format_id = texture->resource.format->id;
|
2016-12-05 12:04:41 +01:00
|
|
|
desc.flags = 0;
|
2016-02-02 19:23:31 +01:00
|
|
|
desc.u.texture.level_idx = sub_resource_idx % texture->level_count;
|
2016-12-05 12:04:41 +01:00
|
|
|
desc.u.texture.level_count = 1;
|
2016-02-02 19:23:31 +01:00
|
|
|
desc.u.texture.layer_idx = sub_resource_idx / texture->level_count;
|
|
|
|
desc.u.texture.layer_count = 1;
|
2015-10-28 14:02:10 +01:00
|
|
|
|
2016-02-02 19:23:31 +01:00
|
|
|
return wined3d_rendertarget_view_create(&desc, &texture->resource, parent, parent_ops, view);
|
2015-10-28 14:02:10 +01:00
|
|
|
}
|
|
|
|
|
2014-09-16 10:44:15 +02:00
|
|
|
ULONG CDECL wined3d_shader_resource_view_incref(struct wined3d_shader_resource_view *view)
|
|
|
|
{
|
|
|
|
ULONG refcount = InterlockedIncrement(&view->refcount);
|
|
|
|
|
|
|
|
TRACE("%p increasing refcount to %u.\n", view, refcount);
|
|
|
|
|
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
2016-06-21 10:32:46 +02:00
|
|
|
static void wined3d_shader_resource_view_destroy_object(void *object)
|
|
|
|
{
|
|
|
|
struct wined3d_shader_resource_view *view = object;
|
|
|
|
|
2016-12-09 11:30:41 +01:00
|
|
|
if (view->gl_view.name)
|
2016-06-21 10:32:46 +02:00
|
|
|
{
|
|
|
|
const struct wined3d_gl_info *gl_info;
|
|
|
|
struct wined3d_context *context;
|
|
|
|
|
2017-02-15 14:17:15 +01:00
|
|
|
context = context_acquire(view->resource->device, NULL, 0);
|
2016-06-21 10:32:46 +02:00
|
|
|
gl_info = context->gl_info;
|
2016-12-09 11:30:41 +01:00
|
|
|
gl_info->gl_ops.gl.p_glDeleteTextures(1, &view->gl_view.name);
|
2016-06-21 10:32:46 +02:00
|
|
|
checkGLcall("glDeleteTextures");
|
|
|
|
context_release(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, view);
|
|
|
|
}
|
|
|
|
|
2014-09-16 10:44:15 +02:00
|
|
|
ULONG CDECL wined3d_shader_resource_view_decref(struct wined3d_shader_resource_view *view)
|
|
|
|
{
|
|
|
|
ULONG refcount = InterlockedDecrement(&view->refcount);
|
|
|
|
|
|
|
|
TRACE("%p decreasing refcount to %u.\n", view, refcount);
|
|
|
|
|
|
|
|
if (!refcount)
|
|
|
|
{
|
2016-07-03 17:49:33 +02:00
|
|
|
struct wined3d_resource *resource = view->resource;
|
|
|
|
struct wined3d_device *device = resource->device;
|
2016-06-21 10:32:46 +02:00
|
|
|
|
2014-12-01 08:45:43 +01:00
|
|
|
/* Call wined3d_object_destroyed() before releasing the resource,
|
|
|
|
* since releasing the resource may end up destroying the parent. */
|
2014-09-16 10:44:15 +02:00
|
|
|
view->parent_ops->wined3d_object_destroyed(view->parent);
|
2017-02-16 00:58:53 +01:00
|
|
|
wined3d_cs_destroy_object(device->cs, wined3d_shader_resource_view_destroy_object, view);
|
2016-07-03 17:49:33 +02:00
|
|
|
wined3d_resource_decref(resource);
|
2014-09-16 10:44:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
2014-09-17 10:40:27 +02:00
|
|
|
void * CDECL wined3d_shader_resource_view_get_parent(const struct wined3d_shader_resource_view *view)
|
|
|
|
{
|
|
|
|
TRACE("view %p.\n", view);
|
|
|
|
|
|
|
|
return view->parent;
|
|
|
|
}
|
|
|
|
|
2017-02-16 00:58:54 +01:00
|
|
|
static void wined3d_shader_resource_view_cs_init(void *object)
|
|
|
|
{
|
|
|
|
struct wined3d_shader_resource_view *view = object;
|
|
|
|
struct wined3d_resource *resource = view->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;
|
|
|
|
gl_info = &resource->device->adapter->gl_info;
|
|
|
|
desc = &view->desc;
|
|
|
|
|
|
|
|
if (resource->type == WINED3D_RTYPE_BUFFER)
|
|
|
|
{
|
|
|
|
struct wined3d_buffer *buffer = buffer_from_resource(resource);
|
2017-03-03 01:30:32 +01:00
|
|
|
struct wined3d_context *context;
|
2017-02-16 00:58:54 +01:00
|
|
|
|
2017-03-03 01:30:32 +01:00
|
|
|
context = context_acquire(resource->device, NULL, 0);
|
|
|
|
create_buffer_view(&view->gl_view, context, desc, buffer, view_format);
|
|
|
|
context_release(context);
|
2017-02-16 00:58:54 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
struct wined3d_texture *texture = texture_from_resource(resource);
|
|
|
|
|
|
|
|
view_target = get_texture_view_target(gl_info, desc, texture);
|
|
|
|
|
|
|
|
if (resource->format->id == view_format->id && texture->target == view_target
|
|
|
|
&& !desc->u.texture.level_idx && desc->u.texture.level_count == texture->level_count
|
|
|
|
&& !desc->u.texture.layer_idx && desc->u.texture.layer_count == texture->layer_count
|
|
|
|
&& !is_stencil_view_format(view_format))
|
|
|
|
{
|
|
|
|
TRACE("Creating identity shader resource view.\n");
|
|
|
|
}
|
|
|
|
else if (texture->swapchain && texture->swapchain->desc.backbuffer_count > 1)
|
|
|
|
{
|
|
|
|
FIXME("Swapchain shader resource views not supported.\n");
|
|
|
|
}
|
|
|
|
else if (resource->format->typeless_id == view_format->typeless_id
|
|
|
|
&& resource->format->gl_view_class == view_format->gl_view_class)
|
|
|
|
{
|
|
|
|
create_texture_view(&view->gl_view, view_target, desc, texture, view_format);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FIXME("Shader resource view not supported, resource format %s, view format %s.\n",
|
|
|
|
debug_d3dformat(resource->format->id), debug_d3dformat(view_format->id));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-07 13:24:39 +02:00
|
|
|
static HRESULT wined3d_shader_resource_view_init(struct wined3d_shader_resource_view *view,
|
2016-12-05 12:04:41 +01:00
|
|
|
const struct wined3d_view_desc *desc, struct wined3d_resource *resource,
|
2016-06-07 13:24:39 +02:00
|
|
|
void *parent, const struct wined3d_parent_ops *parent_ops)
|
|
|
|
{
|
2017-02-16 00:58:54 +01:00
|
|
|
view->refcount = 1;
|
|
|
|
view->parent = parent;
|
|
|
|
view->parent_ops = parent_ops;
|
2017-02-24 12:27:35 +01:00
|
|
|
|
|
|
|
if (!(view->format = validate_shader_resource_view(desc, resource, FALSE)))
|
|
|
|
return E_INVALIDARG;
|
2017-02-16 00:58:54 +01:00
|
|
|
view->desc = *desc;
|
|
|
|
|
2017-02-24 12:27:35 +01:00
|
|
|
wined3d_resource_incref(view->resource = resource);
|
|
|
|
|
2017-02-16 00:58:54 +01:00
|
|
|
wined3d_cs_init_object(resource->device->cs, wined3d_shader_resource_view_cs_init, view);
|
2016-06-07 13:24:39 +02:00
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2016-12-05 12:04:41 +01:00
|
|
|
HRESULT CDECL wined3d_shader_resource_view_create(const struct wined3d_view_desc *desc,
|
2016-06-06 11:39:02 +02:00
|
|
|
struct wined3d_resource *resource, void *parent, const struct wined3d_parent_ops *parent_ops,
|
|
|
|
struct wined3d_shader_resource_view **view)
|
2014-09-16 10:44:15 +02:00
|
|
|
{
|
|
|
|
struct wined3d_shader_resource_view *object;
|
2016-06-07 13:24:39 +02:00
|
|
|
HRESULT hr;
|
2014-09-16 10:44:15 +02:00
|
|
|
|
2016-06-06 11:39:02 +02:00
|
|
|
TRACE("desc %p, resource %p, parent %p, parent_ops %p, view %p.\n",
|
|
|
|
desc, resource, parent, parent_ops, view);
|
2014-09-16 10:44:15 +02:00
|
|
|
|
|
|
|
if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2016-06-07 13:24:39 +02:00
|
|
|
if (FAILED(hr = wined3d_shader_resource_view_init(object, desc, resource, parent, parent_ops)))
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, object);
|
|
|
|
WARN("Failed to initialise view, hr %#x.\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
2014-09-16 10:44:15 +02:00
|
|
|
|
|
|
|
TRACE("Created shader resource view %p.\n", object);
|
|
|
|
*view = object;
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
2016-06-07 13:24:39 +02:00
|
|
|
|
|
|
|
void wined3d_shader_resource_view_bind(struct wined3d_shader_resource_view *view,
|
|
|
|
struct wined3d_context *context)
|
|
|
|
{
|
|
|
|
struct wined3d_texture *texture;
|
|
|
|
|
2016-12-09 11:30:41 +01:00
|
|
|
if (view->gl_view.name)
|
2016-06-07 13:24:39 +02:00
|
|
|
{
|
2016-12-09 11:30:41 +01:00
|
|
|
context_bind_texture(context, view->gl_view.target, view->gl_view.name);
|
2016-06-07 13:24:39 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (view->resource->type == WINED3D_RTYPE_BUFFER)
|
|
|
|
{
|
|
|
|
FIXME("Buffer shader resources not supported.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
texture = wined3d_texture_from_resource(view->resource);
|
|
|
|
wined3d_texture_bind(texture, context, FALSE);
|
|
|
|
}
|
2016-06-24 11:46:02 +02:00
|
|
|
|
|
|
|
ULONG CDECL wined3d_unordered_access_view_incref(struct wined3d_unordered_access_view *view)
|
|
|
|
{
|
|
|
|
ULONG refcount = InterlockedIncrement(&view->refcount);
|
|
|
|
|
|
|
|
TRACE("%p increasing refcount to %u.\n", view, refcount);
|
|
|
|
|
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wined3d_unordered_access_view_destroy_object(void *object)
|
|
|
|
{
|
2017-03-02 09:44:29 +01:00
|
|
|
struct wined3d_unordered_access_view *view = object;
|
|
|
|
|
2017-03-03 01:30:32 +01:00
|
|
|
if (view->gl_view.name || view->counter_bo)
|
2017-03-02 09:44:29 +01:00
|
|
|
{
|
|
|
|
const struct wined3d_gl_info *gl_info;
|
|
|
|
struct wined3d_context *context;
|
|
|
|
|
|
|
|
context = context_acquire(view->resource->device, NULL, 0);
|
|
|
|
gl_info = context->gl_info;
|
2017-03-03 01:30:32 +01:00
|
|
|
if (view->gl_view.name)
|
|
|
|
gl_info->gl_ops.gl.p_glDeleteTextures(1, &view->gl_view.name);
|
|
|
|
if (view->counter_bo)
|
|
|
|
GL_EXTCALL(glDeleteBuffers(1, &view->counter_bo));
|
|
|
|
checkGLcall("delete resources");
|
2017-03-02 09:44:29 +01:00
|
|
|
context_release(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, view);
|
2016-06-24 11:46:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ULONG CDECL wined3d_unordered_access_view_decref(struct wined3d_unordered_access_view *view)
|
|
|
|
{
|
|
|
|
ULONG refcount = InterlockedDecrement(&view->refcount);
|
|
|
|
|
|
|
|
TRACE("%p decreasing refcount to %u.\n", view, refcount);
|
|
|
|
|
|
|
|
if (!refcount)
|
|
|
|
{
|
2016-07-03 17:49:34 +02:00
|
|
|
struct wined3d_resource *resource = view->resource;
|
|
|
|
struct wined3d_device *device = resource->device;
|
2016-06-24 11:46:02 +02:00
|
|
|
|
|
|
|
/* 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);
|
2017-02-16 00:58:53 +01:00
|
|
|
wined3d_cs_destroy_object(device->cs, wined3d_unordered_access_view_destroy_object, view);
|
2016-07-03 17:49:34 +02:00
|
|
|
wined3d_resource_decref(resource);
|
2016-06-24 11:46:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
|
|
|
void * CDECL wined3d_unordered_access_view_get_parent(const struct wined3d_unordered_access_view *view)
|
|
|
|
{
|
|
|
|
TRACE("view %p.\n", view);
|
|
|
|
|
|
|
|
return view->parent;
|
|
|
|
}
|
|
|
|
|
2016-11-23 14:36:07 +01:00
|
|
|
void wined3d_unordered_access_view_invalidate_location(struct wined3d_unordered_access_view *view,
|
|
|
|
DWORD location)
|
|
|
|
{
|
|
|
|
struct wined3d_resource *resource = view->resource;
|
2016-11-29 12:06:28 +01:00
|
|
|
unsigned int i, sub_resource_idx, layer_count;
|
2016-11-23 14:36:07 +01:00
|
|
|
struct wined3d_texture *texture;
|
|
|
|
|
2016-11-29 12:06:28 +01:00
|
|
|
if (resource->type == WINED3D_RTYPE_BUFFER)
|
2016-11-23 14:36:07 +01:00
|
|
|
{
|
2017-02-14 13:15:10 +01:00
|
|
|
wined3d_buffer_invalidate_location(buffer_from_resource(resource), location);
|
2016-11-23 14:36:07 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
texture = texture_from_resource(resource);
|
|
|
|
|
2017-02-16 00:58:55 +01:00
|
|
|
sub_resource_idx = view->desc.u.texture.layer_idx * texture->level_count + view->desc.u.texture.level_idx;
|
|
|
|
layer_count = (resource->type != WINED3D_RTYPE_TEXTURE_3D) ? view->desc.u.texture.layer_count : 1;
|
2016-11-29 12:06:28 +01:00
|
|
|
for (i = 0; i < layer_count; ++i, sub_resource_idx += texture->level_count)
|
2016-11-23 14:36:07 +01:00
|
|
|
wined3d_texture_invalidate_location(texture, sub_resource_idx, location);
|
|
|
|
}
|
|
|
|
|
2017-02-16 00:58:55 +01:00
|
|
|
static void wined3d_unordered_access_view_cs_init(void *object)
|
|
|
|
{
|
|
|
|
struct wined3d_unordered_access_view *view = object;
|
|
|
|
struct wined3d_resource *resource = view->resource;
|
|
|
|
struct wined3d_view_desc *desc = &view->desc;
|
|
|
|
const struct wined3d_gl_info *gl_info;
|
|
|
|
|
|
|
|
gl_info = &resource->device->adapter->gl_info;
|
|
|
|
|
|
|
|
if (resource->type == WINED3D_RTYPE_BUFFER)
|
|
|
|
{
|
|
|
|
struct wined3d_buffer *buffer = buffer_from_resource(resource);
|
2017-03-03 01:30:32 +01:00
|
|
|
struct wined3d_context *context;
|
2017-02-16 00:58:55 +01:00
|
|
|
|
2017-03-03 01:30:32 +01:00
|
|
|
context = context_acquire(resource->device, NULL, 0);
|
|
|
|
gl_info = context->gl_info;
|
|
|
|
create_buffer_view(&view->gl_view, context, desc, buffer, view->format);
|
|
|
|
if (desc->flags & WINED3D_VIEW_BUFFER_COUNTER)
|
|
|
|
{
|
|
|
|
static const GLuint initial_value = 0;
|
|
|
|
GL_EXTCALL(glGenBuffers(1, &view->counter_bo));
|
|
|
|
GL_EXTCALL(glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, view->counter_bo));
|
|
|
|
GL_EXTCALL(glBufferData(GL_ATOMIC_COUNTER_BUFFER,
|
|
|
|
sizeof(initial_value), &initial_value, GL_STATIC_DRAW));
|
|
|
|
checkGLcall("create atomic counter buffer");
|
|
|
|
}
|
|
|
|
context_release(context);
|
2017-02-16 00:58:55 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
struct wined3d_texture *texture = texture_from_resource(resource);
|
|
|
|
unsigned int depth_or_layer_count;
|
|
|
|
|
|
|
|
if (resource->type == WINED3D_RTYPE_TEXTURE_3D)
|
|
|
|
depth_or_layer_count = wined3d_texture_get_level_depth(texture, desc->u.texture.level_idx);
|
|
|
|
else
|
|
|
|
depth_or_layer_count = texture->layer_count;
|
|
|
|
|
|
|
|
if (desc->u.texture.layer_idx || desc->u.texture.layer_count != depth_or_layer_count)
|
|
|
|
{
|
|
|
|
create_texture_view(&view->gl_view, get_texture_view_target(gl_info, desc, texture),
|
|
|
|
desc, texture, view->format);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-24 11:46:02 +02:00
|
|
|
static HRESULT wined3d_unordered_access_view_init(struct wined3d_unordered_access_view *view,
|
2016-12-05 12:04:41 +01:00
|
|
|
const struct wined3d_view_desc *desc, struct wined3d_resource *resource,
|
2016-06-24 11:46:02 +02:00
|
|
|
void *parent, const struct wined3d_parent_ops *parent_ops)
|
|
|
|
{
|
|
|
|
view->refcount = 1;
|
|
|
|
view->parent = parent;
|
|
|
|
view->parent_ops = parent_ops;
|
|
|
|
|
2017-02-24 12:27:35 +01:00
|
|
|
if (!(view->format = validate_shader_resource_view(desc, resource, TRUE)))
|
2016-06-24 11:46:02 +02:00
|
|
|
return E_INVALIDARG;
|
2017-02-24 12:27:35 +01:00
|
|
|
view->desc = *desc;
|
2016-06-24 11:46:02 +02:00
|
|
|
|
2017-03-03 01:30:32 +01:00
|
|
|
if (desc->flags & WINED3D_VIEW_BUFFER_APPEND)
|
2017-03-03 01:30:28 +01:00
|
|
|
FIXME("Unhandled view flags %#x.\n", desc->flags);
|
|
|
|
|
2016-06-24 11:46:02 +02:00
|
|
|
wined3d_resource_incref(view->resource = resource);
|
|
|
|
|
2017-02-16 00:58:55 +01:00
|
|
|
wined3d_cs_init_object(resource->device->cs, wined3d_unordered_access_view_cs_init, view);
|
|
|
|
|
2016-06-24 11:46:02 +02:00
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2016-12-05 12:04:41 +01:00
|
|
|
HRESULT CDECL wined3d_unordered_access_view_create(const struct wined3d_view_desc *desc,
|
2016-06-24 11:46:02 +02:00
|
|
|
struct wined3d_resource *resource, void *parent, const struct wined3d_parent_ops *parent_ops,
|
|
|
|
struct wined3d_unordered_access_view **view)
|
|
|
|
{
|
|
|
|
struct wined3d_unordered_access_view *object;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("desc %p, resource %p, parent %p, parent_ops %p, view %p.\n",
|
|
|
|
desc, resource, parent, parent_ops, view);
|
|
|
|
|
|
|
|
if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
if (FAILED(hr = wined3d_unordered_access_view_init(object, desc, resource, parent, parent_ops)))
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, object);
|
|
|
|
WARN("Failed to initialise view, hr %#x.\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Created unordered access view %p.\n", object);
|
|
|
|
*view = object;
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|