wined3d: Extract common code to validate_shader_resource_view().
Signed-off-by: Józef Kucia <jkucia@codeweavers.com> Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
d51c60e11d
commit
f0bff11738
|
@ -68,6 +68,82 @@ static GLenum get_texture_view_target(const struct wined3d_gl_info *gl_info,
|
||||||
return texture->target;
|
return texture->target;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
static void create_texture_view(struct wined3d_gl_view *view, GLenum view_target,
|
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_view_desc *desc, struct wined3d_texture *texture,
|
||||||
const struct wined3d_format *view_format)
|
const struct wined3d_format *view_format)
|
||||||
|
@ -524,76 +600,16 @@ static HRESULT wined3d_shader_resource_view_init(struct wined3d_shader_resource_
|
||||||
const struct wined3d_view_desc *desc, struct wined3d_resource *resource,
|
const struct wined3d_view_desc *desc, struct wined3d_resource *resource,
|
||||||
void *parent, const struct wined3d_parent_ops *parent_ops)
|
void *parent, const struct wined3d_parent_ops *parent_ops)
|
||||||
{
|
{
|
||||||
const struct wined3d_gl_info *gl_info = &resource->device->adapter->gl_info;
|
|
||||||
const struct wined3d_format *view_format;
|
|
||||||
|
|
||||||
view_format = wined3d_get_format(gl_info, desc->format_id, resource->usage);
|
|
||||||
if (resource->type == WINED3D_RTYPE_BUFFER && desc->flags & WINED3D_VIEW_BUFFER_RAW)
|
|
||||||
{
|
|
||||||
if (view_format->id != WINED3DFMT_R32_TYPELESS)
|
|
||||||
{
|
|
||||||
WARN("Invalid format %s for raw buffer view.\n", debug_d3dformat(view_format->id));
|
|
||||||
return E_INVALIDARG;
|
|
||||||
}
|
|
||||||
|
|
||||||
view_format = wined3d_get_format(gl_info, WINED3DFMT_R32_UINT, resource->usage);
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
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 E_INVALIDARG;
|
|
||||||
}
|
|
||||||
|
|
||||||
view_format = wined3d_get_format(gl_info, WINED3DFMT_R32_UINT, resource->usage);
|
|
||||||
element_size = buffer->desc.structure_byte_stride;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
element_size = view_format->byte_count;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!element_size)
|
|
||||||
return E_INVALIDARG;
|
|
||||||
|
|
||||||
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 E_INVALIDARG;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
struct wined3d_texture *texture = texture_from_resource(resource);
|
|
||||||
|
|
||||||
if (!desc->u.texture.level_count
|
|
||||||
|| 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 >= texture->layer_count
|
|
||||||
|| desc->u.texture.layer_count > texture->layer_count - desc->u.texture.layer_idx)
|
|
||||||
return E_INVALIDARG;
|
|
||||||
}
|
|
||||||
|
|
||||||
view->refcount = 1;
|
view->refcount = 1;
|
||||||
wined3d_resource_incref(view->resource = resource);
|
|
||||||
view->parent = parent;
|
view->parent = parent;
|
||||||
view->parent_ops = parent_ops;
|
view->parent_ops = parent_ops;
|
||||||
view->format = view_format;
|
|
||||||
|
if (!(view->format = validate_shader_resource_view(desc, resource, FALSE)))
|
||||||
|
return E_INVALIDARG;
|
||||||
view->desc = *desc;
|
view->desc = *desc;
|
||||||
|
|
||||||
|
wined3d_resource_incref(view->resource = resource);
|
||||||
|
|
||||||
wined3d_cs_init_object(resource->device->cs, wined3d_shader_resource_view_cs_init, view);
|
wined3d_cs_init_object(resource->device->cs, wined3d_shader_resource_view_cs_init, view);
|
||||||
|
|
||||||
return WINED3D_OK;
|
return WINED3D_OK;
|
||||||
|
@ -746,78 +762,14 @@ static HRESULT wined3d_unordered_access_view_init(struct wined3d_unordered_acces
|
||||||
const struct wined3d_view_desc *desc, struct wined3d_resource *resource,
|
const struct wined3d_view_desc *desc, struct wined3d_resource *resource,
|
||||||
void *parent, const struct wined3d_parent_ops *parent_ops)
|
void *parent, const struct wined3d_parent_ops *parent_ops)
|
||||||
{
|
{
|
||||||
const struct wined3d_gl_info *gl_info = &resource->device->adapter->gl_info;
|
|
||||||
|
|
||||||
view->refcount = 1;
|
view->refcount = 1;
|
||||||
view->parent = parent;
|
view->parent = parent;
|
||||||
view->parent_ops = parent_ops;
|
view->parent_ops = parent_ops;
|
||||||
|
|
||||||
view->format = wined3d_get_format(gl_info, desc->format_id, resource->usage);
|
if (!(view->format = validate_shader_resource_view(desc, resource, TRUE)))
|
||||||
|
return E_INVALIDARG;
|
||||||
view->desc = *desc;
|
view->desc = *desc;
|
||||||
|
|
||||||
if (resource->type == WINED3D_RTYPE_BUFFER && desc->flags & WINED3D_VIEW_BUFFER_RAW)
|
|
||||||
{
|
|
||||||
if (view->format->id != WINED3DFMT_R32_TYPELESS)
|
|
||||||
{
|
|
||||||
WARN("Invalid format %s for raw buffer view.\n", debug_d3dformat(view->format->id));
|
|
||||||
return E_INVALIDARG;
|
|
||||||
}
|
|
||||||
|
|
||||||
view->format = wined3d_get_format(gl_info, WINED3DFMT_R32_UINT, resource->usage);
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
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 E_INVALIDARG;
|
|
||||||
}
|
|
||||||
|
|
||||||
view->format = wined3d_get_format(gl_info, WINED3DFMT_R32_UINT, resource->usage);
|
|
||||||
element_size = buffer->desc.structure_byte_stride;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
element_size = view->format->byte_count;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!element_size)
|
|
||||||
return E_INVALIDARG;
|
|
||||||
|
|
||||||
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 E_INVALIDARG;
|
|
||||||
}
|
|
||||||
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.level_idx >= texture->level_count
|
|
||||||
|| desc->u.texture.level_count != 1
|
|
||||||
|| desc->u.texture.layer_idx >= depth_or_layer_count
|
|
||||||
|| !desc->u.texture.layer_count
|
|
||||||
|| desc->u.texture.layer_count > depth_or_layer_count - desc->u.texture.layer_idx)
|
|
||||||
return E_INVALIDARG;
|
|
||||||
}
|
|
||||||
wined3d_resource_incref(view->resource = resource);
|
wined3d_resource_incref(view->resource = resource);
|
||||||
|
|
||||||
wined3d_cs_init_object(resource->device->cs, wined3d_unordered_access_view_cs_init, view);
|
wined3d_cs_init_object(resource->device->cs, wined3d_unordered_access_view_cs_init, view);
|
||||||
|
|
Loading…
Reference in New Issue