/* Context activation is done by the caller. */ void wined3d_volume_upload_data(struct wined3d_volume *volume, const struct wined3d_context *context, const struct wined3d_const_bo_address *data) { const struct wined3d_gl_info *gl_info = context->gl_info; struct wined3d_texture *texture = volume->container; const struct wined3d_format *format = texture->resource.format; unsigned int width, height, depth; const void *mem = data->addr; void *converted_mem = NULL; TRACE("volume %p, context %p, level %u, format %s (%#x).\n", volume, context, volume->texture_level, debug_d3dformat(format->id), format->id); width = wined3d_texture_get_level_width(texture, volume->texture_level); height = wined3d_texture_get_level_height(texture, volume->texture_level); depth = wined3d_texture_get_level_depth(texture, volume->texture_level); if (format->convert) { UINT dst_row_pitch, dst_slice_pitch; UINT src_row_pitch, src_slice_pitch; if (data->buffer_object) ERR("Loading a converted volume from a PBO.\n"); if (texture->resource.format_flags & WINED3DFMT_FLAG_BLOCKS) ERR("Converting a block-based format.\n"); dst_row_pitch = width * format->conv_byte_count; dst_slice_pitch = dst_row_pitch * height; wined3d_texture_get_pitch(texture, volume->texture_level, &src_row_pitch, &src_slice_pitch); converted_mem = HeapAlloc(GetProcessHeap(), 0, dst_slice_pitch * depth); format->convert(data->addr, converted_mem, src_row_pitch, src_slice_pitch, dst_row_pitch, dst_slice_pitch, width, height, depth); mem = converted_mem; } if (data->buffer_object) { GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, data->buffer_object)); checkGLcall("glBindBuffer"); } GL_EXTCALL(glTexSubImage3D(GL_TEXTURE_3D, volume->texture_level, 0, 0, 0, width, height, depth, format->glFormat, format->glType, mem)); checkGLcall("glTexSubImage3D"); if (data->buffer_object) { GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0)); checkGLcall("glBindBuffer"); } HeapFree(GetProcessHeap(), 0, converted_mem); }
static HRESULT wined3d_rendertarget_view_init(struct wined3d_rendertarget_view *view, const struct wined3d_rendertarget_view_desc *desc, struct wined3d_resource *resource, 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->parent = parent; view->parent_ops = parent_ops; view->format = wined3d_get_format(gl_info, desc->format_id); view->format_flags = view->format->flags[resource->gl_type]; 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) { 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 { 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.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; 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; view->buffer_offset = 0; 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); view->depth = desc->u.texture.layer_count; } wined3d_resource_incref(view->resource = resource); return WINED3D_OK; }
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); struct wined3d_context *context; 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 | WINED3D_VIEW_BUFFER_APPEND)) { 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); } 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); } } wined3d_resource_release(resource); }
static void wined3d_render_target_view_cs_init(void *object) { struct wined3d_rendertarget_view *view = object; struct wined3d_resource *resource = view->resource; const struct wined3d_view_desc *desc = &view->desc; if (resource->type == WINED3D_RTYPE_BUFFER) { FIXME("Not implemented for resources %s.\n", debug_d3dresourcetype(resource->type)); } 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 (resource->format->id != view->format->id || (view->layer_count != 1 && view->layer_count != depth_or_layer_count)) { if (resource->format->gl_view_class != view->format->gl_view_class) { FIXME("Render target view not supported, resource format %s, view format %s.\n", debug_d3dformat(resource->format->id), debug_d3dformat(view->format->id)); return; } if (texture->swapchain && texture->swapchain->desc.backbuffer_count > 1) { FIXME("Swapchain views not supported.\n"); return; } create_texture_view(&view->gl_view, texture->target, desc, texture, view->format); } } }
static HRESULT wined3d_unordered_access_view_init(struct wined3d_unordered_access_view *view, const struct wined3d_unordered_access_view_desc *desc, struct wined3d_resource *resource, 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->parent = parent; view->parent_ops = parent_ops; view->format = wined3d_get_format(gl_info, desc->format_id); 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_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.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); return WINED3D_OK; }
static const struct wined3d_format *validate_resource_view(const struct wined3d_view_desc *desc, struct wined3d_resource *resource, BOOL mip_slice, BOOL allow_srgb_toggle) { 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 (resource->format->id != format->id && !wined3d_format_is_typeless(resource->format) && (!allow_srgb_toggle || !wined3d_formats_are_srgb_variants(resource->format->id, format->id))) { WARN("Trying to create incompatible view for non typeless format %s.\n", debug_d3dformat(format->id)); return NULL; } 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; }