ReactOS 0.4.17-dev-966-gf06eace
texture.c File Reference
#include "wined3d_private.h"
#include "wined3d_gl.h"
#include "wined3d_vk.h"
Include dependency graph for texture.c:

Go to the source code of this file.

Classes

struct  wined3d_texture_idx
 
struct  wined3d_rect_f
 
struct  d3dfmt_alpha_fixup
 

Macros

#define WINED3D_TEXTURE_DYNAMIC_MAP_THRESHOLD   50
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (d3d)
 
 WINE_DECLARE_DEBUG_CHANNEL (d3d_perf)
 
 WINE_DECLARE_DEBUG_CHANNEL (winediag)
 
bool wined3d_texture_validate_sub_resource_idx (const struct wined3d_texture *texture, unsigned int sub_resource_idx)
 
BOOL wined3d_texture_can_use_pbo (const struct wined3d_texture *texture, const struct wined3d_d3d_info *d3d_info)
 
static BOOL wined3d_texture_use_pbo (const struct wined3d_texture *texture, const struct wined3d_d3d_info *d3d_info)
 
static BOOL wined3d_texture_use_immutable_storage (const struct wined3d_texture *texture, const struct wined3d_gl_info *gl_info)
 
void wined3d_texture_translate_drawable_coords (const struct wined3d_texture *texture, HWND window, RECT *rect)
 
GLenum wined3d_texture_get_gl_buffer (const struct wined3d_texture *texture)
 
static uint32_t wined3d_resource_access_from_location (uint32_t location)
 
static void cube_coords_float (const RECT *r, UINT w, UINT h, struct wined3d_rect_f *f)
 
void texture2d_get_blt_info (const struct wined3d_texture_gl *texture_gl, unsigned int sub_resource_idx, const RECT *rect, struct wined3d_blt_info *info)
 
static bool fbo_blitter_supported (enum wined3d_blit_op blit_op, const struct wined3d_gl_info *gl_info, const struct wined3d_resource *src_resource, DWORD src_location, const struct wined3d_resource *dst_resource, DWORD dst_location)
 
static void texture2d_blt_fbo (struct wined3d_device *device, struct wined3d_context *context, enum wined3d_texture_filter_type filter, struct wined3d_texture *src_texture, unsigned int src_sub_resource_idx, DWORD src_location, const RECT *src_rect, struct wined3d_texture *dst_texture, unsigned int dst_sub_resource_idx, DWORD dst_location, const RECT *dst_rect, const struct wined3d_format *resolve_format)
 
static void texture2d_depth_blt_fbo (const struct wined3d_device *device, struct wined3d_context *context, struct wined3d_texture *src_texture, unsigned int src_sub_resource_idx, DWORD src_location, const RECT *src_rect, struct wined3d_texture *dst_texture, unsigned int dst_sub_resource_idx, DWORD dst_location, const RECT *dst_rect)
 
static void wined3d_texture_evict_sysmem (struct wined3d_texture *texture)
 
void wined3d_texture_validate_location (struct wined3d_texture *texture, unsigned int sub_resource_idx, uint32_t location)
 
static void wined3d_texture_set_dirty (struct wined3d_texture *texture)
 
void wined3d_texture_invalidate_location (struct wined3d_texture *texture, unsigned int sub_resource_idx, uint32_t location)
 
void wined3d_texture_get_bo_address (const struct wined3d_texture *texture, unsigned int sub_resource_idx, struct wined3d_bo_address *data, uint32_t location)
 
void wined3d_texture_clear_dirty_regions (struct wined3d_texture *texture)
 
BOOL wined3d_texture_load_location (struct wined3d_texture *texture, unsigned int sub_resource_idx, struct wined3d_context *context, uint32_t location)
 
static void wined3d_texture_get_memory (struct wined3d_texture *texture, unsigned int sub_resource_idx, struct wined3d_context *context, struct wined3d_bo_address *data)
 
static void wined3d_texture_remove_buffer_object (struct wined3d_texture *texture, unsigned int sub_resource_idx, struct wined3d_context_gl *context_gl)
 
static void wined3d_texture_unload_location (struct wined3d_texture *texture, struct wined3d_context *context, unsigned int location)
 
static void wined3d_texture_update_map_binding (struct wined3d_texture *texture)
 
static void wined3d_texture_set_map_binding (struct wined3d_texture *texture, DWORD map_binding)
 
static void gltexture_delete (struct wined3d_device *device, const struct wined3d_gl_info *gl_info, struct gl_texture *tex)
 
static void wined3d_texture_gl_allocate_mutable_storage (struct wined3d_texture_gl *texture_gl, GLenum gl_internal_format, const struct wined3d_format_gl *format, const struct wined3d_gl_info *gl_info)
 
static void wined3d_texture_gl_allocate_immutable_storage (struct wined3d_texture_gl *texture_gl, GLenum gl_internal_format, const struct wined3d_gl_info *gl_info)
 
static void wined3d_texture_dirty_region_add (struct wined3d_texture *texture, unsigned int layer, const struct wined3d_box *box)
 
void wined3d_texture_sub_resources_destroyed (struct wined3d_texture *texture)
 
static void wined3d_texture_create_dc (void *object)
 
static void wined3d_texture_destroy_dc (void *object)
 
void wined3d_texture_set_swapchain (struct wined3d_texture *texture, struct wined3d_swapchain *swapchain)
 
void wined3d_gl_texture_swizzle_from_color_fixup (GLint swizzle[4], struct color_fixup_desc fixup)
 
void wined3d_texture_gl_bind (struct wined3d_texture_gl *texture_gl, struct wined3d_context_gl *context_gl, BOOL srgb)
 
void wined3d_texture_gl_bind_and_dirtify (struct wined3d_texture_gl *texture_gl, struct wined3d_context_gl *context_gl, BOOL srgb)
 
void wined3d_texture_gl_apply_sampler_desc (struct wined3d_texture_gl *texture_gl, const struct wined3d_sampler_desc *sampler_desc, const struct wined3d_context_gl *context_gl)
 
ULONG CDECL wined3d_texture_incref (struct wined3d_texture *texture)
 
static void wined3d_texture_destroy_object (void *object)
 
void wined3d_texture_cleanup (struct wined3d_texture *texture)
 
static void wined3d_texture_cleanup_sync (struct wined3d_texture *texture)
 
ULONG CDECL wined3d_texture_decref (struct wined3d_texture *texture)
 
struct wined3d_resource *CDECL wined3d_texture_get_resource (struct wined3d_texture *texture)
 
void wined3d_texture_load (struct wined3d_texture *texture, struct wined3d_context *context, BOOL srgb)
 
void *CDECL wined3d_texture_get_parent (const struct wined3d_texture *texture)
 
void CDECL wined3d_texture_get_pitch (const struct wined3d_texture *texture, unsigned int level, unsigned int *row_pitch, unsigned int *slice_pitch)
 
unsigned int CDECL wined3d_texture_get_lod (const struct wined3d_texture *texture)
 
unsigned int CDECL wined3d_texture_set_lod (struct wined3d_texture *texture, unsigned int lod)
 
UINT CDECL wined3d_texture_get_level_count (const struct wined3d_texture *texture)
 
HRESULT CDECL wined3d_texture_set_color_key (struct wined3d_texture *texture, uint32_t flags, const struct wined3d_color_key *color_key)
 
void wined3d_texture_gl_set_compatible_renderbuffer (struct wined3d_texture_gl *texture_gl, struct wined3d_context_gl *context_gl, unsigned int level, const struct wined3d_rendertarget_info *rt)
 
HRESULT CDECL wined3d_texture_update_desc (struct wined3d_texture *texture, unsigned int sub_resource_idx, void *mem, unsigned int pitch)
 
static void wined3d_texture_gl_prepare_buffer_object (struct wined3d_texture_gl *texture_gl, unsigned int sub_resource_idx, struct wined3d_context_gl *context_gl)
 
static void wined3d_texture_force_reload (struct wined3d_texture *texture)
 
void wined3d_texture_gl_prepare_texture (struct wined3d_texture_gl *texture_gl, struct wined3d_context_gl *context_gl, BOOL srgb)
 
static void wined3d_texture_gl_prepare_rb (struct wined3d_texture_gl *texture_gl, const struct wined3d_gl_info *gl_info, BOOL multisample)
 
BOOL wined3d_texture_prepare_location (struct wined3d_texture *texture, unsigned int sub_resource_idx, struct wined3d_context *context, unsigned int location)
 
static struct wined3d_texture_sub_resource * wined3d_texture_get_sub_resource (struct wined3d_texture *texture, unsigned int sub_resource_idx)
 
HRESULT CDECL wined3d_texture_add_dirty_region (struct wined3d_texture *texture, UINT layer, const struct wined3d_box *dirty_region)
 
static void wined3d_texture_gl_upload_bo (const struct wined3d_format *src_format, GLenum target, unsigned int level, unsigned int src_row_pitch, unsigned int src_slice_pitch, unsigned int dst_x, unsigned int dst_y, unsigned int dst_z, unsigned int update_w, unsigned int update_h, unsigned int update_d, const BYTE *addr, BOOL srgb, struct wined3d_texture *dst_texture, const struct wined3d_gl_info *gl_info)
 
static enum wined3d_format_id wined3d_get_alpha_fixup_format (enum wined3d_format_id format_id, const struct wined3d_format *dst_format)
 
static void wined3d_fixup_alpha (const struct wined3d_format *format, const uint8_t *src, unsigned int src_row_pitch, uint8_t *dst, unsigned int dst_row_pitch, unsigned int width, unsigned int height)
 
static void wined3d_texture_gl_upload_data (struct wined3d_context *context, const struct wined3d_const_bo_address *src_bo_addr, const struct wined3d_format *src_format, const struct wined3d_box *src_box, unsigned int src_row_pitch, unsigned int src_slice_pitch, struct wined3d_texture *dst_texture, unsigned int dst_sub_resource_idx, unsigned int dst_location, unsigned int dst_x, unsigned int dst_y, unsigned int dst_z)
 
static void wined3d_texture_gl_download_data_slow_path (struct wined3d_texture_gl *texture_gl, unsigned int sub_resource_idx, struct wined3d_context_gl *context_gl, const struct wined3d_bo_address *data)
 
static void wined3d_texture_gl_download_data (struct wined3d_context *context, struct wined3d_texture *src_texture, unsigned int src_sub_resource_idx, unsigned int src_location, const struct wined3d_box *src_box, const struct wined3d_bo_address *dst_bo_addr, const struct wined3d_format *dst_format, unsigned int dst_x, unsigned int dst_y, unsigned int dst_z, unsigned int dst_row_pitch, unsigned int dst_slice_pitch)
 
static BOOL wined3d_texture_gl_load_sysmem (struct wined3d_texture_gl *texture_gl, unsigned int sub_resource_idx, struct wined3d_context_gl *context_gl, DWORD dst_location)
 
static BOOL wined3d_texture_load_drawable (struct wined3d_texture *texture, unsigned int sub_resource_idx, struct wined3d_context *context)
 
static BOOL wined3d_texture_load_renderbuffer (struct wined3d_texture *texture, unsigned int sub_resource_idx, struct wined3d_context *context, DWORD dst_location)
 
static BOOL wined3d_texture_gl_load_texture (struct wined3d_texture_gl *texture_gl, unsigned int sub_resource_idx, struct wined3d_context_gl *context_gl, BOOL srgb)
 
static BOOL wined3d_texture_gl_prepare_location (struct wined3d_texture *texture, unsigned int sub_resource_idx, struct wined3d_context *context, unsigned int location)
 
static bool use_ffp_clear (const struct wined3d_texture *texture, unsigned int location)
 
static bool wined3d_texture_gl_clear (struct wined3d_texture *texture, unsigned int sub_resource_idx, struct wined3d_context_gl *context_gl, unsigned int location)
 
static BOOL wined3d_texture_gl_load_location (struct wined3d_texture *texture, unsigned int sub_resource_idx, struct wined3d_context *context, uint32_t location)
 
static void wined3d_texture_gl_unload_location (struct wined3d_texture *texture, struct wined3d_context *context, unsigned int location)
 
struct wined3d_texture *__cdecl wined3d_texture_from_resource (struct wined3d_resource *resource)
 
static ULONG texture_resource_incref (struct wined3d_resource *resource)
 
static ULONG texture_resource_decref (struct wined3d_resource *resource)
 
static void texture_resource_preload (struct wined3d_resource *resource)
 
static void texture_resource_unload (struct wined3d_resource *resource)
 
static HRESULT texture_resource_sub_resource_get_desc (struct wined3d_resource *resource, unsigned int sub_resource_idx, struct wined3d_sub_resource_desc *desc)
 
static void texture_resource_sub_resource_get_map_pitch (struct wined3d_resource *resource, unsigned int sub_resource_idx, unsigned int *row_pitch, unsigned int *slice_pitch)
 
static HRESULT texture_resource_sub_resource_map (struct wined3d_resource *resource, unsigned int sub_resource_idx, void **map_ptr, const struct wined3d_box *box, uint32_t flags)
 
static HRESULT texture_resource_sub_resource_unmap (struct wined3d_resource *resource, unsigned int sub_resource_idx)
 
static HRESULT wined3d_texture_init (struct wined3d_texture *texture, const struct wined3d_resource_desc *desc, unsigned int layer_count, unsigned int level_count, uint32_t flags, struct wined3d_device *device, void *parent, const struct wined3d_parent_ops *parent_ops, void *sub_resources, const struct wined3d_texture_ops *texture_ops)
 
HRESULT CDECL wined3d_device_context_blt (struct wined3d_device_context *context, struct wined3d_texture *dst_texture, unsigned int dst_sub_resource_idx, const RECT *dst_rect, struct wined3d_texture *src_texture, unsigned int src_sub_resource_idx, const RECT *src_rect, unsigned int flags, const struct wined3d_blt_fx *fx, enum wined3d_texture_filter_type filter)
 
HRESULT CDECL wined3d_texture_get_overlay_position (const struct wined3d_texture *texture, unsigned int sub_resource_idx, LONG *x, LONG *y)
 
HRESULT CDECL wined3d_texture_set_overlay_position (struct wined3d_texture *texture, unsigned int sub_resource_idx, LONG x, LONG y)
 
HRESULT CDECL wined3d_texture_update_overlay (struct wined3d_texture *texture, unsigned int sub_resource_idx, const RECT *src_rect, struct wined3d_texture *dst_texture, unsigned int dst_sub_resource_idx, const RECT *dst_rect, uint32_t flags)
 
struct wined3d_swapchain *CDECL wined3d_texture_get_swapchain (struct wined3d_texture *texture)
 
void *CDECL wined3d_texture_get_sub_resource_parent (struct wined3d_texture *texture, unsigned int sub_resource_idx)
 
void CDECL wined3d_texture_set_sub_resource_parent (struct wined3d_texture *texture, unsigned int sub_resource_idx, void *parent, const struct wined3d_parent_ops *parent_ops)
 
HRESULT CDECL wined3d_texture_get_sub_resource_desc (const struct wined3d_texture *texture, unsigned int sub_resource_idx, struct wined3d_sub_resource_desc *desc)
 
HRESULT wined3d_texture_gl_init (struct wined3d_texture_gl *texture_gl, struct wined3d_device *device, const struct wined3d_resource_desc *desc, unsigned int layer_count, unsigned int level_count, uint32_t flags, void *parent, const struct wined3d_parent_ops *parent_ops)
 
HRESULT CDECL wined3d_texture_create (struct wined3d_device *device, const struct wined3d_resource_desc *desc, UINT layer_count, UINT level_count, uint32_t flags, const struct wined3d_sub_resource_data *data, void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_texture **texture)
 
HRESULT CDECL wined3d_texture_get_dc (struct wined3d_texture *texture, unsigned int sub_resource_idx, HDC *dc)
 
HRESULT CDECL wined3d_texture_release_dc (struct wined3d_texture *texture, unsigned int sub_resource_idx, HDC dc)
 
void wined3d_texture_upload_from_texture (struct wined3d_texture *dst_texture, unsigned int dst_sub_resource_idx, unsigned int dst_x, unsigned int dst_y, unsigned int dst_z, struct wined3d_texture *src_texture, unsigned int src_sub_resource_idx, const struct wined3d_box *src_box)
 
void wined3d_texture_download_from_texture (struct wined3d_texture *dst_texture, unsigned int dst_sub_resource_idx, struct wined3d_texture *src_texture, unsigned int src_sub_resource_idx)
 
static void wined3d_texture_set_bo (struct wined3d_texture *texture, unsigned sub_resource_idx, struct wined3d_context *context, struct wined3d_bo *bo)
 
void wined3d_texture_update_sub_resource (struct wined3d_texture *texture, unsigned int sub_resource_idx, struct wined3d_context *context, const struct upload_bo *upload_bo, const struct wined3d_box *box, unsigned int row_pitch, unsigned int slice_pitch)
 
struct wined3d_shader_resource_view *CDECL wined3d_texture_acquire_identity_srv (struct wined3d_texture *texture)
 
static void wined3d_texture_no3d_upload_data (struct wined3d_context *context, const struct wined3d_const_bo_address *src_bo_addr, const struct wined3d_format *src_format, const struct wined3d_box *src_box, unsigned int src_row_pitch, unsigned int src_slice_pitch, struct wined3d_texture *dst_texture, unsigned int dst_sub_resource_idx, unsigned int dst_location, unsigned int dst_x, unsigned int dst_y, unsigned int dst_z)
 
static void wined3d_texture_no3d_download_data (struct wined3d_context *context, struct wined3d_texture *src_texture, unsigned int src_sub_resource_idx, unsigned int src_location, const struct wined3d_box *src_box, const struct wined3d_bo_address *dst_bo_addr, const struct wined3d_format *dst_format, unsigned int dst_x, unsigned int dst_y, unsigned int dst_z, unsigned int dst_row_pitch, unsigned int dst_slice_pitch)
 
static BOOL wined3d_texture_no3d_prepare_location (struct wined3d_texture *texture, unsigned int sub_resource_idx, struct wined3d_context *context, unsigned int location)
 
static BOOL wined3d_texture_no3d_load_location (struct wined3d_texture *texture, unsigned int sub_resource_idx, struct wined3d_context *context, uint32_t location)
 
static void wined3d_texture_no3d_unload_location (struct wined3d_texture *texture, struct wined3d_context *context, unsigned int location)
 
HRESULT wined3d_texture_no3d_init (struct wined3d_texture *texture_no3d, struct wined3d_device *device, const struct wined3d_resource_desc *desc, unsigned int layer_count, unsigned int level_count, uint32_t flags, void *parent, const struct wined3d_parent_ops *parent_ops)
 
void wined3d_vk_swizzle_from_color_fixup (VkComponentMapping *mapping, struct color_fixup_desc fixup)
 
const VkDescriptorImageInfo * wined3d_texture_vk_get_default_image_info (struct wined3d_texture_vk *texture_vk, struct wined3d_context_vk *context_vk)
 
static void wined3d_texture_vk_upload_data (struct wined3d_context *context, const struct wined3d_const_bo_address *src_bo_addr, const struct wined3d_format *src_format, const struct wined3d_box *src_box, unsigned int src_row_pitch, unsigned int src_slice_pitch, struct wined3d_texture *dst_texture, unsigned int dst_sub_resource_idx, unsigned int dst_location, unsigned int dst_x, unsigned int dst_y, unsigned int dst_z)
 
static void wined3d_texture_vk_download_data (struct wined3d_context *context, struct wined3d_texture *src_texture, unsigned int src_sub_resource_idx, unsigned int src_location, const struct wined3d_box *src_box, const struct wined3d_bo_address *dst_bo_addr, const struct wined3d_format *dst_format, unsigned int dst_x, unsigned int dst_y, unsigned int dst_z, unsigned int dst_row_pitch, unsigned int dst_slice_pitch)
 
static bool wined3d_texture_vk_clear (struct wined3d_texture_vk *texture_vk, unsigned int sub_resource_idx, struct wined3d_context *context)
 
static BOOL wined3d_texture_vk_load_texture (struct wined3d_texture_vk *texture_vk, unsigned int sub_resource_idx, struct wined3d_context *context)
 
static BOOL wined3d_texture_vk_load_sysmem (struct wined3d_texture_vk *texture_vk, unsigned int sub_resource_idx, struct wined3d_context *context, unsigned int location)
 
BOOL wined3d_texture_vk_prepare_texture (struct wined3d_texture_vk *texture_vk, struct wined3d_context_vk *context_vk)
 
static BOOL wined3d_texture_vk_prepare_buffer_object (struct wined3d_texture_vk *texture_vk, unsigned int sub_resource_idx, struct wined3d_context_vk *context_vk)
 
static BOOL wined3d_texture_vk_prepare_location (struct wined3d_texture *texture, unsigned int sub_resource_idx, struct wined3d_context *context, unsigned int location)
 
static BOOL wined3d_texture_vk_load_location (struct wined3d_texture *texture, unsigned int sub_resource_idx, struct wined3d_context *context, uint32_t location)
 
static void wined3d_texture_vk_unload_location (struct wined3d_texture *texture, struct wined3d_context *context, unsigned int location)
 
HRESULT wined3d_texture_vk_init (struct wined3d_texture_vk *texture_vk, struct wined3d_device *device, const struct wined3d_resource_desc *desc, unsigned int layer_count, unsigned int level_count, uint32_t flags, void *parent, const struct wined3d_parent_ops *parent_ops)
 
enum VkImageLayout wined3d_layout_from_bind_mask (const struct wined3d_texture_vk *texture_vk, const uint32_t bind_mask)
 
void wined3d_texture_vk_barrier (struct wined3d_texture_vk *texture_vk, struct wined3d_context_vk *context_vk, uint32_t bind_mask)
 
void wined3d_texture_vk_make_generic (struct wined3d_texture_vk *texture_vk, struct wined3d_context_vk *context_vk)
 
static void ffp_blitter_destroy (struct wined3d_blitter *blitter, struct wined3d_context *context)
 
static bool is_full_clear (const struct wined3d_rendertarget_view *rtv, const RECT *draw_rect, const RECT *clear_rect)
 
static void ffp_blitter_clear_rendertargets (struct wined3d_device *device, unsigned int rt_count, const struct wined3d_fb_state *fb, unsigned int rect_count, const RECT *clear_rect, const RECT *draw_rect, uint32_t flags, const struct wined3d_color *colour, float depth, unsigned int stencil)
 
static bool blitter_use_cpu_clear (struct wined3d_rendertarget_view *view)
 
static void ffp_blitter_clear (struct wined3d_blitter *blitter, struct wined3d_device *device, unsigned int rt_count, const struct wined3d_fb_state *fb, unsigned int rect_count, const RECT *clear_rects, const RECT *draw_rect, uint32_t flags, const struct wined3d_color *colour, float depth, unsigned int stencil)
 
static DWORD ffp_blitter_blit (struct wined3d_blitter *blitter, enum wined3d_blit_op op, struct wined3d_context *context, struct wined3d_texture *src_texture, unsigned int src_sub_resource_idx, DWORD src_location, const RECT *src_rect, struct wined3d_texture *dst_texture, unsigned int dst_sub_resource_idx, DWORD dst_location, const RECT *dst_rect, const struct wined3d_color_key *colour_key, enum wined3d_texture_filter_type filter, const struct wined3d_format *resolve_format)
 
void wined3d_ffp_blitter_create (struct wined3d_blitter **next, const struct wined3d_gl_info *gl_info)
 
static void fbo_blitter_destroy (struct wined3d_blitter *blitter, struct wined3d_context *context)
 
static void fbo_blitter_clear (struct wined3d_blitter *blitter, struct wined3d_device *device, unsigned int rt_count, const struct wined3d_fb_state *fb, unsigned int rect_count, const RECT *clear_rects, const RECT *draw_rect, uint32_t flags, const struct wined3d_color *colour, float depth, unsigned int stencil)
 
static DWORD fbo_blitter_blit (struct wined3d_blitter *blitter, enum wined3d_blit_op op, struct wined3d_context *context, struct wined3d_texture *src_texture, unsigned int src_sub_resource_idx, DWORD src_location, const RECT *src_rect, struct wined3d_texture *dst_texture, unsigned int dst_sub_resource_idx, DWORD dst_location, const RECT *dst_rect, const struct wined3d_color_key *colour_key, enum wined3d_texture_filter_type filter, const struct wined3d_format *resolve_format)
 
void wined3d_fbo_blitter_create (struct wined3d_blitter **next, const struct wined3d_gl_info *gl_info)
 
static void raw_blitter_destroy (struct wined3d_blitter *blitter, struct wined3d_context *context)
 
static void raw_blitter_clear (struct wined3d_blitter *blitter, struct wined3d_device *device, unsigned int rt_count, const struct wined3d_fb_state *fb, unsigned int rect_count, const RECT *clear_rects, const RECT *draw_rect, uint32_t flags, const struct wined3d_color *colour, float depth, unsigned int stencil)
 
static bool gl_formats_compatible (struct wined3d_texture *src_texture, DWORD src_location, struct wined3d_texture *dst_texture, DWORD dst_location)
 
static DWORD raw_blitter_blit (struct wined3d_blitter *blitter, enum wined3d_blit_op op, struct wined3d_context *context, struct wined3d_texture *src_texture, unsigned int src_sub_resource_idx, DWORD src_location, const RECT *src_rect, struct wined3d_texture *dst_texture, unsigned int dst_sub_resource_idx, DWORD dst_location, const RECT *dst_rect, const struct wined3d_color_key *colour_key, enum wined3d_texture_filter_type filter, const struct wined3d_format *resolve_format)
 
void wined3d_raw_blitter_create (struct wined3d_blitter **next, const struct wined3d_gl_info *gl_info)
 
static void vk_blitter_destroy (struct wined3d_blitter *blitter, struct wined3d_context *context)
 
static void vk_blitter_clear_rendertargets (struct wined3d_context_vk *context_vk, unsigned int rt_count, const struct wined3d_fb_state *fb, unsigned int rect_count, const RECT *clear_rects, const RECT *draw_rect, uint32_t flags, const struct wined3d_color *colour, float depth, unsigned int stencil)
 
static void vk_blitter_clear (struct wined3d_blitter *blitter, struct wined3d_device *device, unsigned int rt_count, const struct wined3d_fb_state *fb, unsigned int rect_count, const RECT *clear_rects, const RECT *draw_rect, uint32_t flags, const struct wined3d_color *colour, float depth, unsigned int stencil)
 
static bool vk_blitter_blit_supported (enum wined3d_blit_op op, const struct wined3d_context *context, const struct wined3d_resource *src_resource, const RECT *src_rect, const struct wined3d_resource *dst_resource, const RECT *dst_rect, const struct wined3d_format *resolve_format)
 
static DWORD vk_blitter_blit (struct wined3d_blitter *blitter, enum wined3d_blit_op op, struct wined3d_context *context, struct wined3d_texture *src_texture, unsigned int src_sub_resource_idx, DWORD src_location, const RECT *src_rect, struct wined3d_texture *dst_texture, unsigned int dst_sub_resource_idx, DWORD dst_location, const RECT *dst_rect, const struct wined3d_color_key *colour_key, enum wined3d_texture_filter_type filter, const struct wined3d_format *resolve_format)
 
void wined3d_vk_blitter_create (struct wined3d_blitter **next)
 

Variables

static const uint32_t wined3d_texture_sysmem_locations = WINED3D_LOCATION_SYSMEM | WINED3D_LOCATION_BUFFER
 
static const struct wined3d_texture_ops texture_gl_ops
 
static const struct d3dfmt_alpha_fixup formats_src_alpha_fixup []
 
static const struct wined3d_resource_ops texture_resource_ops
 
static const struct wined3d_texture_ops wined3d_texture_no3d_ops
 
static const struct wined3d_texture_ops wined3d_texture_vk_ops
 
static const struct wined3d_blitter_ops ffp_blitter_ops
 
static const struct wined3d_blitter_ops fbo_blitter_ops
 
static const struct wined3d_blitter_ops raw_blitter_ops
 
static const struct wined3d_blitter_ops vk_blitter_ops
 

Macro Definition Documentation

◆ WINED3D_TEXTURE_DYNAMIC_MAP_THRESHOLD

#define WINED3D_TEXTURE_DYNAMIC_MAP_THRESHOLD   50

Definition at line 31 of file texture.c.

Function Documentation

◆ blitter_use_cpu_clear()

static bool blitter_use_cpu_clear ( struct wined3d_rendertarget_view *  view)
static

Definition at line 5853 of file texture.c.

5854{
5855 struct wined3d_resource *resource;
5856 struct wined3d_texture *texture;
5858
5859 resource = view->resource;
5860 if (resource->type == WINED3D_RTYPE_BUFFER)
5861 return !(resource->access & WINED3D_RESOURCE_ACCESS_GPU);
5862
5864 locations = texture->sub_resources[view->sub_resource_idx].locations;
5865 if (locations & (resource->map_binding | WINED3D_LOCATION_DISCARDED))
5866 return !(resource->access & WINED3D_RESOURCE_ACCESS_GPU)
5867 || texture->resource.pin_sysmem;
5868
5869 return !(resource->access & WINED3D_RESOURCE_ACCESS_GPU)
5870 && !(texture->flags & WINED3D_TEXTURE_CONVERTED);
5871}
unsigned long DWORD
Definition: ntddk_ex.h:95
GLenum GLuint texture
Definition: glext.h:6295
GLsizei const GLint * locations
Definition: glext.h:10542
#define resource
Definition: kernel32.h:9
#define WINED3D_RESOURCE_ACCESS_GPU
Definition: wined3d.h:51
@ WINED3D_RTYPE_BUFFER
Definition: wined3d.h:718
#define WINED3D_TEXTURE_CONVERTED
#define WINED3D_LOCATION_DISCARDED
static struct wined3d_texture * texture_from_resource(struct wined3d_resource *resource)

Referenced by ffp_blitter_clear(), and vk_blitter_clear().

◆ cube_coords_float()

static void cube_coords_float ( const RECT *  r,
UINT  w,
UINT  h,
struct wined3d_rect_f *  f 
)
inlinestatic

Definition at line 165 of file texture.c.

166{
167 f->l = ((r->left * 2.0f) / w) - 1.0f;
168 f->t = ((r->top * 2.0f) / h) - 1.0f;
169 f->r = ((r->right * 2.0f) / w) - 1.0f;
170 f->b = ((r->bottom * 2.0f) / h) - 1.0f;
171}
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLfloat f
Definition: glext.h:7540
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:6102
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723

Referenced by texture2d_get_blt_info().

◆ fbo_blitter_blit()

static DWORD fbo_blitter_blit ( struct wined3d_blitter *  blitter,
enum wined3d_blit_op  op,
struct wined3d_context *  context,
struct wined3d_texture *  src_texture,
unsigned int  src_sub_resource_idx,
DWORD  src_location,
const RECT *  src_rect,
struct wined3d_texture *  dst_texture,
unsigned int  dst_sub_resource_idx,
DWORD  dst_location,
const RECT *  dst_rect,
const struct wined3d_color_key *  colour_key,
enum wined3d_texture_filter_type  filter,
const struct wined3d_format *  resolve_format 
)
static

Definition at line 6030 of file texture.c.

6036{
6037 struct wined3d_context_gl *context_gl = wined3d_context_gl(context);
6038 struct wined3d_resource *src_resource, *dst_resource;
6039 enum wined3d_blit_op blit_op = op;
6040 struct wined3d_device *device;
6041 struct wined3d_blitter *next;
6042
6043 TRACE("blitter %p, op %#x, context %p, src_texture %p, src_sub_resource_idx %u, src_location %s, "
6044 "src_rect %s, dst_texture %p, dst_sub_resource_idx %u, dst_location %s, dst_rect %s, "
6045 "colour_key %p, filter %s, resolve_format %p.\n",
6046 blitter, op, context, src_texture, src_sub_resource_idx, wined3d_debug_location(src_location),
6047 wine_dbgstr_rect(src_rect), dst_texture, dst_sub_resource_idx, wined3d_debug_location(dst_location),
6048 wine_dbgstr_rect(dst_rect), colour_key, debug_d3dtexturefiltertype(filter), resolve_format);
6049
6050 src_resource = &src_texture->resource;
6051 dst_resource = &dst_texture->resource;
6052
6053 device = dst_resource->device;
6054
6055 if (blit_op == WINED3D_BLIT_OP_RAW_BLIT && dst_resource->format->id == src_resource->format->id)
6056 {
6057 if (dst_resource->format->depth_size || dst_resource->format->stencil_size)
6059 else
6061 }
6062
6063 if (!fbo_blitter_supported(blit_op, context_gl->gl_info,
6064 src_resource, src_location, dst_resource, dst_location))
6065 {
6066 if (!(next = blitter->next))
6067 {
6068 ERR("No blitter to handle blit op %#x.\n", op);
6069 return dst_location;
6070 }
6071
6072 TRACE("Forwarding to blitter %p.\n", next);
6073 return next->ops->blitter_blit(next, op, context, src_texture, src_sub_resource_idx, src_location,
6074 src_rect, dst_texture, dst_sub_resource_idx, dst_location, dst_rect, colour_key, filter,
6075 resolve_format);
6076 }
6077
6078 if (blit_op == WINED3D_BLIT_OP_COLOR_BLIT)
6079 {
6080 TRACE("Colour blit.\n");
6081 texture2d_blt_fbo(device, context, filter, src_texture, src_sub_resource_idx, src_location,
6082 src_rect, dst_texture, dst_sub_resource_idx, dst_location, dst_rect, resolve_format);
6083 return dst_location;
6084 }
6085
6086 if (blit_op == WINED3D_BLIT_OP_DEPTH_BLIT)
6087 {
6088 TRACE("Depth/stencil blit.\n");
6089 texture2d_depth_blt_fbo(device, context, src_texture, src_sub_resource_idx, src_location,
6090 src_rect, dst_texture, dst_sub_resource_idx, dst_location, dst_rect);
6091 return dst_location;
6092 }
6093
6094 ERR("This blitter does not implement blit op %#x.\n", blit_op);
6095 return dst_location;
6096}
static const char * wine_dbgstr_rect(const RECT *prc)
Definition: atltest.h:160
#define ERR(fmt,...)
Definition: precomp.h:57
UINT op
Definition: effect.c:235
static bool fbo_blitter_supported(enum wined3d_blit_op blit_op, const struct wined3d_gl_info *gl_info, const struct wined3d_resource *src_resource, DWORD src_location, const struct wined3d_resource *dst_resource, DWORD dst_location)
Definition: texture.c:273
static void texture2d_depth_blt_fbo(const struct wined3d_device *device, struct wined3d_context *context, struct wined3d_texture *src_texture, unsigned int src_sub_resource_idx, DWORD src_location, const RECT *src_rect, struct wined3d_texture *dst_texture, unsigned int dst_sub_resource_idx, DWORD dst_location, const RECT *dst_rect)
Definition: texture.c:573
static void texture2d_blt_fbo(struct wined3d_device *device, struct wined3d_context *context, enum wined3d_texture_filter_type filter, struct wined3d_texture *src_texture, unsigned int src_sub_resource_idx, DWORD src_location, const RECT *src_rect, struct wined3d_texture *dst_texture, unsigned int dst_sub_resource_idx, DWORD dst_location, const RECT *dst_rect, const struct wined3d_format *resolve_format)
Definition: texture.c:337
const char * wined3d_debug_location(uint32_t location)
Definition: utils.c:6588
const char * debug_d3dtexturefiltertype(enum wined3d_texture_filter_type filter_type)
Definition: utils.c:5194
static unsigned __int64 next
Definition: rand_nt.c:6
#define TRACE(s)
Definition: solgame.cpp:4
Definition: http.c:7252
Definition: devices.h:37
Definition: filter.c:165
struct wined3d_blitter * next
const struct wined3d_gl_info * gl_info
Definition: wined3d_gl.h:603
struct wined3d_device * device
const struct wined3d_format * format
struct wined3d_resource resource
wined3d_blit_op
@ WINED3D_BLIT_OP_RAW_BLIT
@ WINED3D_BLIT_OP_DEPTH_BLIT
@ WINED3D_BLIT_OP_COLOR_BLIT

◆ fbo_blitter_clear()

static void fbo_blitter_clear ( struct wined3d_blitter *  blitter,
struct wined3d_device *  device,
unsigned int  rt_count,
const struct wined3d_fb_state *  fb,
unsigned int  rect_count,
const RECT *  clear_rects,
const RECT *  draw_rect,
uint32_t  flags,
const struct wined3d_color *  colour,
float  depth,
unsigned int  stencil 
)
static

Definition at line 6019 of file texture.c.

6022{
6023 struct wined3d_blitter *next;
6024
6025 if ((next = blitter->next))
6026 next->ops->blitter_clear(next, device, rt_count, fb, rect_count,
6027 clear_rects, draw_rect, flags, colour, depth, stencil);
6028}
GLint GLint GLsizei GLsizei GLsizei depth
Definition: gl.h:1546
GLbitfield flags
Definition: glext.h:7161
GLint GLfloat GLint stencil
Definition: glext.h:6260

◆ fbo_blitter_destroy()

static void fbo_blitter_destroy ( struct wined3d_blitter *  blitter,
struct wined3d_context *  context 
)
static

Definition at line 6009 of file texture.c.

6010{
6011 struct wined3d_blitter *next;
6012
6013 if ((next = blitter->next))
6014 next->ops->blitter_destroy(next, context);
6015
6016 free(blitter);
6017}
#define free
Definition: debug_ros.c:5

◆ fbo_blitter_supported()

static bool fbo_blitter_supported ( enum wined3d_blit_op  blit_op,
const struct wined3d_gl_info *  gl_info,
const struct wined3d_resource *  src_resource,
DWORD  src_location,
const struct wined3d_resource *  dst_resource,
DWORD  dst_location 
)
static

Definition at line 273 of file texture.c.

276{
277 const struct wined3d_format *src_format = src_resource->format;
278 const struct wined3d_format *dst_format = dst_resource->format;
279 bool src_ds, dst_ds;
280
281 if ((src_resource->format_attrs | dst_resource->format_attrs) & WINED3D_FORMAT_ATTR_HEIGHT_SCALE)
282 return false;
283
284 /* Source and/or destination need to be on the GL side. */
285 if (!(src_resource->access & dst_resource->access & WINED3D_RESOURCE_ACCESS_GPU))
286 return false;
287
288 if (src_resource->type != WINED3D_RTYPE_TEXTURE_2D)
289 return false;
290
291 /* We can't copy between depth/stencil and colour attachments. One notable
292 * way we can end up here is when copying between typeless resources with
293 * formats like R16_TYPELESS, which can end up using either a
294 * depth/stencil or a colour format on the OpenGL side, depending on the
295 * resource's bind flags. */
296 src_ds = src_format->depth_size || src_format->stencil_size;
297 dst_ds = dst_format->depth_size || dst_format->stencil_size;
298 if (src_ds != dst_ds)
299 return false;
300
301 switch (blit_op)
302 {
305 || (src_resource->bind_flags & WINED3D_BIND_RENDER_TARGET)))
306 return false;
308 || (dst_resource->bind_flags & WINED3D_BIND_RENDER_TARGET)))
309 return false;
310 if ((src_format->id != dst_format->id || dst_location == WINED3D_LOCATION_DRAWABLE)
311 && (!is_identity_fixup(src_format->color_fixup) || !is_identity_fixup(dst_format->color_fixup)))
312 return false;
313 break;
314
317 return false;
319 return false;
320 /* Accept pure swizzle fixups for depth formats. In general we
321 * ignore the stencil component (if present) at the moment and the
322 * swizzle is not relevant with just the depth component. */
323 if (is_complex_fixup(src_format->color_fixup) || is_complex_fixup(dst_format->color_fixup)
324 || is_scaling_fixup(src_format->color_fixup) || is_scaling_fixup(dst_format->color_fixup))
325 return false;
326 break;
327
328 default:
329 return false;
330 }
331
332 return true;
333}
static const char * dst_format
Definition: dib.c:1339
unsigned int caps[WINED3D_GL_RES_TYPE_COUNT]
enum wined3d_format_id id
struct color_fixup_desc color_fixup
unsigned int format_attrs
enum wined3d_resource_type type
unsigned int access
unsigned int bind_flags
@ WINED3D_RTYPE_TEXTURE_2D
Definition: wined3d.h:720
#define WINED3D_BIND_RENDER_TARGET
Definition: wined3d.h:914
#define WINED3D_FORMAT_ATTR_HEIGHT_SCALE
static BOOL is_scaling_fixup(struct color_fixup_desc fixup)
static BOOL is_complex_fixup(struct color_fixup_desc fixup)
#define WINED3D_FORMAT_CAP_FBO_ATTACHABLE
static BOOL is_identity_fixup(struct color_fixup_desc fixup)
@ WINED3D_GL_RES_TYPE_TEX_2D
#define WINED3D_FORMAT_CAP_DEPTH_STENCIL
#define WINED3D_LOCATION_DRAWABLE

Referenced by fbo_blitter_blit(), and wined3d_texture_gl_load_texture().

◆ ffp_blitter_blit()

static DWORD ffp_blitter_blit ( struct wined3d_blitter *  blitter,
enum wined3d_blit_op  op,
struct wined3d_context *  context,
struct wined3d_texture *  src_texture,
unsigned int  src_sub_resource_idx,
DWORD  src_location,
const RECT *  src_rect,
struct wined3d_texture *  dst_texture,
unsigned int  dst_sub_resource_idx,
DWORD  dst_location,
const RECT *  dst_rect,
const struct wined3d_color_key *  colour_key,
enum wined3d_texture_filter_type  filter,
const struct wined3d_format *  resolve_format 
)
static

Definition at line 5968 of file texture.c.

5974{
5975 struct wined3d_blitter *next;
5976
5977 if (!(next = blitter->next))
5978 {
5979 ERR("No blitter to handle blit op %#x.\n", op);
5980 return dst_location;
5981 }
5982
5983 return next->ops->blitter_blit(next, op, context, src_texture, src_sub_resource_idx, src_location,
5984 src_rect, dst_texture, dst_sub_resource_idx, dst_location, dst_rect, colour_key, filter,
5985 resolve_format);
5986}

◆ ffp_blitter_clear()

static void ffp_blitter_clear ( struct wined3d_blitter *  blitter,
struct wined3d_device *  device,
unsigned int  rt_count,
const struct wined3d_fb_state *  fb,
unsigned int  rect_count,
const RECT *  clear_rects,
const RECT *  draw_rect,
uint32_t  flags,
const struct wined3d_color *  colour,
float  depth,
unsigned int  stencil 
)
static

Definition at line 5873 of file texture.c.

5876{
5877 struct wined3d_rendertarget_view *view, *previous = NULL;
5878 bool have_identical_size = TRUE;
5879 struct wined3d_fb_state tmp_fb;
5880 unsigned int next_rt_count = 0;
5881 struct wined3d_blitter *next;
5882 DWORD next_flags = 0;
5883 unsigned int i;
5884
5886 {
5887 for (i = 0; i < rt_count; ++i)
5888 {
5889 if (!(view = fb->render_targets[i]))
5890 continue;
5891
5893 || (!(view->resource->bind_flags & WINED3D_BIND_RENDER_TARGET)
5894 && !(view->format_caps & WINED3D_FORMAT_CAP_FBO_ATTACHABLE)))
5895 {
5896 next_flags |= WINED3DCLEAR_TARGET;
5897 flags &= ~WINED3DCLEAR_TARGET;
5898 next_rt_count = rt_count;
5899 rt_count = 0;
5900 break;
5901 }
5902
5903 /* FIXME: We should reject colour fills on formats with fixups,
5904 * but this would break P8 colour fills for example. */
5905 }
5906 }
5907
5909 && (!view->format->depth_size || (flags & WINED3DCLEAR_ZBUFFER))
5910 && (!view->format->stencil_size || (flags & WINED3DCLEAR_STENCIL))
5912 {
5915 }
5916
5917 if (flags)
5918 {
5919 for (i = 0; i < rt_count; ++i)
5920 {
5921 if (!(view = fb->render_targets[i]))
5922 continue;
5923
5924 if (previous && (previous->width != view->width || previous->height != view->height))
5925 have_identical_size = false;
5926 previous = view;
5927 }
5929 {
5930 view = fb->depth_stencil;
5931
5932 if (previous && (previous->width != view->width || previous->height != view->height))
5933 have_identical_size = false;
5934 }
5935
5936 if (have_identical_size)
5937 {
5938 ffp_blitter_clear_rendertargets(device, rt_count, fb, rect_count,
5939 clear_rects, draw_rect, flags, colour, depth, stencil);
5940 }
5941 else
5942 {
5943 for (i = 0; i < rt_count; ++i)
5944 {
5945 if (!(view = fb->render_targets[i]))
5946 continue;
5947
5948 tmp_fb.render_targets[0] = view;
5949 tmp_fb.depth_stencil = NULL;
5950 ffp_blitter_clear_rendertargets(device, 1, &tmp_fb, rect_count,
5951 clear_rects, draw_rect, WINED3DCLEAR_TARGET, colour, depth, stencil);
5952 }
5954 {
5955 tmp_fb.render_targets[0] = NULL;
5956 tmp_fb.depth_stencil = fb->depth_stencil;
5957 ffp_blitter_clear_rendertargets(device, 0, &tmp_fb, rect_count,
5958 clear_rects, draw_rect, flags & ~WINED3DCLEAR_TARGET, colour, depth, stencil);
5959 }
5960 }
5961 }
5962
5963 if (next_flags && (next = blitter->next))
5964 next->ops->blitter_clear(next, device, next_rt_count, fb, rect_count,
5965 clear_rects, draw_rect, next_flags, colour, depth, stencil);
5966}
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
static bool blitter_use_cpu_clear(struct wined3d_rendertarget_view *view)
Definition: texture.c:5853
static void ffp_blitter_clear_rendertargets(struct wined3d_device *device, unsigned int rt_count, const struct wined3d_fb_state *fb, unsigned int rect_count, const RECT *clear_rect, const RECT *draw_rect, uint32_t flags, const struct wined3d_color *colour, float depth, unsigned int stencil)
Definition: texture.c:5632
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
struct wined3d_rendertarget_view * depth_stencil
struct wined3d_rendertarget_view * render_targets[WINED3D_MAX_RENDER_TARGETS]
#define WINED3DCLEAR_TARGET
Definition: wined3d.h:1008
#define WINED3DCLEAR_STENCIL
Definition: wined3d.h:1010
#define WINED3DCLEAR_ZBUFFER
Definition: wined3d.h:1009

◆ ffp_blitter_clear_rendertargets()

static void ffp_blitter_clear_rendertargets ( struct wined3d_device *  device,
unsigned int  rt_count,
const struct wined3d_fb_state *  fb,
unsigned int  rect_count,
const RECT *  clear_rect,
const RECT *  draw_rect,
uint32_t  flags,
const struct wined3d_color *  colour,
float  depth,
unsigned int  stencil 
)
static

Definition at line 5632 of file texture.c.

5635{
5636 struct wined3d_rendertarget_view *rtv = rt_count ? fb->render_targets[0] : NULL;
5637 struct wined3d_rendertarget_view *dsv = fb->depth_stencil;
5638 const struct wined3d_state *state = &device->cs->state;
5640 unsigned int drawable_width, drawable_height;
5641 const struct wined3d_gl_info *gl_info;
5642 struct wined3d_context_gl *context_gl;
5643 struct wined3d_texture *target = NULL;
5644 struct wined3d_color colour_srgb;
5645 struct wined3d_context *context;
5646 GLbitfield clear_mask = 0;
5647 bool render_offscreen;
5648 unsigned int i;
5649
5650 if (rtv && rtv->resource->type != WINED3D_RTYPE_BUFFER)
5651 {
5654 }
5655 else
5656 {
5658 }
5659 context_gl = wined3d_context_gl(context);
5660
5661 if (dsv && dsv->resource->type != WINED3D_RTYPE_BUFFER)
5663
5664 if (!context_gl->valid)
5665 {
5667 WARN("Invalid context, skipping clear.\n");
5668 return;
5669 }
5670 gl_info = context_gl->gl_info;
5671
5672 /* When we're clearing parts of the drawable, make sure that the target
5673 * surface is well up to date in the drawable. After the clear we'll mark
5674 * the drawable up to date, so we have to make sure that this is true for
5675 * the cleared parts, and the untouched parts.
5676 *
5677 * If we're clearing the whole target there is no need to copy it into the
5678 * drawable, it will be overwritten anyway. If we're not clearing the
5679 * colour buffer we don't have to copy either since we're not going to set
5680 * the drawable up to date. We have to check all settings that limit the
5681 * clear area though. Do not bother checking all this if the destination
5682 * surface is in the drawable anyway. */
5683 for (i = 0; i < rt_count; ++i)
5684 {
5685 struct wined3d_rendertarget_view *rtv = fb->render_targets[i];
5686
5687 if (rtv && rtv->format->id != WINED3DFMT_NULL)
5688 {
5689 if (flags & WINED3DCLEAR_TARGET && !is_full_clear(rtv, draw_rect, rect_count ? clear_rect : NULL))
5691 else
5693 }
5694 }
5695
5696 if (target)
5697 {
5698 render_offscreen = wined3d_resource_is_offscreen(&target->resource);
5699 wined3d_rendertarget_view_get_drawable_size(rtv, context, &drawable_width, &drawable_height);
5700 }
5701 else
5702 {
5703 unsigned int ds_level = dsv->sub_resource_idx % depth_stencil->level_count;
5704
5705 render_offscreen = true;
5706 drawable_width = wined3d_texture_get_level_width(depth_stencil, ds_level);
5707 drawable_height = wined3d_texture_get_level_height(depth_stencil, ds_level);
5708 }
5709
5710 if (depth_stencil)
5711 {
5712 DWORD ds_location = render_offscreen ? dsv->resource->draw_binding : WINED3D_LOCATION_DRAWABLE;
5713
5715 && !is_full_clear(dsv, draw_rect, rect_count ? clear_rect : NULL))
5717 else
5719
5721 {
5724 }
5725 }
5726
5727 if (!wined3d_context_gl_apply_clear_state(context_gl, state, rt_count, fb))
5728 {
5730 WARN("Failed to apply clear state, skipping clear.\n");
5731 return;
5732 }
5733
5734 /* Only set the values up once, as they are not changing. */
5736 {
5737 if (gl_info->supported[EXT_STENCIL_TWO_SIDE])
5738 gl_info->gl_ops.gl.p_glDisable(GL_STENCIL_TEST_TWO_SIDE_EXT);
5739 gl_info->gl_ops.gl.p_glStencilMask(~0u);
5741 gl_info->gl_ops.gl.p_glClearStencil(stencil);
5742 checkGLcall("glClearStencil");
5743 clear_mask = clear_mask | GL_STENCIL_BUFFER_BIT;
5744 }
5745
5747 {
5748 gl_info->gl_ops.gl.p_glDepthMask(GL_TRUE);
5750 if (gl_info->supported[ARB_ES2_COMPATIBILITY])
5751 GL_EXTCALL(glClearDepthf(depth));
5752 else
5753 gl_info->gl_ops.gl.p_glClearDepth(depth);
5754 checkGLcall("glClearDepth");
5755 clear_mask = clear_mask | GL_DEPTH_BUFFER_BIT;
5756 }
5757
5759 {
5760 for (i = 0; i < rt_count; ++i)
5761 {
5762 struct wined3d_rendertarget_view *rtv = fb->render_targets[i];
5763
5764 if (!rtv)
5765 continue;
5766
5767 if (rtv->resource->type == WINED3D_RTYPE_BUFFER)
5768 {
5769 FIXME("Not supported on buffer resources.\n");
5770 continue;
5771 }
5772
5775 }
5776
5777 if (!gl_info->supported[ARB_FRAMEBUFFER_SRGB] && needs_srgb_write(context->d3d_info, state, fb))
5778 {
5779 if (rt_count > 1)
5780 WARN("Clearing multiple sRGB render targets without GL_ARB_framebuffer_sRGB "
5781 "support, this might cause graphical issues.\n");
5782
5783 wined3d_colour_srgb_from_linear(&colour_srgb, colour);
5784 colour = &colour_srgb;
5785 }
5786
5787 gl_info->gl_ops.gl.p_glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
5789 gl_info->gl_ops.gl.p_glClearColor(colour->r, colour->g, colour->b, colour->a);
5790 checkGLcall("glClearColor");
5791 clear_mask = clear_mask | GL_COLOR_BUFFER_BIT;
5792 }
5793
5794 if (!rect_count)
5795 {
5796 if (render_offscreen)
5797 {
5798 gl_info->gl_ops.gl.p_glScissor(draw_rect->left, draw_rect->top,
5799 draw_rect->right - draw_rect->left, draw_rect->bottom - draw_rect->top);
5800 }
5801 else
5802 {
5803 gl_info->gl_ops.gl.p_glScissor(draw_rect->left, drawable_height - draw_rect->bottom,
5804 draw_rect->right - draw_rect->left, draw_rect->bottom - draw_rect->top);
5805 }
5806 gl_info->gl_ops.gl.p_glClear(clear_mask);
5807 }
5808 else
5809 {
5810 RECT current_rect;
5811
5812 /* Now process each rect in turn. */
5813 for (i = 0; i < rect_count; ++i)
5814 {
5815 /* Note that GL uses lower left, width/height. */
5816 IntersectRect(&current_rect, draw_rect, &clear_rect[i]);
5817
5818 TRACE("clear_rect[%u] %s, current_rect %s.\n", i,
5819 wine_dbgstr_rect(&clear_rect[i]),
5820 wine_dbgstr_rect(&current_rect));
5821
5822 /* Tests show that rectangles where x1 > x2 or y1 > y2 are ignored
5823 * silently. The rectangle is not cleared, no error is returned,
5824 * but further rectangles are still cleared if they are valid. */
5825 if (current_rect.left > current_rect.right || current_rect.top > current_rect.bottom)
5826 {
5827 TRACE("Rectangle with negative dimensions, ignoring.\n");
5828 continue;
5829 }
5830
5831 if (render_offscreen)
5832 {
5833 gl_info->gl_ops.gl.p_glScissor(current_rect.left, current_rect.top,
5834 current_rect.right - current_rect.left, current_rect.bottom - current_rect.top);
5835 }
5836 else
5837 {
5838 gl_info->gl_ops.gl.p_glScissor(current_rect.left, drawable_height - current_rect.bottom,
5839 current_rect.right - current_rect.left, current_rect.bottom - current_rect.top);
5840 }
5841 gl_info->gl_ops.gl.p_glClear(clear_mask);
5842 }
5843 }
5844 context->scissor_rect_count = WINED3D_MAX_VIEWPORTS;
5845 checkGLcall("clear");
5846
5847 if (flags & WINED3DCLEAR_TARGET && target->swapchain && target->swapchain->front_buffer == target)
5848 gl_info->gl_ops.gl.p_glFlush();
5849
5851}
static int state
Definition: maze.c:121
#define FIXME(fmt,...)
Definition: precomp.h:53
#define WARN(fmt,...)
Definition: precomp.h:61
BOOL wined3d_context_gl_apply_clear_state(struct wined3d_context_gl *context_gl, const struct wined3d_state *state, unsigned int rt_count, const struct wined3d_fb_state *fb)
Definition: context_gl.c:3250
void context_invalidate_state(struct wined3d_context *context, unsigned int state_id)
Definition: context.c:76
BOOL wined3d_resource_is_offscreen(struct wined3d_resource *resource)
Definition: resource.c:406
static bool is_full_clear(const struct wined3d_rendertarget_view *rtv, const RECT *draw_rect, const RECT *clear_rect)
Definition: texture.c:5615
void wined3d_rendertarget_view_prepare_location(struct wined3d_rendertarget_view *view, struct wined3d_context *context, uint32_t location)
Definition: view.c:469
void wined3d_rendertarget_view_load_location(struct wined3d_rendertarget_view *view, struct wined3d_context *context, uint32_t location)
Definition: view.c:489
void wined3d_rendertarget_view_validate_location(struct wined3d_rendertarget_view *view, uint32_t location)
Definition: view.c:495
void wined3d_rendertarget_view_get_drawable_size(const struct wined3d_rendertarget_view *view, const struct wined3d_context *context, unsigned int *width, unsigned int *height)
Definition: view.c:437
void wined3d_rendertarget_view_invalidate_location(struct wined3d_rendertarget_view *view, uint32_t location)
Definition: view.c:514
static void depth_stencil(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
Definition: ffp_gl.c:766
#define GL_TRUE
Definition: gl.h:174
unsigned int GLbitfield
Definition: gl.h:152
#define GL_COLOR_BUFFER_BIT
Definition: gl.h:716
#define GL_STENCIL_BUFFER_BIT
Definition: gl.h:712
#define GL_DEPTH_BUFFER_BIT
Definition: gl.h:710
#define GL_STENCIL_TEST_TWO_SIDE_EXT
Definition: glext.h:4210
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble * u
Definition: glfuncs.h:240
BOOL WINAPI IntersectRect(_Out_ LPRECT, _In_ LPCRECT, _In_ LPCRECT)
Definition: dcommon.idl:28
long bottom
Definition: dcommon.idl:29
long right
Definition: dcommon.idl:29
long left
Definition: dcommon.idl:29
long top
Definition: dcommon.idl:29
Definition: tools.h:99
BOOL supported[WINED3D_GL_EXT_COUNT]
Definition: wined3d_gl.h:347
struct opengl_funcs gl_ops
Definition: wined3d_gl.h:353
struct wined3d_resource * resource
const struct wined3d_format * format
#define WINED3D_MAX_VIEWPORTS
Definition: wined3d.h:1590
@ WINED3DFMT_NULL
Definition: wined3d.h:276
@ EXT_STENCIL_TWO_SIDE
Definition: wined3d_gl.h:188
@ ARB_ES2_COMPATIBILITY
Definition: wined3d_gl.h:75
@ ARB_FRAMEBUFFER_SRGB
Definition: wined3d_gl.h:85
#define GL_EXTCALL(f)
Definition: wined3d_gl.h:360
#define checkGLcall(A)
Definition: wined3d_gl.h:402
#define STATE_DEPTH_STENCIL
static unsigned int wined3d_texture_get_level_height(const struct wined3d_texture *texture, unsigned int level)
static unsigned int wined3d_texture_get_level_width(const struct wined3d_texture *texture, unsigned int level)
static void context_release(struct wined3d_context *context)
static void wined3d_colour_srgb_from_linear(struct wined3d_color *colour_srgb, const struct wined3d_color *colour)
static BOOL needs_srgb_write(const struct wined3d_d3d_info *d3d_info, const struct wined3d_state *state, const struct wined3d_fb_state *fb)
static struct wined3d_context * context_acquire(struct wined3d_device *device, struct wined3d_texture *texture, unsigned int sub_resource_idx)
#define STATE_BLEND

Referenced by ffp_blitter_clear().

◆ ffp_blitter_destroy()

static void ffp_blitter_destroy ( struct wined3d_blitter *  blitter,
struct wined3d_context *  context 
)
static

Definition at line 5605 of file texture.c.

5606{
5607 struct wined3d_blitter *next;
5608
5609 if ((next = blitter->next))
5610 next->ops->blitter_destroy(next, context);
5611
5612 free(blitter);
5613}

◆ gl_formats_compatible()

static bool gl_formats_compatible ( struct wined3d_texture *  src_texture,
DWORD  src_location,
struct wined3d_texture *  dst_texture,
DWORD  dst_location 
)
static

Definition at line 6146 of file texture.c.

6148{
6149 GLuint src_internal, dst_internal;
6150 bool src_ds, dst_ds;
6151
6152 src_ds = src_texture->resource.format->depth_size || src_texture->resource.format->stencil_size;
6153 dst_ds = dst_texture->resource.format->depth_size || dst_texture->resource.format->stencil_size;
6154 if (src_ds == dst_ds)
6155 return true;
6156 /* Also check the internal format because, e.g. WINED3DFMT_D24_UNORM_S8_UINT has nonzero depth and stencil
6157 * sizes as does WINED3DFMT_R24G8_TYPELESS when bound with flag WINED3D_BIND_DEPTH_STENCIL, but these share
6158 * the same internal format with WINED3DFMT_R24_UNORM_X8_TYPELESS. */
6159 src_internal = wined3d_gl_get_internal_format(&src_texture->resource,
6160 wined3d_format_gl(src_texture->resource.format), src_location == WINED3D_LOCATION_TEXTURE_SRGB);
6161 dst_internal = wined3d_gl_get_internal_format(&dst_texture->resource,
6162 wined3d_format_gl(dst_texture->resource.format), dst_location == WINED3D_LOCATION_TEXTURE_SRGB);
6163 return src_internal == dst_internal;
6164}
unsigned int GLuint
Definition: gl.h:159
static GLuint wined3d_gl_get_internal_format(struct wined3d_resource *resource, const struct wined3d_format_gl *format_gl, bool srgb)
Definition: wined3d_gl.h:1161
#define WINED3D_LOCATION_TEXTURE_SRGB

Referenced by raw_blitter_blit().

◆ gltexture_delete()

static void gltexture_delete ( struct wined3d_device *  device,
const struct wined3d_gl_info *  gl_info,
struct gl_texture *  tex 
)
static

Definition at line 967 of file texture.c.

969{
971 gl_info->gl_ops.gl.p_glDeleteTextures(1, &tex->name);
972 tex->name = 0;
973}
void context_gl_resource_released(struct wined3d_device *device, GLuint name, BOOL rb_namespace)
Definition: context_gl.c:1137
#define FALSE
Definition: types.h:117
GLuint name
Definition: wined3d_gl.h:929

Referenced by wined3d_texture_gl_unload_location().

◆ is_full_clear()

static bool is_full_clear ( const struct wined3d_rendertarget_view *  rtv,
const RECT *  draw_rect,
const RECT *  clear_rect 
)
static

Definition at line 5615 of file texture.c.

5616{
5617 unsigned int height = rtv->height;
5618 unsigned int width = rtv->width;
5619
5620 /* partial draw rect */
5621 if (draw_rect->left || draw_rect->top || draw_rect->right < width || draw_rect->bottom < height)
5622 return false;
5623
5624 /* partial clear rect */
5625 if (clear_rect && (clear_rect->left > 0 || clear_rect->top > 0
5626 || clear_rect->right < width || clear_rect->bottom < height))
5627 return false;
5628
5629 return true;
5630}
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
GLint GLint GLsizei width
Definition: gl.h:1546

Referenced by ffp_blitter_clear_rendertargets(), and vk_blitter_clear_rendertargets().

◆ raw_blitter_blit()

static DWORD raw_blitter_blit ( struct wined3d_blitter *  blitter,
enum wined3d_blit_op  op,
struct wined3d_context *  context,
struct wined3d_texture *  src_texture,
unsigned int  src_sub_resource_idx,
DWORD  src_location,
const RECT *  src_rect,
struct wined3d_texture *  dst_texture,
unsigned int  dst_sub_resource_idx,
DWORD  dst_location,
const RECT *  dst_rect,
const struct wined3d_color_key *  colour_key,
enum wined3d_texture_filter_type  filter,
const struct wined3d_format *  resolve_format 
)
static

Definition at line 6166 of file texture.c.

6172{
6173 struct wined3d_texture_gl *src_texture_gl = wined3d_texture_gl(src_texture);
6174 struct wined3d_texture_gl *dst_texture_gl = wined3d_texture_gl(dst_texture);
6175 struct wined3d_context_gl *context_gl = wined3d_context_gl(context);
6176 const struct wined3d_gl_info *gl_info = context_gl->gl_info;
6177 unsigned int src_level, src_layer, dst_level, dst_layer;
6178 struct wined3d_blitter *next;
6179 GLuint src_name, dst_name;
6181
6182 /* If we would need to copy from a renderbuffer or drawable, we'd probably
6183 * be better off using the FBO blitter directly, since we'd need to use it
6184 * to copy the resource contents to the texture anyway.
6185 *
6186 * We also can't copy between depth/stencil and colour resources, since
6187 * the formats are considered incompatible in OpenGL. */
6188 if (op != WINED3D_BLIT_OP_RAW_BLIT || !gl_formats_compatible(src_texture, src_location, dst_texture, dst_location)
6189 || ((src_texture->resource.format_attrs | dst_texture->resource.format_attrs)
6191 || (src_texture->resource.format->id == dst_texture->resource.format->id
6194 {
6195 if (!(next = blitter->next))
6196 {
6197 ERR("No blitter to handle blit op %#x.\n", op);
6198 return dst_location;
6199 }
6200
6201 TRACE("Forwarding to blitter %p.\n", next);
6202 return next->ops->blitter_blit(next, op, context, src_texture, src_sub_resource_idx, src_location,
6203 src_rect, dst_texture, dst_sub_resource_idx, dst_location, dst_rect, colour_key, filter,
6204 resolve_format);
6205 }
6206
6207 TRACE("Blit using ARB_copy_image.\n");
6208
6209 src_level = src_sub_resource_idx % src_texture->level_count;
6210 src_layer = src_sub_resource_idx / src_texture->level_count;
6211
6212 dst_level = dst_sub_resource_idx % dst_texture->level_count;
6213 dst_layer = dst_sub_resource_idx / dst_texture->level_count;
6214
6216 if (!location)
6217 location = src_texture->flags & WINED3D_TEXTURE_IS_SRGB
6219 if (!wined3d_texture_load_location(src_texture, src_sub_resource_idx, context, location))
6220 ERR("Failed to load the source sub-resource into %s.\n", wined3d_debug_location(location));
6221 src_name = wined3d_texture_gl_get_texture_name(src_texture_gl,
6223
6225 if (!location)
6226 location = dst_texture->flags & WINED3D_TEXTURE_IS_SRGB
6228 if (wined3d_texture_is_full_rect(dst_texture, dst_level, dst_rect))
6229 {
6230 if (!wined3d_texture_prepare_location(dst_texture, dst_sub_resource_idx, context, location))
6231 ERR("Failed to prepare the destination sub-resource into %s.\n", wined3d_debug_location(location));
6232 }
6233 else
6234 {
6235 if (!wined3d_texture_load_location(dst_texture, dst_sub_resource_idx, context, location))
6236 ERR("Failed to load the destination sub-resource into %s.\n", wined3d_debug_location(location));
6237 }
6238 dst_name = wined3d_texture_gl_get_texture_name(dst_texture_gl,
6240
6241 GL_EXTCALL(glCopyImageSubData(src_name, src_texture_gl->target, src_level,
6242 src_rect->left, src_rect->top, src_layer, dst_name, dst_texture_gl->target, dst_level,
6243 dst_rect->left, dst_rect->top, dst_layer, src_rect->right - src_rect->left,
6244 src_rect->bottom - src_rect->top, 1));
6245 checkGLcall("copy image data");
6246
6247 wined3d_texture_validate_location(dst_texture, dst_sub_resource_idx, location);
6248 wined3d_texture_invalidate_location(dst_texture, dst_sub_resource_idx, ~location);
6249 if (!wined3d_texture_load_location(dst_texture, dst_sub_resource_idx, context, dst_location))
6250 ERR("Failed to load the destination sub-resource into %s.\n", wined3d_debug_location(dst_location));
6251
6252 return dst_location | location;
6253}
void wined3d_texture_invalidate_location(struct wined3d_texture *texture, unsigned int sub_resource_idx, uint32_t location)
Definition: texture.c:702
void wined3d_texture_validate_location(struct wined3d_texture *texture, unsigned int sub_resource_idx, uint32_t location)
Definition: texture.c:678
BOOL wined3d_texture_prepare_location(struct wined3d_texture *texture, unsigned int sub_resource_idx, struct wined3d_context *context, unsigned int location)
Definition: texture.c:2116
BOOL wined3d_texture_load_location(struct wined3d_texture *texture, unsigned int sub_resource_idx, struct wined3d_context *context, uint32_t location)
Definition: texture.c:770
static bool gl_formats_compatible(struct wined3d_texture *src_texture, DWORD src_location, struct wined3d_texture *dst_texture, DWORD dst_location)
Definition: texture.c:6146
#define location(file, line)
Definition: kmtest.h:18
unsigned int level_count
static GLuint wined3d_texture_gl_get_texture_name(const struct wined3d_texture_gl *texture_gl, const struct wined3d_context *context, bool srgb)
Definition: wined3d_gl.h:982
static bool wined3d_texture_is_full_rect(const struct wined3d_texture *texture, unsigned int level, const RECT *r)
#define WINED3D_LOCATION_TEXTURE_RGB
#define WINED3D_TEXTURE_IS_SRGB

◆ raw_blitter_clear()

static void raw_blitter_clear ( struct wined3d_blitter *  blitter,
struct wined3d_device *  device,
unsigned int  rt_count,
const struct wined3d_fb_state *  fb,
unsigned int  rect_count,
const RECT *  clear_rects,
const RECT *  draw_rect,
uint32_t  flags,
const struct wined3d_color *  colour,
float  depth,
unsigned int  stencil 
)
static

Definition at line 6129 of file texture.c.

6132{
6133 struct wined3d_blitter *next;
6134
6135 if (!(next = blitter->next))
6136 {
6137 ERR("No blitter to handle clear.\n");
6138 return;
6139 }
6140
6141 TRACE("Forwarding to blitter %p.\n", next);
6142 next->ops->blitter_clear(next, device, rt_count, fb, rect_count,
6143 clear_rects, draw_rect, flags, colour, depth, stencil);
6144}

◆ raw_blitter_destroy()

static void raw_blitter_destroy ( struct wined3d_blitter *  blitter,
struct wined3d_context *  context 
)
static

Definition at line 6119 of file texture.c.

6120{
6121 struct wined3d_blitter *next;
6122
6123 if ((next = blitter->next))
6124 next->ops->blitter_destroy(next, context);
6125
6126 free(blitter);
6127}

◆ texture2d_blt_fbo()

static void texture2d_blt_fbo ( struct wined3d_device *  device,
struct wined3d_context *  context,
enum wined3d_texture_filter_type  filter,
struct wined3d_texture *  src_texture,
unsigned int  src_sub_resource_idx,
DWORD  src_location,
const RECT *  src_rect,
struct wined3d_texture *  dst_texture,
unsigned int  dst_sub_resource_idx,
DWORD  dst_location,
const RECT *  dst_rect,
const struct wined3d_format *  resolve_format 
)
static

Definition at line 337 of file texture.c.

342{
343 struct wined3d_texture *required_texture, *restore_texture, *dst_save_texture = dst_texture;
344 unsigned int restore_idx, dst_save_sub_resource_idx = dst_sub_resource_idx;
345 bool resolve, scaled_resolve, restore_context = false;
346 struct wined3d_texture *src_staging_texture = NULL;
347 const struct wined3d_gl_info *gl_info;
348 struct wined3d_context_gl *context_gl;
349 GLenum gl_filter;
351 RECT s, d;
352
353 TRACE("device %p, context %p, filter %s, src_texture %p, src_sub_resource_idx %u, src_location %s, "
354 "src_rect %s, dst_texture %p, dst_sub_resource_idx %u, dst_location %s, dst_rect %s, resolve format %p.\n",
355 device, context, debug_d3dtexturefiltertype(filter), src_texture, src_sub_resource_idx,
356 wined3d_debug_location(src_location), wine_dbgstr_rect(src_rect), dst_texture,
357 dst_sub_resource_idx, wined3d_debug_location(dst_location), wine_dbgstr_rect(dst_rect), resolve_format);
358
359 resolve = wined3d_texture_gl_is_multisample_location(wined3d_texture_gl(src_texture), src_location);
360 scaled_resolve = resolve
361 && (abs(src_rect->bottom - src_rect->top) != abs(dst_rect->bottom - dst_rect->top)
362 || abs(src_rect->right - src_rect->left) != abs(dst_rect->right - dst_rect->left));
363
365 gl_filter = scaled_resolve ? GL_SCALED_RESOLVE_NICEST_EXT : GL_LINEAR;
366 else
367 gl_filter = scaled_resolve ? GL_SCALED_RESOLVE_FASTEST_EXT : GL_NEAREST;
368
369 if (resolve)
370 {
371 GLint resolve_internal, src_internal, dst_internal;
372 enum wined3d_format_id resolve_format_id;
373
374 src_internal = wined3d_gl_get_internal_format(&src_texture->resource,
375 wined3d_format_gl(src_texture->resource.format), src_location == WINED3D_LOCATION_TEXTURE_SRGB);
376 dst_internal = wined3d_gl_get_internal_format(&dst_texture->resource,
377 wined3d_format_gl(dst_texture->resource.format), dst_location == WINED3D_LOCATION_TEXTURE_SRGB);
378
379 if (resolve_format)
380 {
381 resolve_internal = wined3d_format_gl(resolve_format)->internal;
382 resolve_format_id = resolve_format->id;
383 }
384 else if (!wined3d_format_is_typeless(src_texture->resource.format))
385 {
386 resolve_internal = src_internal;
387 resolve_format_id = src_texture->resource.format->id;
388 }
389 else
390 {
391 resolve_internal = dst_internal;
392 resolve_format_id = dst_texture->resource.format->id;
393 }
394
395 /* In case of typeless resolve the texture type may not match the resolve type.
396 * To handle that, allocate intermediate texture(s) to resolve from/to.
397 * A possible performance improvement would be to resolve using a shader instead. */
398 if (src_internal != resolve_internal)
399 {
401 unsigned src_level;
402 HRESULT hr;
403
404 src_level = src_sub_resource_idx % src_texture->level_count;
405 desc.resource_type = WINED3D_RTYPE_TEXTURE_2D;
406 desc.format = resolve_format_id;
407 desc.multisample_type = src_texture->resource.multisample_type;
408 desc.multisample_quality = src_texture->resource.multisample_quality;
409 desc.usage = WINED3DUSAGE_CS;
410 desc.bind_flags = 0;
412 desc.width = wined3d_texture_get_level_width(src_texture, src_level);
413 desc.height = wined3d_texture_get_level_height(src_texture, src_level);
414 desc.depth = 1;
415 desc.size = 0;
416
418 &src_staging_texture);
419 if (FAILED(hr))
420 {
421 ERR("Failed to create staging texture, hr %#lx.\n", hr);
422 goto done;
423 }
424
425 if (src_location == WINED3D_LOCATION_DRAWABLE)
426 FIXME("WINED3D_LOCATION_DRAWABLE not supported for the source of a typeless resolve.\n");
427
428 device->blitter->ops->blitter_blit(device->blitter, WINED3D_BLIT_OP_RAW_BLIT, context,
429 src_texture, src_sub_resource_idx, src_location, src_rect,
430 src_staging_texture, 0, src_location, src_rect,
432
433 src_texture = src_staging_texture;
434 src_sub_resource_idx = 0;
435 }
436
437 if (dst_internal != resolve_internal)
438 {
440 unsigned dst_level;
441 HRESULT hr;
442
443 dst_level = dst_sub_resource_idx % dst_texture->level_count;
444 desc.resource_type = WINED3D_RTYPE_TEXTURE_2D;
445 desc.format = resolve_format_id;
446 desc.multisample_type = dst_texture->resource.multisample_type;
447 desc.multisample_quality = dst_texture->resource.multisample_quality;
448 desc.usage = WINED3DUSAGE_CS;
449 desc.bind_flags = 0;
451 desc.width = wined3d_texture_get_level_width(dst_texture, dst_level);
452 desc.height = wined3d_texture_get_level_height(dst_texture, dst_level);
453 desc.depth = 1;
454 desc.size = 0;
455
457 &dst_texture);
458 if (FAILED(hr))
459 {
460 ERR("Failed to create staging texture, hr %#lx.\n", hr);
461 goto done;
462 }
463
464 wined3d_texture_load_location(dst_texture, 0, context, dst_location);
465 dst_sub_resource_idx = 0;
466 }
467 }
468
469 /* Make sure the locations are up-to-date. Loading the destination
470 * surface isn't required if the entire surface is overwritten. (And is
471 * in fact harmful if we're being called by surface_load_location() with
472 * the purpose of loading the destination surface.) */
473 wined3d_texture_load_location(src_texture, src_sub_resource_idx, context, src_location);
474 if (!wined3d_texture_is_full_rect(dst_texture, dst_sub_resource_idx % dst_texture->level_count, dst_rect))
475 wined3d_texture_load_location(dst_texture, dst_sub_resource_idx, context, dst_location);
476 else
477 wined3d_texture_prepare_location(dst_texture, dst_sub_resource_idx, context, dst_location);
478
479 /* Acquire a context for the front-buffer, even though we may be blitting
480 * to/from a back-buffer. Since context_acquire() doesn't take the
481 * resource location into account, it may consider the back-buffer to be
482 * offscreen. */
483 if (src_location == WINED3D_LOCATION_DRAWABLE)
484 required_texture = src_texture->swapchain->front_buffer;
485 else if (dst_location == WINED3D_LOCATION_DRAWABLE)
486 required_texture = dst_texture->swapchain->front_buffer;
487 else
488 required_texture = NULL;
489
490 restore_texture = context->current_rt.texture;
491 restore_idx = context->current_rt.sub_resource_idx;
492 if (restore_texture != required_texture)
493 {
494 context = context_acquire(device, required_texture, 0);
495 restore_context = true;
496 }
497
498 context_gl = wined3d_context_gl(context);
499 if (!context_gl->valid)
500 {
502 WARN("Invalid context, skipping blit.\n");
503 restore_context = false;
504 goto done;
505 }
506
507 gl_info = context_gl->gl_info;
508
509 if (src_location == WINED3D_LOCATION_DRAWABLE)
510 {
511 TRACE("Source texture %p is onscreen.\n", src_texture);
513 s = *src_rect;
514 wined3d_texture_translate_drawable_coords(src_texture, context_gl->window, &s);
515 src_rect = &s;
516 }
517 else
518 {
519 TRACE("Source texture %p is offscreen.\n", src_texture);
521 }
522
524 &src_texture->resource, src_sub_resource_idx, NULL, 0, src_location);
525 gl_info->gl_ops.gl.p_glReadBuffer(buffer);
526 checkGLcall("glReadBuffer()");
528
529 context_gl_apply_texture_draw_state(context_gl, dst_texture, dst_sub_resource_idx, dst_location);
530
531 if (dst_location == WINED3D_LOCATION_DRAWABLE)
532 {
533 d = *dst_rect;
534 wined3d_texture_translate_drawable_coords(dst_texture, context_gl->window, &d);
535 dst_rect = &d;
536 }
537
538 gl_info->gl_ops.gl.p_glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
540
541 gl_info->gl_ops.gl.p_glDisable(GL_SCISSOR_TEST);
543
544 gl_info->fbo_ops.glBlitFramebuffer(src_rect->left, src_rect->top, src_rect->right, src_rect->bottom,
545 dst_rect->left, dst_rect->top, dst_rect->right, dst_rect->bottom, GL_COLOR_BUFFER_BIT, gl_filter);
546 checkGLcall("glBlitFramebuffer()");
547
548 if (dst_location == WINED3D_LOCATION_DRAWABLE && dst_texture->swapchain->front_buffer == dst_texture)
549 gl_info->gl_ops.gl.p_glFlush();
550
551 if (dst_texture != dst_save_texture)
552 {
553 if (dst_location == WINED3D_LOCATION_DRAWABLE)
554 FIXME("WINED3D_LOCATION_DRAWABLE not supported for the destination of a typeless resolve.\n");
555
556 device->blitter->ops->blitter_blit(device->blitter, WINED3D_BLIT_OP_RAW_BLIT, context,
557 dst_texture, 0, dst_location, dst_rect,
558 dst_save_texture, dst_save_sub_resource_idx, dst_location, dst_rect,
560 }
561
562done:
563 if (dst_texture != dst_save_texture)
564 wined3d_texture_decref(dst_texture);
565
566 if (src_staging_texture)
567 wined3d_texture_decref(src_staging_texture);
568
569 if (restore_context)
570 context_restore(context, restore_texture, restore_idx);
571}
void context_gl_apply_texture_draw_state(struct wined3d_context_gl *context_gl, struct wined3d_texture *texture, unsigned int sub_resource_idx, unsigned int location)
Definition: context_gl.c:3384
void wined3d_context_gl_check_fbo_status(const struct wined3d_context_gl *context_gl, GLenum target)
Definition: context_gl.c:419
void wined3d_context_gl_apply_fbo_state_explicit(struct wined3d_context_gl *context_gl, GLenum target, struct wined3d_resource *rt, unsigned int rt_sub_resource_idx, struct wined3d_resource *ds, unsigned int ds_sub_resource_idx, uint32_t location)
Definition: context_gl.c:852
HRESULT hr
Definition: delayimp.cpp:582
void context_restore(struct wined3d_context *context, struct wined3d_texture *texture, unsigned int sub_resource_idx)
Definition: context.c:55
GLenum wined3d_texture_get_gl_buffer(const struct wined3d_texture *texture)
Definition: texture.c:113
HRESULT CDECL wined3d_texture_create(struct wined3d_device *device, const struct wined3d_resource_desc *desc, UINT layer_count, UINT level_count, uint32_t flags, const struct wined3d_sub_resource_data *data, void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_texture **texture)
Definition: texture.c:4158
void wined3d_texture_translate_drawable_coords(const struct wined3d_texture *texture, HWND window, RECT *rect)
Definition: texture.c:91
ULONG CDECL wined3d_texture_decref(struct wined3d_texture *texture)
Definition: texture.c:1606
#define abs(i)
Definition: fconv.c:206
#define GL_LINEAR
Definition: gl.h:421
unsigned int GLenum
Definition: gl.h:150
GLdouble s
Definition: gl.h:2039
#define GL_NEAREST
Definition: gl.h:678
#define GL_SCISSOR_TEST
Definition: gl.h:589
int GLint
Definition: gl.h:156
GLuint buffer
Definition: glext.h:5915
#define GL_COLOR_ATTACHMENT0
Definition: glext.h:1714
#define GL_SCALED_RESOLVE_NICEST_EXT
Definition: glext.h:5317
#define GL_SCALED_RESOLVE_FASTEST_EXT
Definition: glext.h:5316
#define GL_READ_FRAMEBUFFER
Definition: glext.h:1698
#define FAILED(hr)
Definition: intsafe.h:51
#define d
Definition: ke_i.h:81
D3D11_SHADER_VARIABLE_DESC desc
Definition: reflection.c:1683
struct wined3d_fbo_ops fbo_ops
Definition: wined3d_gl.h:354
struct wined3d_swapchain * swapchain
const struct wined3d_parent_ops wined3d_null_parent_ops
Definition: directx.c:3472
@ WINED3D_TEXF_NONE
Definition: wined3d.h:705
@ WINED3D_TEXF_LINEAR
Definition: wined3d.h:707
wined3d_format_id
Definition: wined3d.h:126
#define WINED3DUSAGE_CS
Definition: wined3d.h:933
static bool wined3d_texture_gl_is_multisample_location(const struct wined3d_texture_gl *texture_gl, uint32_t location)
Definition: wined3d_gl.h:990
static BOOL wined3d_format_is_typeless(const struct wined3d_format *format)
#define STATE_RASTERIZER

Referenced by fbo_blitter_blit(), wined3d_texture_gl_load_texture(), and wined3d_texture_load_renderbuffer().

◆ texture2d_depth_blt_fbo()

static void texture2d_depth_blt_fbo ( const struct wined3d_device *  device,
struct wined3d_context *  context,
struct wined3d_texture *  src_texture,
unsigned int  src_sub_resource_idx,
DWORD  src_location,
const RECT *  src_rect,
struct wined3d_texture *  dst_texture,
unsigned int  dst_sub_resource_idx,
DWORD  dst_location,
const RECT *  dst_rect 
)
static

Definition at line 573 of file texture.c.

577{
578 struct wined3d_context_gl *context_gl = wined3d_context_gl(context);
579 const struct wined3d_gl_info *gl_info = context_gl->gl_info;
580 GLbitfield src_mask, dst_mask;
581 GLbitfield gl_mask;
582
583 TRACE("device %p, src_texture %p, src_sub_resource_idx %u, src_location %s, src_rect %s, "
584 "dst_texture %p, dst_sub_resource_idx %u, dst_location %s, dst_rect %s.\n", device,
585 src_texture, src_sub_resource_idx, wined3d_debug_location(src_location), wine_dbgstr_rect(src_rect),
586 dst_texture, dst_sub_resource_idx, wined3d_debug_location(dst_location), wine_dbgstr_rect(dst_rect));
587
588 src_mask = 0;
589 if (src_texture->resource.format->depth_size)
591 if (src_texture->resource.format->stencil_size)
593
594 dst_mask = 0;
595 if (dst_texture->resource.format->depth_size)
596 dst_mask |= GL_DEPTH_BUFFER_BIT;
597 if (dst_texture->resource.format->stencil_size)
598 dst_mask |= GL_STENCIL_BUFFER_BIT;
599
600 if (src_mask != dst_mask)
601 {
602 ERR("Incompatible formats %s and %s.\n",
603 debug_d3dformat(src_texture->resource.format->id),
604 debug_d3dformat(dst_texture->resource.format->id));
605 return;
606 }
607
608 if (!src_mask)
609 {
610 ERR("Not a depth / stencil format: %s.\n",
611 debug_d3dformat(src_texture->resource.format->id));
612 return;
613 }
614 gl_mask = src_mask;
615
616 /* Make sure the locations are up-to-date. Loading the destination
617 * surface isn't required if the entire surface is overwritten. */
618 wined3d_texture_load_location(src_texture, src_sub_resource_idx, context, src_location);
619 if (!wined3d_texture_is_full_rect(dst_texture, dst_sub_resource_idx % dst_texture->level_count, dst_rect))
620 wined3d_texture_load_location(dst_texture, dst_sub_resource_idx, context, dst_location);
621 else
622 wined3d_texture_prepare_location(dst_texture, dst_sub_resource_idx, context, dst_location);
623
625 &src_texture->resource, src_sub_resource_idx, src_location);
627
628 context_gl_apply_texture_draw_state(context_gl, dst_texture, dst_sub_resource_idx, dst_location);
629
630 if (gl_mask & GL_DEPTH_BUFFER_BIT)
631 {
632 gl_info->gl_ops.gl.p_glDepthMask(GL_TRUE);
634 }
635 if (gl_mask & GL_STENCIL_BUFFER_BIT)
636 {
637 if (gl_info->supported[EXT_STENCIL_TWO_SIDE])
638 gl_info->gl_ops.gl.p_glDisable(GL_STENCIL_TEST_TWO_SIDE_EXT);
639 gl_info->gl_ops.gl.p_glStencilMask(~0U);
641 }
642
643 gl_info->gl_ops.gl.p_glDisable(GL_SCISSOR_TEST);
645
646 gl_info->fbo_ops.glBlitFramebuffer(src_rect->left, src_rect->top, src_rect->right, src_rect->bottom,
647 dst_rect->left, dst_rect->top, dst_rect->right, dst_rect->bottom, gl_mask, GL_NEAREST);
648 checkGLcall("glBlitFramebuffer()");
649}
UCHAR src_mask[]
Definition: GetObject.c:14
#define U(x)
Definition: wordpad.c:45
const char * debug_d3dformat(enum wined3d_format_id format_id)
Definition: utils.c:4605

Referenced by fbo_blitter_blit().

◆ texture2d_get_blt_info()

void texture2d_get_blt_info ( const struct wined3d_texture_gl *  texture_gl,
unsigned int  sub_resource_idx,
const RECT *  rect,
struct wined3d_blt_info *  info 
)

Definition at line 173 of file texture.c.

175{
176 struct wined3d_vec3 *coords = info->texcoords;
177 struct wined3d_rect_f f;
178 unsigned int level;
180 GLsizei w, h;
181
182 level = sub_resource_idx % texture_gl->t.level_count;
183 w = wined3d_texture_get_level_width(&texture_gl->t, level);
184 h = wined3d_texture_get_level_height(&texture_gl->t, level);
185 target = wined3d_texture_gl_get_sub_resource_target(texture_gl, sub_resource_idx);
186
187 switch (target)
188 {
189 default:
190 FIXME("Unsupported texture target %#x.\n", target);
191 /* Fall back to GL_TEXTURE_2D */
192 case GL_TEXTURE_2D:
193 info->bind_target = GL_TEXTURE_2D;
194 coords[0].x = (float)rect->left / w;
195 coords[0].y = (float)rect->top / h;
196 coords[0].z = 0.0f;
197
198 coords[1].x = (float)rect->right / w;
199 coords[1].y = (float)rect->top / h;
200 coords[1].z = 0.0f;
201
202 coords[2].x = (float)rect->left / w;
203 coords[2].y = (float)rect->bottom / h;
204 coords[2].z = 0.0f;
205
206 coords[3].x = (float)rect->right / w;
207 coords[3].y = (float)rect->bottom / h;
208 coords[3].z = 0.0f;
209 break;
210
212 info->bind_target = GL_TEXTURE_CUBE_MAP_ARB;
214
215 coords[0].x = 1.0f; coords[0].y = -f.t; coords[0].z = -f.l;
216 coords[1].x = 1.0f; coords[1].y = -f.t; coords[1].z = -f.r;
217 coords[2].x = 1.0f; coords[2].y = -f.b; coords[2].z = -f.l;
218 coords[3].x = 1.0f; coords[3].y = -f.b; coords[3].z = -f.r;
219 break;
220
222 info->bind_target = GL_TEXTURE_CUBE_MAP_ARB;
224
225 coords[0].x = -1.0f; coords[0].y = -f.t; coords[0].z = f.l;
226 coords[1].x = -1.0f; coords[1].y = -f.t; coords[1].z = f.r;
227 coords[2].x = -1.0f; coords[2].y = -f.b; coords[2].z = f.l;
228 coords[3].x = -1.0f; coords[3].y = -f.b; coords[3].z = f.r;
229 break;
230
232 info->bind_target = GL_TEXTURE_CUBE_MAP_ARB;
234
235 coords[0].x = f.l; coords[0].y = 1.0f; coords[0].z = f.t;
236 coords[1].x = f.r; coords[1].y = 1.0f; coords[1].z = f.t;
237 coords[2].x = f.l; coords[2].y = 1.0f; coords[2].z = f.b;
238 coords[3].x = f.r; coords[3].y = 1.0f; coords[3].z = f.b;
239 break;
240
242 info->bind_target = GL_TEXTURE_CUBE_MAP_ARB;
244
245 coords[0].x = f.l; coords[0].y = -1.0f; coords[0].z = -f.t;
246 coords[1].x = f.r; coords[1].y = -1.0f; coords[1].z = -f.t;
247 coords[2].x = f.l; coords[2].y = -1.0f; coords[2].z = -f.b;
248 coords[3].x = f.r; coords[3].y = -1.0f; coords[3].z = -f.b;
249 break;
250
252 info->bind_target = GL_TEXTURE_CUBE_MAP_ARB;
254
255 coords[0].x = f.l; coords[0].y = -f.t; coords[0].z = 1.0f;
256 coords[1].x = f.r; coords[1].y = -f.t; coords[1].z = 1.0f;
257 coords[2].x = f.l; coords[2].y = -f.b; coords[2].z = 1.0f;
258 coords[3].x = f.r; coords[3].y = -f.b; coords[3].z = 1.0f;
259 break;
260
262 info->bind_target = GL_TEXTURE_CUBE_MAP_ARB;
264
265 coords[0].x = -f.l; coords[0].y = -f.t; coords[0].z = -1.0f;
266 coords[1].x = -f.r; coords[1].y = -f.t; coords[1].z = -1.0f;
267 coords[2].x = -f.l; coords[2].y = -f.b; coords[2].z = -1.0f;
268 coords[3].x = -f.r; coords[3].y = -f.b; coords[3].z = -1.0f;
269 break;
270 }
271}
RECT rect
Definition: combotst.c:67
static void cube_coords_float(const RECT *r, UINT w, UINT h, struct wined3d_rect_f *f)
Definition: texture.c:165
#define GL_TEXTURE_CUBE_MAP_POSITIVE_Y
Definition: gl.h:1792
GLint level
Definition: gl.h:1546
#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
Definition: gl.h:1795
#define GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
Definition: gl.h:1793
#define GL_TEXTURE_CUBE_MAP_POSITIVE_Z
Definition: gl.h:1794
#define GL_TEXTURE_CUBE_MAP_POSITIVE_X
Definition: gl.h:1790
int GLsizei
Definition: gl.h:160
#define GL_TEXTURE_2D
Definition: gl.h:645
#define GL_TEXTURE_CUBE_MAP_NEGATIVE_X
Definition: gl.h:1791
GLuint coords
Definition: glext.h:7368
#define GL_TEXTURE_CUBE_MAP_ARB
Definition: glext.h:1230
static float(__cdecl *square_half_float)(float x
struct wined3d_texture t
Definition: wined3d_gl.h:941
static GLenum wined3d_texture_gl_get_sub_resource_target(const struct wined3d_texture_gl *texture_gl, unsigned int sub_resource_idx)
Definition: wined3d_gl.h:964

Referenced by wined3d_context_gl_draw_shaded_quad().

◆ texture_resource_decref()

static ULONG texture_resource_decref ( struct wined3d_resource *  resource)
static

Definition at line 3353 of file texture.c.

◆ texture_resource_incref()

static ULONG texture_resource_incref ( struct wined3d_resource *  resource)
static

Definition at line 3348 of file texture.c.

3349{
3351}
ULONG CDECL wined3d_texture_incref(struct wined3d_texture *texture)
Definition: texture.c:1516

◆ texture_resource_preload()

static void texture_resource_preload ( struct wined3d_resource *  resource)
static

Definition at line 3358 of file texture.c.

3359{
3361 struct wined3d_context *context;
3362
3363 context = context_acquire(resource->device, NULL, 0);
3366}
void wined3d_texture_load(struct wined3d_texture *texture, struct wined3d_context *context, BOOL srgb)
Definition: texture.c:1657

◆ texture_resource_sub_resource_get_desc()

static HRESULT texture_resource_sub_resource_get_desc ( struct wined3d_resource *  resource,
unsigned int  sub_resource_idx,
struct wined3d_sub_resource_desc *  desc 
)
static

Definition at line 3425 of file texture.c.

3427{
3429
3430 return wined3d_texture_get_sub_resource_desc(texture, sub_resource_idx, desc);
3431}
HRESULT CDECL wined3d_texture_get_sub_resource_desc(const struct wined3d_texture *texture, unsigned int sub_resource_idx, struct wined3d_sub_resource_desc *desc)
Definition: texture.c:4055

◆ texture_resource_sub_resource_get_map_pitch()

static void texture_resource_sub_resource_get_map_pitch ( struct wined3d_resource *  resource,
unsigned int  sub_resource_idx,
unsigned int *  row_pitch,
unsigned int *  slice_pitch 
)
static

Definition at line 3433 of file texture.c.

3435{
3437 unsigned int level = sub_resource_idx % texture->level_count;
3438
3439 if (resource->format_attrs & WINED3D_FORMAT_ATTR_BROKEN_PITCH)
3440 {
3443 }
3444 else
3445 {
3447 }
3448}
void CDECL wined3d_texture_get_pitch(const struct wined3d_texture *texture, unsigned int level, unsigned int *row_pitch, unsigned int *slice_pitch)
Definition: texture.c:1697
unsigned int slice_pitch
unsigned int row_pitch
#define WINED3D_FORMAT_ATTR_BROKEN_PITCH

◆ texture_resource_sub_resource_map()

static HRESULT texture_resource_sub_resource_map ( struct wined3d_resource *  resource,
unsigned int  sub_resource_idx,
void **  map_ptr,
const struct wined3d_box *  box,
uint32_t  flags 
)
static

Definition at line 3450 of file texture.c.

3452{
3453 struct wined3d_texture_sub_resource *sub_resource;
3454 struct wined3d_device *device = resource->device;
3455 struct wined3d_context *context;
3456 struct wined3d_texture *texture;
3457 struct wined3d_bo_address data;
3458 unsigned int texture_level;
3459 BYTE *base_memory;
3460 BOOL ret = TRUE;
3461
3462 TRACE("resource %p, sub_resource_idx %u, map_ptr %p, box %s, flags %#x.\n",
3463 resource, sub_resource_idx, map_ptr, debug_box(box), flags);
3464
3466 sub_resource = wined3d_texture_get_sub_resource(texture, sub_resource_idx);
3467
3468 texture_level = sub_resource_idx % texture->level_count;
3469
3471 {
3472 WARN("DC is in use.\n");
3474 }
3475
3476 if (sub_resource->map_count)
3477 {
3478 WARN("Sub-resource is already mapped.\n");
3480 }
3481
3483
3485 {
3486 TRACE("WINED3D_MAP_DISCARD flag passed, marking %s as up to date.\n",
3487 wined3d_debug_location(resource->map_binding));
3488 if ((ret = wined3d_texture_prepare_location(texture, sub_resource_idx, context, resource->map_binding)))
3489 wined3d_texture_validate_location(texture, sub_resource_idx, resource->map_binding);
3490 }
3491 else
3492 {
3493 if (resource->usage & WINED3DUSAGE_DYNAMIC)
3494 WARN_(d3d_perf)("Mapping a dynamic texture without WINED3D_MAP_DISCARD.\n");
3495 if (!texture_level)
3496 {
3497 unsigned int i;
3498
3499 for (i = 0; i < texture->level_count; ++i)
3500 {
3501 if (!(ret = wined3d_texture_load_location(texture, sub_resource_idx + i, context, resource->map_binding)))
3502 break;
3503 }
3504 }
3505 else
3506 {
3507 ret = wined3d_texture_load_location(texture, sub_resource_idx, context, resource->map_binding);
3508 }
3509 }
3510
3511 if (!ret)
3512 {
3513 ERR("Failed to prepare location.\n");
3515 return E_OUTOFMEMORY;
3516 }
3517
3518 /* We only record dirty regions for the top-most level. */
3519 if (texture->dirty_regions && flags & WINED3D_MAP_WRITE
3520 && !(flags & WINED3D_MAP_NO_DIRTY_UPDATE) && !texture_level)
3521 wined3d_texture_dirty_region_add(texture, sub_resource_idx / texture->level_count, box);
3522
3524 {
3525 if (!texture_level)
3526 {
3527 unsigned int i;
3528
3529 for (i = 0; i < texture->level_count; ++i)
3530 wined3d_texture_invalidate_location(texture, sub_resource_idx + i, ~resource->map_binding);
3531 }
3532 else
3533 {
3534 wined3d_texture_invalidate_location(texture, sub_resource_idx, ~resource->map_binding);
3535 }
3536 }
3537
3538 wined3d_texture_get_bo_address(texture, sub_resource_idx, &data, resource->map_binding);
3539 base_memory = wined3d_context_map_bo_address(context, &data, sub_resource->size, flags);
3540 sub_resource->map_flags = flags;
3541 TRACE("Base memory pointer %p.\n", base_memory);
3542
3544
3545 *map_ptr = resource_offset_map_pointer(resource, sub_resource_idx, base_memory, box);
3546
3547 if (texture->swapchain && texture->swapchain->front_buffer == texture)
3548 {
3549 RECT *r = &texture->swapchain->front_buffer_update;
3550
3551 SetRect(r, box->left, box->top, box->right, box->bottom);
3552 TRACE("Mapped front buffer %s.\n", wine_dbgstr_rect(r));
3553 }
3554
3555 ++resource->map_count;
3556 ++sub_resource->map_count;
3557
3558 TRACE("Returning memory %p.\n", *map_ptr);
3559
3560 return WINED3D_OK;
3561}
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
void * resource_offset_map_pointer(struct wined3d_resource *resource, unsigned int sub_resource_idx, uint8_t *base_memory, const struct wined3d_box *box)
Definition: resource.c:574
static void wined3d_texture_dirty_region_add(struct wined3d_texture *texture, unsigned int layer, const struct wined3d_box *box)
Definition: texture.c:1080
static struct wined3d_texture_sub_resource * wined3d_texture_get_sub_resource(struct wined3d_texture *texture, unsigned int sub_resource_idx)
Definition: texture.c:2122
void wined3d_texture_get_bo_address(const struct wined3d_texture *texture, unsigned int sub_resource_idx, struct wined3d_bo_address *data, uint32_t location)
Definition: texture.c:727
const char * debug_box(const struct wined3d_box *box)
Definition: utils.c:4552
return ret
Definition: mutex.c:147
unsigned int BOOL
Definition: ntddk_ex.h:94
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
BOOL WINAPI SetRect(_Out_ LPRECT, _In_ int, _In_ int, _In_ int, _In_ int)
#define WARN_(ch,...)
Definition: debug.h:157
Definition: palette.c:466
#define WINED3D_MAP_NO_DIRTY_UPDATE
Definition: wined3d.h:955
#define WINED3D_OK
Definition: wined3d.h:33
#define WINED3D_MAP_DISCARD
Definition: wined3d.h:953
#define WINED3D_MAP_WRITE
Definition: wined3d.h:956
#define WINED3DUSAGE_DYNAMIC
Definition: wined3d.h:924
#define WINED3DERR_INVALIDCALL
Definition: wined3d.h:44
#define WINED3D_TEXTURE_DC_IN_USE
static void * wined3d_context_map_bo_address(struct wined3d_context *context, const struct wined3d_bo_address *data, size_t size, uint32_t map_flags)
unsigned char BYTE
Definition: xxhash.c:193

◆ texture_resource_sub_resource_unmap()

static HRESULT texture_resource_sub_resource_unmap ( struct wined3d_resource *  resource,
unsigned int  sub_resource_idx 
)
static

Definition at line 3563 of file texture.c.

3564{
3565 struct wined3d_texture_sub_resource *sub_resource;
3566 struct wined3d_device *device = resource->device;
3567 struct wined3d_context *context;
3568 struct wined3d_texture *texture;
3569 struct wined3d_bo_address data;
3570 struct wined3d_range range;
3571
3572 TRACE("resource %p, sub_resource_idx %u.\n", resource, sub_resource_idx);
3573
3575 if (!(sub_resource = wined3d_texture_get_sub_resource(texture, sub_resource_idx)))
3576 return E_INVALIDARG;
3577
3578 if (!sub_resource->map_count)
3579 {
3580 WARN("Trying to unmap unmapped sub-resource.\n");
3582 return WINED3D_OK;
3583 return WINEDDERR_NOTLOCKED;
3584 }
3585
3587
3588 wined3d_texture_get_bo_address(texture, sub_resource_idx, &data, texture->resource.map_binding);
3589 range.offset = 0;
3590 range.size = sub_resource->size;
3591 wined3d_context_unmap_bo_address(context, &data, !!(sub_resource->map_flags & WINED3D_MAP_WRITE), &range);
3592
3594
3595 if (texture->swapchain && texture->swapchain->front_buffer == texture)
3596 {
3597 if (!(sub_resource->locations & (WINED3D_LOCATION_DRAWABLE | WINED3D_LOCATION_TEXTURE_RGB)))
3598 texture->swapchain->swapchain_ops->swapchain_frontbuffer_updated(texture->swapchain);
3599 }
3600
3601 --sub_resource->map_count;
3602 if (!--resource->map_count && texture->update_map_binding)
3604
3605 return WINED3D_OK;
3606}
range
Definition: d3dx9_private.h:58
#define E_INVALIDARG
Definition: ddrawi.h:101
static void wined3d_texture_update_map_binding(struct wined3d_texture *texture)
Definition: texture.c:933
#define WINEDDERR_NOTLOCKED
Definition: wined3d.h:46
static void wined3d_context_unmap_bo_address(struct wined3d_context *context, const struct wined3d_bo_address *data, unsigned int range_count, const struct wined3d_range *ranges)

◆ texture_resource_unload()

static void texture_resource_unload ( struct wined3d_resource *  resource)
static

Definition at line 3368 of file texture.c.

3369{
3371 struct wined3d_device *device = resource->device;
3372 unsigned int location = resource->map_binding;
3373 struct wined3d_context *context;
3374 unsigned int sub_count, i;
3375
3376 TRACE("resource %p.\n", resource);
3377
3378 /* D3D is not initialised, so no GPU locations should currently exist.
3379 * Moreover, we may not be able to acquire a valid context. */
3380 if (!device->d3d_initialized)
3381 return;
3382
3384
3387
3388 sub_count = texture->level_count * texture->layer_count;
3389 for (i = 0; i < sub_count; ++i)
3390 {
3393 {
3395 }
3396 else
3397 {
3399 ERR("Discarding %s %p sub-resource %u with resource access %s.\n",
3404 }
3405 }
3406
3412
3414
3416
3417 if (texture->resource.bind_count && (texture->resource.bind_flags & WINED3D_BIND_SHADER_RESOURCE))
3419
3421
3422 resource_unload(&texture->resource);
3423}
void device_invalidate_state(const struct wined3d_device *device, unsigned int state_id)
Definition: device.c:5565
void resource_unload(struct wined3d_resource *resource)
Definition: resource.c:241
static void wined3d_texture_set_dirty(struct wined3d_texture *texture)
Definition: texture.c:697
static void wined3d_texture_force_reload(struct wined3d_texture *texture)
Definition: texture.c:2013
static void wined3d_texture_unload_location(struct wined3d_texture *texture, struct wined3d_context *context, unsigned int location)
Definition: texture.c:927
const char * wined3d_debug_resource_access(uint32_t access)
Definition: utils.c:4828
const char * debug_d3dresourcetype(enum wined3d_resource_type resource_type)
Definition: utils.c:4992
#define WINED3D_RESOURCE_ACCESS_CPU
Definition: wined3d.h:52
#define WINED3D_BIND_SHADER_RESOURCE
Definition: wined3d.h:912
#define STATE_GRAPHICS_SHADER_RESOURCE_BINDING
#define WINED3D_LOCATION_SYSMEM
#define WINED3D_LOCATION_BUFFER
#define WINED3D_LOCATION_RB_RESOLVED
#define WINED3D_LOCATION_RB_MULTISAMPLE

◆ use_ffp_clear()

static bool use_ffp_clear ( const struct wined3d_texture *  texture,
unsigned int  location 
)
static

Definition at line 3119 of file texture.c.

3120{
3122 return true;
3123
3125 && !(texture->resource.format_caps & WINED3D_FORMAT_CAP_FBO_ATTACHABLE))
3126 return false;
3128 && !(texture->resource.format_caps & WINED3D_FORMAT_CAP_FBO_ATTACHABLE_SRGB))
3129 return false;
3130
3133}
#define WINED3D_FORMAT_CAP_FBO_ATTACHABLE_SRGB

Referenced by wined3d_texture_gl_clear().

◆ vk_blitter_blit()

static DWORD vk_blitter_blit ( struct wined3d_blitter *  blitter,
enum wined3d_blit_op  op,
struct wined3d_context *  context,
struct wined3d_texture *  src_texture,
unsigned int  src_sub_resource_idx,
DWORD  src_location,
const RECT *  src_rect,
struct wined3d_texture *  dst_texture,
unsigned int  dst_sub_resource_idx,
DWORD  dst_location,
const RECT *  dst_rect,
const struct wined3d_color_key *  colour_key,
enum wined3d_texture_filter_type  filter,
const struct wined3d_format *  resolve_format 
)
static

Definition at line 6678 of file texture.c.

6684{
6685 struct wined3d_texture_vk *src_texture_vk = wined3d_texture_vk(src_texture);
6686 struct wined3d_texture_vk *dst_texture_vk = wined3d_texture_vk(dst_texture);
6687 struct wined3d_context_vk *context_vk = wined3d_context_vk(context);
6688 const struct wined3d_vk_info *vk_info = context_vk->vk_info;
6689 VkImageSubresourceRange vk_src_range, vk_dst_range;
6690 VkImageLayout src_layout, dst_layout;
6691 VkCommandBuffer vk_command_buffer;
6692 struct wined3d_blitter *next;
6693 unsigned src_sample_count;
6694 bool resolve = false;
6695
6696 TRACE("blitter %p, op %#x, context %p, src_texture %p, src_sub_resource_idx %u, src_location %s, "
6697 "src_rect %s, dst_texture %p, dst_sub_resource_idx %u, dst_location %s, dst_rect %s, "
6698 "colour_key %p, filter %s, resolve format %p.\n",
6699 blitter, op, context, src_texture, src_sub_resource_idx, wined3d_debug_location(src_location),
6700 wine_dbgstr_rect(src_rect), dst_texture, dst_sub_resource_idx, wined3d_debug_location(dst_location),
6701 wine_dbgstr_rect(dst_rect), colour_key, debug_d3dtexturefiltertype(filter), resolve_format);
6702
6703 if (!vk_blitter_blit_supported(op, context, &src_texture->resource, src_rect, &dst_texture->resource, dst_rect,
6704 resolve_format))
6705 goto next;
6706
6707 src_sample_count = wined3d_resource_get_sample_count(&src_texture_vk->t.resource);
6708 if (src_sample_count > 1)
6709 resolve = true;
6710
6711 vk_src_range.aspectMask = vk_aspect_mask_from_format(src_texture_vk->t.resource.format);
6712 vk_src_range.baseMipLevel = src_sub_resource_idx % src_texture->level_count;
6713 vk_src_range.levelCount = 1;
6714 vk_src_range.baseArrayLayer = src_sub_resource_idx / src_texture->level_count;
6715 vk_src_range.layerCount = 1;
6716
6717 vk_dst_range.aspectMask = vk_aspect_mask_from_format(dst_texture_vk->t.resource.format);
6718 vk_dst_range.baseMipLevel = dst_sub_resource_idx % dst_texture->level_count;
6719 vk_dst_range.levelCount = 1;
6720 vk_dst_range.baseArrayLayer = dst_sub_resource_idx / dst_texture->level_count;
6721 vk_dst_range.layerCount = 1;
6722
6723 if (!wined3d_texture_load_location(src_texture, src_sub_resource_idx, context, WINED3D_LOCATION_TEXTURE_RGB))
6724 ERR("Failed to load the source sub-resource.\n");
6725
6726 if (wined3d_texture_is_full_rect(dst_texture, vk_dst_range.baseMipLevel, dst_rect))
6727 {
6728 if (!wined3d_texture_prepare_location(dst_texture,
6729 dst_sub_resource_idx, context, WINED3D_LOCATION_TEXTURE_RGB))
6730 {
6731 ERR("Failed to prepare the destination sub-resource.\n");
6732 goto next;
6733 }
6734 }
6735 else
6736 {
6737 if (!wined3d_texture_load_location(dst_texture,
6738 dst_sub_resource_idx, context, WINED3D_LOCATION_TEXTURE_RGB))
6739 {
6740 ERR("Failed to load the destination sub-resource.\n");
6741 goto next;
6742 }
6743 }
6744
6745 if (!(vk_command_buffer = wined3d_context_vk_get_command_buffer(context_vk)))
6746 {
6747 ERR("Failed to get command buffer.\n");
6748 goto next;
6749 }
6750
6751 if (src_texture_vk->layout == VK_IMAGE_LAYOUT_GENERAL)
6752 src_layout = VK_IMAGE_LAYOUT_GENERAL;
6753 else
6755
6756 if (dst_texture_vk->layout == VK_IMAGE_LAYOUT_GENERAL)
6757 dst_layout = VK_IMAGE_LAYOUT_GENERAL;
6758 else
6760
6761 wined3d_context_vk_image_barrier(context_vk, vk_command_buffer,
6763 vk_access_mask_from_bind_flags(src_texture_vk->t.resource.bind_flags),
6764 VK_ACCESS_TRANSFER_READ_BIT, src_texture_vk->layout, src_layout,
6765 src_texture_vk->image.vk_image, &vk_src_range);
6766 wined3d_context_vk_image_barrier(context_vk, vk_command_buffer,
6768 vk_access_mask_from_bind_flags(dst_texture_vk->t.resource.bind_flags),
6769 VK_ACCESS_TRANSFER_WRITE_BIT, dst_texture_vk->layout, dst_layout,
6770 dst_texture_vk->image.vk_image, &vk_dst_range);
6771
6772 if (resolve)
6773 {
6774 const struct wined3d_format_vk *src_format_vk = wined3d_format_vk(src_texture->resource.format);
6775 const struct wined3d_format_vk *dst_format_vk = wined3d_format_vk(dst_texture->resource.format);
6776 const unsigned int usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT
6778 VkImageLayout resolve_src_layout, resolve_dst_layout;
6779 VkImage src_vk_image, dst_vk_image;
6780 VkImageSubresourceRange vk_range;
6781 VkImageResolve resolve_region;
6782 VkImageType vk_image_type;
6783 VkImageCopy copy_region;
6785
6786 if (resolve_format)
6787 {
6788 vk_format = wined3d_format_vk(resolve_format)->vk_format;
6789 }
6790 else if (!wined3d_format_is_typeless(src_texture->resource.format))
6791 {
6792 vk_format = src_format_vk->vk_format;
6793 }
6794 else
6795 {
6796 vk_format = dst_format_vk->vk_format;
6797 }
6798
6799 switch (src_texture->resource.type)
6800 {
6802 vk_image_type = VK_IMAGE_TYPE_1D;
6803 break;
6805 vk_image_type = VK_IMAGE_TYPE_2D;
6806 break;
6808 vk_image_type = VK_IMAGE_TYPE_3D;
6809 break;
6810 default:
6811 ERR("Unexpected resource type: %s\n", debug_d3dresourcetype(src_texture->resource.type));
6812 goto barrier_next;
6813 }
6814
6815 vk_range.baseMipLevel = 0;
6816 vk_range.levelCount = 1;
6817 vk_range.baseArrayLayer = 0;
6818 vk_range.layerCount = 1;
6819
6820 resolve_region.srcSubresource.aspectMask = vk_src_range.aspectMask;
6821 resolve_region.dstSubresource.aspectMask = vk_dst_range.aspectMask;
6822 resolve_region.extent.width = src_rect->right - src_rect->left;
6823 resolve_region.extent.height = src_rect->bottom - src_rect->top;
6824 resolve_region.extent.depth = 1;
6825
6826 /* In case of typeless resolve the texture type may not match the resolve type.
6827 * To handle that, allocate intermediate texture(s) to resolve from/to.
6828 * A possible performance improvement would be to resolve using a shader instead. */
6829 if (src_format_vk->vk_format != vk_format)
6830 {
6831 struct wined3d_image_vk src_image;
6832
6833 if (!wined3d_context_vk_create_image(context_vk, vk_image_type, usage, vk_format,
6834 resolve_region.extent.width, resolve_region.extent.height, 1,
6835 src_sample_count, 1, 1, 0, &src_image))
6836 goto barrier_next;
6837
6838 wined3d_context_vk_reference_image(context_vk, &src_image);
6839 src_vk_image = src_image.vk_image;
6840 wined3d_context_vk_destroy_image(context_vk, &src_image);
6841
6842 vk_range.aspectMask = vk_src_range.aspectMask;
6843
6844 wined3d_context_vk_image_barrier(context_vk, vk_command_buffer,
6847 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, src_vk_image, &vk_range);
6848
6849 copy_region.srcSubresource.aspectMask = vk_src_range.aspectMask;
6850 copy_region.srcSubresource.mipLevel = vk_src_range.baseMipLevel;
6851 copy_region.srcSubresource.baseArrayLayer = vk_src_range.baseArrayLayer;
6852 copy_region.srcSubresource.layerCount = 1;
6853 copy_region.srcOffset.x = src_rect->left;
6854 copy_region.srcOffset.y = src_rect->top;
6855 copy_region.srcOffset.z = 0;
6856 copy_region.dstSubresource.aspectMask = vk_src_range.aspectMask;
6857 copy_region.dstSubresource.mipLevel = 0;
6858 copy_region.dstSubresource.baseArrayLayer = 0;
6859 copy_region.dstSubresource.layerCount = 1;
6860 copy_region.dstOffset.x = 0;
6861 copy_region.dstOffset.y = 0;
6862 copy_region.dstOffset.z = 0;
6863 copy_region.extent.width = resolve_region.extent.width;
6864 copy_region.extent.height = resolve_region.extent.height;
6865 copy_region.extent.depth = 1;
6866
6867 VK_CALL(vkCmdCopyImage(vk_command_buffer, src_texture_vk->image.vk_image,
6868 src_layout, src_vk_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
6869 1, &copy_region));
6870
6871 wined3d_context_vk_image_barrier(context_vk, vk_command_buffer,
6875 src_vk_image, &vk_range);
6876 resolve_src_layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
6877
6878 resolve_region.srcSubresource.mipLevel = 0;
6879 resolve_region.srcSubresource.baseArrayLayer = 0;
6880 resolve_region.srcSubresource.layerCount = 1;
6881 resolve_region.srcOffset.x = 0;
6882 resolve_region.srcOffset.y = 0;
6883 resolve_region.srcOffset.z = 0;
6884 }
6885 else
6886 {
6887 src_vk_image = src_texture_vk->image.vk_image;
6888 resolve_src_layout = src_layout;
6889
6890 resolve_region.srcSubresource.mipLevel = vk_src_range.baseMipLevel;
6891 resolve_region.srcSubresource.baseArrayLayer = vk_src_range.baseArrayLayer;
6892 resolve_region.srcSubresource.layerCount = 1;
6893 resolve_region.srcOffset.x = src_rect->left;
6894 resolve_region.srcOffset.y = src_rect->top;
6895 resolve_region.srcOffset.z = 0;
6896 }
6897
6898 if (dst_format_vk->vk_format != vk_format)
6899 {
6900 struct wined3d_image_vk dst_image;
6901
6902 if (!wined3d_context_vk_create_image(context_vk, vk_image_type, usage, vk_format,
6903 resolve_region.extent.width, resolve_region.extent.height, 1,
6904 VK_SAMPLE_COUNT_1_BIT, 1, 1, 0, &dst_image))
6905 goto barrier_next;
6906
6907 wined3d_context_vk_reference_image(context_vk, &dst_image);
6908 dst_vk_image = dst_image.vk_image;
6909 wined3d_context_vk_destroy_image(context_vk, &dst_image);
6910
6911 vk_range.aspectMask = vk_dst_range.aspectMask;
6912 wined3d_context_vk_image_barrier(context_vk, vk_command_buffer,
6915 resolve_dst_layout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
6916
6917 resolve_region.dstSubresource.mipLevel = 0;
6918 resolve_region.dstSubresource.baseArrayLayer = 0;
6919 resolve_region.dstSubresource.layerCount = 1;
6920 resolve_region.dstOffset.x = 0;
6921 resolve_region.dstOffset.y = 0;
6922 resolve_region.dstOffset.z = 0;
6923 }
6924 else
6925 {
6926 dst_vk_image = dst_texture_vk->image.vk_image;
6927 resolve_dst_layout = dst_layout;
6928
6929 resolve_region.dstSubresource.mipLevel = vk_dst_range.baseMipLevel;
6930 resolve_region.dstSubresource.baseArrayLayer = vk_dst_range.baseArrayLayer;
6931 resolve_region.dstSubresource.layerCount = 1;
6932 resolve_region.dstOffset.x = dst_rect->left;
6933 resolve_region.dstOffset.y = dst_rect->top;
6934 resolve_region.dstOffset.z = 0;
6935 }
6936
6937 VK_CALL(vkCmdResolveImage(vk_command_buffer, src_vk_image, resolve_src_layout,
6938 dst_vk_image, resolve_dst_layout, 1, &resolve_region));
6939
6940 if (dst_vk_image != dst_texture_vk->image.vk_image)
6941 {
6942 wined3d_context_vk_image_barrier(context_vk, vk_command_buffer,
6945 resolve_dst_layout, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
6946 dst_vk_image, &vk_range);
6947
6948 copy_region.srcSubresource.aspectMask = vk_dst_range.aspectMask;
6949 copy_region.srcSubresource.mipLevel = 0;
6950 copy_region.srcSubresource.baseArrayLayer = 0;
6951 copy_region.srcSubresource.layerCount = 1;
6952 copy_region.srcOffset.x = 0;
6953 copy_region.srcOffset.y = 0;
6954 copy_region.srcOffset.z = 0;
6955 copy_region.dstSubresource.aspectMask = vk_dst_range.aspectMask;
6956 copy_region.dstSubresource.mipLevel = vk_dst_range.baseMipLevel;
6957 copy_region.dstSubresource.baseArrayLayer = vk_dst_range.baseArrayLayer;
6958 copy_region.dstSubresource.layerCount = 1;
6959 copy_region.dstOffset.x = dst_rect->left;
6960 copy_region.dstOffset.y = dst_rect->top;
6961 copy_region.dstOffset.z = 0;
6962 copy_region.extent.width = resolve_region.extent.width;
6963 copy_region.extent.height = resolve_region.extent.height;
6964 copy_region.extent.depth = 1;
6965
6966 VK_CALL(vkCmdCopyImage(vk_command_buffer, dst_vk_image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
6967 dst_texture_vk->image.vk_image, dst_layout, 1, &copy_region));
6968 }
6969 }
6970 else
6971 {
6973
6974 region.srcSubresource.aspectMask = vk_src_range.aspectMask;
6975 region.srcSubresource.mipLevel = vk_src_range.baseMipLevel;
6976 region.srcSubresource.baseArrayLayer = vk_src_range.baseArrayLayer;
6977 region.srcSubresource.layerCount = vk_src_range.layerCount;
6978 region.srcOffset.x = src_rect->left;
6979 region.srcOffset.y = src_rect->top;
6980 region.srcOffset.z = 0;
6981 region.dstSubresource.aspectMask = vk_dst_range.aspectMask;
6982 region.dstSubresource.mipLevel = vk_dst_range.baseMipLevel;
6983 region.dstSubresource.baseArrayLayer = vk_dst_range.baseArrayLayer;
6984 region.dstSubresource.layerCount = vk_dst_range.layerCount;
6985 region.dstOffset.x = dst_rect->left;
6986 region.dstOffset.y = dst_rect->top;
6987 region.dstOffset.z = 0;
6988 region.extent.width = src_rect->right - src_rect->left;
6989 region.extent.height = src_rect->bottom - src_rect->top;
6990 region.extent.depth = 1;
6991
6992 VK_CALL(vkCmdCopyImage(vk_command_buffer, src_texture_vk->image.vk_image, src_layout,
6993 dst_texture_vk->image.vk_image, dst_layout, 1, &region));
6994 }
6995
6996 wined3d_context_vk_image_barrier(context_vk, vk_command_buffer,
6999 vk_access_mask_from_bind_flags(dst_texture_vk->t.resource.bind_flags),
7000 dst_layout, dst_texture_vk->layout, dst_texture_vk->image.vk_image, &vk_dst_range);
7001 wined3d_context_vk_image_barrier(context_vk, vk_command_buffer,
7004 vk_access_mask_from_bind_flags(src_texture_vk->t.resource.bind_flags),
7005 src_layout, src_texture_vk->layout, src_texture_vk->image.vk_image, &vk_src_range);
7006
7007 wined3d_texture_validate_location(dst_texture, dst_sub_resource_idx, WINED3D_LOCATION_TEXTURE_RGB);
7008 wined3d_texture_invalidate_location(dst_texture, dst_sub_resource_idx, ~WINED3D_LOCATION_TEXTURE_RGB);
7009 if (!wined3d_texture_load_location(dst_texture, dst_sub_resource_idx, context, dst_location))
7010 ERR("Failed to load the destination sub-resource into %s.\n", wined3d_debug_location(dst_location));
7011
7012 wined3d_context_vk_reference_texture(context_vk, src_texture_vk);
7013 wined3d_context_vk_reference_texture(context_vk, dst_texture_vk);
7014
7015 return dst_location | WINED3D_LOCATION_TEXTURE_RGB;
7016
7017barrier_next:
7018 wined3d_context_vk_image_barrier(context_vk, vk_command_buffer,
7021 vk_access_mask_from_bind_flags(dst_texture_vk->t.resource.bind_flags),
7022 dst_layout, dst_texture_vk->layout, dst_texture_vk->image.vk_image, &vk_dst_range);
7023 wined3d_context_vk_image_barrier(context_vk, vk_command_buffer,
7026 vk_access_mask_from_bind_flags(src_texture_vk->t.resource.bind_flags),
7027 src_layout, src_texture_vk->layout, src_texture_vk->image.vk_image, &vk_src_range);
7028
7029next:
7030 if (!(next = blitter->next))
7031 {
7032 ERR("No blitter to handle blit op %#x.\n", op);
7033 return dst_location;
7034 }
7035
7036 TRACE("Forwarding to blitter %p.\n", next);
7037 return next->ops->blitter_blit(next, op, context, src_texture, src_sub_resource_idx, src_location,
7038 src_rect, dst_texture, dst_sub_resource_idx, dst_location, dst_rect, colour_key, filter, resolve_format);
7039}
void wined3d_context_vk_destroy_image(struct wined3d_context_vk *context_vk, struct wined3d_image_vk *image)
Definition: context_vk.c:1092
VkCommandBuffer wined3d_context_vk_get_command_buffer(struct wined3d_context_vk *context_vk)
Definition: context_vk.c:1805
BOOL wined3d_context_vk_create_image(struct wined3d_context_vk *context_vk, VkImageType vk_image_type, VkImageUsageFlags usage, VkFormat vk_format, unsigned int width, unsigned int height, unsigned int depth, unsigned int sample_count, unsigned int mip_levels, unsigned int layer_count, unsigned int flags, struct wined3d_image_vk *image)
Definition: context_vk.c:610
void wined3d_context_vk_image_barrier(struct wined3d_context_vk *context_vk, VkCommandBuffer vk_command_buffer, VkPipelineStageFlags src_stage_mask, VkPipelineStageFlags dst_stage_mask, VkAccessFlags src_access_mask, VkAccessFlags dst_access_mask, VkImageLayout old_layout, VkImageLayout new_layout, VkImage image, const VkImageSubresourceRange *range)
Definition: context_vk.c:2022
VkAccessFlags vk_access_mask_from_bind_flags(uint32_t bind_flags)
Definition: resource.c:526
unsigned int wined3d_resource_get_sample_count(const struct wined3d_resource *resource)
Definition: resource.c:456
static bool vk_blitter_blit_supported(enum wined3d_blit_op op, const struct wined3d_context *context, const struct wined3d_resource *src_resource, const RECT *src_rect, const struct wined3d_resource *dst_resource, const RECT *dst_rect, const struct wined3d_format *resolve_format)
Definition: texture.c:6610
GLsizeiptr const GLvoid GLenum usage
Definition: glext.h:5919
uint32_t depth
Definition: vulkan.h:8674
uint32_t height
Definition: vulkan.h:8673
uint32_t width
Definition: vulkan.h:8672
VkExtent3D extent
Definition: vulkan.h:16373
VkOffset3D srcOffset
Definition: vulkan.h:16370
VkImageSubresourceLayers srcSubresource
Definition: vulkan.h:16369
VkImageSubresourceLayers dstSubresource
Definition: vulkan.h:16371
VkOffset3D dstOffset
Definition: vulkan.h:16372
VkImageSubresourceLayers dstSubresource
Definition: vulkan.h:16423
VkOffset3D srcOffset
Definition: vulkan.h:16422
VkImageSubresourceLayers srcSubresource
Definition: vulkan.h:16421
VkExtent3D extent
Definition: vulkan.h:16425
VkOffset3D dstOffset
Definition: vulkan.h:16424
VkImageAspectFlags aspectMask
Definition: vulkan.h:9065
uint32_t baseArrayLayer
Definition: vulkan.h:9076
VkImageAspectFlags aspectMask
Definition: vulkan.h:9073
int32_t x
Definition: vulkan.h:9579
int32_t y
Definition: vulkan.h:9580
int32_t z
Definition: vulkan.h:9581
const struct wined3d_vk_info * vk_info
Definition: wined3d_vk.h:590
VkFormat vk_format
Definition: wined3d_vk.h:1083
struct wined3d_image_vk image
Definition: wined3d_vk.h:877
struct wined3d_texture t
Definition: wined3d_vk.h:875
enum VkImageLayout layout
Definition: wined3d_vk.h:878
VkImageLayout
Definition: vulkan.h:3450
@ VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL
Definition: vulkan.h:3457
@ VK_IMAGE_LAYOUT_UNDEFINED
Definition: vulkan.h:3451
@ VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
Definition: vulkan.h:3458
@ VK_IMAGE_LAYOUT_GENERAL
Definition: vulkan.h:3452
@ VK_IMAGE_USAGE_TRANSFER_DST_BIT
Definition: vulkan.h:3511
@ VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
Definition: vulkan.h:3514
@ VK_IMAGE_USAGE_TRANSFER_SRC_BIT
Definition: vulkan.h:3510
@ VK_SAMPLE_COUNT_1_BIT
Definition: vulkan.h:4701
void VKAPI_CALL vkCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, const VkImageCopy *pRegions)
VkImageType
Definition: vulkan.h:3501
@ VK_IMAGE_TYPE_2D
Definition: vulkan.h:3503
@ VK_IMAGE_TYPE_3D
Definition: vulkan.h:3504
@ VK_IMAGE_TYPE_1D
Definition: vulkan.h:3502
@ VK_ACCESS_TRANSFER_WRITE_BIT
Definition: vulkan.h:1641
@ VK_ACCESS_TRANSFER_READ_BIT
Definition: vulkan.h:1640
void VKAPI_CALL vkCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, const VkImageResolve *pRegions)
VkFormat
Definition: vulkan.h:2815
@ VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT
Definition: vulkan.h:4272
@ VK_PIPELINE_STAGE_ALL_COMMANDS_BIT
Definition: vulkan.h:4288
@ VK_PIPELINE_STAGE_TRANSFER_BIT
Definition: vulkan.h:4284
@ WINED3D_RTYPE_TEXTURE_1D
Definition: wined3d.h:719
@ WINED3D_RTYPE_TEXTURE_3D
Definition: wined3d.h:721
static void wined3d_context_vk_reference_image(const struct wined3d_context_vk *context_vk, struct wined3d_image_vk *image)
Definition: wined3d_vk.h:1097
static VkImageAspectFlags vk_aspect_mask_from_format(const struct wined3d_format *format)
Definition: wined3d_vk.h:294
static void wined3d_context_vk_reference_texture(const struct wined3d_context_vk *context_vk, struct wined3d_texture_vk *texture_vk)
Definition: wined3d_vk.h:1103
#define VK_CALL(f)
Definition: wined3d_vk.h:272

◆ vk_blitter_blit_supported()

static bool vk_blitter_blit_supported ( enum wined3d_blit_op  op,
const struct wined3d_context *  context,
const struct wined3d_resource *  src_resource,
const RECT *  src_rect,
const struct wined3d_resource *  dst_resource,
const RECT *  dst_rect,
const struct wined3d_format *  resolve_format 
)
static

Definition at line 6610 of file texture.c.

6613{
6614 const struct wined3d_format *src_format = src_resource->format;
6615 const struct wined3d_format *dst_format = dst_resource->format;
6616
6617 if (!(dst_resource->access & WINED3D_RESOURCE_ACCESS_GPU))
6618 {
6619 TRACE("Destination resource does not have GPU access.\n");
6620 return false;
6621 }
6622
6623 if (!(src_resource->access & WINED3D_RESOURCE_ACCESS_GPU))
6624 {
6625 TRACE("Source resource does not have GPU access.\n");
6626 return false;
6627 }
6628
6629 if (dst_format->id != src_format->id)
6630 {
6631 if (!is_identity_fixup(dst_format->color_fixup))
6632 {
6633 TRACE("Destination fixups are not supported.\n");
6634 return false;
6635 }
6636
6637 if (!is_identity_fixup(src_format->color_fixup))
6638 {
6639 TRACE("Source fixups are not supported.\n");
6640 return false;
6641 }
6642
6644 && wined3d_format_vk(src_format)->vk_format != wined3d_format_vk(dst_format)->vk_format
6646 || !resolve_format))
6647 {
6648 TRACE("Format conversion not supported.\n");
6649 return false;
6650 }
6651 }
6652
6653 if (wined3d_resource_get_sample_count(dst_resource) > 1)
6654 {
6655 TRACE("Multi-sample destination resource not supported.\n");
6656 return false;
6657 }
6658
6660 return true;
6661
6663 {
6664 TRACE("Unsupported blit operation %#x.\n", op);
6665 return false;
6666 }
6667
6668 if ((src_rect->right - src_rect->left != dst_rect->right - dst_rect->left)
6669 || (src_rect->bottom - src_rect->top != dst_rect->bottom - dst_rect->top))
6670 {
6671 TRACE("Scaling not supported.\n");
6672 return false;
6673 }
6674
6675 return true;
6676}

Referenced by vk_blitter_blit().

◆ vk_blitter_clear()

static void vk_blitter_clear ( struct wined3d_blitter *  blitter,
struct wined3d_device *  device,
unsigned int  rt_count,
const struct wined3d_fb_state *  fb,
unsigned int  rect_count,
const RECT *  clear_rects,
const RECT *  draw_rect,
uint32_t  flags,
const struct wined3d_color *  colour,
float  depth,
unsigned int  stencil 
)
static

Definition at line 6494 of file texture.c.

6497{
6498 struct wined3d_device_vk *device_vk = wined3d_device_vk(device);
6499 struct wined3d_rendertarget_view *view, *previous = NULL;
6500 struct wined3d_context_vk *context_vk;
6501 bool have_identical_size = true;
6502 struct wined3d_fb_state tmp_fb;
6503 unsigned int next_rt_count = 0;
6504 struct wined3d_blitter *next;
6505 uint32_t next_flags = 0;
6506 unsigned int i;
6507
6508 TRACE("blitter %p, device %p, rt_count %u, fb %p, rect_count %u, clear_rects %p, "
6509 "draw_rect %s, flags %#x, colour %s, depth %.8e, stencil %#x.\n",
6510 blitter, device, rt_count, fb, rect_count, clear_rects,
6511 wine_dbgstr_rect(draw_rect), flags, debug_color(colour), depth, stencil);
6512
6513 if (!rect_count)
6514 {
6515 rect_count = 1;
6516 clear_rects = draw_rect;
6517 }
6518
6520 {
6521 for (i = 0; i < rt_count; ++i)
6522 {
6523 if (!(view = fb->render_targets[i]))
6524 continue;
6525
6527 {
6528 next_flags |= WINED3DCLEAR_TARGET;
6529 flags &= ~WINED3DCLEAR_TARGET;
6530 next_rt_count = rt_count;
6531 rt_count = 0;
6532 break;
6533 }
6534 }
6535 }
6536
6538 && (!view->format->depth_size || (flags & WINED3DCLEAR_ZBUFFER))
6539 && (!view->format->stencil_size || (flags & WINED3DCLEAR_STENCIL))
6541 {
6544 }
6545
6546 if (flags)
6547 {
6548 context_vk = wined3d_context_vk(context_acquire(&device_vk->d, NULL, 0));
6549
6550 for (i = 0; i < rt_count; ++i)
6551 {
6552 if (!(view = fb->render_targets[i]))
6553 continue;
6554
6555 if (previous && (previous->width != view->width || previous->height != view->height))
6556 have_identical_size = false;
6557 previous = view;
6558 }
6560 {
6561 view = fb->depth_stencil;
6562
6563 if (previous && (previous->width != view->width || previous->height != view->height))
6564 have_identical_size = false;
6565 }
6566
6567 if (have_identical_size)
6568 {
6569 vk_blitter_clear_rendertargets(context_vk, rt_count, fb, rect_count,
6570 clear_rects, draw_rect, flags, colour, depth, stencil);
6571 }
6572 else
6573 {
6574 for (i = 0; i < rt_count; ++i)
6575 {
6576 if (!(view = fb->render_targets[i]))
6577 continue;
6578
6579 tmp_fb.render_targets[0] = view;
6580 tmp_fb.depth_stencil = NULL;
6581 vk_blitter_clear_rendertargets(context_vk, 1, &tmp_fb, rect_count,
6582 clear_rects, draw_rect, WINED3DCLEAR_TARGET, colour, depth, stencil);
6583 }
6585 {
6586 tmp_fb.render_targets[0] = NULL;
6587 tmp_fb.depth_stencil = fb->depth_stencil;
6588 vk_blitter_clear_rendertargets(context_vk, 0, &tmp_fb, rect_count,
6589 clear_rects, draw_rect, flags & ~WINED3DCLEAR_TARGET, colour, depth, stencil);
6590 }
6591 }
6592
6593 context_release(&context_vk->c);
6594 }
6595
6596 if (!next_flags)
6597 return;
6598
6599 if (!(next = blitter->next))
6600 {
6601 ERR("No blitter to handle clear.\n");
6602 return;
6603 }
6604
6605 TRACE("Forwarding to blitter %p.\n", next);
6606 next->ops->blitter_clear(next, device, next_rt_count, fb, rect_count,
6607 clear_rects, draw_rect, next_flags, colour, depth, stencil);
6608}
UINT32 uint32_t
Definition: types.h:75
static void vk_blitter_clear_rendertargets(struct wined3d_context_vk *context_vk, unsigned int rt_count, const struct wined3d_fb_state *fb, unsigned int rect_count, const RECT *clear_rects, const RECT *draw_rect, uint32_t flags, const struct wined3d_color *colour, float depth, unsigned int stencil)
Definition: texture.c:6291
const char * debug_color(const struct wined3d_color *color)
Definition: utils.c:4561
struct wined3d_context c
Definition: wined3d_vk.h:588
struct wined3d_device d
Definition: wined3d_vk.h:821

◆ vk_blitter_clear_rendertargets()

static void vk_blitter_clear_rendertargets ( struct wined3d_context_vk *  context_vk,
unsigned int  rt_count,
const struct wined3d_fb_state *  fb,
unsigned int  rect_count,
const RECT *  clear_rects,
const RECT *  draw_rect,
uint32_t  flags,
const struct wined3d_color *  colour,
float  depth,
unsigned int  stencil 
)
static

Definition at line 6291 of file texture.c.

6294{
6295 unsigned int i, attachment_count, immediate_rt_count = 0, delay_count = 0;
6296 VkClearValue clear_values[WINED3D_MAX_RENDER_TARGETS + 1];
6297 VkImageView views[WINED3D_MAX_RENDER_TARGETS + 1];
6298 struct wined3d_rendertarget_view_vk *rtv_vk;
6300 const struct wined3d_vk_info *vk_info;
6301 struct wined3d_fb_state immediate_fb;
6302 struct wined3d_device_vk *device_vk;
6303 VkCommandBuffer vk_command_buffer;
6304 VkRenderPassBeginInfo begin_desc;
6306 VkFramebuffer vk_framebuffer;
6307 VkRenderPass vk_render_pass;
6308 bool depth_stencil = false;
6309 unsigned int layer_count;
6311 VkResult vr;
6312 RECT r;
6313
6314 TRACE("context_vk %p, rt_count %u, fb %p, rect_count %u, clear_rects %p, "
6315 "draw_rect %s, flags %#x, colour %s, depth %.8e, stencil %#x.\n",
6316 context_vk, rt_count, fb, rect_count, clear_rects,
6317 wine_dbgstr_rect(draw_rect), flags, debug_color(colour), depth, stencil);
6318
6319 device_vk = wined3d_device_vk(context_vk->c.device);
6320 vk_info = context_vk->vk_info;
6321
6322 if (!(flags & WINED3DCLEAR_TARGET))
6323 rt_count = 0;
6324
6325 for (i = 0, attachment_count = 0, layer_count = 1; i < rt_count; ++i)
6326 {
6327 if (!(view = fb->render_targets[i]))
6328 continue;
6329
6330 /* Don't delay typeless clears because the data written into the resource depends on the
6331 * view format. Except all-zero clears, those should result in zeros in either case.
6332 *
6333 * We could store the clear format along with the clear value, but then we'd have to
6334 * create a matching RTV at draw time, which would need its own render pass, thus mooting
6335 * the point of the delayed clear. (Unless we are lucky enough that the application
6336 * draws with the same RTV as it clears.) */
6337 if (is_full_clear(view, draw_rect, clear_rects)
6338 && (!wined3d_format_is_typeless(view->resource->format) || (!colour->r && !colour->g
6339 && !colour->b && !colour->a)))
6340 {
6344 texture->sub_resources[view->sub_resource_idx].clear_value.colour = *colour;
6345 delay_count++;
6346 continue;
6347 }
6348 else
6349 {
6350 wined3d_rendertarget_view_load_location(view, &context_vk->c, view->resource->draw_binding);
6351 }
6352 wined3d_rendertarget_view_validate_location(view, view->resource->draw_binding);
6353 wined3d_rendertarget_view_invalidate_location(view, ~view->resource->draw_binding);
6354
6355 immediate_fb.render_targets[immediate_rt_count++] = view;
6357 views[attachment_count] = wined3d_rendertarget_view_vk_get_image_view(rtv_vk, context_vk);
6359
6360 c = &clear_values[attachment_count].color;
6361 wined3d_format_colour_to_vk(view->format, colour, c);
6362
6363 if (view->layer_count > layer_count)
6364 layer_count = view->layer_count;
6365
6366 ++attachment_count;
6367 }
6368
6369 if (!attachment_count)
6370 flags &= ~WINED3DCLEAR_TARGET;
6371
6373 {
6374 DWORD full_flags = 0;
6375
6376 /* Vulkan can clear only depth or stencil, but at the moment we can't put the depth and
6377 * stencil parts in separate locations. It isn't easy to do either, as such a half-cleared
6378 * texture would need to be handled not just as a DS target but also when used as a shader
6379 * resource or accessed on sysmem. */
6380 if (view->format->depth_size)
6381 full_flags = WINED3DCLEAR_ZBUFFER;
6382 if (view->format->stencil_size)
6383 full_flags |= WINED3DCLEAR_STENCIL;
6384
6385 if (!is_full_clear(view, draw_rect, clear_rects) || (flags & full_flags) != full_flags
6386 || (wined3d_format_is_typeless(view->resource->format) && (depth || stencil)))
6387 {
6388 wined3d_rendertarget_view_load_location(view, &context_vk->c, view->resource->draw_binding);
6389 wined3d_rendertarget_view_validate_location(view, view->resource->draw_binding);
6390 wined3d_rendertarget_view_invalidate_location(view, ~view->resource->draw_binding);
6391
6392 immediate_fb.depth_stencil = view;
6394 views[attachment_count] = wined3d_rendertarget_view_vk_get_image_view(rtv_vk, context_vk);
6396
6397 clear_values[attachment_count].depthStencil.depth = depth;
6398 clear_values[attachment_count].depthStencil.stencil = stencil;
6399
6400 if (view->layer_count > layer_count)
6401 layer_count = view->layer_count;
6402
6403 depth_stencil = true;
6404 ++attachment_count;
6405 }
6406 else
6407 {
6409 texture->sub_resources[view->sub_resource_idx].clear_value.depth = depth;
6410 texture->sub_resources[view->sub_resource_idx].clear_value.stencil = stencil;
6414 delay_count++;
6415 }
6416 }
6417
6418 if (!attachment_count)
6419 {
6420 TRACE("The clear has been delayed until draw time.\n");
6421 return;
6422 }
6423
6424 TRACE("Doing an immediate clear of %u attachments.\n", attachment_count);
6425 if (delay_count)
6426 TRACE_(d3d_perf)("Partial clear: %u immediate, %u delayed.\n", attachment_count, delay_count);
6427
6428 if (!(vk_render_pass = wined3d_context_vk_get_render_pass(context_vk, &immediate_fb,
6429 immediate_rt_count, flags & (WINED3DCLEAR_ZBUFFER | WINED3DCLEAR_STENCIL), flags)))
6430 {
6431 ERR("Failed to get render pass.\n");
6432 return;
6433 }
6434
6435 if (!(vk_command_buffer = wined3d_context_vk_get_command_buffer(context_vk)))
6436 {
6437 ERR("Failed to get command buffer.\n");
6438 return;
6439 }
6440
6442 fb_desc.pNext = NULL;
6443 fb_desc.flags = 0;
6444 fb_desc.renderPass = vk_render_pass;
6445 fb_desc.attachmentCount = attachment_count;
6446 fb_desc.pAttachments = views;
6447 fb_desc.width = draw_rect->right - draw_rect->left;
6448 fb_desc.height = draw_rect->bottom - draw_rect->top;
6449 fb_desc.layers = layer_count;
6450 if ((vr = VK_CALL(vkCreateFramebuffer(device_vk->vk_device, &fb_desc, NULL, &vk_framebuffer))) < 0)
6451 {
6452 ERR("Failed to create Vulkan framebuffer, vr %s.\n", wined3d_debug_vkresult(vr));
6453 return;
6454 }
6455
6457 begin_desc.pNext = NULL;
6458 begin_desc.renderPass = vk_render_pass;
6459 begin_desc.framebuffer = vk_framebuffer;
6460 begin_desc.clearValueCount = attachment_count;
6461 begin_desc.pClearValues = clear_values;
6462
6464
6465 for (i = 0; i < rect_count; ++i)
6466 {
6467 r.left = max(clear_rects[i].left, draw_rect->left);
6468 r.top = max(clear_rects[i].top, draw_rect->top);
6469 r.right = min(clear_rects[i].right, draw_rect->right);
6470 r.bottom = min(clear_rects[i].bottom, draw_rect->bottom);
6471
6472 if (r.left >= r.right || r.top >= r.bottom)
6473 continue;
6474
6475 begin_desc.renderArea.offset.x = r.left;
6476 begin_desc.renderArea.offset.y = r.top;
6477 begin_desc.renderArea.extent.width = r.right - r.left;
6478 begin_desc.renderArea.extent.height = r.bottom - r.top;
6479 VK_CALL(vkCmdBeginRenderPass(vk_command_buffer, &begin_desc, VK_SUBPASS_CONTENTS_INLINE));
6480 VK_CALL(vkCmdEndRenderPass(vk_command_buffer));
6481 }
6482
6483 wined3d_context_vk_destroy_vk_framebuffer(context_vk, vk_framebuffer, context_vk->current_command_buffer.id);
6484
6485 for (i = 0; i < immediate_rt_count; ++i)
6487 wined3d_rendertarget_view_vk(immediate_fb.render_targets[i]));
6488
6489 if (depth_stencil)
6491 wined3d_rendertarget_view_vk(immediate_fb.depth_stencil));
6492}
VkRenderPass wined3d_context_vk_get_render_pass(struct wined3d_context_vk *context_vk, const struct wined3d_fb_state *fb, unsigned int rt_count, bool depth_stencil, uint32_t clear_flags)
Definition: context_vk.c:1533
void wined3d_context_vk_destroy_vk_framebuffer(struct wined3d_context_vk *context_vk, VkFramebuffer vk_framebuffer, uint64_t command_buffer_id)
Definition: context_vk.c:712
void wined3d_context_vk_end_current_render_pass(struct wined3d_context_vk *context_vk)
Definition: context_vk.c:1564
const char * wined3d_debug_vkresult(VkResult vr)
Definition: utils.c:5463
void wined3d_format_colour_to_vk(const struct wined3d_format *format, const struct wined3d_color *c, VkClearColorValue *retval)
Definition: utils.c:5790
#define TRACE_(x)
Definition: compat.h:76
const GLubyte * c
Definition: glext.h:8905
GLdouble GLdouble GLdouble GLdouble top
Definition: glext.h:10859
GLdouble GLdouble right
Definition: glext.h:10859
GLint left
Definition: glext.h:7726
GLint GLint bottom
Definition: glext.h:7726
#define c
Definition: ke_i.h:80
#define min(a, b)
Definition: monoChain.cc:55
static unsigned int delay_count
Definition: pchw.c:39
uint32_t width
Definition: vulkan.h:8666
uint32_t height
Definition: vulkan.h:8667
const VkImageView * pAttachments
Definition: vulkan.h:8821
VkStructureType sType
Definition: vulkan.h:8816
VkFramebufferCreateFlags flags
Definition: vulkan.h:8818
const void * pNext
Definition: vulkan.h:8817
uint32_t attachmentCount
Definition: vulkan.h:8820
int32_t x
Definition: vulkan.h:9573
int32_t y
Definition: vulkan.h:9574
VkExtent2D extent
Definition: vulkan.h:13605
VkOffset2D offset
Definition: vulkan.h:13604
const void * pNext
Definition: vulkan.h:13643
const VkClearValue * pClearValues
Definition: vulkan.h:13648
VkStructureType sType
Definition: vulkan.h:13642
uint32_t clearValueCount
Definition: vulkan.h:13647
struct wined3d_command_buffer_vk current_command_buffer
Definition: wined3d_vk.h:617
VkDevice vk_device
Definition: wined3d_vk.h:825
struct wined3d_vk_info vk_info
Definition: wined3d_vk.h:830
struct wined3d_context_vk context_vk
Definition: wined3d_vk.h:823
#define max(a, b)
Definition: svc.c:63
VkClearColorValue color
Definition: vulkan.h:7731
VkClearDepthStencilValue depthStencil
Definition: vulkan.h:7732
void VKAPI_CALL vkCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin, VkSubpassContents contents)
void VKAPI_CALL vkCmdEndRenderPass(VkCommandBuffer commandBuffer)
VkResult VKAPI_CALL vkCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkFramebuffer *pFramebuffer)
VkResult
Definition: vulkan.h:4639
@ VK_SUBPASS_CONTENTS_INLINE
Definition: vulkan.h:6094
@ VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
Definition: vulkan.h:5001
@ VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO
Definition: vulkan.h:5007
#define WINED3D_MAX_RENDER_TARGETS
Definition: wined3d.h:1606
#define WINED3D_BIND_DEPTH_STENCIL
Definition: wined3d.h:915
#define WINED3D_LOCATION_CLEARED
static void wined3d_context_vk_reference_rendertarget_view(const struct wined3d_context_vk *context_vk, struct wined3d_rendertarget_view_vk *rtv_vk)
Definition: wined3d_vk.h:1130
static VkImageView wined3d_rendertarget_view_vk_get_image_view(struct wined3d_rendertarget_view_vk *rtv_vk, struct wined3d_context_vk *context_vk)
Definition: wined3d_vk.h:967
static void wined3d_rendertarget_view_vk_barrier(struct wined3d_rendertarget_view_vk *rtv_vk, struct wined3d_context_vk *context_vk, uint32_t bind_mask)
Definition: wined3d_vk.h:961

Referenced by vk_blitter_clear().

◆ vk_blitter_destroy()

static void vk_blitter_destroy ( struct wined3d_blitter *  blitter,
struct wined3d_context *  context 
)
static

Definition at line 6279 of file texture.c.

6280{
6281 struct wined3d_blitter *next;
6282
6283 TRACE("blitter %p, context %p.\n", blitter, context);
6284
6285 if ((next = blitter->next))
6286 next->ops->blitter_destroy(next, context);
6287
6288 free(blitter);
6289}

◆ WINE_DECLARE_DEBUG_CHANNEL() [1/2]

WINE_DECLARE_DEBUG_CHANNEL ( d3d_perf  )

◆ WINE_DECLARE_DEBUG_CHANNEL() [2/2]

WINE_DECLARE_DEBUG_CHANNEL ( winediag  )

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( d3d  )

◆ wined3d_device_context_blt()

HRESULT CDECL wined3d_device_context_blt ( struct wined3d_device_context *  context,
struct wined3d_texture *  dst_texture,
unsigned int  dst_sub_resource_idx,
const RECT *  dst_rect,
struct wined3d_texture *  src_texture,
unsigned int  src_sub_resource_idx,
const RECT *  src_rect,
unsigned int  flags,
const struct wined3d_blt_fx *  fx,
enum wined3d_texture_filter_type  filter 
)

Definition at line 3854 of file texture.c.

3858{
3859 struct wined3d_box src_box = {src_rect->left, src_rect->top, src_rect->right, src_rect->bottom, 0, 1};
3860 struct wined3d_box dst_box = {dst_rect->left, dst_rect->top, dst_rect->right, dst_rect->bottom, 0, 1};
3861 HRESULT hr;
3862
3863 TRACE("context %p, dst_texture %p, dst_sub_resource_idx %u, dst_rect %s, src_texture %p, "
3864 "src_sub_resource_idx %u, src_rect %s, flags %#x, fx %p, filter %s.\n",
3865 context, dst_texture, dst_sub_resource_idx, wine_dbgstr_rect(dst_rect), src_texture,
3866 src_sub_resource_idx, wine_dbgstr_rect(src_rect), flags, fx, debug_d3dtexturefiltertype(filter));
3867
3868 if (!wined3d_texture_validate_sub_resource_idx(dst_texture, dst_sub_resource_idx)
3869 || dst_texture->resource.type != WINED3D_RTYPE_TEXTURE_2D)
3871
3872 if (!wined3d_texture_validate_sub_resource_idx(src_texture, src_sub_resource_idx)
3873 || src_texture->resource.type != WINED3D_RTYPE_TEXTURE_2D)
3875
3879
3880 if (FAILED(hr = wined3d_resource_check_box_dimensions(&dst_texture->resource, dst_sub_resource_idx, &dst_box)))
3881 return hr;
3882
3883 if (FAILED(hr = wined3d_resource_check_box_dimensions(&src_texture->resource, src_sub_resource_idx, &src_box)))
3884 return hr;
3885
3886 if (dst_texture->sub_resources[dst_sub_resource_idx].map_count
3887 || src_texture->sub_resources[src_sub_resource_idx].map_count)
3888 {
3889 WARN("Sub-resource is busy, returning WINEDDERR_SURFACEBUSY.\n");
3890 return WINEDDERR_SURFACEBUSY;
3891 }
3892
3893 if (!src_texture->resource.format->depth_size != !dst_texture->resource.format->depth_size
3894 || !src_texture->resource.format->stencil_size != !dst_texture->resource.format->stencil_size)
3895 {
3896 WARN("Rejecting depth/stencil blit between incompatible formats.\n");
3898 }
3899
3900 if (dst_texture->resource.device != src_texture->resource.device)
3901 {
3902 FIXME("Rejecting cross-device blit.\n");
3903 return E_NOTIMPL;
3904 }
3905
3906 wined3d_device_context_emit_blt_sub_resource(context, &dst_texture->resource, dst_sub_resource_idx,
3907 &dst_box, &src_texture->resource, src_sub_resource_idx, &src_box, flags, fx, filter);
3908
3909 if (dst_texture->dirty_regions)
3910 wined3d_texture_add_dirty_region(dst_texture, dst_sub_resource_idx, &dst_box);
3911
3912 return WINED3D_OK;
3913}
void wined3d_device_context_emit_blt_sub_resource(struct wined3d_device_context *context, struct wined3d_resource *dst_resource, unsigned int dst_sub_resource_idx, const struct wined3d_box *dst_box, struct wined3d_resource *src_resource, unsigned int src_sub_resource_idx, const struct wined3d_box *src_box, unsigned int flags, const struct wined3d_blt_fx *fx, enum wined3d_texture_filter_type filter)
Definition: cs.c:2703
#define E_NOTIMPL
Definition: ddrawi.h:99
HRESULT wined3d_resource_check_box_dimensions(struct wined3d_resource *resource, unsigned int sub_resource_idx, const struct wined3d_box *box)
Definition: resource.c:488
HRESULT CDECL wined3d_texture_add_dirty_region(struct wined3d_texture *texture, UINT layer, const struct wined3d_box *dirty_region)
Definition: texture.c:2132
bool wined3d_texture_validate_sub_resource_idx(const struct wined3d_texture *texture, unsigned int sub_resource_idx)
Definition: texture.c:50
struct wined3d_texture::wined3d_texture_sub_resource * sub_resources
struct wined3d_texture::wined3d_dirty_regions * dirty_regions
GLfixed fx
Definition: tritemp.h:484
@ WINED3D_TEXF_POINT
Definition: wined3d.h:706
#define WINEDDERR_SURFACEBUSY
Definition: wined3d.h:47

Referenced by copy_mipmap_chain(), d3d8_device_CopyRects(), d3d9_device_GetRenderTargetData(), d3d9_device_StretchRect(), ddraw_surface7_BltFast(), ddraw_surface_blt(), ddraw_surface_update_frontbuffer(), wined3d_cs_exec_present(), wined3d_device_context_resolve_sub_resource(), and wined3d_swapchain_get_front_buffer_data().

◆ wined3d_fbo_blitter_create()

void wined3d_fbo_blitter_create ( struct wined3d_blitter **  next,
const struct wined3d_gl_info *  gl_info 
)

Definition at line 6105 of file texture.c.

6106{
6107 struct wined3d_blitter *blitter;
6108
6109 if (!(blitter = malloc(sizeof(*blitter))))
6110 return;
6111
6112 TRACE("Created blitter %p.\n", blitter);
6113
6114 blitter->ops = &fbo_blitter_ops;
6115 blitter->next = *next;
6116 *next = blitter;
6117}
#define malloc
Definition: debug_ros.c:4
static const struct wined3d_blitter_ops fbo_blitter_ops
Definition: texture.c:6098
const struct wined3d_blitter_ops * ops

Referenced by wined3d_device_gl_create_primary_opengl_context_cs().

◆ wined3d_ffp_blitter_create()

void wined3d_ffp_blitter_create ( struct wined3d_blitter **  next,
const struct wined3d_gl_info *  gl_info 
)

Definition at line 5995 of file texture.c.

5996{
5997 struct wined3d_blitter *blitter;
5998
5999 if (!(blitter = malloc(sizeof(*blitter))))
6000 return;
6001
6002 TRACE("Created blitter %p.\n", blitter);
6003
6004 blitter->ops = &ffp_blitter_ops;
6005 blitter->next = *next;
6006 *next = blitter;
6007}
static const struct wined3d_blitter_ops ffp_blitter_ops
Definition: texture.c:5988

Referenced by wined3d_device_gl_create_primary_opengl_context_cs().

◆ wined3d_fixup_alpha()

static void wined3d_fixup_alpha ( const struct wined3d_format *  format,
const uint8_t *  src,
unsigned int  src_row_pitch,
uint8_t *  dst,
unsigned int  dst_row_pitch,
unsigned int  width,
unsigned int  height 
)
static

Definition at line 2318 of file texture.c.

2321{
2322 unsigned int byte_count, alpha_mask;
2323 unsigned int x, y;
2324
2325 byte_count = format->byte_count;
2326 alpha_mask = wined3d_mask_from_size(format->alpha_size) << format->alpha_offset;
2327
2328 switch (byte_count)
2329 {
2330 case 2:
2331 for (y = 0; y < height; ++y)
2332 {
2333 const uint16_t *src_row = (const uint16_t *)&src[y * src_row_pitch];
2334 uint16_t *dst_row = (uint16_t *)&dst[y * dst_row_pitch];
2335
2336 for (x = 0; x < width; ++x)
2337 {
2338 dst_row[x] = src_row[x] | alpha_mask;
2339 }
2340 }
2341 break;
2342
2343 case 4:
2344 for (y = 0; y < height; ++y)
2345 {
2346 const uint32_t *src_row = (const uint32_t *)&src[y * src_row_pitch];
2347 uint32_t *dst_row = (uint32_t *)&dst[y * dst_row_pitch];
2348
2349 for (x = 0; x < width; ++x)
2350 {
2351 dst_row[x] = src_row[x] | alpha_mask;
2352 }
2353 }
2354 break;
2355
2356 default:
2357 ERR("Unsupported byte count %u.\n", byte_count);
2358 break;
2359 }
2360}
unsigned short uint16_t
Definition: stdint.h:35
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
GLenum src
Definition: glext.h:6340
GLenum GLenum dst
Definition: glext.h:6340
static uint32_t wined3d_mask_from_size(unsigned int size)

Referenced by wined3d_texture_gl_upload_data().

◆ wined3d_get_alpha_fixup_format()

static enum wined3d_format_id wined3d_get_alpha_fixup_format ( enum wined3d_format_id  format_id,
const struct wined3d_format *  dst_format 
)
static

Definition at line 2301 of file texture.c.

2303{
2304 unsigned int i;
2305
2306 if (!(dst_format->attrs & WINED3D_FORMAT_ATTR_COMPRESSED) && !dst_format->alpha_size)
2307 return WINED3DFMT_UNKNOWN;
2308
2309 for (i = 0; i < ARRAY_SIZE(formats_src_alpha_fixup); ++i)
2310 {
2312 return formats_src_alpha_fixup[i].conv_format_id;
2313 }
2314
2315 return WINED3DFMT_UNKNOWN;
2316}
#define ARRAY_SIZE(A)
Definition: main.h:20
static const struct d3dfmt_alpha_fixup formats_src_alpha_fixup[]
static UINT format_id
Definition: clipboard.c:1455
@ WINED3DFMT_UNKNOWN
Definition: wined3d.h:127
#define WINED3D_FORMAT_ATTR_COMPRESSED

Referenced by wined3d_texture_gl_upload_data().

◆ wined3d_gl_texture_swizzle_from_color_fixup()

void wined3d_gl_texture_swizzle_from_color_fixup ( GLint  swizzle[4],
struct color_fixup_desc  fixup 
)

Definition at line 1269 of file texture.c.

1270{
1271 static const GLenum swizzle_source[] =
1272 {
1273 GL_ZERO, /* CHANNEL_SOURCE_ZERO */
1274 GL_ONE, /* CHANNEL_SOURCE_ONE */
1275 GL_RED, /* CHANNEL_SOURCE_X */
1276 GL_GREEN, /* CHANNEL_SOURCE_Y */
1277 GL_BLUE, /* CHANNEL_SOURCE_Z */
1278 GL_ALPHA, /* CHANNEL_SOURCE_W */
1279 };
1280
1281 swizzle[0] = swizzle_source[fixup.x_source];
1282 swizzle[1] = swizzle_source[fixup.y_source];
1283 swizzle[2] = swizzle_source[fixup.z_source];
1284 swizzle[3] = swizzle_source[fixup.w_source];
1285}
#define GL_BLUE
Definition: gl.h:482
#define GL_ZERO
Definition: gl.h:374
#define GL_RED
Definition: gl.h:480
#define GL_ONE
Definition: gl.h:375
#define GL_ALPHA
Definition: gl.h:483
#define GL_GREEN
Definition: gl.h:481
GLuint GLenum swizzle
Definition: glext.h:9511
unsigned short x_source
unsigned short w_source
unsigned short y_source
unsigned short z_source

Referenced by create_texture_view(), and wined3d_texture_gl_bind().

◆ wined3d_layout_from_bind_mask()

enum VkImageLayout wined3d_layout_from_bind_mask ( const struct wined3d_texture_vk *  texture_vk,
const uint32_t  bind_mask 
)

Definition at line 5497 of file texture.c.

5498{
5499 assert(wined3d_popcount(bind_mask) == 1);
5500
5501 /* We want to avoid switching between LAYOUT_GENERAL and other layouts. In Radeon GPUs (and presumably
5502 * others), this will trigger decompressing and recompressing the texture. We also hardcode the layout
5503 * into views when they are created. */
5504 if (texture_vk->layout == VK_IMAGE_LAYOUT_GENERAL)
5506
5507 switch (bind_mask)
5508 {
5511
5514
5517
5518 default:
5519 ERR("Unexpected bind mask %s.\n", wined3d_debug_bind_flags(bind_mask));
5521 }
5522}
const char * wined3d_debug_bind_flags(uint32_t bind_flags)
Definition: utils.c:4845
#define assert(_expr)
Definition: assert.h:32
@ VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL
Definition: vulkan.h:3454
@ VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
Definition: vulkan.h:3456
@ VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
Definition: vulkan.h:3453
static unsigned int wined3d_popcount(unsigned int x)

Referenced by wined3d_texture_vk_barrier().

◆ wined3d_raw_blitter_create()

void wined3d_raw_blitter_create ( struct wined3d_blitter **  next,
const struct wined3d_gl_info *  gl_info 
)

Definition at line 6262 of file texture.c.

6263{
6264 struct wined3d_blitter *blitter;
6265
6266 if (!gl_info->supported[ARB_COPY_IMAGE])
6267 return;
6268
6269 if (!(blitter = malloc(sizeof(*blitter))))
6270 return;
6271
6272 TRACE("Created blitter %p.\n", blitter);
6273
6274 blitter->ops = &raw_blitter_ops;
6275 blitter->next = *next;
6276 *next = blitter;
6277}
static const struct wined3d_blitter_ops raw_blitter_ops
Definition: texture.c:6255
@ ARB_COPY_IMAGE
Definition: wined3d_gl.h:63

Referenced by wined3d_device_gl_create_primary_opengl_context_cs().

◆ wined3d_resource_access_from_location()

static uint32_t wined3d_resource_access_from_location ( uint32_t  location)
static

Definition at line 141 of file texture.c.

142{
143 switch (location)
144 {
146 return 0;
147
150
158
159 default:
160 FIXME("Unhandled location %#x.\n", location);
161 return 0;
162 }
163}

Referenced by wined3d_texture_load_location().

◆ wined3d_texture_acquire_identity_srv()

struct wined3d_shader_resource_view *CDECL wined3d_texture_acquire_identity_srv ( struct wined3d_texture *  texture)

Definition at line 4476 of file texture.c.

4477{
4478 struct wined3d_view_desc desc;
4479 HRESULT hr;
4480
4481 TRACE("texture %p.\n", texture);
4482
4483 if (texture->identity_srv)
4484 return texture->identity_srv;
4485
4486 desc.format_id = texture->resource.format->id;
4487 /* The texture owns a reference to the SRV, so we can't have the SRV hold
4488 * a reference to the texture.
4489 * At the same time, a view must be destroyed before its texture, and we
4490 * need a bound SRV to keep the texture alive even if it doesn't have any
4491 * other references.
4492 * In order to achieve this we have the objects share reference counts.
4493 * This means the view doesn't hold a reference to the resource, but any
4494 * references to the view are forwarded to the resource instead. The view
4495 * is destroyed manually when all references are released. */
4497 desc.u.texture.level_idx = 0;
4498 desc.u.texture.level_count = texture->level_count;
4499 desc.u.texture.layer_idx = 0;
4500 desc.u.texture.layer_count = texture->layer_count;
4502 NULL, &wined3d_null_parent_ops, &texture->identity_srv)))
4503 {
4504 ERR("Failed to create shader resource view, hr %#lx.\n", hr);
4505 return NULL;
4506 }
4508
4509 return texture->identity_srv;
4510}
HRESULT CDECL wined3d_shader_resource_view_create(const struct wined3d_view_desc *desc, struct wined3d_resource *resource, void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_shader_resource_view **view)
Definition: view.c:1261
ULONG CDECL wined3d_shader_resource_view_decref(struct wined3d_shader_resource_view *view)
Definition: view.c:990
#define WINED3D_VIEW_FORWARD_REFERENCE
Definition: wined3d.h:1588

Referenced by d3d9_texture_gen_auto_mipmap(), and wined3d_device_set_texture().

◆ wined3d_texture_add_dirty_region()

HRESULT CDECL wined3d_texture_add_dirty_region ( struct wined3d_texture *  texture,
UINT  layer,
const struct wined3d_box *  dirty_region 
)

Definition at line 2132 of file texture.c.

2134{
2135 TRACE("texture %p, layer %u, dirty_region %s.\n", texture, layer, debug_box(dirty_region));
2136
2137 if (layer >= texture->layer_count)
2138 {
2139 WARN("Invalid layer %u specified.\n", layer);
2141 }
2142
2143 if (dirty_region && FAILED(wined3d_resource_check_box_dimensions(&texture->resource, 0, dirty_region)))
2144 {
2145 WARN("Invalid dirty_region %s specified.\n", debug_box(dirty_region));
2147 }
2148
2151
2152 return WINED3D_OK;
2153}
void wined3d_cs_emit_add_dirty_texture_region(struct wined3d_cs *cs, struct wined3d_texture *texture, unsigned int layer)
Definition: cs.c:2828
GLenum GLuint GLint GLint layer
Definition: glext.h:7007

Referenced by d3d8_texture_2d_AddDirtyRect(), d3d8_texture_3d_AddDirtyBox(), d3d8_texture_cube_AddDirtyRect(), d3d9_texture_2d_AddDirtyRect(), d3d9_texture_3d_AddDirtyBox(), d3d9_texture_cube_AddDirtyRect(), mark_managed_resource_dirty(), and wined3d_device_context_blt().

◆ wined3d_texture_can_use_pbo()

BOOL wined3d_texture_can_use_pbo ( const struct wined3d_texture *  texture,
const struct wined3d_d3d_info *  d3d_info 
)

Definition at line 59 of file texture.c.

60{
61 if (!d3d_info->pbo || texture->resource.format->conv_byte_count || texture->resource.pin_sysmem)
62 return FALSE;
63
64 return TRUE;
65}

Referenced by wined3d_cs_exec_blt_sub_resource(), and wined3d_texture_use_pbo().

◆ wined3d_texture_cleanup()

void wined3d_texture_cleanup ( struct wined3d_texture *  texture)

Definition at line 1593 of file texture.c.

1594{
1596 resource_cleanup(&texture->resource);
1597}
void wined3d_cs_destroy_object(struct wined3d_cs *cs, void(*callback)(void *object), void *object)
Definition: cs.c:2299
void resource_cleanup(struct wined3d_resource *resource)
Definition: resource.c:224
static void wined3d_texture_destroy_object(void *object)
Definition: texture.c:1528

Referenced by adapter_gl_destroy_texture(), adapter_no3d_destroy_texture(), adapter_vk_destroy_texture(), and wined3d_texture_cleanup_sync().

◆ wined3d_texture_cleanup_sync()

static void wined3d_texture_cleanup_sync ( struct wined3d_texture *  texture)
static

Definition at line 1599 of file texture.c.

1600{
1604}
void wined3d_texture_cleanup(struct wined3d_texture *texture)
Definition: texture.c:1593
void wined3d_texture_sub_resources_destroyed(struct wined3d_texture *texture)
Definition: texture.c:1111
static void wined3d_resource_wait_idle(const struct wined3d_resource *resource)

Referenced by wined3d_texture_init().

◆ wined3d_texture_clear_dirty_regions()

void wined3d_texture_clear_dirty_regions ( struct wined3d_texture *  texture)

Definition at line 753 of file texture.c.

754{
755 unsigned int i;
756
757 TRACE("texture %p\n", texture);
758
759 if (!texture->dirty_regions)
760 return;
761
762 for (i = 0; i < texture->layer_count; ++i)
763 {
764 texture->dirty_regions[i].box_count = 0;
765 }
766}

Referenced by wined3d_device_update_texture().

◆ wined3d_texture_create()

HRESULT CDECL wined3d_texture_create ( struct wined3d_device *  device,
const struct wined3d_resource_desc *  desc,
UINT  layer_count,
UINT  level_count,
uint32_t  flags,
const struct wined3d_sub_resource_data *  data,
void *  parent,
const struct wined3d_parent_ops *  parent_ops,
struct wined3d_texture **  texture 
)

Definition at line 4158 of file texture.c.

4161{
4162 unsigned int sub_count = level_count * layer_count;
4163 unsigned int i;
4164 HRESULT hr;
4165
4166 TRACE("device %p, desc %p, layer_count %u, level_count %u, flags %#x, data %p, "
4167 "parent %p, parent_ops %p, texture %p.\n",
4168 device, desc, layer_count, level_count, flags, data, parent, parent_ops, texture);
4169
4170 if (!layer_count)
4171 {
4172 WARN("Invalid layer count.\n");
4173 return E_INVALIDARG;
4174 }
4175 if ((desc->usage & WINED3DUSAGE_LEGACY_CUBEMAP) && layer_count != 6)
4176 {
4177 ERR("Invalid layer count %u for legacy cubemap.\n", layer_count);
4178 layer_count = 6;
4179 }
4180
4181 if (!level_count)
4182 {
4183 WARN("Invalid level count.\n");
4185 }
4186
4187 if (desc->multisample_type != WINED3D_MULTISAMPLE_NONE)
4188 {
4189 const struct wined3d_format *format = wined3d_get_format(device->adapter, desc->format, desc->bind_flags);
4190
4191 if (desc->multisample_type == WINED3D_MULTISAMPLE_NON_MASKABLE
4192 && desc->multisample_quality >= wined3d_popcount(format->multisample_types))
4193 {
4194 WARN("Unsupported quality level %u requested for WINED3D_MULTISAMPLE_NON_MASKABLE.\n",
4195 desc->multisample_quality);
4197 }
4198 if (desc->multisample_type != WINED3D_MULTISAMPLE_NON_MASKABLE
4199 && (!(format->multisample_types & 1u << (desc->multisample_type - 1))
4200 || (desc->multisample_quality && desc->multisample_quality != WINED3D_STANDARD_MULTISAMPLE_PATTERN)))
4201 {
4202 WARN("Unsupported multisample type %u quality %u requested.\n", desc->multisample_type,
4203 desc->multisample_quality);
4205 }
4206 }
4207
4208 if (data)
4209 {
4210 for (i = 0; i < sub_count; ++i)
4211 {
4212 if (data[i].data)
4213 continue;
4214
4215 WARN("Invalid sub-resource data specified for sub-resource %u.\n", i);
4216 return E_INVALIDARG;
4217 }
4218 }
4219
4220 if (FAILED(hr = device->adapter->adapter_ops->adapter_create_texture(device, desc,
4221 layer_count, level_count, flags, parent, parent_ops, texture)))
4222 return hr;
4223
4224 /* FIXME: We'd like to avoid ever allocating system memory for the texture
4225 * in this case. */
4226 if (data)
4227 {
4228 struct wined3d_box box;
4229
4230 for (i = 0; i < sub_count; ++i)
4231 {
4232 wined3d_texture_get_level_box(*texture, i % (*texture)->level_count, &box);
4233 wined3d_device_context_emit_update_sub_resource(&device->cs->c, &(*texture)->resource,
4234 i, &box, data[i].data, data[i].row_pitch, data[i].slice_pitch);
4235 }
4236 }
4237
4238 TRACE("Created texture %p.\n", *texture);
4239
4240 return WINED3D_OK;
4241}
void wined3d_device_context_emit_update_sub_resource(struct wined3d_device_context *context, struct wined3d_resource *resource, unsigned int sub_resource_idx, const struct wined3d_box *box, const void *data, unsigned int row_pitch, unsigned int slice_pitch)
Definition: cs.c:2766
const struct wined3d_format * wined3d_get_format(const struct wined3d_adapter *adapter, enum wined3d_format_id format_id, unsigned int bind_flags)
Definition: utils.c:4428
r parent
Definition: btrfs.c:3010
#define WINED3D_STANDARD_MULTISAMPLE_PATTERN
Definition: wined3d.h:1569
@ WINED3D_MULTISAMPLE_NON_MASKABLE
Definition: wined3d.h:574
@ WINED3D_MULTISAMPLE_NONE
Definition: wined3d.h:573
#define WINED3DUSAGE_LEGACY_CUBEMAP
Definition: wined3d.h:934
#define WINED3DERR_NOTAVAILABLE
Definition: wined3d.h:42
static void wined3d_texture_get_level_box(const struct wined3d_texture *texture, unsigned int level, struct wined3d_box *box)

Referenced by d3d8_device_create_surface(), d3d8_texture_init(), d3d9_device_create_surface(), d3d9_texture_init(), d3d_texture1d_create(), d3d_texture2d_create(), d3d_texture3d_init(), ddraw_surface7_SetSurfaceDesc(), ddraw_texture_init(), device_load_logo(), dxgi_device_CreateSurface(), glsl_blitter_blit(), surface_convert_format(), swapchain_create_texture(), texture2d_blt_fbo(), wined3d_device_create_cursor_texture(), and wined3d_device_reset().

◆ wined3d_texture_create_dc()

static void wined3d_texture_create_dc ( void *  object)
static

Definition at line 1129 of file texture.c.

1130{
1131 const struct wined3d_texture_idx *idx = object;
1132 struct wined3d_context *context = NULL;
1133 unsigned int sub_resource_idx, level;
1134 const struct wined3d_format *format;
1135 unsigned int row_pitch, slice_pitch;
1136 struct wined3d_texture *texture;
1137 struct wined3d_dc_info *dc_info;
1138 struct wined3d_bo_address data;
1140 struct wined3d_device *device;
1142
1143 TRACE("texture %p, sub_resource_idx %u.\n", idx->texture, idx->sub_resource_idx);
1144
1145 texture = idx->texture;
1146 sub_resource_idx = idx->sub_resource_idx;
1147 level = sub_resource_idx % texture->level_count;
1148 device = texture->resource.device;
1149
1150 format = texture->resource.format;
1151 if (!format->ddi_format)
1152 {
1153 WARN("Cannot create a DC for format %s.\n", debug_d3dformat(format->id));
1154 return;
1155 }
1156
1157 if (!texture->dc_info)
1158 {
1159 unsigned int sub_count = texture->level_count * texture->layer_count;
1160
1161 if (!(texture->dc_info = calloc(sub_count, sizeof(*texture->dc_info))))
1162 {
1163 ERR("Failed to allocate DC info.\n");
1164 return;
1165 }
1166 }
1167
1168 if (!(texture->sub_resources[sub_resource_idx].locations & texture->resource.map_binding))
1169 {
1171 wined3d_texture_load_location(texture, sub_resource_idx, context, texture->resource.map_binding);
1172 }
1173
1174 if (texture->dirty_regions)
1175 wined3d_texture_dirty_region_add(texture, sub_resource_idx / texture->level_count, NULL);
1176
1177 wined3d_texture_invalidate_location(texture, sub_resource_idx, ~texture->resource.map_binding);
1178 wined3d_texture_get_pitch(texture, level, &row_pitch, &slice_pitch);
1179 wined3d_texture_get_bo_address(texture, sub_resource_idx, &data, texture->resource.map_binding);
1180 if (data.buffer_object)
1181 {
1182 if (!context)
1185 texture->sub_resources[sub_resource_idx].size, WINED3D_MAP_READ | WINED3D_MAP_WRITE);
1186 }
1187 else
1188 {
1189 desc.pMemory = data.addr;
1190 }
1191
1192 if (context)
1194
1195 desc.Format = format->ddi_format;
1198 desc.Pitch = row_pitch;
1199 desc.hDeviceDc = CreateCompatibleDC(NULL);
1200 desc.pColorTable = NULL;
1201
1203 DeleteDC(desc.hDeviceDc);
1204 if (status)
1205 {
1206 WARN("Failed to create DC, status %#lx.\n", status);
1207 return;
1208 }
1209
1210 dc_info = &texture->dc_info[sub_resource_idx];
1211 dc_info->dc = desc.hDc;
1212 dc_info->bitmap = desc.hBitmap;
1213
1214 TRACE("Created DC %p, bitmap %p for texture %p, %u.\n", dc_info->dc, dc_info->bitmap, texture, sub_resource_idx);
1215}
LONG NTSTATUS
Definition: precomp.h:26
unsigned int idx
Definition: utils.c:40
#define calloc
Definition: rosglue.h:14
Definition: ps.c:97
unsigned int sub_resource_idx
NTSTATUS WINAPI D3DKMTCreateDCFromMemory(D3DKMT_CREATEDCFROMMEMORY *desc)
#define WINED3D_MAP_READ
Definition: wined3d.h:957
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
BOOL WINAPI DeleteDC(_In_ HDC)

Referenced by wined3d_texture_get_dc(), wined3d_texture_init(), and wined3d_texture_update_desc().

◆ wined3d_texture_decref()

ULONG CDECL wined3d_texture_decref ( struct wined3d_texture *  texture)

Definition at line 1606 of file texture.c.

1607{
1608 unsigned int i, sub_resource_count, refcount;
1609
1610 TRACE("texture %p, swapchain %p.\n", texture, texture->swapchain);
1611
1612 refcount = InterlockedDecrement(&texture->resource.ref);
1613 TRACE("%p decreasing refcount to %u.\n", texture, refcount);
1614
1615 if (!refcount)
1616 {
1617 bool in_cs_thread = GetCurrentThreadId() == texture->resource.device->cs->thread_id;
1618
1619 if (texture->identity_srv)
1620 {
1621 assert(!in_cs_thread);
1623 }
1624
1625 /* This is called from the CS thread to destroy temporary textures. */
1626 if (!in_cs_thread)
1628 /* Wait for the texture to become idle if it's using user memory,
1629 * since the application is allowed to free that memory once the
1630 * texture is destroyed. Note that this implies that
1631 * the destroy handler can't access that memory either. */
1632 sub_resource_count = texture->layer_count * texture->level_count;
1633 for (i = 0; i < sub_resource_count; ++i)
1634 {
1635 if (texture->sub_resources[i].user_memory)
1636 {
1638 break;
1639 }
1640 }
1641 texture->resource.device->adapter->adapter_ops->adapter_destroy_texture(texture);
1642 if (!in_cs_thread)
1644 }
1645
1646 return refcount;
1647}
#define InterlockedDecrement
Definition: armddk.h:52
void wined3d_shader_resource_view_destroy(struct wined3d_shader_resource_view *view)
Definition: view.c:983
DWORD WINAPI GetCurrentThreadId(void)
Definition: thread.c:459
void WINAPI wined3d_mutex_unlock(void)
Definition: wined3d_main.c:544
void WINAPI wined3d_mutex_lock(void)
Definition: wined3d_main.c:539

Referenced by d3d11_texture1d_Release(), d3d11_texture2d_Release(), d3d11_texture3d_Release(), d3d8_device_create_surface(), d3d8_surface_Release(), d3d8_texture_decref(), d3d8_texture_init(), d3d8_texture_wined3d_object_destroyed(), d3d9_device_create_surface(), d3d9_surface_Release(), d3d9_texture_decref(), d3d9_texture_init(), d3d9_texture_wined3d_object_destroyed(), d3d_texture1d_create(), d3d_texture2d_create(), d3d_texture3d_init(), ddraw_surface7_SetSurfaceDesc(), ddraw_surface_cleanup(), ddraw_surface_wined3d_object_destroyed(), ddraw_texture_init(), device_load_logo(), dxgi_device_CreateSurface(), glsl_blitter_blit(), surface_cpu_blt(), texture2d_blt_fbo(), texture_resource_decref(), wined3d_cs_packet_decref_objects(), wined3d_device_reset(), wined3d_device_set_cursor_properties(), wined3d_device_uninit_3d(), wined3d_stateblock_capture(), wined3d_stateblock_set_texture(), wined3d_stateblock_state_cleanup(), wined3d_swapchain_cleanup(), wined3d_swapchain_init(), and wined3d_swapchain_resize_buffers().

◆ wined3d_texture_destroy_dc()

static void wined3d_texture_destroy_dc ( void *  object)
static

Definition at line 1217 of file texture.c.

1218{
1219 const struct wined3d_texture_idx *idx = object;
1220 D3DKMT_DESTROYDCFROMMEMORY destroy_desc;
1221 struct wined3d_context *context;
1222 struct wined3d_texture *texture;
1223 struct wined3d_dc_info *dc_info;
1224 struct wined3d_bo_address data;
1225 unsigned int sub_resource_idx;
1226 struct wined3d_device *device;
1227 struct wined3d_range range;
1229
1230 TRACE("texture %p, sub_resource_idx %u.\n", idx->texture, idx->sub_resource_idx);
1231
1232 texture = idx->texture;
1233 sub_resource_idx = idx->sub_resource_idx;
1234 device = texture->resource.device;
1235 dc_info = &texture->dc_info[sub_resource_idx];
1236
1237 if (!dc_info->dc)
1238 {
1239 ERR("Sub-resource {%p, %u} has no DC.\n", texture, sub_resource_idx);
1240 return;
1241 }
1242
1243 TRACE("dc %p, bitmap %p.\n", dc_info->dc, dc_info->bitmap);
1244
1245 destroy_desc.hDc = dc_info->dc;
1246 destroy_desc.hBitmap = dc_info->bitmap;
1247 if ((status = D3DKMTDestroyDCFromMemory(&destroy_desc)))
1248 ERR("Failed to destroy dc, status %#lx.\n", status);
1249 dc_info->dc = NULL;
1250 dc_info->bitmap = NULL;
1251
1252 wined3d_texture_get_bo_address(texture, sub_resource_idx, &data, texture->resource.map_binding);
1253 if (data.buffer_object)
1254 {
1256 range.offset = 0;
1257 range.size = texture->sub_resources[sub_resource_idx].size;
1260 }
1261}
NTSTATUS WINAPI D3DKMTDestroyDCFromMemory(const D3DKMT_DESTROYDCFROMMEMORY *desc)

Referenced by wined3d_texture_destroy_object(), wined3d_texture_release_dc(), and wined3d_texture_update_desc().

◆ wined3d_texture_destroy_object()

static void wined3d_texture_destroy_object ( void *  object)
static

Definition at line 1528 of file texture.c.

1529{
1530 struct wined3d_texture *texture = object;
1531 struct wined3d_resource *resource;
1532 struct wined3d_dc_info *dc_info;
1533 unsigned int sub_count;
1534 unsigned int i;
1535
1536 TRACE("texture %p.\n", texture);
1537
1538 resource = &texture->resource;
1539 sub_count = texture->level_count * texture->layer_count;
1540
1541 if ((dc_info = texture->dc_info))
1542 {
1543 for (i = 0; i < sub_count; ++i)
1544 {
1545 if (dc_info[i].dc)
1546 {
1547 struct wined3d_texture_idx texture_idx = {texture, i};
1548
1549 wined3d_texture_destroy_dc(&texture_idx);
1550 }
1551 }
1552 free(dc_info);
1553 }
1554
1555 if (texture->overlay_info)
1556 {
1557 for (i = 0; i < sub_count; ++i)
1558 {
1559 struct wined3d_overlay_info *info = &texture->overlay_info[i];
1560 struct wined3d_overlay_info *overlay, *cur;
1561
1562 list_remove(&info->entry);
1563 LIST_FOR_EACH_ENTRY_SAFE(overlay, cur, &info->overlays, struct wined3d_overlay_info, entry)
1564 {
1565 list_remove(&overlay->entry);
1566 }
1567 }
1568 free(texture->overlay_info);
1569 }
1570
1571 if (texture->dirty_regions)
1572 {
1573 for (i = 0; i < texture->layer_count; ++i)
1574 {
1575 free(texture->dirty_regions[i].boxes);
1576 }
1577 free(texture->dirty_regions);
1578 }
1579
1580 /* Discard the contents of resources with CPU access, to avoid downloading
1581 * them to SYSMEM on unload. */
1583 {
1584 for (i = 0; i < sub_count; ++i)
1585 {
1588 }
1589 }
1590 resource->resource_ops->resource_unload(resource);
1591}
static void list_remove(struct list_entry *entry)
Definition: list.h:90
HDC dc
Definition: cylfrac.c:34
static void wined3d_texture_destroy_dc(void *object)
Definition: texture.c:1217
FxCollectionEntry * cur
uint32_t entry
Definition: isohybrid.c:63
#define LIST_FOR_EACH_ENTRY_SAFE(cursor, cursor2, list, type, field)
Definition: list.h:242

Referenced by wined3d_texture_cleanup().

◆ wined3d_texture_dirty_region_add()

static void wined3d_texture_dirty_region_add ( struct wined3d_texture *  texture,
unsigned int  layer,
const struct wined3d_box *  box 
)
static

Definition at line 1080 of file texture.c.

1082{
1083 struct wined3d_dirty_regions *regions;
1084 unsigned int count;
1085
1086 if (!texture->dirty_regions)
1087 return;
1088
1089 regions = &texture->dirty_regions[layer];
1090 count = regions->box_count + 1;
1092 || (!box->left && !box->top && !box->front
1093 && box->right == texture->resource.width
1094 && box->bottom == texture->resource.height
1095 && box->back == texture->resource.depth))
1096 {
1097 regions->box_count = WINED3D_MAX_DIRTY_REGION_COUNT;
1098 return;
1099 }
1100
1101 if (!wined3d_array_reserve((void **)&regions->boxes, &regions->boxes_size, count, sizeof(*regions->boxes)))
1102 {
1103 ERR("Failed to grow boxes array, marking entire texture dirty.\n");
1104 regions->box_count = WINED3D_MAX_DIRTY_REGION_COUNT;
1105 return;
1106 }
1107
1108 regions->boxes[regions->box_count++] = *box;
1109}
BOOL wined3d_array_reserve(void **elements, SIZE_T *capacity, SIZE_T count, SIZE_T size)
Definition: utils.c:6740
GLuint GLuint GLsizei count
Definition: gl.h:1545
#define WINED3D_MAX_DIRTY_REGION_COUNT

Referenced by texture_resource_sub_resource_map(), wined3d_texture_add_dirty_region(), wined3d_texture_create_dc(), and wined3d_texture_init().

◆ wined3d_texture_download_from_texture()

void wined3d_texture_download_from_texture ( struct wined3d_texture *  dst_texture,
unsigned int  dst_sub_resource_idx,
struct wined3d_texture *  src_texture,
unsigned int  src_sub_resource_idx 
)

Definition at line 4381 of file texture.c.

4383{
4384 unsigned int src_level, dst_level, dst_row_pitch, dst_slice_pitch;
4385 unsigned int dst_location = dst_texture->resource.map_binding;
4386 struct wined3d_context *context;
4387 struct wined3d_bo_address data;
4388 struct wined3d_box src_box;
4389 unsigned int src_location;
4390
4391 context = context_acquire(src_texture->resource.device, NULL, 0);
4392
4393 wined3d_texture_prepare_location(dst_texture, dst_sub_resource_idx, context, dst_location);
4394 wined3d_texture_get_bo_address(dst_texture, dst_sub_resource_idx, &data, dst_location);
4395
4396 if (src_texture->sub_resources[src_sub_resource_idx].locations & WINED3D_LOCATION_TEXTURE_RGB)
4397 src_location = WINED3D_LOCATION_TEXTURE_RGB;
4398 else
4399 src_location = WINED3D_LOCATION_TEXTURE_SRGB;
4400 src_level = src_sub_resource_idx % src_texture->level_count;
4401 wined3d_texture_get_level_box(src_texture, src_level, &src_box);
4402
4403 dst_level = dst_sub_resource_idx % dst_texture->level_count;
4404 wined3d_texture_get_pitch(dst_texture, dst_level, &dst_row_pitch, &dst_slice_pitch);
4405
4406 src_texture->texture_ops->texture_download_data(context, src_texture, src_sub_resource_idx, src_location,
4407 &src_box, &data, dst_texture->resource.format, 0, 0, 0, dst_row_pitch, dst_slice_pitch);
4408
4410
4411 wined3d_texture_validate_location(dst_texture, dst_sub_resource_idx, dst_location);
4412 wined3d_texture_invalidate_location(dst_texture, dst_sub_resource_idx, ~dst_location);
4413}
const struct wined3d_texture_ops * texture_ops

Referenced by texture2d_blt().

◆ wined3d_texture_evict_sysmem()

static void wined3d_texture_evict_sysmem ( struct wined3d_texture *  texture)
static

Definition at line 651 of file texture.c.

652{
653 struct wined3d_texture_sub_resource *sub_resource;
654 unsigned int i, sub_count;
655
657 || texture->resource.pin_sysmem
659 {
660 TRACE("Not evicting system memory for texture %p.\n", texture);
661 return;
662 }
663
664 TRACE("Evicting system memory for texture %p.\n", texture);
665
666 sub_count = texture->level_count * texture->layer_count;
667 for (i = 0; i < sub_count; ++i)
668 {
669 sub_resource = &texture->sub_resources[i];
670 if (sub_resource->locations == WINED3D_LOCATION_SYSMEM)
671 ERR("WINED3D_LOCATION_SYSMEM is the only location for sub-resource %u of texture %p.\n",
672 i, texture);
673 sub_resource->locations &= ~WINED3D_LOCATION_SYSMEM;
674 }
676}
void wined3d_resource_free_sysmem(struct wined3d_resource *resource)
Definition: resource.c:345
#define WINED3D_TEXTURE_DYNAMIC_MAP_THRESHOLD
Definition: texture.c:31

Referenced by wined3d_texture_validate_location().

◆ wined3d_texture_force_reload()

static void wined3d_texture_force_reload ( struct wined3d_texture *  texture)
static

Definition at line 2013 of file texture.c.

2014{
2015 unsigned int sub_count = texture->level_count * texture->layer_count;
2016 unsigned int i;
2017
2020 texture->async.flags &= ~WINED3D_TEXTURE_ASYNC_COLOR_KEY;
2021 for (i = 0; i < sub_count; ++i)
2022 {
2025 }
2026}
#define WINED3D_TEXTURE_RGB_ALLOCATED
#define WINED3D_TEXTURE_SRGB_ALLOCATED

Referenced by texture_resource_unload().

◆ wined3d_texture_from_resource()

◆ wined3d_texture_get_bo_address()

void wined3d_texture_get_bo_address ( const struct wined3d_texture *  texture,
unsigned int  sub_resource_idx,
struct wined3d_bo_address *  data,
uint32_t  location 
)

Definition at line 727 of file texture.c.

729{
730 struct wined3d_texture_sub_resource *sub_resource = &texture->sub_resources[sub_resource_idx];
731
733 {
734 data->addr = NULL;
735 data->buffer_object = sub_resource->bo;
736 }
737 else
738 {
740 if (sub_resource->user_memory)
741 {
742 data->addr = sub_resource->user_memory;
743 }
744 else
745 {
746 data->addr = texture->resource.heap_memory;
747 data->addr += sub_resource->offset;
748 }
749 data->buffer_object = 0;
750 }
751}

Referenced by cpu_blitter_clear_texture(), surface_convert_format(), surface_cpu_blt(), texture2d_read_from_framebuffer(), texture_resource_sub_resource_map(), texture_resource_sub_resource_unmap(), wined3d_cs_exec_blt_sub_resource(), wined3d_texture_create_dc(), wined3d_texture_destroy_dc(), wined3d_texture_download_from_texture(), wined3d_texture_get_memory(), wined3d_texture_gl_clear(), wined3d_texture_gl_load_sysmem(), wined3d_texture_load_location(), wined3d_texture_vk_clear(), and wined3d_texture_vk_load_sysmem().

◆ wined3d_texture_get_dc()

HRESULT CDECL wined3d_texture_get_dc ( struct wined3d_texture *  texture,
unsigned int  sub_resource_idx,
HDC *  dc 
)

Definition at line 4243 of file texture.c.

4244{
4245 struct wined3d_device *device = texture->resource.device;
4246 struct wined3d_texture_sub_resource *sub_resource;
4247 struct wined3d_dc_info *dc_info;
4248
4249 TRACE("texture %p, sub_resource_idx %u, dc %p.\n", texture, sub_resource_idx, dc);
4250
4251 if (!(texture->flags & WINED3D_TEXTURE_GET_DC))
4252 {
4253 WARN("Texture does not support GetDC\n");
4254 /* Don't touch the DC */
4256 }
4257
4258 if (!(sub_resource = wined3d_texture_get_sub_resource(texture, sub_resource_idx)))
4260
4261 if (texture->resource.type != WINED3D_RTYPE_TEXTURE_2D)
4262 {
4263 WARN("Not supported on %s resources.\n", debug_d3dresourcetype(texture->resource.type));
4265 }
4266
4267 if (texture->resource.map_count && !(texture->flags & WINED3D_TEXTURE_GET_DC_LENIENT))
4269
4270 if (!(dc_info = texture->dc_info) || !dc_info[sub_resource_idx].dc)
4271 {
4272 struct wined3d_texture_idx texture_idx = {texture, sub_resource_idx};
4273
4276 if (!(dc_info = texture->dc_info) || !dc_info[sub_resource_idx].dc)
4278 }
4279
4282 ++texture->resource.map_count;
4283 ++sub_resource->map_count;
4284
4285 *dc = dc_info[sub_resource_idx].dc;
4286 TRACE("Returning dc %p.\n", *dc);
4287
4288 return WINED3D_OK;
4289}
void wined3d_cs_init_object(struct wined3d_cs *cs, void(*callback)(void *object), void *object)
Definition: cs.c:2304
static void wined3d_texture_create_dc(void *object)
Definition: texture.c:1129
unsigned int sub_resource_idx
Definition: texture.c:39
#define WINED3D_TEXTURE_GET_DC_LENIENT
static void wined3d_cs_finish(struct wined3d_cs *cs, enum wined3d_cs_queue_id queue_id)
#define WINED3D_TEXTURE_GET_DC
@ WINED3D_CS_QUEUE_DEFAULT

Referenced by d3d9_surface_GetDC(), ddraw_surface7_GetDC(), ddraw_surface_update_frontbuffer(), device_load_logo(), and dxgi_surface_GetDC().

◆ wined3d_texture_get_gl_buffer()

GLenum wined3d_texture_get_gl_buffer ( const struct wined3d_texture *  texture)

Definition at line 113 of file texture.c.

114{
115 const struct wined3d_swapchain *swapchain = texture->swapchain;
116
117 TRACE("texture %p.\n", texture);
118
119 if (!swapchain)
120 {
121 ERR("Texture %p is not part of a swapchain.\n", texture);
122 return GL_NONE;
123 }
124
125 if (texture == swapchain->front_buffer)
126 {
127 TRACE("Returning GL_FRONT.\n");
128 return GL_FRONT;
129 }
130
131 if (texture == swapchain->back_buffers[0])
132 {
133 TRACE("Returning GL_BACK.\n");
134 return GL_BACK;
135 }
136
137 FIXME("Higher back buffer, returning GL_BACK.\n");
138 return GL_BACK;
139}
#define GL_NONE
Definition: gl.h:465
#define GL_BACK
Definition: gl.h:271
#define GL_FRONT
Definition: gl.h:270
struct wined3d_texture ** back_buffers
struct wined3d_texture * front_buffer

Referenced by context_generate_rt_mask_from_resource(), texture2d_blt_fbo(), and texture2d_read_from_framebuffer().

◆ wined3d_texture_get_level_count()

◆ wined3d_texture_get_lod()

unsigned int CDECL wined3d_texture_get_lod ( const struct wined3d_texture *  texture)

Definition at line 1715 of file texture.c.

1716{
1717 TRACE("texture %p, returning %u.\n", texture, texture->lod);
1718
1719 return texture->lod;
1720}

Referenced by d3d8_texture_2d_GetLOD(), d3d8_texture_3d_GetLOD(), d3d8_texture_cube_GetLOD(), d3d9_texture_2d_GetLOD(), d3d9_texture_3d_GetLOD(), d3d9_texture_cube_GetLOD(), and ddraw_surface7_GetLOD().

◆ wined3d_texture_get_memory()

static void wined3d_texture_get_memory ( struct wined3d_texture *  texture,
unsigned int  sub_resource_idx,
struct wined3d_context *  context,
struct wined3d_bo_address *  data 
)
static

Definition at line 876 of file texture.c.

878{
879 struct wined3d_texture_sub_resource *sub_resource = &texture->sub_resources[sub_resource_idx];
880 DWORD locations = sub_resource->locations;
881
882 TRACE("texture %p, context %p, sub_resource_idx %u, data %p, locations %s.\n",
883 texture, context, sub_resource_idx, data, wined3d_debug_location(locations));
884
886 {
888 if (!wined3d_texture_load_location(texture, sub_resource_idx, context, locations))
889 {
890 data->buffer_object = 0;
891 data->addr = NULL;
892 return;
893 }
894 }
896 {
898 return;
899 }
900
902 {
904 return;
905 }
906
907 ERR("Unexpected locations %s.\n", wined3d_debug_location(locations));
908 data->addr = NULL;
909 data->buffer_object = 0;
910}
static BOOL wined3d_texture_use_pbo(const struct wined3d_texture *texture, const struct wined3d_d3d_info *d3d_info)
Definition: texture.c:67

Referenced by wined3d_texture_gl_load_texture(), wined3d_texture_upload_from_texture(), and wined3d_texture_vk_load_texture().

◆ wined3d_texture_get_overlay_position()

HRESULT CDECL wined3d_texture_get_overlay_position ( const struct wined3d_texture *  texture,
unsigned int  sub_resource_idx,
LONG *  x,
LONG *  y 
)

Definition at line 3915 of file texture.c.

3917{
3918 struct wined3d_overlay_info *overlay;
3919
3920 TRACE("texture %p, sub_resource_idx %u, x %p, y %p.\n", texture, sub_resource_idx, x, y);
3921
3922 if (!(texture->resource.usage & WINED3DUSAGE_OVERLAY)
3925
3926 overlay = &texture->overlay_info[sub_resource_idx];
3927 if (!overlay->dst_texture)
3928 {
3929 TRACE("Overlay not visible.\n");
3930 *x = 0;
3931 *y = 0;
3933 }
3934
3935 *x = overlay->dst_rect.left;
3936 *y = overlay->dst_rect.top;
3937
3938 TRACE("Returning position %ld, %ld.\n", *x, *y);
3939
3940 return WINED3D_OK;
3941}
#define WINEDDERR_OVERLAYNOTVISIBLE
Definition: wined3d.h:49
#define WINED3DUSAGE_OVERLAY
Definition: wined3d.h:937
#define WINEDDERR_NOTAOVERLAYSURFACE
Definition: wined3d.h:45

Referenced by ddraw_surface7_GetOverlayPosition().

◆ wined3d_texture_get_parent()

◆ wined3d_texture_get_pitch()

void CDECL wined3d_texture_get_pitch ( const struct wined3d_texture *  texture,
unsigned int  level,
unsigned int *  row_pitch,
unsigned int *  slice_pitch 
)

Definition at line 1697 of file texture.c.

1699{
1700 const struct wined3d_resource *resource = &texture->resource;
1703
1704 if (texture->row_pitch)
1705 {
1706 *row_pitch = texture->row_pitch;
1707 *slice_pitch = texture->slice_pitch;
1708 return;
1709 }
1710
1711 wined3d_format_calculate_pitch(resource->format, resource->device->surface_alignment,
1712 width, height, row_pitch, slice_pitch);
1713}
void wined3d_format_calculate_pitch(const struct wined3d_format *format, unsigned int alignment, unsigned int width, unsigned int height, unsigned int *row_pitch, unsigned int *slice_pitch)
Definition: utils.c:4489

Referenced by cpu_blitter_clear_texture(), ddraw_surface_reserve_memory(), ddraw_texture_init(), surface_convert_format(), surface_cpu_blt(), swapchain_blit_gdi(), texture2d_read_from_framebuffer(), texture_resource_sub_resource_get_map_pitch(), wined3d_cs_exec_blt_sub_resource(), wined3d_texture_create_dc(), wined3d_texture_download_from_texture(), wined3d_texture_gl_download_data(), wined3d_texture_gl_download_data_slow_path(), wined3d_texture_gl_load_sysmem(), wined3d_texture_gl_load_texture(), wined3d_texture_load_location(), wined3d_texture_update_desc(), wined3d_texture_upload_from_texture(), wined3d_texture_vk_download_data(), wined3d_texture_vk_load_sysmem(), wined3d_texture_vk_load_texture(), and wined3d_texture_vk_upload_data().

◆ wined3d_texture_get_resource()

struct wined3d_resource *CDECL wined3d_texture_get_resource ( struct wined3d_texture *  texture)

Definition at line 1649 of file texture.c.

1650{
1651 TRACE("texture %p.\n", texture);
1652
1653 return &texture->resource;
1654}

Referenced by d3d10_texture1d_Map(), d3d10_texture1d_Unmap(), d3d10_texture2d_Map(), d3d10_texture2d_Unmap(), d3d10_texture3d_Map(), d3d10_texture3d_Unmap(), d3d11_texture2d_GetDesc(), d3d8_surface_LockRect(), d3d8_surface_UnlockRect(), d3d8_texture_2d_GetPriority(), d3d8_texture_2d_SetPriority(), d3d8_texture_3d_GetPriority(), d3d8_texture_3d_SetPriority(), d3d8_texture_cube_GetPriority(), d3d8_texture_cube_SetPriority(), d3d8_texture_preload(), d3d8_volume_LockBox(), d3d8_volume_UnlockBox(), d3d9_device_UpdateSurface(), d3d9_surface_LockRect(), d3d9_surface_PreLoad(), d3d9_surface_UnlockRect(), d3d9_texture_2d_GetPriority(), d3d9_texture_2d_SetPriority(), d3d9_texture_3d_GetPriority(), d3d9_texture_3d_SetPriority(), d3d9_texture_cube_GetPriority(), d3d9_texture_cube_SetPriority(), d3d9_texture_preload(), d3d9_volume_LockBox(), d3d9_volume_UnlockBox(), d3d_device7_PreLoad(), d3d_texture1d_create(), d3d_texture2_Load(), d3d_texture2d_create(), d3d_texture3d_init(), ddraw_surface1_Unlock(), ddraw_surface7_GetPriority(), ddraw_surface7_SetPriority(), ddraw_surface7_SetSurfaceDesc(), ddraw_surface_get_default_texture(), ddraw_surface_get_draw_texture(), ddraw_surface_reserve_memory(), ddraw_texture_init(), ddraw_texture_rename_to(), dxgi_device_parent_register_swapchain_texture(), fixup_texture_alpha_op(), resolve_depth_buffer(), surface_lock(), wined3d_resource_from_d3d10_resource(), and wined3d_resource_from_d3d11_resource().

◆ wined3d_texture_get_sub_resource()

static struct wined3d_texture_sub_resource * wined3d_texture_get_sub_resource ( struct wined3d_texture *  texture,
unsigned int  sub_resource_idx 
)
static

Definition at line 2122 of file texture.c.

2124{
2125 TRACE("texture %p, sub_resource_idx %u.\n", texture, sub_resource_idx);
2126
2127 if (!wined3d_texture_validate_sub_resource_idx(texture, sub_resource_idx))
2128 return NULL;
2129 return &texture->sub_resources[sub_resource_idx];
2130}

Referenced by texture_resource_sub_resource_map(), texture_resource_sub_resource_unmap(), wined3d_texture_get_dc(), and wined3d_texture_release_dc().

◆ wined3d_texture_get_sub_resource_desc()

HRESULT CDECL wined3d_texture_get_sub_resource_desc ( const struct wined3d_texture *  texture,
unsigned int  sub_resource_idx,
struct wined3d_sub_resource_desc *  desc 
)

Definition at line 4055 of file texture.c.

4057{
4058 const struct wined3d_resource *resource;
4059 unsigned int level_idx;
4060
4061 TRACE("texture %p, sub_resource_idx %u, desc %p.\n", texture, sub_resource_idx, desc);
4062
4063 if (!wined3d_texture_validate_sub_resource_idx(texture, sub_resource_idx))
4065
4066 resource = &texture->resource;
4067 desc->format = resource->format->id;
4068 desc->multisample_type = resource->multisample_type;
4069 desc->multisample_quality = resource->multisample_quality;
4070 desc->usage = resource->usage;
4071 desc->bind_flags = resource->bind_flags;
4072 desc->access = resource->access;
4073
4074 level_idx = sub_resource_idx % texture->level_count;
4075 desc->width = wined3d_texture_get_level_width(texture, level_idx);
4076 desc->height = wined3d_texture_get_level_height(texture, level_idx);
4077 desc->depth = wined3d_texture_get_level_depth(texture, level_idx);
4078 desc->size = texture->sub_resources[sub_resource_idx].size;
4079
4080 return WINED3D_OK;
4081}
static unsigned int wined3d_texture_get_level_depth(const struct wined3d_texture *texture, unsigned int level)

Referenced by d3d8_device_CopyRects(), d3d8_device_SetRenderTarget(), d3d8_device_SetViewport(), d3d8_surface_GetDesc(), d3d8_texture_2d_GetLevelDesc(), d3d8_texture_3d_GetLevelDesc(), d3d8_texture_cube_GetLevelDesc(), d3d8_volume_GetDesc(), d3d9_device_ColorFill(), d3d9_device_GetRenderTargetData(), d3d9_device_StretchRect(), d3d9_device_UpdateSurface(), d3d9_surface_GetDesc(), d3d9_texture_2d_GetLevelDesc(), d3d9_texture_3d_GetLevelDesc(), d3d9_texture_cube_GetLevelDesc(), d3d9_volume_GetDesc(), d3d_device7_SetViewport(), d3d_viewport_SetViewport(), d3d_viewport_SetViewport2(), ddraw_surface7_Restore(), ddraw_surface_reserve_memory(), ddraw_texture_init(), and texture_resource_sub_resource_get_desc().

◆ wined3d_texture_get_sub_resource_parent()

◆ wined3d_texture_get_swapchain()

struct wined3d_swapchain *CDECL wined3d_texture_get_swapchain ( struct wined3d_texture *  texture)

Definition at line 4028 of file texture.c.

4029{
4030 return texture->swapchain;
4031}

Referenced by d3d8_surface_create(), d3d9_surface_create(), d3d_texture2d_create(), and dxgi_resource_GetUsage().

◆ wined3d_texture_gl_allocate_immutable_storage()

static void wined3d_texture_gl_allocate_immutable_storage ( struct wined3d_texture_gl *  texture_gl,
GLenum  gl_internal_format,
const struct wined3d_gl_info *  gl_info 
)
static

Definition at line 1037 of file texture.c.

1039{
1040 unsigned int samples = wined3d_resource_get_sample_count(&texture_gl->t.resource);
1041 GLboolean standard_pattern = texture_gl->t.resource.multisample_type != WINED3D_MULTISAMPLE_NON_MASKABLE
1042 && texture_gl->t.resource.multisample_quality == WINED3D_STANDARD_MULTISAMPLE_PATTERN;
1045
1046 switch (texture_gl->target)
1047 {
1048 case GL_TEXTURE_3D:
1049 GL_EXTCALL(glTexStorage3D(texture_gl->target, texture_gl->t.level_count,
1050 gl_internal_format, width, height, wined3d_texture_get_level_depth(&texture_gl->t, 0)));
1051 break;
1053 GL_EXTCALL(glTexStorage3D(texture_gl->target, texture_gl->t.level_count,
1054 gl_internal_format, width, height, texture_gl->t.layer_count));
1055 break;
1057 GL_EXTCALL(glTexStorage2DMultisample(texture_gl->target, samples,
1058 gl_internal_format, width, height, standard_pattern));
1059 break;
1061 GL_EXTCALL(glTexStorage3DMultisample(texture_gl->target, samples,
1062 gl_internal_format, width, height, texture_gl->t.layer_count, standard_pattern));
1063 break;
1065 GL_EXTCALL(glTexStorage2D(texture_gl->target, texture_gl->t.level_count,
1066 gl_internal_format, width, texture_gl->t.layer_count));
1067 break;
1068 case GL_TEXTURE_1D:
1069 GL_EXTCALL(glTexStorage1D(texture_gl->target, texture_gl->t.level_count, gl_internal_format, width));
1070 break;
1071 default:
1072 GL_EXTCALL(glTexStorage2D(texture_gl->target, texture_gl->t.level_count,
1073 gl_internal_format, width, height));
1074 break;
1075 }
1076
1077 checkGLcall("allocate immutable storage");
1078}
#define GL_TEXTURE_3D
Definition: gl.h:1515
#define GL_TEXTURE_1D
Definition: gl.h:644
unsigned char GLboolean
Definition: gl.h:151
GLsizei samples
Definition: glext.h:7006
#define GL_TEXTURE_1D_ARRAY
Definition: glext.h:533
#define GL_TEXTURE_2D_MULTISAMPLE_ARRAY
Definition: glext.h:1941
#define GL_TEXTURE_2D_MULTISAMPLE
Definition: glext.h:1939
#define GL_TEXTURE_2D_ARRAY
Definition: glext.h:535

Referenced by wined3d_texture_gl_prepare_texture().

◆ wined3d_texture_gl_allocate_mutable_storage()

static void wined3d_texture_gl_allocate_mutable_storage ( struct wined3d_texture_gl *  texture_gl,
GLenum  gl_internal_format,
const struct wined3d_format_gl *  format,
const struct wined3d_gl_info *  gl_info 
)
static

Definition at line 977 of file texture.c.

980{
981 unsigned int level, level_count, layer, layer_count;
984
985 level_count = texture_gl->t.level_count;
986 if (texture_gl->target == GL_TEXTURE_1D_ARRAY || texture_gl->target == GL_TEXTURE_2D_ARRAY)
987 layer_count = 1;
988 else
989 layer_count = texture_gl->t.layer_count;
990
991 GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0));
992 checkGLcall("glBindBuffer");
993
994 for (layer = 0; layer < layer_count; ++layer)
995 {
996 target = wined3d_texture_gl_get_sub_resource_target(texture_gl, layer * level_count);
997
998 for (level = 0; level < level_count; ++level)
999 {
1002 if (texture_gl->t.resource.format_attrs & WINED3D_FORMAT_ATTR_HEIGHT_SCALE)
1003 {
1004 height *= format->f.height_scale.numerator;
1005 height /= format->f.height_scale.denominator;
1006 }
1007
1008 TRACE("texture_gl %p, layer %u, level %u, target %#x, width %u, height %u.\n",
1009 texture_gl, layer, level, target, width, height);
1010
1012 {
1014 GL_EXTCALL(glTexImage3D(target, level, gl_internal_format, width, height,
1015 target == GL_TEXTURE_2D_ARRAY ? texture_gl->t.layer_count : depth, 0,
1016 format->format, format->type, NULL));
1017 checkGLcall("glTexImage3D");
1018 }
1019 else if (target == GL_TEXTURE_1D)
1020 {
1021 gl_info->gl_ops.gl.p_glTexImage1D(target, level, gl_internal_format,
1022 width, 0, format->format, format->type, NULL);
1023 }
1024 else
1025 {
1026 gl_info->gl_ops.gl.p_glTexImage2D(target, level, gl_internal_format, width,
1027 target == GL_TEXTURE_1D_ARRAY ? texture_gl->t.layer_count : height, 0,
1028 format->format, format->type, NULL);
1029 checkGLcall("glTexImage2D");
1030 }
1031 }
1032 }
1033}
GLAPI void GLAPIENTRY glTexImage3D(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels)
#define GL_PIXEL_UNPACK_BUFFER
Definition: glext.h:477

Referenced by wined3d_texture_gl_prepare_texture().

◆ wined3d_texture_gl_apply_sampler_desc()

void wined3d_texture_gl_apply_sampler_desc ( struct wined3d_texture_gl *  texture_gl,
const struct wined3d_sampler_desc *  sampler_desc,
const struct wined3d_context_gl *  context_gl 
)

Definition at line 1418 of file texture.c.

1420{
1421 const struct wined3d_gl_info *gl_info = context_gl->gl_info;
1422 GLenum target = texture_gl->target;
1423 struct gl_texture *gl_tex;
1424 DWORD state;
1425
1426 TRACE("texture_gl %p, sampler_desc %p, context_gl %p.\n", texture_gl, sampler_desc, context_gl);
1427
1428 gl_tex = wined3d_texture_gl_get_gl_texture(texture_gl, texture_gl->t.flags & WINED3D_TEXTURE_IS_SRGB);
1429
1430 state = sampler_desc->address_u;
1431 if (state != gl_tex->sampler_desc.address_u)
1432 {
1433 gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_WRAP_S,
1435 gl_tex->sampler_desc.address_u = state;
1436 }
1437
1438 state = sampler_desc->address_v;
1439 if (state != gl_tex->sampler_desc.address_v)
1440 {
1441 gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_WRAP_T,
1443 gl_tex->sampler_desc.address_v = state;
1444 }
1445
1446 state = sampler_desc->address_w;
1447 if (state != gl_tex->sampler_desc.address_w)
1448 {
1449 gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_WRAP_R,
1451 gl_tex->sampler_desc.address_w = state;
1452 }
1453
1454 if (memcmp(gl_tex->sampler_desc.border_color, sampler_desc->border_color,
1455 sizeof(gl_tex->sampler_desc.border_color)))
1456 {
1457 gl_info->gl_ops.gl.p_glTexParameterfv(target, GL_TEXTURE_BORDER_COLOR, &sampler_desc->border_color[0]);
1458 memcpy(gl_tex->sampler_desc.border_color, sampler_desc->border_color,
1459 sizeof(gl_tex->sampler_desc.border_color));
1460 }
1461
1462 state = sampler_desc->mag_filter;
1463 if (state != gl_tex->sampler_desc.mag_filter)
1464 {
1465 gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_MAG_FILTER, wined3d_gl_mag_filter(state));
1466 gl_tex->sampler_desc.mag_filter = state;
1467 }
1468
1469 if (sampler_desc->min_filter != gl_tex->sampler_desc.min_filter
1470 || sampler_desc->mip_filter != gl_tex->sampler_desc.mip_filter)
1471 {
1472 gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_MIN_FILTER,
1473 wined3d_gl_min_mip_filter(sampler_desc->min_filter, sampler_desc->mip_filter));
1474 gl_tex->sampler_desc.min_filter = sampler_desc->min_filter;
1475 gl_tex->sampler_desc.mip_filter = sampler_desc->mip_filter;
1476 }
1477
1478 state = sampler_desc->max_anisotropy;
1479 if (state != gl_tex->sampler_desc.max_anisotropy)
1480 {
1482 gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_MAX_ANISOTROPY, state);
1483 else
1484 WARN("Anisotropic filtering not supported.\n");
1485 gl_tex->sampler_desc.max_anisotropy = state;
1486 }
1487
1488 if (!sampler_desc->srgb_decode != !gl_tex->sampler_desc.srgb_decode
1489 && (context_gl->c.d3d_info->wined3d_creation_flags & WINED3D_SRGB_READ_WRITE_CONTROL)
1491 {
1492 gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_SRGB_DECODE_EXT,
1494 gl_tex->sampler_desc.srgb_decode = sampler_desc->srgb_decode;
1495 }
1496
1497 if (!sampler_desc->compare != !gl_tex->sampler_desc.compare)
1498 {
1499 if (sampler_desc->compare)
1501 else
1502 gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_COMPARE_MODE_ARB, GL_NONE);
1503 gl_tex->sampler_desc.compare = sampler_desc->compare;
1504 }
1505
1506 checkGLcall("Texture parameter application");
1507
1508 if (gl_info->supported[EXT_TEXTURE_LOD_BIAS])
1509 {
1510 gl_info->gl_ops.gl.p_glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT,
1512 checkGLcall("glTexEnvf(GL_TEXTURE_LOD_BIAS_EXT, ...)");
1513 }
1514}
_ACRTIMP int __cdecl memcmp(const void *, const void *, size_t)
Definition: string.c:2807
#define GL_TEXTURE_MIN_FILTER
Definition: gl.h:649
#define GL_TEXTURE_BORDER_COLOR
Definition: gl.h:656
#define GL_TEXTURE_WRAP_R
Definition: gl.h:1518
#define GL_TEXTURE_WRAP_S
Definition: gl.h:646
#define GL_TEXTURE_WRAP_T
Definition: gl.h:647
#define GL_TEXTURE_MAG_FILTER
Definition: gl.h:648
#define GL_SKIP_DECODE_EXT
Definition: glext.h:5291
#define GL_DECODE_EXT
Definition: glext.h:5290
#define GL_TEXTURE_SRGB_DECODE_EXT
Definition: glext.h:5289
#define GL_TEXTURE_COMPARE_MODE_ARB
Definition: glext.h:1371
#define GL_TEXTURE_LOD_BIAS_EXT
Definition: glext.h:3362
#define GL_COMPARE_R_TO_TEXTURE_ARB
Definition: glext.h:1373
#define GL_TEXTURE_FILTER_CONTROL_EXT
Definition: glext.h:3361
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
struct wined3d_sampler_desc sampler_desc
Definition: wined3d_gl.h:928
struct wined3d_context c
Definition: wined3d_gl.h:601
GLint wrap_lookup[WINED3D_TADDRESS_MIRROR_ONCE - WINED3D_TADDRESS_WRAP+1]
Definition: wined3d_gl.h:348
#define GL_TEXTURE_MAX_ANISOTROPY
Definition: wgl.h:4461
@ WINED3D_TADDRESS_WRAP
Definition: wined3d.h:658
#define WINED3D_SRGB_READ_WRITE_CONTROL
Definition: wined3d.h:1330
@ ARB_TEXTURE_FILTER_ANISOTROPIC
Definition: wined3d_gl.h:134
@ EXT_TEXTURE_SRGB_DECODE
Definition: wined3d_gl.h:203
@ EXT_TEXTURE_LOD_BIAS
Definition: wined3d_gl.h:197
static GLenum wined3d_gl_mag_filter(enum wined3d_texture_filter_type mag_filter)
Definition: wined3d_gl.h:377
static struct gl_texture * wined3d_texture_gl_get_gl_texture(struct wined3d_texture_gl *texture_gl, bool srgb)
Definition: wined3d_gl.h:959
static GLenum wined3d_gl_min_mip_filter(enum wined3d_texture_filter_type min_filter, enum wined3d_texture_filter_type mip_filter)
Definition: wined3d_gl.h:382

Referenced by wined3d_sampler_gl_bind().

◆ wined3d_texture_gl_bind()

void wined3d_texture_gl_bind ( struct wined3d_texture_gl *  texture_gl,
struct wined3d_context_gl *  context_gl,
BOOL  srgb 
)

Definition at line 1288 of file texture.c.

1290{
1291 const struct wined3d_format *format = texture_gl->t.resource.format;
1292 const struct wined3d_gl_info *gl_info = context_gl->gl_info;
1293 const struct color_fixup_desc fixup = format->color_fixup;
1294 struct gl_texture *gl_tex;
1295 GLenum target;
1296
1297 TRACE("texture_gl %p, context_gl %p, srgb %#x.\n", texture_gl, context_gl, srgb);
1298
1299 if (!needs_separate_srgb_gl_texture(&context_gl->c, &texture_gl->t))
1300 srgb = FALSE;
1301
1302 /* sRGB mode cache for preload() calls outside drawprim. */
1303 if (srgb)
1304 texture_gl->t.flags |= WINED3D_TEXTURE_IS_SRGB;
1305 else
1306 texture_gl->t.flags &= ~WINED3D_TEXTURE_IS_SRGB;
1307
1308 gl_tex = wined3d_texture_gl_get_gl_texture(texture_gl, srgb);
1309 target = texture_gl->target;
1310
1311 if (gl_tex->name)
1312 {
1313 wined3d_context_gl_bind_texture(context_gl, target, gl_tex->name);
1314 return;
1315 }
1316
1317 gl_info->gl_ops.gl.p_glGenTextures(1, &gl_tex->name);
1318 checkGLcall("glGenTextures");
1319 TRACE("Generated texture %d.\n", gl_tex->name);
1320
1321 if (!gl_tex->name)
1322 {
1323 ERR("Failed to generate a texture name.\n");
1324 return;
1325 }
1326
1327 /* Initialise the state of the texture object to the OpenGL defaults, not
1328 * the wined3d defaults. */
1329 gl_tex->sampler_desc.address_u = WINED3D_TADDRESS_WRAP;
1330 gl_tex->sampler_desc.address_v = WINED3D_TADDRESS_WRAP;
1331 gl_tex->sampler_desc.address_w = WINED3D_TADDRESS_WRAP;
1332 memset(gl_tex->sampler_desc.border_color, 0, sizeof(gl_tex->sampler_desc.border_color));
1333 gl_tex->sampler_desc.mag_filter = WINED3D_TEXF_LINEAR;
1334 gl_tex->sampler_desc.min_filter = WINED3D_TEXF_POINT; /* GL_NEAREST_MIPMAP_LINEAR */
1335 gl_tex->sampler_desc.mip_filter = WINED3D_TEXF_LINEAR; /* GL_NEAREST_MIPMAP_LINEAR */
1336 gl_tex->sampler_desc.lod_bias = 0.0f;
1337 gl_tex->sampler_desc.min_lod = -1000.0f;
1338 gl_tex->sampler_desc.max_lod = 1000.0f;
1339 gl_tex->sampler_desc.max_anisotropy = 1;
1340 gl_tex->sampler_desc.compare = FALSE;
1341 gl_tex->sampler_desc.comparison_func = WINED3D_CMP_LESSEQUAL;
1342 if (gl_info->supported[EXT_TEXTURE_SRGB_DECODE])
1343 gl_tex->sampler_desc.srgb_decode = TRUE;
1344 else
1345 gl_tex->sampler_desc.srgb_decode = srgb;
1346 gl_tex->sampler_desc.mip_base_level = 0;
1347 wined3d_texture_set_dirty(&texture_gl->t);
1348
1349 wined3d_context_gl_bind_texture(context_gl, target, gl_tex->name);
1350
1351 /* For a new texture we have to set the texture levels after binding the
1352 * texture. */
1353 TRACE("Setting GL_TEXTURE_MAX_LEVEL to %u.\n", texture_gl->t.level_count - 1);
1354 gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, texture_gl->t.level_count - 1);
1355 checkGLcall("glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, texture->level_count)");
1356
1358 {
1359 /* Cubemaps are always set to clamp, regardless of the sampler state. */
1360 gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1361 gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1362 gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
1363 }
1364
1365 if (texture_gl->t.flags & WINED3D_TEXTURE_COND_NP2 && target != GL_TEXTURE_2D_MULTISAMPLE
1367 {
1368 /* Conditional non power of two textures use a different clamping
1369 * default. If we're using the GL_WINE_normalized_texrect partial
1370 * driver emulation, we're dealing with a GL_TEXTURE_2D texture which
1371 * has the address mode set to repeat - something that prevents us
1372 * from hitting the accelerated codepath. Thus manually set the GL
1373 * state. The same applies to filtering. Even if the texture has only
1374 * one mip level, the default LINEAR_MIPMAP_LINEAR filter causes a SW
1375 * fallback on macos. */
1376 gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1377 gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1378 gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1379 gl_info->gl_ops.gl.p_glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1380 checkGLcall("glTexParameteri");
1381 gl_tex->sampler_desc.address_u = WINED3D_TADDRESS_CLAMP;
1382 gl_tex->sampler_desc.address_v = WINED3D_TADDRESS_CLAMP;
1383 gl_tex->sampler_desc.mag_filter = WINED3D_TEXF_POINT;
1384 gl_tex->sampler_desc.min_filter = WINED3D_TEXF_POINT;
1385 gl_tex->sampler_desc.mip_filter = WINED3D_TEXF_NONE;
1386 }
1387
1389 {
1390 gl_info->gl_ops.gl.p_glTexParameteri(target, GL_DEPTH_TEXTURE_MODE_ARB, GL_INTENSITY);
1391 checkGLcall("glTexParameteri(GL_DEPTH_TEXTURE_MODE_ARB, GL_INTENSITY)");
1392 }
1393
1394 if (!is_identity_fixup(fixup) && can_use_texture_swizzle(context_gl->c.d3d_info, format))
1395 {
1396 GLint swizzle[4];
1397
1399 gl_info->gl_ops.gl.p_glTexParameteriv(target, GL_TEXTURE_SWIZZLE_RGBA, swizzle);
1400 checkGLcall("set format swizzle");
1401 }
1402}
void wined3d_context_gl_bind_texture(struct wined3d_context_gl *context_gl, GLenum target, GLuint name)
Definition: context_gl.c:2507
void wined3d_gl_texture_swizzle_from_color_fixup(GLint swizzle[4], struct color_fixup_desc fixup)
Definition: texture.c:1269
#define GL_TEXTURE_MAX_LEVEL
Definition: gl.h:1504
#define GL_INTENSITY
Definition: gl.h:747
#define GL_CLAMP_TO_EDGE
Definition: gl.h:1481
#define GL_DEPTH_TEXTURE_MODE_ARB
Definition: glext.h:1367
#define GL_TEXTURE_SWIZZLE_RGBA
Definition: glext.h:2032
#define memset(x, y, z)
Definition: compat.h:39
@ WINED3D_TADDRESS_CLAMP
Definition: wined3d.h:660
@ WINED3D_CMP_LESSEQUAL
Definition: wined3d.h:464
@ ARB_DEPTH_TEXTURE
Definition: wined3d_gl.h:68
@ WINED3D_GL_LEGACY_CONTEXT
Definition: wined3d_gl.h:232
#define WINED3D_TEXTURE_COND_NP2
static BOOL can_use_texture_swizzle(const struct wined3d_d3d_info *d3d_info, const struct wined3d_format *format)
static BOOL needs_separate_srgb_gl_texture(const struct wined3d_context *context, const struct wined3d_texture *texture)

Referenced by wined3d_shader_resource_view_gl_bind(), and wined3d_texture_gl_bind_and_dirtify().

◆ wined3d_texture_gl_bind_and_dirtify()

void wined3d_texture_gl_bind_and_dirtify ( struct wined3d_texture_gl *  texture_gl,
struct wined3d_context_gl *  context_gl,
BOOL  srgb 
)

Definition at line 1405 of file texture.c.

1407{
1408 /* FIXME: Ideally we'd only do this when touching a binding that's used by
1409 * a shader. */
1412
1413 wined3d_texture_gl_bind(texture_gl, context_gl, srgb);
1414}
void context_invalidate_compute_state(struct wined3d_context *context, DWORD state_id)
Definition: context.c:66
void wined3d_texture_gl_bind(struct wined3d_texture_gl *texture_gl, struct wined3d_context_gl *context_gl, BOOL srgb)
Definition: texture.c:1288
#define STATE_COMPUTE_SHADER_RESOURCE_BINDING

Referenced by wined3d_shader_resource_view_gl_generate_mipmap(), wined3d_texture_gl_download_data(), wined3d_texture_gl_prepare_texture(), and wined3d_texture_gl_upload_data().

◆ wined3d_texture_gl_clear()

static bool wined3d_texture_gl_clear ( struct wined3d_texture *  texture,
unsigned int  sub_resource_idx,
struct wined3d_context_gl *  context_gl,
unsigned int  location 
)
static

Definition at line 3135 of file texture.c.

3137{
3138 struct wined3d_texture_sub_resource *sub_resource = &texture->sub_resources[sub_resource_idx];
3139 const struct wined3d_format *format = texture->resource.format;
3140 const struct wined3d_gl_info *gl_info = context_gl->gl_info;
3141 struct wined3d_bo_address addr;
3142
3143 /* The code that delays clears is Vulkan-specific, so here we should only
3144 * encounter WINED3D_LOCATION_CLEARED on newly created resources and thus
3145 * a zero clear value. */
3146 if (!format->depth_size && !format->stencil_size)
3147 {
3148 if (sub_resource->clear_value.colour.r || sub_resource->clear_value.colour.g
3149 || sub_resource->clear_value.colour.b || sub_resource->clear_value.colour.a)
3150 {
3151 ERR("Unexpected color clear value r=%08e, g=%08e, b=%08e, a=%08e.\n",
3152 sub_resource->clear_value.colour.r, sub_resource->clear_value.colour.g,
3153 sub_resource->clear_value.colour.b, sub_resource->clear_value.colour.a);
3154 }
3155 }
3156 else
3157 {
3158 if (format->depth_size && sub_resource->clear_value.depth)
3159 ERR("Unexpected depth clear value %08e.\n", sub_resource->clear_value.depth);
3160 if (format->stencil_size && sub_resource->clear_value.stencil)
3161 ERR("Unexpected stencil clear value %x.\n", sub_resource->clear_value.stencil);
3162 }
3163
3165 {
3166 GLbitfield clear_mask = 0;
3167
3168 context_gl_apply_texture_draw_state(context_gl, texture, sub_resource_idx, location);
3169
3170 gl_info->gl_ops.gl.p_glDisable(GL_SCISSOR_TEST);
3172
3173 if (format->depth_size)
3174 {
3175 gl_info->gl_ops.gl.p_glDepthMask(GL_TRUE);
3177
3178 if (gl_info->supported[ARB_ES2_COMPATIBILITY])
3179 GL_EXTCALL(glClearDepthf(0.0f));
3180 else
3181 gl_info->gl_ops.gl.p_glClearDepth(0.0);
3182 clear_mask |= GL_DEPTH_BUFFER_BIT;
3183 }
3184
3185 if (format->stencil_size)
3186 {
3187 if (gl_info->supported[EXT_STENCIL_TWO_SIDE])
3188 gl_info->gl_ops.gl.p_glDisable(GL_STENCIL_TEST_TWO_SIDE_EXT);
3189 gl_info->gl_ops.gl.p_glStencilMask(~0u);
3191 gl_info->gl_ops.gl.p_glClearStencil(0);
3192 clear_mask |= GL_STENCIL_BUFFER_BIT;
3193 }
3194
3195 if (!format->depth_size && !format->stencil_size)
3196 {
3197 gl_info->gl_ops.gl.p_glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
3198 context_invalidate_state(&context_gl->c, STATE_BLEND);
3199 gl_info->gl_ops.gl.p_glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
3200 clear_mask |= GL_COLOR_BUFFER_BIT;
3201 }
3202
3203 gl_info->gl_ops.gl.p_glClear(clear_mask);
3204 checkGLcall("clear texture");
3205
3207 return true;
3208 }
3209
3210 if (!wined3d_texture_prepare_location(texture, sub_resource_idx, &context_gl->c, WINED3D_LOCATION_SYSMEM))
3211 return false;
3213 memset(addr.addr, 0, sub_resource->size);
3215 return true;
3216}
static bool use_ffp_clear(const struct wined3d_texture *texture, unsigned int location)
Definition: texture.c:3119
GLenum const GLvoid * addr
Definition: glext.h:9621

Referenced by wined3d_texture_gl_load_location().

◆ wined3d_texture_gl_download_data()

static void wined3d_texture_gl_download_data ( struct wined3d_context *  context,
struct wined3d_texture *  src_texture,
unsigned int  src_sub_resource_idx,
unsigned int  src_location,
const struct wined3d_box *  src_box,
const struct wined3d_bo_address *  dst_bo_addr,
const struct wined3d_format *  dst_format,
unsigned int  dst_x,
unsigned int  dst_y,
unsigned int  dst_z,
unsigned int  dst_row_pitch,
unsigned int  dst_slice_pitch 
)
static

Definition at line 2687 of file texture.c.

2692{
2693 struct wined3d_texture_gl *src_texture_gl = wined3d_texture_gl(src_texture);
2694 struct wined3d_context_gl *context_gl = wined3d_context_gl(context);
2695 const struct wined3d_gl_info *gl_info = context_gl->gl_info;
2696 unsigned int src_level, src_width, src_height, src_depth;
2697 unsigned int src_row_pitch, src_slice_pitch;
2698 const struct wined3d_format_gl *format_gl;
2699 uint8_t *offset = dst_bo_addr->addr;
2700 struct wined3d_bo *dst_bo;
2701 BOOL srgb = FALSE;
2702 GLenum target;
2703
2704 TRACE("context %p, src_texture %p, src_sub_resource_idx %u, src_location %s, src_box %s, dst_bo_addr %s, "
2705 "dst_format %s, dst_x %u, dst_y %u, dst_z %u, dst_row_pitch %u, dst_slice_pitch %u.\n",
2706 context, src_texture, src_sub_resource_idx, wined3d_debug_location(src_location),
2707 debug_box(src_box), debug_bo_address(dst_bo_addr), debug_d3dformat(dst_format->id),
2708 dst_x, dst_y, dst_z, dst_row_pitch, dst_slice_pitch);
2709
2710 if (src_location == WINED3D_LOCATION_TEXTURE_SRGB)
2711 {
2712 srgb = TRUE;
2713 }
2714 else if (src_location != WINED3D_LOCATION_TEXTURE_RGB)
2715 {
2716 FIXME("Unhandled location %s.\n", wined3d_debug_location(src_location));
2717 return;
2718 }
2719
2720 src_level = src_sub_resource_idx % src_texture->level_count;
2721 src_width = wined3d_texture_get_level_width(src_texture, src_level);
2722 src_height = wined3d_texture_get_level_height(src_texture, src_level);
2723 src_depth = wined3d_texture_get_level_depth(src_texture, src_level);
2724 if (src_box->left || src_box->top || src_box->right != src_width || src_box->bottom != src_height
2725 || src_box->front || src_box->back != src_depth)
2726 {
2727 FIXME("Unhandled source box %s.\n", debug_box(src_box));
2728 return;
2729 }
2730
2731 if (dst_x || dst_y || dst_z)
2732 {
2733 FIXME("Unhandled destination (%u, %u, %u).\n", dst_x, dst_y, dst_z);
2734 return;
2735 }
2736
2737 if (dst_format->id != src_texture->resource.format->id)
2738 {
2739 FIXME("Unhandled format conversion (%s -> %s).\n",
2740 debug_d3dformat(src_texture->resource.format->id),
2742 return;
2743 }
2744
2745 wined3d_texture_get_pitch(src_texture, src_level, &src_row_pitch, &src_slice_pitch);
2746 if (src_row_pitch != dst_row_pitch || src_slice_pitch != dst_slice_pitch)
2747 {
2748 FIXME("Unhandled destination pitches %u/%u (source pitches %u/%u).\n",
2749 dst_row_pitch, dst_slice_pitch, src_row_pitch, src_slice_pitch);
2750 return;
2751 }
2752
2753 wined3d_texture_gl_bind_and_dirtify(src_texture_gl, context_gl, srgb);
2754
2755 format_gl = wined3d_format_gl(src_texture->resource.format);
2756 target = wined3d_texture_gl_get_sub_resource_target(src_texture_gl, src_sub_resource_idx);
2757
2758 if ((src_texture->resource.type == WINED3D_RTYPE_TEXTURE_2D
2759 && (target == GL_TEXTURE_2D_ARRAY || format_gl->f.conv_byte_count
2760 || (src_texture->flags & WINED3D_TEXTURE_CONVERTED)))
2762 {
2763 wined3d_texture_gl_download_data_slow_path(src_texture_gl, src_sub_resource_idx, context_gl, dst_bo_addr);
2764 return;
2765 }
2766
2767 if (format_gl->f.conv_byte_count)
2768 {
2769 FIXME("Attempting to download a converted texture, type %s format %s.\n",
2770 debug_d3dresourcetype(src_texture->resource.type),
2771 debug_d3dformat(format_gl->f.id));
2772 return;
2773 }
2774
2775 if ((dst_bo = dst_bo_addr->buffer_object))
2776 {
2777 GL_EXTCALL(glBindBuffer(GL_PIXEL_PACK_BUFFER, wined3d_bo_gl(dst_bo)->id));
2778 checkGLcall("glBindBuffer");
2779 offset += dst_bo->buffer_offset;
2780 }
2781 else
2782 {
2783 GL_EXTCALL(glBindBuffer(GL_PIXEL_PACK_BUFFER, 0));
2784 checkGLcall("glBindBuffer");
2785 }
2786
2787 if (src_texture->resource.format_attrs & WINED3D_FORMAT_ATTR_COMPRESSED)
2788 {
2789 TRACE("Downloading compressed texture %p, %u, level %u, format %#x, type %#x, data %p.\n",
2790 src_texture, src_sub_resource_idx, src_level, format_gl->format, format_gl->type, offset);
2791
2793 checkGLcall("glGetCompressedTexImage");
2794 }
2795 else
2796 {
2797 TRACE("Downloading texture %p, %u, level %u, format %#x, type %#x, data %p.\n",
2798 src_texture, src_sub_resource_idx, src_level, format_gl->format, format_gl->type, offset);
2799
2800 gl_info->gl_ops.gl.p_glGetTexImage(target, src_level, format_gl->format, format_gl->type, offset);
2801 checkGLcall("glGetTexImage");
2802 }
2803
2804 if (dst_bo)
2805 {
2806 GL_EXTCALL(glBindBuffer(GL_PIXEL_PACK_BUFFER, 0));
2808 checkGLcall("glBindBuffer");
2809 }
2810}
static void wined3d_texture_gl_download_data_slow_path(struct wined3d_texture_gl *texture_gl, unsigned int sub_resource_idx, struct wined3d_context_gl *context_gl, const struct wined3d_bo_address *data)
Definition: texture.c:2546
void wined3d_texture_gl_bind_and_dirtify(struct wined3d_texture_gl *texture_gl, struct wined3d_context_gl *context_gl, BOOL srgb)
Definition: texture.c:1405
const char * debug_bo_address(const struct wined3d_bo_address *address)
Definition: utils.c:4600
unsigned char uint8_t
Definition: stdint.h:33
GLAPI void GLAPIENTRY glGetCompressedTexImage(GLenum target, GLint lod, GLvoid *img)
GLintptr offset
Definition: glext.h:5920
#define GL_PIXEL_PACK_BUFFER
Definition: glext.h:476
struct wined3d_bo * buffer_object
size_t buffer_offset
UINT left
Definition: wined3d.h:1873
UINT right
Definition: wined3d.h:1875
UINT back
Definition: wined3d.h:1878
UINT front
Definition: wined3d.h:1877
UINT bottom
Definition: wined3d.h:1876
UINT top
Definition: wined3d.h:1874
struct wined3d_format f
Definition: wined3d_gl.h:1142
static void wined3d_context_gl_reference_bo(struct wined3d_context_gl *context_gl, struct wined3d_bo_gl *bo_gl)
Definition: wined3d_gl.h:912

Referenced by wined3d_texture_gl_load_sysmem().

◆ wined3d_texture_gl_download_data_slow_path()

static void wined3d_texture_gl_download_data_slow_path ( struct wined3d_texture_gl *  texture_gl,
unsigned int  sub_resource_idx,
struct wined3d_context_gl *  context_gl,
const struct wined3d_bo_address *  data 
)
static

Definition at line 2546 of file texture.c.

2548{
2549 struct wined3d_bo_gl *bo = wined3d_bo_gl(data->buffer_object);
2550 const struct wined3d_gl_info *gl_info = context_gl->gl_info;
2551 struct wined3d_texture_sub_resource *sub_resource;
2552 unsigned int dst_row_pitch, dst_slice_pitch;
2553 unsigned int src_row_pitch, src_slice_pitch;
2554 const struct wined3d_format_gl *format_gl;
2555 BYTE *temporary_mem = NULL;
2556 unsigned int level;
2557 GLenum target;
2558 void *mem;
2559
2560 format_gl = wined3d_format_gl(texture_gl->t.resource.format);
2561
2562 /* Only support read back of converted P8 textures. */
2563 if (texture_gl->t.flags & WINED3D_TEXTURE_CONVERTED && format_gl->f.id != WINED3DFMT_P8_UINT
2564 && !format_gl->f.download)
2565 {
2566 ERR("Trying to read back converted texture %p, %u with format %s.\n",
2567 texture_gl, sub_resource_idx, debug_d3dformat(format_gl->f.id));
2568 return;
2569 }
2570
2571 sub_resource = &texture_gl->t.sub_resources[sub_resource_idx];
2572 target = wined3d_texture_gl_get_sub_resource_target(texture_gl, sub_resource_idx);
2573 level = sub_resource_idx % texture_gl->t.level_count;
2574
2576 {
2577 if (format_gl->f.download)
2578 {
2579 FIXME("Reading back converted array texture %p is not supported.\n", texture_gl);
2580 return;
2581 }
2582
2583 WARN_(d3d_perf)("Downloading all miplevel layers to get the data for a single sub-resource.\n");
2584
2585 if (!(temporary_mem = calloc(texture_gl->t.layer_count, sub_resource->size)))
2586 {
2587 ERR("Out of memory.\n");
2588 return;
2589 }
2590 }
2591
2592 if (format_gl->f.download)
2593 {
2594 struct wined3d_format f;
2595
2596 if (bo)
2597 ERR("Converted texture %p uses PBO unexpectedly.\n", texture_gl);
2598
2599 WARN_(d3d_perf)("Downloading converted texture %p, %u with format %s.\n",
2600 texture_gl, sub_resource_idx, debug_d3dformat(format_gl->f.id));
2601
2602 f = format_gl->f;
2603 f.byte_count = format_gl->f.conv_byte_count;
2604 wined3d_texture_get_pitch(&texture_gl->t, level, &dst_row_pitch, &dst_slice_pitch);
2605 wined3d_format_calculate_pitch(&f, texture_gl->t.resource.device->surface_alignment,
2608 &src_row_pitch, &src_slice_pitch);
2609
2610 if (!(temporary_mem = malloc(src_slice_pitch)))
2611 {
2612 ERR("Failed to allocate memory.\n");
2613 return;
2614 }
2615 }
2616
2617 if (temporary_mem)
2618 {
2619 GL_EXTCALL(glBindBuffer(GL_PIXEL_PACK_BUFFER, 0));
2620 checkGLcall("glBindBuffer");
2621 mem = temporary_mem;
2622 }
2623 else if (bo)
2624 {
2625 GL_EXTCALL(glBindBuffer(GL_PIXEL_PACK_BUFFER, bo->id));
2626 checkGLcall("glBindBuffer");
2627 mem = (uint8_t *)data->addr + bo->b.buffer_offset;
2628 }
2629 else
2630 {
2631 GL_EXTCALL(glBindBuffer(GL_PIXEL_PACK_BUFFER, 0));
2632 checkGLcall("glBindBuffer");
2633 mem = data->addr;
2634 }
2635
2636 if (texture_gl->t.resource.format_attrs & WINED3D_FORMAT_ATTR_COMPRESSED)
2637 {
2638 TRACE("Downloading compressed texture %p, %u, level %u, format %#x, type %#x, data %p.\n",
2639 texture_gl, sub_resource_idx, level, format_gl->format, format_gl->type, mem);
2640
2642 checkGLcall("glGetCompressedTexImage");
2643 }
2644 else
2645 {
2646 TRACE("Downloading texture %p, %u, level %u, format %#x, type %#x, data %p.\n",
2647 texture_gl, sub_resource_idx, level, format_gl->format, format_gl->type, mem);
2648
2649 gl_info->gl_ops.gl.p_glGetTexImage(target, level, format_gl->format, format_gl->type, mem);
2650 checkGLcall("glGetTexImage");
2651 }
2652
2653 if (format_gl->f.download)
2654 {
2655 format_gl->f.download(mem, data->addr, src_row_pitch, src_slice_pitch, dst_row_pitch, dst_slice_pitch,
2657 wined3d_texture_get_level_height(&texture_gl->t, level), 1);
2658 }
2659 else if (temporary_mem)
2660 {
2661 unsigned int layer = sub_resource_idx / texture_gl->t.level_count;
2662 void *src_data = temporary_mem + layer * sub_resource->size;
2663 if (bo)
2664 {
2665 GL_EXTCALL(glBindBuffer(GL_PIXEL_PACK_BUFFER, bo->id));
2666 checkGLcall("glBindBuffer");
2667 GL_EXTCALL(glBufferSubData(GL_PIXEL_PACK_BUFFER,
2668 (GLintptr)data->addr + bo->b.buffer_offset, sub_resource->size, src_data));
2669 checkGLcall("glBufferSubData");
2670 }
2671 else
2672 {
2673 memcpy(data->addr, src_data, sub_resource->size);
2674 }
2675 }
2676
2677 if (bo)
2678 {
2679 GL_EXTCALL(glBindBuffer(GL_PIXEL_PACK_BUFFER, 0));
2680 wined3d_context_gl_reference_bo(context_gl, bo);
2681 checkGLcall("glBindBuffer");
2682 }
2683
2684 free(temporary_mem);
2685}
ptrdiff_t GLintptr
Definition: glext.h:5498
Definition: mem.c:349
struct wined3d_bo b
Definition: wined3d_gl.h:415
@ WINED3DFMT_P8_UINT
Definition: wined3d.h:137

Referenced by wined3d_texture_gl_download_data().

◆ wined3d_texture_gl_init()

HRESULT wined3d_texture_gl_init ( struct wined3d_texture_gl *  texture_gl,
struct wined3d_device *  device,
const struct wined3d_resource_desc *  desc,
unsigned int  layer_count,
unsigned int  level_count,
uint32_t  flags,
void *  parent,
const struct wined3d_parent_ops *  parent_ops 
)

Definition at line 4083 of file texture.c.

4086{
4087 const struct wined3d_gl_info *gl_info = &wined3d_adapter_gl(device->adapter)->gl_info;
4088 HRESULT hr;
4089
4090 TRACE("texture_gl %p, device %p, desc %p, layer_count %u, "
4091 "level_count %u, flags %#x, parent %p, parent_ops %p.\n",
4092 texture_gl, device, desc, layer_count,
4093 level_count, flags, parent, parent_ops);
4094
4095 if (!(desc->usage & WINED3DUSAGE_LEGACY_CUBEMAP) && layer_count > 1
4096 && !gl_info->supported[EXT_TEXTURE_ARRAY])
4097 {
4098 WARN("OpenGL implementation does not support array textures.\n");
4100 }
4101
4102 switch (desc->resource_type)
4103 {
4105 if (layer_count > 1)
4106 texture_gl->target = GL_TEXTURE_1D_ARRAY;
4107 else
4108 texture_gl->target = GL_TEXTURE_1D;
4109 break;
4110
4112 if (desc->usage & WINED3DUSAGE_LEGACY_CUBEMAP)
4113 {
4114 texture_gl->target = GL_TEXTURE_CUBE_MAP_ARB;
4115 }
4116 else if (desc->multisample_type && gl_info->supported[ARB_TEXTURE_MULTISAMPLE])
4117 {
4118 if (layer_count > 1)
4120 else
4121 texture_gl->target = GL_TEXTURE_2D_MULTISAMPLE;
4122 }
4123 else
4124 {
4125 if (layer_count > 1)
4126 texture_gl->target = GL_TEXTURE_2D_ARRAY;
4127 else
4128 texture_gl->target = GL_TEXTURE_2D;
4129 }
4130 break;
4131
4133 if (!gl_info->supported[EXT_TEXTURE3D])
4134 {
4135 WARN("OpenGL implementation does not support 3D textures.\n");
4137 }
4138 texture_gl->target = GL_TEXTURE_3D;
4139 break;
4140
4141 default:
4142 ERR("Invalid resource type %s.\n", debug_d3dresourcetype(desc->resource_type));
4144 }
4145
4146 list_init(&texture_gl->renderbuffers);
4147
4148 if (FAILED(hr = wined3d_texture_init(&texture_gl->t, desc, layer_count, level_count,
4149 flags, device, parent, parent_ops, &texture_gl[1], &texture_gl_ops)))
4150 return hr;
4151
4152 if (texture_gl->target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY || texture_gl->target == GL_TEXTURE_2D_MULTISAMPLE)
4153 texture_gl->t.flags &= ~WINED3D_TEXTURE_DOWNLOADABLE;
4154
4155 return WINED3D_OK;
4156}
static void list_init(struct list_entry *head)
Definition: list.h:51
static HRESULT wined3d_texture_init(struct wined3d_texture *texture, const struct wined3d_resource_desc *desc, unsigned int layer_count, unsigned int level_count, uint32_t flags, struct wined3d_device *device, void *parent, const struct wined3d_parent_ops *parent_ops, void *sub_resources, const struct wined3d_texture_ops *texture_ops)
Definition: texture.c:3620
static const struct wined3d_texture_ops texture_gl_ops
Definition: texture.c:34
struct wined3d_gl_info gl_info
Definition: wined3d_gl.h:800
struct list renderbuffers
Definition: wined3d_gl.h:950
@ EXT_TEXTURE3D
Definition: wined3d_gl.h:190
@ ARB_TEXTURE_MULTISAMPLE
Definition: wined3d_gl.h:139
@ EXT_TEXTURE_ARRAY
Definition: wined3d_gl.h:191

Referenced by adapter_gl_create_texture().

◆ wined3d_texture_gl_load_location()

static BOOL wined3d_texture_gl_load_location ( struct wined3d_texture *  texture,
unsigned int  sub_resource_idx,
struct wined3d_context *  context,
uint32_t  location 
)
static

Definition at line 3219 of file texture.c.

3221{
3222 struct wined3d_texture_sub_resource *sub_resource = &texture->sub_resources[sub_resource_idx];
3223 struct wined3d_texture_gl *texture_gl = wined3d_texture_gl(texture);
3224 struct wined3d_context_gl *context_gl = wined3d_context_gl(context);
3225
3226 TRACE("texture %p, sub_resource_idx %u, context %p, location %s.\n",
3227 texture, sub_resource_idx, context, wined3d_debug_location(location));
3228
3230 return FALSE;
3231
3232 if (sub_resource->locations & WINED3D_LOCATION_CLEARED)
3233 {
3234 if (!wined3d_texture_gl_clear(texture, sub_resource_idx, context_gl, location))
3235 return FALSE;
3236
3237 if (sub_resource->locations & location)
3238 return TRUE;
3239 }
3240
3241 switch (location)
3242 {
3245 return wined3d_texture_gl_load_sysmem(texture_gl, sub_resource_idx, context_gl, location);
3246
3248 return wined3d_texture_load_drawable(texture, sub_resource_idx, context);
3249
3252 return wined3d_texture_load_renderbuffer(texture, sub_resource_idx, context, location);
3253
3256 return wined3d_texture_gl_load_texture(texture_gl, sub_resource_idx,
3258
3259 default:
3260 FIXME("Unhandled %s load from %s.\n", wined3d_debug_location(location),
3261 wined3d_debug_location(texture->sub_resources[sub_resource_idx].locations));
3262 return FALSE;
3263 }
3264}
static bool wined3d_texture_gl_clear(struct wined3d_texture *texture, unsigned int sub_resource_idx, struct wined3d_context_gl *context_gl, unsigned int location)
Definition: texture.c:3135
static BOOL wined3d_texture_load_renderbuffer(struct wined3d_texture *texture, unsigned int sub_resource_idx, struct wined3d_context *context, DWORD dst_location)
Definition: texture.c:2899
static BOOL wined3d_texture_gl_load_sysmem(struct wined3d_texture_gl *texture_gl, unsigned int sub_resource_idx, struct wined3d_context_gl *context_gl, DWORD dst_location)
Definition: texture.c:2813
static BOOL wined3d_texture_load_drawable(struct wined3d_texture *texture, unsigned int sub_resource_idx, struct wined3d_context *context)
Definition: texture.c:2865
static BOOL wined3d_texture_gl_load_texture(struct wined3d_texture_gl *texture_gl, unsigned int sub_resource_idx, struct wined3d_context_gl *context_gl, BOOL srgb)
Definition: texture.c:2937
static BOOL wined3d_texture_gl_prepare_location(struct wined3d_texture *texture, unsigned int sub_resource_idx, struct wined3d_context *context, unsigned int location)
Definition: texture.c:3076

◆ wined3d_texture_gl_load_sysmem()

static BOOL wined3d_texture_gl_load_sysmem ( struct wined3d_texture_gl *  texture_gl,
unsigned int  sub_resource_idx,
struct wined3d_context_gl *  context_gl,
DWORD  dst_location 
)
static

Definition at line 2813 of file texture.c.

2815{
2816 struct wined3d_texture_sub_resource *sub_resource;
2817
2818 sub_resource = &texture_gl->t.sub_resources[sub_resource_idx];
2819
2820 /* We cannot download data from multisample textures directly. */
2822 || sub_resource->locations & WINED3D_LOCATION_RB_MULTISAMPLE)
2823 wined3d_texture_load_location(&texture_gl->t, sub_resource_idx, &context_gl->c, WINED3D_LOCATION_RB_RESOLVED);
2824
2825 if (sub_resource->locations & WINED3D_LOCATION_RB_RESOLVED)
2826 {
2827 texture2d_read_from_framebuffer(&texture_gl->t, sub_resource_idx, &context_gl->c,
2828 WINED3D_LOCATION_RB_RESOLVED, dst_location);
2829 return TRUE;
2830 }
2831
2832 if (sub_resource->locations & (WINED3D_LOCATION_TEXTURE_RGB | WINED3D_LOCATION_TEXTURE_SRGB))
2833 {
2834 unsigned int row_pitch, slice_pitch, level;
2835 struct wined3d_bo_address data;
2836 struct wined3d_box src_box;
2837 unsigned int src_location;
2838
2839 level = sub_resource_idx % texture_gl->t.level_count;
2840 wined3d_texture_get_bo_address(&texture_gl->t, sub_resource_idx, &data, dst_location);
2841 src_location = sub_resource->locations & WINED3D_LOCATION_TEXTURE_RGB
2843 wined3d_texture_get_level_box(&texture_gl->t, level, &src_box);
2844 wined3d_texture_get_pitch(&texture_gl->t, level, &row_pitch, &slice_pitch);
2845 wined3d_texture_gl_download_data(&context_gl->c, &texture_gl->t, sub_resource_idx, src_location,
2846 &src_box, &data, texture_gl->t.resource.format, 0, 0, 0, row_pitch, slice_pitch);
2847
2848 ++texture_gl->t.download_count;
2849 return TRUE;
2850 }
2851
2852 if (sub_resource->locations & WINED3D_LOCATION_DRAWABLE)
2853 {
2854 texture2d_read_from_framebuffer(&texture_gl->t, sub_resource_idx, &context_gl->c,
2855 texture_gl->t.resource.draw_binding, dst_location);
2856 return TRUE;
2857 }
2858
2859 FIXME("Can't load texture %p, %u with location flags %s into sysmem.\n",
2860 texture_gl, sub_resource_idx, wined3d_debug_location(sub_resource->locations));
2861
2862 return FALSE;
2863}
void texture2d_read_from_framebuffer(struct wined3d_texture *texture, unsigned int sub_resource_idx, struct wined3d_context *context, DWORD src_location, DWORD dst_location)
Definition: surface.c:343
static void wined3d_texture_gl_download_data(struct wined3d_context *context, struct wined3d_texture *src_texture, unsigned int src_sub_resource_idx, unsigned int src_location, const struct wined3d_box *src_box, const struct wined3d_bo_address *dst_bo_addr, const struct wined3d_format *dst_format, unsigned int dst_x, unsigned int dst_y, unsigned int dst_z, unsigned int dst_row_pitch, unsigned int dst_slice_pitch)
Definition: texture.c:2687

Referenced by wined3d_texture_gl_load_location().

◆ wined3d_texture_gl_load_texture()

static BOOL wined3d_texture_gl_load_texture ( struct wined3d_texture_gl *  texture_gl,
unsigned int  sub_resource_idx,
struct wined3d_context_gl *  context_gl,
BOOL  srgb 
)
static

Definition at line 2937 of file texture.c.

2939{
2940 unsigned int width, height, level, src_row_pitch, src_slice_pitch, dst_row_pitch, dst_slice_pitch;
2941 struct wined3d_device *device = texture_gl->t.resource.device;
2942 const struct wined3d_gl_info *gl_info = context_gl->gl_info;
2943 const struct wined3d_color_key_conversion *conversion;
2944 struct wined3d_texture_sub_resource *sub_resource;
2945 const struct wined3d_format *format;
2946 struct wined3d_bo_address data;
2947 BYTE *src_mem, *dst_mem = NULL;
2948 struct wined3d_box src_box;
2949 DWORD dst_location;
2950 BOOL depth;
2951
2952 depth = texture_gl->t.resource.bind_flags & WINED3D_BIND_DEPTH_STENCIL;
2953 sub_resource = &texture_gl->t.sub_resources[sub_resource_idx];
2954 level = sub_resource_idx % texture_gl->t.level_count;
2955 wined3d_texture_get_level_box(&texture_gl->t, level, &src_box);
2956
2957 if (!depth && sub_resource->locations & (WINED3D_LOCATION_TEXTURE_SRGB | WINED3D_LOCATION_TEXTURE_RGB)
2958 && (texture_gl->t.resource.format_caps & WINED3D_FORMAT_CAP_FBO_ATTACHABLE_SRGB)
2960 &texture_gl->t.resource, WINED3D_LOCATION_TEXTURE_RGB,
2961 &texture_gl->t.resource, WINED3D_LOCATION_TEXTURE_SRGB))
2962 {
2963 RECT src_rect;
2964
2965 SetRect(&src_rect, src_box.left, src_box.top, src_box.right, src_box.bottom);
2966 if (srgb)
2968 &texture_gl->t, sub_resource_idx, WINED3D_LOCATION_TEXTURE_RGB, &src_rect,
2969 &texture_gl->t, sub_resource_idx, WINED3D_LOCATION_TEXTURE_SRGB, &src_rect, NULL);
2970 else
2972 &texture_gl->t, sub_resource_idx, WINED3D_LOCATION_TEXTURE_SRGB, &src_rect,
2973 &texture_gl->t, sub_resource_idx, WINED3D_LOCATION_TEXTURE_RGB, &src_rect, NULL);
2974
2975 return TRUE;
2976 }
2977
2978 if (!depth && sub_resource->locations & (WINED3D_LOCATION_RB_MULTISAMPLE | WINED3D_LOCATION_RB_RESOLVED)
2979 && (!srgb || (texture_gl->t.resource.format_caps & WINED3D_FORMAT_CAP_FBO_ATTACHABLE_SRGB)))
2980 {
2981 DWORD src_location = sub_resource->locations & WINED3D_LOCATION_RB_RESOLVED ?
2983 RECT src_rect;
2984
2985 SetRect(&src_rect, src_box.left, src_box.top, src_box.right, src_box.bottom);
2988 &texture_gl->t.resource, src_location, &texture_gl->t.resource, dst_location))
2989 texture2d_blt_fbo(device, &context_gl->c, WINED3D_TEXF_POINT, &texture_gl->t, sub_resource_idx,
2990 src_location, &src_rect, &texture_gl->t, sub_resource_idx, dst_location, &src_rect, NULL);
2991
2992 return TRUE;
2993 }
2994
2995 /* Upload from system memory */
2996
2997 if (srgb)
2998 {
2999 dst_location = WINED3D_LOCATION_TEXTURE_SRGB;
3000 if ((sub_resource->locations & (WINED3D_LOCATION_TEXTURE_RGB | texture_gl->t.resource.map_binding))
3002 {
3003 FIXME_(d3d_perf)("Downloading RGB texture %p, %u to reload it as sRGB.\n", texture_gl, sub_resource_idx);
3004 wined3d_texture_load_location(&texture_gl->t, sub_resource_idx,
3005 &context_gl->c, texture_gl->t.resource.map_binding);
3006 }
3007 }
3008 else
3009 {
3010 dst_location = WINED3D_LOCATION_TEXTURE_RGB;
3011 if ((sub_resource->locations & (WINED3D_LOCATION_TEXTURE_SRGB | texture_gl->t.resource.map_binding))
3013 {
3014 FIXME_(d3d_perf)("Downloading sRGB texture %p, %u to reload it as RGB.\n", texture_gl, sub_resource_idx);
3015 wined3d_texture_load_location(&texture_gl->t, sub_resource_idx,
3016 &context_gl->c, texture_gl->t.resource.map_binding);
3017 }
3018 }
3019
3020 if (!(sub_resource->locations & wined3d_texture_sysmem_locations))
3021 {
3022 WARN("Trying to load a texture from sysmem, but no simple location is valid.\n");
3023 /* Lets hope we get it from somewhere... */
3024 wined3d_texture_load_location(&texture_gl->t, sub_resource_idx, &context_gl->c, WINED3D_LOCATION_SYSMEM);
3025 }
3026
3027 wined3d_texture_get_pitch(&texture_gl->t, level, &src_row_pitch, &src_slice_pitch);
3028
3029 format = texture_gl->t.resource.format;
3030 if ((conversion = wined3d_format_get_color_key_conversion(&texture_gl->t, TRUE)))
3031 format = wined3d_get_format(device->adapter, conversion->dst_format, texture_gl->t.resource.bind_flags);
3032
3033 /* Don't use PBOs for converted surfaces. During PBO conversion we look at
3034 * WINED3D_TEXTURE_CONVERTED but it isn't set (yet) in all cases it is
3035 * getting called. */
3036 if (conversion && sub_resource->bo)
3037 {
3038 TRACE("Removing the pbo attached to texture %p, %u.\n", texture_gl, sub_resource_idx);
3039
3040 wined3d_texture_load_location(&texture_gl->t, sub_resource_idx, &context_gl->c, WINED3D_LOCATION_SYSMEM);
3042 }
3043
3044 wined3d_texture_get_memory(&texture_gl->t, sub_resource_idx, &context_gl->c, &data);
3045 if (conversion)
3046 {
3047 width = src_box.right - src_box.left;
3048 height = src_box.bottom - src_box.top;
3049 wined3d_format_calculate_pitch(format, device->surface_alignment,
3050 width, height, &dst_row_pitch, &dst_slice_pitch);
3051
3052 src_mem = wined3d_context_gl_map_bo_address(context_gl, &data, src_slice_pitch, WINED3D_MAP_READ);
3053 if (!(dst_mem = malloc(dst_slice_pitch)))
3054 {
3055 ERR("Out of memory (%u).\n", dst_slice_pitch);
3056 return FALSE;
3057 }
3058 conversion->convert(src_mem, src_row_pitch, dst_mem, dst_row_pitch,
3059 width, height, &texture_gl->t.async.gl_color_key);
3060 src_row_pitch = dst_row_pitch;
3061 src_slice_pitch = dst_slice_pitch;
3063
3064 data.buffer_object = 0;
3065 data.addr = dst_mem;
3066 }
3067
3069 src_row_pitch, src_slice_pitch, &texture_gl->t, sub_resource_idx, dst_location, 0, 0, 0);
3070
3071 free(dst_mem);
3072
3073 return TRUE;
3074}
void wined3d_context_gl_unmap_bo_address(struct wined3d_context_gl *context_gl, const struct wined3d_bo_address *data, unsigned int range_count, const struct wined3d_range *ranges)
Definition: context_gl.c:2988
void * wined3d_context_gl_map_bo_address(struct wined3d_context_gl *context_gl, const struct wined3d_bo_address *data, size_t size, uint32_t flags)
Definition: context_gl.c:2932
static void wined3d_texture_gl_upload_data(struct wined3d_context *context, const struct wined3d_const_bo_address *src_bo_addr, const struct wined3d_format *src_format, const struct wined3d_box *src_box, unsigned int src_row_pitch, unsigned int src_slice_pitch, struct wined3d_texture *dst_texture, unsigned int dst_sub_resource_idx, unsigned int dst_location, unsigned int dst_x, unsigned int dst_y, unsigned int dst_z)
Definition: texture.c:2362
static void wined3d_texture_set_map_binding(struct wined3d_texture *texture, DWORD map_binding)
Definition: texture.c:959
static void wined3d_texture_get_memory(struct wined3d_texture *texture, unsigned int sub_resource_idx, struct wined3d_context *context, struct wined3d_bo_address *data)
Definition: texture.c:876
static const uint32_t wined3d_texture_sysmem_locations
Definition: texture.c:33
const struct wined3d_color_key_conversion * wined3d_format_get_color_key_conversion(const struct wined3d_texture *texture, BOOL need_alpha_ck)
Definition: utils.c:1293
#define FIXME_(x)
Definition: compat.h:77
enum wined3d_format_id dst_format
void(* convert)(const BYTE *src, unsigned int src_pitch, BYTE *dst, unsigned int dst_pitch, unsigned int width, unsigned int height, const struct wined3d_color_key *colour_key)

Referenced by wined3d_texture_gl_load_location().

◆ wined3d_texture_gl_prepare_buffer_object()

static void wined3d_texture_gl_prepare_buffer_object ( struct wined3d_texture_gl *  texture_gl,
unsigned int  sub_resource_idx,
struct wined3d_context_gl *  context_gl 
)
static

Definition at line 1987 of file texture.c.

1989{
1990 struct wined3d_texture_sub_resource *sub_resource;
1991 struct wined3d_bo_gl *bo;
1992
1993 sub_resource = &texture_gl->t.sub_resources[sub_resource_idx];
1994
1995 if (sub_resource->bo)
1996 return;
1997
1998 if (!(bo = malloc(sizeof(*bo))))
1999 return;
2000
2001 if (!wined3d_device_gl_create_bo(wined3d_device_gl(texture_gl->t.resource.device),
2002 context_gl, sub_resource->size, GL_PIXEL_UNPACK_BUFFER, GL_STREAM_DRAW, true,
2004 {
2005 free(bo);
2006 return;
2007 }
2008
2009 TRACE("Created buffer object %u for texture %p, sub-resource %u.\n", bo->id, texture_gl, sub_resource_idx);
2010 sub_resource->bo = &bo->b;
2011}
bool wined3d_device_gl_create_bo(struct wined3d_device_gl *device_gl, struct wined3d_context_gl *context_gl, GLsizeiptr size, GLenum binding, GLenum usage, bool coherent, GLbitfield flags, struct wined3d_bo_gl *bo)
Definition: device.c:1335
#define GL_MAP_READ_BIT
Definition: glext.h:1793
#define GL_MAP_WRITE_BIT
Definition: glext.h:1794
#define GL_STREAM_DRAW
Definition: glext.h:347
#define GL_CLIENT_STORAGE_BIT
Definition: wgl.h:399

Referenced by wined3d_texture_gl_prepare_location().

◆ wined3d_texture_gl_prepare_location()

static BOOL wined3d_texture_gl_prepare_location ( struct wined3d_texture *  texture,
unsigned int  sub_resource_idx,
struct wined3d_context *  context,
unsigned int  location 
)
static

Definition at line 3076 of file texture.c.

3078{
3079 struct wined3d_texture_gl *texture_gl = wined3d_texture_gl(texture);
3080 struct wined3d_context_gl *context_gl = wined3d_context_gl(context);
3081
3082 switch (location)
3083 {
3085 return texture->sub_resources[sub_resource_idx].user_memory ? TRUE
3087
3089 wined3d_texture_gl_prepare_buffer_object(texture_gl, sub_resource_idx, context_gl);
3090 return TRUE;
3091
3093 wined3d_texture_gl_prepare_texture(texture_gl, context_gl, FALSE);
3094 return TRUE;
3095
3097 wined3d_texture_gl_prepare_texture(texture_gl, context_gl, TRUE);
3098 return TRUE;
3099
3101 if (!texture->swapchain)
3102 ERR("Texture %p does not have a drawable.\n", texture);
3103 return TRUE;
3104
3106 wined3d_texture_gl_prepare_rb(texture_gl, context_gl->gl_info, TRUE);
3107 return TRUE;
3108
3110 wined3d_texture_gl_prepare_rb(texture_gl, context_gl->gl_info, FALSE);
3111 return TRUE;
3112
3113 default:
3114 ERR("Invalid location %s.\n", wined3d_debug_location(location));
3115 return FALSE;
3116 }
3117}
BOOL wined3d_resource_prepare_sysmem(struct wined3d_resource *resource)
Definition: resource.c:337
void wined3d_texture_gl_prepare_texture(struct wined3d_texture_gl *texture_gl, struct wined3d_context_gl *context_gl, BOOL srgb)
Definition: texture.c:2029
static void wined3d_texture_gl_prepare_buffer_object(struct wined3d_texture_gl *texture_gl, unsigned int sub_resource_idx, struct wined3d_context_gl *context_gl)
Definition: texture.c:1987
static void wined3d_texture_gl_prepare_rb(struct wined3d_texture_gl *texture_gl, const struct wined3d_gl_info *gl_info, BOOL multisample)
Definition: texture.c:2080

Referenced by wined3d_texture_gl_load_location().

◆ wined3d_texture_gl_prepare_rb()

static void wined3d_texture_gl_prepare_rb ( struct wined3d_texture_gl *  texture_gl,
const struct wined3d_gl_info *  gl_info,
BOOL  multisample 
)
static

Definition at line 2080 of file texture.c.

2082{
2083 const struct wined3d_format_gl *format_gl;
2084
2085 format_gl = wined3d_format_gl(texture_gl->t.resource.format);
2086 if (multisample)
2087 {
2088 DWORD samples;
2089
2090 if (texture_gl->rb_multisample)
2091 return;
2092
2093 samples = wined3d_resource_get_sample_count(&texture_gl->t.resource);
2094
2095 gl_info->fbo_ops.glGenRenderbuffers(1, &texture_gl->rb_multisample);
2096 gl_info->fbo_ops.glBindRenderbuffer(GL_RENDERBUFFER, texture_gl->rb_multisample);
2097 gl_info->fbo_ops.glRenderbufferStorageMultisample(GL_RENDERBUFFER, samples,
2098 format_gl->internal, texture_gl->t.resource.width, texture_gl->t.resource.height);
2099 checkGLcall("glRenderbufferStorageMultisample()");
2100 TRACE("Created multisample rb %u.\n", texture_gl->rb_multisample);
2101 }
2102 else
2103 {
2104 if (texture_gl->rb_resolved)
2105 return;
2106
2107 gl_info->fbo_ops.glGenRenderbuffers(1, &texture_gl->rb_resolved);
2108 gl_info->fbo_ops.glBindRenderbuffer(GL_RENDERBUFFER, texture_gl->rb_resolved);
2109 gl_info->fbo_ops.glRenderbufferStorage(GL_RENDERBUFFER, format_gl->internal,
2110 texture_gl->t.resource.width, texture_gl->t.resource.height);
2111 checkGLcall("glRenderbufferStorage()");
2112 TRACE("Created resolved rb %u.\n", texture_gl->rb_resolved);
2113 }
2114}
#define GL_RENDERBUFFER
Definition: glext.h:1733

Referenced by wined3d_texture_gl_prepare_location().

◆ wined3d_texture_gl_prepare_texture()

void wined3d_texture_gl_prepare_texture ( struct wined3d_texture_gl *  texture_gl,
struct wined3d_context_gl *  context_gl,
BOOL  srgb 
)

Definition at line 2029 of file texture.c.

2031{
2033 const struct wined3d_gl_info *gl_info = context_gl->gl_info;
2034 struct wined3d_resource *resource = &texture_gl->t.resource;
2035 const struct wined3d_device *device = resource->device;
2036 const struct wined3d_format *format = resource->format;
2037 const struct wined3d_color_key_conversion *conversion;
2038 const struct wined3d_format_gl *format_gl;
2040
2041 TRACE("texture_gl %p, context_gl %p, srgb %d, format %s.\n",
2042 texture_gl, context_gl, srgb, debug_d3dformat(format->id));
2043
2044 if (texture_gl->t.flags & alloc_flag)
2045 return;
2046
2047 if (resource->format_caps & WINED3D_FORMAT_CAP_DECOMPRESS)
2048 {
2049 TRACE("WINED3D_FORMAT_CAP_DECOMPRESS set.\n");
2050 texture_gl->t.flags |= WINED3D_TEXTURE_CONVERTED;
2052 }
2053 else if (format->conv_byte_count)
2054 {
2055 texture_gl->t.flags |= WINED3D_TEXTURE_CONVERTED;
2056 }
2057 else if ((conversion = wined3d_format_get_color_key_conversion(&texture_gl->t, TRUE)))
2058 {
2059 texture_gl->t.flags |= WINED3D_TEXTURE_CONVERTED;
2060 format = wined3d_get_format(device->adapter, conversion->dst_format, resource->bind_flags);
2061 TRACE("Using format %s for color key conversion.\n", debug_d3dformat(format->id));
2062 }
2063 format_gl = wined3d_format_gl(format);
2064
2065 wined3d_texture_gl_bind_and_dirtify(texture_gl, context_gl, srgb);
2066
2068 if (!internal)
2069 FIXME("No GL internal format for format %s.\n", debug_d3dformat(format->id));
2070
2071 TRACE("internal %#x, format %#x, type %#x.\n", internal, format_gl->format, format_gl->type);
2072
2073 if (wined3d_texture_use_immutable_storage(&texture_gl->t, gl_info))
2075 else
2076 wined3d_texture_gl_allocate_mutable_storage(texture_gl, internal, format_gl, gl_info);
2077 texture_gl->t.flags |= alloc_flag;
2078}
ios_base &_STLP_CALL internal(ios_base &__s)
Definition: _ios_base.h:311
const struct wined3d_format * wined3d_resource_get_decompress_format(const struct wined3d_resource *resource)
Definition: resource.c:447
static BOOL wined3d_texture_use_immutable_storage(const struct wined3d_texture *texture, const struct wined3d_gl_info *gl_info)
Definition: texture.c:78
static void wined3d_texture_gl_allocate_immutable_storage(struct wined3d_texture_gl *texture_gl, GLenum gl_internal_format, const struct wined3d_gl_info *gl_info)
Definition: texture.c:1037
static void wined3d_texture_gl_allocate_mutable_storage(struct wined3d_texture_gl *texture_gl, GLenum gl_internal_format, const struct wined3d_format_gl *format, const struct wined3d_gl_info *gl_info)
Definition: texture.c:977
#define WINED3D_FORMAT_CAP_DECOMPRESS

Referenced by create_texture_view(), and wined3d_texture_gl_prepare_location().

◆ wined3d_texture_gl_set_compatible_renderbuffer()

void wined3d_texture_gl_set_compatible_renderbuffer ( struct wined3d_texture_gl *  texture_gl,
struct wined3d_context_gl *  context_gl,
unsigned int  level,
const struct wined3d_rendertarget_info *  rt 
)

Definition at line 1788 of file texture.c.

1790{
1791 const struct wined3d_gl_info *gl_info = context_gl->gl_info;
1793 unsigned int src_width, src_height;
1794 unsigned int width, height;
1795 GLuint renderbuffer = 0;
1796
1797 if (gl_info->supported[ARB_FRAMEBUFFER_OBJECT])
1798 return;
1799
1800 if (rt && rt->resource->format->id != WINED3DFMT_NULL)
1801 {
1802 struct wined3d_texture *rt_texture;
1803 unsigned int rt_level;
1804
1805 if (rt->resource->type == WINED3D_RTYPE_BUFFER)
1806 {
1807 FIXME("Unsupported resource type %s.\n", debug_d3dresourcetype(rt->resource->type));
1808 return;
1809 }
1810 rt_texture = wined3d_texture_from_resource(rt->resource);
1811 rt_level = rt->sub_resource_idx % rt_texture->level_count;
1812
1813 width = wined3d_texture_get_level_width(rt_texture, rt_level);
1814 height = wined3d_texture_get_level_height(rt_texture, rt_level);
1815 }
1816 else
1817 {
1820 }
1821
1822 src_width = wined3d_texture_get_level_width(&texture_gl->t, level);
1823 src_height = wined3d_texture_get_level_height(&texture_gl->t, level);
1824
1825 /* A depth stencil smaller than the render target is not valid */
1826 if (width > src_width || height > src_height)
1827 return;
1828
1829 /* Remove any renderbuffer set if the sizes match */
1830 if (width == src_width && height == src_height)
1831 {
1832 texture_gl->current_renderbuffer = NULL;
1833 return;
1834 }
1835
1836 /* Look if we've already got a renderbuffer of the correct dimensions */
1838 {
1839 if (entry->width == width && entry->height == height)
1840 {
1841 renderbuffer = entry->id;
1842 texture_gl->current_renderbuffer = entry;
1843 break;
1844 }
1845 }
1846
1847 if (!renderbuffer)
1848 {
1849 const struct wined3d_format_gl *format_gl;
1850
1851 format_gl = wined3d_format_gl(texture_gl->t.resource.format);
1852 gl_info->fbo_ops.glGenRenderbuffers(1, &renderbuffer);
1853 gl_info->fbo_ops.glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
1854 gl_info->fbo_ops.glRenderbufferStorage(GL_RENDERBUFFER, format_gl->internal, width, height);
1855
1856 entry = malloc(sizeof(*entry));
1857 entry->width = width;
1858 entry->height = height;
1859 entry->id = renderbuffer;
1860 list_add_head(&texture_gl->renderbuffers, &entry->entry);
1861
1862 texture_gl->current_renderbuffer = entry;
1863 }
1864
1865 checkGLcall("set compatible renderbuffer");
1866}
static void list_add_head(struct list_entry *head, struct list_entry *entry)
Definition: list.h:76
struct wined3d_texture *__cdecl wined3d_texture_from_resource(struct wined3d_resource *resource)
Definition: texture.c:3343
GLuint renderbuffer
Definition: glext.h:6989
#define LIST_FOR_EACH_ENTRY(elem, list, type, field)
Definition: list.h:236
Definition: wined3d_gl.h:933
unsigned int sub_resource_idx
Definition: wined3d_gl.h:563
struct wined3d_resource * resource
Definition: wined3d_gl.h:562
const struct wined3d_renderbuffer_entry * current_renderbuffer
Definition: wined3d_gl.h:951
@ ARB_FRAMEBUFFER_OBJECT
Definition: wined3d_gl.h:84

Referenced by wined3d_context_gl_find_fbo_entry().

◆ wined3d_texture_gl_unload_location()

static void wined3d_texture_gl_unload_location ( struct wined3d_texture *  texture,
struct wined3d_context *  context,
unsigned int  location 
)
static

Definition at line 3266 of file texture.c.

3268{
3269 struct wined3d_texture_gl *texture_gl = wined3d_texture_gl(texture);
3270 struct wined3d_context_gl *context_gl = wined3d_context_gl(context);
3271 struct wined3d_renderbuffer_entry *entry, *entry2;
3272 unsigned int i, sub_count;
3273
3274 TRACE("texture %p, context %p, location %s.\n", texture, context, wined3d_debug_location(location));
3275
3276 switch (location)
3277 {
3279 sub_count = texture->level_count * texture->layer_count;
3280 for (i = 0; i < sub_count; ++i)
3281 {
3282 if (texture_gl->t.sub_resources[i].bo)
3283 wined3d_texture_remove_buffer_object(&texture_gl->t, i, context_gl);
3284 }
3285 break;
3286
3288 if (texture_gl->texture_rgb.name)
3289 gltexture_delete(texture_gl->t.resource.device, context_gl->gl_info, &texture_gl->texture_rgb);
3290 break;
3291
3293 if (texture_gl->texture_srgb.name)
3294 gltexture_delete(texture_gl->t.resource.device, context_gl->gl_info, &texture_gl->texture_srgb);
3295 break;
3296
3298 if (texture_gl->rb_multisample)
3299 {
3300 TRACE("Deleting multisample renderbuffer %u.\n", texture_gl->rb_multisample);
3301 context_gl_resource_released(texture_gl->t.resource.device, texture_gl->rb_multisample, TRUE);
3302 context_gl->gl_info->fbo_ops.glDeleteRenderbuffers(1, &texture_gl->rb_multisample);
3303 texture_gl->rb_multisample = 0;
3304 }
3305 break;
3306
3308 LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, &texture_gl->renderbuffers,
3310 {
3311 context_gl_resource_released(texture_gl->t.resource.device, entry->id, TRUE);
3312 context_gl->gl_info->fbo_ops.glDeleteRenderbuffers(1, &entry->id);
3313 list_remove(&entry->entry);
3314 free(entry);
3315 }
3316 list_init(&texture_gl->renderbuffers);
3317 texture_gl->current_renderbuffer = NULL;
3318
3319 if (texture_gl->rb_resolved)
3320 {
3321 TRACE("Deleting resolved renderbuffer %u.\n", texture_gl->rb_resolved);
3322 context_gl_resource_released(texture_gl->t.resource.device, texture_gl->rb_resolved, TRUE);
3323 context_gl->gl_info->fbo_ops.glDeleteRenderbuffers(1, &texture_gl->rb_resolved);
3324 texture_gl->rb_resolved = 0;
3325 }
3326 break;
3327
3328 default:
3329 ERR("Unhandled location %s.\n", wined3d_debug_location(location));
3330 break;
3331 }
3332}
static void wined3d_texture_remove_buffer_object(struct wined3d_texture *texture, unsigned int sub_resource_idx, struct wined3d_context_gl *context_gl)
Definition: texture.c:913
static void gltexture_delete(struct wined3d_device *device, const struct wined3d_gl_info *gl_info, struct gl_texture *tex)
Definition: texture.c:967
struct gl_texture texture_rgb texture_srgb
Definition: wined3d_gl.h:943

◆ wined3d_texture_gl_upload_bo()

static void wined3d_texture_gl_upload_bo ( const struct wined3d_format *  src_format,
GLenum  target,
unsigned int  level,
unsigned int  src_row_pitch,
unsigned int  src_slice_pitch,
unsigned int  dst_x,
unsigned int  dst_y,
unsigned int  dst_z,
unsigned int  update_w,
unsigned int  update_h,
unsigned int  update_d,
const BYTE *  addr,
BOOL  srgb,
struct wined3d_texture *  dst_texture,
const struct wined3d_gl_info *  gl_info 
)
static

Definition at line 2155 of file texture.c.

2160{
2161 const struct wined3d_format_gl *format_gl = wined3d_format_gl(src_format);
2162
2163 if (src_format->attrs & WINED3D_FORMAT_ATTR_COMPRESSED)
2164 {
2165 GLenum internal = wined3d_gl_get_internal_format(&dst_texture->resource, format_gl, srgb);
2166 unsigned int dst_row_pitch, dst_slice_pitch;
2167
2168 wined3d_format_calculate_pitch(src_format, 1, update_w, update_h, &dst_row_pitch, &dst_slice_pitch);
2169
2170 TRACE("Uploading compressed data, target %#x, level %u, x %u, y %u, z %u, "
2171 "w %u, h %u, d %u, format %#x, image_size %#x, addr %p.\n",
2172 target, level, dst_x, dst_y, dst_z, update_w, update_h,
2173 update_d, internal, dst_slice_pitch, addr);
2174
2175 if (target == GL_TEXTURE_1D)
2176 {
2178 update_w, internal, dst_row_pitch, addr));
2179 }
2180 else
2181 {
2182 unsigned int row, y, slice, slice_count = 1, row_count = 1;
2183
2184 /* glCompressedTexSubImage2D() ignores pixel store state, so we
2185 * can't use the unpack row length like for glTexSubImage2D. */
2186 if (dst_row_pitch != src_row_pitch)
2187 {
2188 row_count = (update_h + src_format->block_height - 1) / src_format->block_height;
2189 update_h = src_format->block_height;
2190 wined3d_format_calculate_pitch(src_format, 1, update_w, update_h,
2191 &dst_row_pitch, &dst_slice_pitch);
2192 }
2193
2194 if (dst_slice_pitch != src_slice_pitch)
2195 {
2196 slice_count = update_d;
2197 update_d = 1;
2198 }
2199
2200 for (slice = 0; slice < slice_count; ++slice)
2201 {
2202 for (row = 0, y = dst_y; row < row_count; ++row)
2203 {
2204 const BYTE *upload_addr = &addr[slice * src_slice_pitch + row * src_row_pitch];
2205
2207 {
2208 GL_EXTCALL(glCompressedTexSubImage3D(target, level, dst_x, y, dst_z + slice, update_w,
2209 update_h, update_d, internal, update_d * dst_slice_pitch, upload_addr));
2210 }
2211 else
2212 {
2214 update_h, internal, dst_slice_pitch, upload_addr));
2215 }
2216
2217 y += src_format->block_height;
2218 }
2219 }
2220 }
2221 checkGLcall("Upload compressed texture data");
2222 }
2223 else
2224 {
2225 unsigned int y, y_count, z, z_count;
2226 bool unpacking_rows = false;
2227
2228 TRACE("Uploading data, target %#x, level %u, x %u, y %u, z %u, "
2229 "w %u, h %u, d %u, format %#x, type %#x, addr %p.\n",
2230 target, level, dst_x, dst_y, dst_z, update_w, update_h,
2231 update_d, format_gl->format, format_gl->type, addr);
2232
2233 if (src_row_pitch && !(src_row_pitch % src_format->byte_count))
2234 {
2235 gl_info->gl_ops.gl.p_glPixelStorei(GL_UNPACK_ROW_LENGTH, src_row_pitch / src_format->byte_count);
2236 y_count = 1;
2237 unpacking_rows = true;
2238 }
2239 else
2240 {
2241 y_count = update_h;
2242 update_h = 1;
2243 }
2244
2245 if (src_slice_pitch && unpacking_rows && !(src_slice_pitch % src_row_pitch))
2246 {
2247 gl_info->gl_ops.gl.p_glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, src_slice_pitch / src_row_pitch);
2248 z_count = 1;
2249 }
2250 else if (src_slice_pitch && !unpacking_rows && !(src_slice_pitch % (update_w * src_format->byte_count)))
2251 {
2252 gl_info->gl_ops.gl.p_glPixelStorei(GL_UNPACK_IMAGE_HEIGHT,
2253 src_slice_pitch / (update_w * src_format->byte_count));
2254 z_count = 1;
2255 }
2256 else
2257 {
2258 z_count = update_d;
2259 update_d = 1;
2260 }
2261
2262 for (z = 0; z < z_count; ++z)
2263 {
2264 for (y = 0; y < y_count; ++y)
2265 {
2266 const BYTE *upload_addr = &addr[z * src_slice_pitch + y * src_row_pitch];
2268 {
2269 GL_EXTCALL(glTexSubImage3D(target, level, dst_x, dst_y + y, dst_z + z, update_w,
2270 update_h, update_d, format_gl->format, format_gl->type, upload_addr));
2271 }
2272 else if (target == GL_TEXTURE_1D)
2273 {
2274 gl_info->gl_ops.gl.p_glTexSubImage1D(target, level, dst_x,
2275 update_w, format_gl->format, format_gl->type, upload_addr);
2276 }
2277 else
2278 {
2279 gl_info->gl_ops.gl.p_glTexSubImage2D(target, level, dst_x, dst_y + y,
2280 update_w, update_h, format_gl->format, format_gl->type, upload_addr);
2281 }
2282 }
2283 }
2284 gl_info->gl_ops.gl.p_glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
2285 gl_info->gl_ops.gl.p_glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, 0);
2286 checkGLcall("Upload texture data");
2287 }
2288}
struct png_info_def *typedef unsigned char **typedef struct png_info_def *typedef struct png_info_def *typedef struct png_info_def *typedef unsigned char ** row
Definition: typeof.h:78
GLAPI void GLAPIENTRY glCompressedTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data)
GLAPI void GLAPIENTRY glCompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data)
#define GL_UNPACK_IMAGE_HEIGHT
Definition: gl.h:1514
GLAPI void GLAPIENTRY glCompressedTexSubImage1D(GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const GLvoid *data)
GLAPI void GLAPIENTRY glTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels)
#define GL_UNPACK_ROW_LENGTH
Definition: gl.h:634
GLdouble GLdouble z
Definition: glext.h:5874
unsigned int attrs

Referenced by wined3d_texture_gl_upload_data().

◆ wined3d_texture_gl_upload_data()

static void wined3d_texture_gl_upload_data ( struct wined3d_context *  context,
const struct wined3d_const_bo_address *  src_bo_addr,
const struct wined3d_format *  src_format,
const struct wined3d_box *  src_box,
unsigned int  src_row_pitch,
unsigned int  src_slice_pitch,
struct wined3d_texture *  dst_texture,
unsigned int  dst_sub_resource_idx,
unsigned int  dst_location,
unsigned int  dst_x,
unsigned int  dst_y,
unsigned int  dst_z 
)
static

Definition at line 2362 of file texture.c.

2367{
2368 struct wined3d_context_gl *context_gl = wined3d_context_gl(context);
2369 enum wined3d_format_id alpha_fixup_format_id = WINED3DFMT_UNKNOWN;
2370 const struct wined3d_gl_info *gl_info = context_gl->gl_info;
2371 unsigned int update_w = src_box->right - src_box->left;
2372 unsigned int update_h = src_box->bottom - src_box->top;
2373 unsigned int update_d = src_box->back - src_box->front;
2374 struct wined3d_bo_address bo;
2375 unsigned int level;
2376 BOOL srgb = FALSE;
2377 BOOL decompress;
2378 GLenum target;
2379
2380 TRACE("context %p, src_bo_addr %s, src_format %s, src_box %s, src_row_pitch %u, src_slice_pitch %u, "
2381 "dst_texture %p, dst_sub_resource_idx %u, dst_location %s, dst_x %u, dst_y %u, dst_z %u.\n",
2382 context, debug_const_bo_address(src_bo_addr), debug_d3dformat(src_format->id), debug_box(src_box),
2383 src_row_pitch, src_slice_pitch, dst_texture, dst_sub_resource_idx,
2384 wined3d_debug_location(dst_location), dst_x, dst_y, dst_z);
2385
2386 if (dst_location == WINED3D_LOCATION_TEXTURE_SRGB)
2387 {
2388 srgb = TRUE;
2389 }
2390 else if (dst_location != WINED3D_LOCATION_TEXTURE_RGB)
2391 {
2392 FIXME("Unhandled location %s.\n", wined3d_debug_location(dst_location));
2393 return;
2394 }
2395
2397
2398 if (dst_texture->sub_resources[dst_sub_resource_idx].map_count)
2399 {
2400 WARN("Uploading a texture that is currently mapped, pinning sysmem.\n");
2401 dst_texture->resource.pin_sysmem = 1;
2402 }
2403
2404 if (src_format->attrs & WINED3D_FORMAT_ATTR_HEIGHT_SCALE)
2405 {
2406 update_h *= src_format->height_scale.numerator;
2407 update_h /= src_format->height_scale.denominator;
2408 }
2409
2410 target = wined3d_texture_gl_get_sub_resource_target(wined3d_texture_gl(dst_texture), dst_sub_resource_idx);
2411 level = dst_sub_resource_idx % dst_texture->level_count;
2412
2413 switch (target)
2414 {
2416 dst_y = dst_sub_resource_idx / dst_texture->level_count;
2417 update_h = 1;
2418 break;
2420 dst_z = dst_sub_resource_idx / dst_texture->level_count;
2421 update_d = 1;
2422 break;
2425 FIXME("Not supported for multisample textures.\n");
2426 return;
2427 }
2428
2429 bo.buffer_object = src_bo_addr->buffer_object;
2430 bo.addr = (BYTE *)src_bo_addr->addr + src_box->front * src_slice_pitch;
2431 if (dst_texture->resource.format_attrs & WINED3D_FORMAT_ATTR_BLOCKS)
2432 {
2433 bo.addr += (src_box->top / src_format->block_height) * src_row_pitch;
2434 bo.addr += (src_box->left / src_format->block_width) * src_format->block_byte_count;
2435 }
2436 else
2437 {
2438 bo.addr += src_box->top * src_row_pitch;
2439 bo.addr += src_box->left * src_format->byte_count;
2440 }
2441
2442 decompress = (dst_texture->resource.format_caps & WINED3D_FORMAT_CAP_DECOMPRESS)
2443 || (src_format->decompress && src_format->id != dst_texture->resource.format->id);
2444
2445 if (src_format->upload || decompress
2446 || (alpha_fixup_format_id = wined3d_get_alpha_fixup_format(src_format->id,
2447 dst_texture->resource.format)) != WINED3DFMT_UNKNOWN)
2448 {
2449 const struct wined3d_format *compressed_format = src_format;
2450 unsigned int dst_row_pitch, dst_slice_pitch;
2451 struct wined3d_format_gl f;
2452 void *converted_mem;
2453 unsigned int z;
2454 BYTE *src_mem;
2455
2456 if (decompress)
2457 {
2458 src_format = wined3d_resource_get_decompress_format(&dst_texture->resource);
2459 }
2460 else if (alpha_fixup_format_id != WINED3DFMT_UNKNOWN)
2461 {
2462 src_format = wined3d_get_format(context->device->adapter, alpha_fixup_format_id, 0);
2463 assert(!!src_format);
2464 }
2465 else
2466 {
2467 if (dst_texture->resource.format_attrs & WINED3D_FORMAT_ATTR_BLOCKS)
2468 ERR("Converting a block-based format.\n");
2469
2470 f = *wined3d_format_gl(src_format);
2471 f.f.byte_count = src_format->conv_byte_count;
2472 src_format = &f.f;
2473 }
2474
2475 wined3d_format_calculate_pitch(src_format, 1, update_w, update_h, &dst_row_pitch, &dst_slice_pitch);
2476
2477 if (!(converted_mem = malloc(dst_slice_pitch)))
2478 {
2479 ERR("Failed to allocate upload buffer.\n");
2480 return;
2481 }
2482
2483 src_mem = wined3d_context_gl_map_bo_address(context_gl, &bo, src_slice_pitch * update_d, WINED3D_MAP_READ);
2484
2485 GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0));
2486 checkGLcall("glBindBuffer");
2487
2488 for (z = 0; z < update_d; ++z, src_mem += src_slice_pitch)
2489 {
2490 if (decompress)
2491 compressed_format->decompress(src_mem, converted_mem, src_row_pitch, src_slice_pitch,
2492 dst_row_pitch, dst_slice_pitch, update_w, update_h, 1);
2493 else if (alpha_fixup_format_id != WINED3DFMT_UNKNOWN)
2494 wined3d_fixup_alpha(src_format, src_mem, src_row_pitch, converted_mem, dst_row_pitch,
2495 update_w, update_h);
2496 else
2497 src_format->upload(src_mem, converted_mem, src_row_pitch, src_slice_pitch,
2498 dst_row_pitch, dst_slice_pitch, update_w, update_h, 1);
2499
2500 wined3d_texture_gl_upload_bo(src_format, target, level, dst_row_pitch, dst_slice_pitch, dst_x,
2501 dst_y, dst_z + z, update_w, update_h, 1, converted_mem, srgb, dst_texture, gl_info);
2502 }
2503
2504 wined3d_context_gl_unmap_bo_address(context_gl, &bo, 0, NULL);
2505 free(converted_mem);
2506 }
2507 else
2508 {
2509 const uint8_t *offset = bo.addr;
2510
2511 if (bo.buffer_object)
2512 {
2513 GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, wined3d_bo_gl(bo.buffer_object)->id));
2514 checkGLcall("glBindBuffer");
2515 offset += bo.buffer_object->buffer_offset;
2516 }
2517 else
2518 {
2519 GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0));
2520 checkGLcall("glBindBuffer");
2521 }
2522
2523 wined3d_texture_gl_upload_bo(src_format, target, level, src_row_pitch, src_slice_pitch, dst_x,
2524 dst_y, dst_z, update_w, update_h, update_d, offset, srgb, dst_texture, gl_info);
2525
2526 if (bo.buffer_object)
2527 {
2528 GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0));
2529 wined3d_context_gl_reference_bo(context_gl, wined3d_bo_gl(bo.buffer_object));
2530 checkGLcall("glBindBuffer");
2531 }
2532 }
2533
2534 if (gl_info->quirks & WINED3D_QUIRK_FBO_TEX_UPDATE)
2535 {
2536 struct wined3d_device *device = dst_texture->resource.device;
2537 unsigned int i;
2538
2539 for (i = 0; i < device->context_count; ++i)
2540 {
2542 }
2543 }
2544}
void wined3d_context_gl_texture_update(struct wined3d_context_gl *context_gl, const struct wined3d_texture_gl *texture_gl)
Definition: context_gl.c:1143
static enum wined3d_format_id wined3d_get_alpha_fixup_format(enum wined3d_format_id format_id, const struct wined3d_format *dst_format)
Definition: texture.c:2301
static void wined3d_fixup_alpha(const struct wined3d_format *format, const uint8_t *src, unsigned int src_row_pitch, uint8_t *dst, unsigned int dst_row_pitch, unsigned int width, unsigned int height)
Definition: texture.c:2318
static void wined3d_texture_gl_upload_bo(const struct wined3d_format *src_format, GLenum target, unsigned int level, unsigned int src_row_pitch, unsigned int src_slice_pitch, unsigned int dst_x, unsigned int dst_y, unsigned int dst_z, unsigned int update_w, unsigned int update_h, unsigned int update_d, const BYTE *addr, BOOL srgb, struct wined3d_texture *dst_texture, const struct wined3d_gl_info *gl_info)
Definition: texture.c:2155
const char * debug_const_bo_address(const struct wined3d_const_bo_address *address)
Definition: utils.c:4593
if(dx< 0)
Definition: linetemp.h:194
struct wined3d_bo * buffer_object
struct wined3d_rational height_scale
void(* upload)(const BYTE *src, BYTE *dst, unsigned int src_row_pitch, unsigned int src_slice_pitch, unsigned int dst_row_pitch, unsigned dst_slice_pitch, unsigned int width, unsigned int height, unsigned int depth)
void(* decompress)(const BYTE *src, BYTE *dst, unsigned int src_row_pitch, unsigned int src_slice_pitch, unsigned int dst_row_pitch, unsigned dst_slice_pitch, unsigned int width, unsigned int height, unsigned int depth)
uint32_t quirks
Definition: wined3d_gl.h:346
#define WINED3D_QUIRK_FBO_TEX_UPDATE
Definition: wined3d_gl.h:326
#define WINED3D_FORMAT_ATTR_BLOCKS

Referenced by wined3d_texture_gl_load_texture().

◆ wined3d_texture_incref()

ULONG CDECL wined3d_texture_incref ( struct wined3d_texture *  texture)

Definition at line 1516 of file texture.c.

1517{
1518 unsigned int refcount;
1519
1520 TRACE("texture %p, swapchain %p.\n", texture, texture->swapchain);
1521
1522 refcount = InterlockedIncrement(&texture->resource.ref);
1523 TRACE("%p increasing refcount to %u.\n", texture, refcount);
1524
1525 return refcount;
1526}
#define InterlockedIncrement
Definition: armddk.h:53

Referenced by d3d11_texture1d_AddRef(), d3d11_texture2d_AddRef(), d3d11_texture3d_AddRef(), d3d8_surface_AddRef(), d3d8_texture_incref(), d3d9_surface_AddRef(), d3d9_texture_incref(), d3d_texture2d_create(), ddraw_surface_add_iface(), ddraw_surface_init(), ddraw_texture_init(), texture_resource_incref(), wined3d_cs_packet_incref_objects(), wined3d_stateblock_capture(), and wined3d_stateblock_set_texture().

◆ wined3d_texture_init()

static HRESULT wined3d_texture_init ( struct wined3d_texture *  texture,
const struct wined3d_resource_desc *  desc,
unsigned int  layer_count,
unsigned int  level_count,
uint32_t  flags,
struct wined3d_device *  device,
void *  parent,
const struct wined3d_parent_ops *  parent_ops,
void *  sub_resources,
const struct wined3d_texture_ops *  texture_ops 
)
static

Definition at line 3620 of file texture.c.

3624{
3625 const struct wined3d_d3d_info *d3d_info = &device->adapter->d3d_info;
3626 struct wined3d_device_parent *device_parent = device->device_parent;
3627 unsigned int sub_count, i, j, size, offset = 0;
3628 const struct wined3d_format *format;
3629 HRESULT hr;
3630
3631 TRACE("texture %p, resource_type %s, format %s, multisample_type %#x, multisample_quality %#x, "
3632 "usage %s, bind_flags %s, access %s, width %u, height %u, depth %u, layer_count %u, level_count %u, "
3633 "flags %#x, device %p, parent %p, parent_ops %p, sub_resources %p, texture_ops %p.\n",
3634 texture, debug_d3dresourcetype(desc->resource_type), debug_d3dformat(desc->format), desc->multisample_type,
3635 desc->multisample_quality, debug_d3dusage(desc->usage), wined3d_debug_bind_flags(desc->bind_flags),
3636 wined3d_debug_resource_access(desc->access), desc->width, desc->height, desc->depth,
3637 layer_count, level_count, flags, device, parent, parent_ops, sub_resources, texture_ops);
3638
3639 if (!desc->width || !desc->height || !desc->depth)
3641
3642 if (desc->resource_type == WINED3D_RTYPE_TEXTURE_3D && layer_count != 1)
3643 {
3644 ERR("Invalid layer count for volume texture.\n");
3645 return E_INVALIDARG;
3646 }
3647
3648 texture->sub_resources = sub_resources;
3649
3650 /* TODO: It should only be possible to create textures for formats
3651 * that are reported as supported. */
3652 if (WINED3DFMT_UNKNOWN >= desc->format)
3653 {
3654 WARN("Texture cannot be created with a format of WINED3DFMT_UNKNOWN.\n");
3656 }
3657 format = wined3d_get_format(device->adapter, desc->format, desc->bind_flags);
3658
3660 {
3661 WARN("Attempted to create a dynamic texture with usage %s.\n", debug_d3dusage(desc->usage));
3663 }
3664
3665 if (((desc->width & (desc->width - 1)) || (desc->height & (desc->height - 1)) || (desc->depth & (desc->depth - 1)))
3666 && !d3d_info->unconditional_npot)
3667 {
3668 /* level_count == 0 returns an error as well. */
3669 if (level_count != 1 || layer_count != 1 || desc->resource_type == WINED3D_RTYPE_TEXTURE_3D)
3670 {
3671 if (!(desc->usage & WINED3DUSAGE_SCRATCH))
3672 {
3673 WARN("Attempted to create a mipmapped/cube/array/volume NPOT "
3674 "texture without unconditional NPOT support.\n");
3676 }
3677
3678 WARN("Creating a scratch mipmapped/cube/array NPOT texture despite lack of HW support.\n");
3679 }
3681 }
3682
3683 if ((desc->width > d3d_info->limits.texture_size || desc->height > d3d_info->limits.texture_size)
3684 && (desc->bind_flags & WINED3D_BIND_SHADER_RESOURCE))
3685 {
3686 /* One of four options:
3687 * 1: Scale the texture. (Any texture ops would require the texture to
3688 * be scaled which is potentially slow.)
3689 * 2: Set the texture to the maximum size (bad idea).
3690 * 3: WARN and return WINED3DERR_NOTAVAILABLE.
3691 * 4: Create the surface, but allow it to be used only for DirectDraw
3692 * Blts. Some apps (e.g. Swat 3) create textures with a height of
3693 * 16 and a width > 3000 and blt 16x16 letter areas from them to
3694 * the render target. */
3695 if (desc->access & WINED3D_RESOURCE_ACCESS_GPU)
3696 {
3697 WARN("Dimensions (%ux%u) exceed the maximum texture size.\n", desc->width, desc->height);
3699 }
3700
3701 /* We should never use this surface in combination with OpenGL. */
3702 TRACE("Creating an oversized (%ux%u) surface.\n", desc->width, desc->height);
3703 }
3704
3705 for (i = 0; i < layer_count; ++i)
3706 {
3707 for (j = 0; j < level_count; ++j)
3708 {
3709 unsigned int idx = i * level_count + j;
3710
3711 size = wined3d_format_calculate_size(format, device->surface_alignment,
3712 max(1, desc->width >> j), max(1, desc->height >> j), max(1, desc->depth >> j));
3713 texture->sub_resources[idx].offset = offset;
3714 texture->sub_resources[idx].size = size;
3715 offset += size;
3716 }
3718 }
3719
3720 if (!offset)
3722
3723 /* Ensure the last mip-level is at least large enough to hold a single
3724 * compressed block. It is questionable how useful these mip-levels are to
3725 * the application with "broken pitch" formats, but we want to avoid
3726 * memory corruption when loading textures into WINED3D_LOCATION_SYSMEM. */
3728 {
3729 unsigned int min_size;
3730
3731 min_size = texture->sub_resources[level_count * layer_count - 1].offset + format->block_byte_count;
3732 min_size = (min_size + (RESOURCE_ALIGNMENT - 1)) & ~(RESOURCE_ALIGNMENT - 1);
3733 if (min_size > offset)
3734 offset = min_size;
3735 }
3736
3737 if (FAILED(hr = resource_init(&texture->resource, device, desc->resource_type, format,
3738 desc->multisample_type, desc->multisample_quality, desc->usage, desc->bind_flags, desc->access,
3739 desc->width, desc->height, desc->depth, offset, parent, parent_ops, &texture_resource_ops)))
3740 {
3741 static unsigned int once;
3742
3743 /* DXTn 3D textures are not supported. Do not write the ERR for them. */
3744 if ((desc->format == WINED3DFMT_DXT1 || desc->format == WINED3DFMT_DXT2 || desc->format == WINED3DFMT_DXT3
3745 || desc->format == WINED3DFMT_DXT4 || desc->format == WINED3DFMT_DXT5)
3747 && desc->resource_type != WINED3D_RTYPE_TEXTURE_3D && !once++)
3748 ERR_(winediag)("The application tried to create a DXTn texture, but the driver does not support them.\n");
3749
3750 WARN("Failed to initialize resource, returning %#lx\n", hr);
3751 return hr;
3752 }
3754
3755 texture->texture_ops = texture_ops;
3756
3757 texture->layer_count = layer_count;
3758 texture->level_count = level_count;
3759 texture->lod = 0;
3762 {
3764 texture->resource.pin_sysmem = 1;
3765 }
3771 {
3772 if (!(texture->resource.format_caps & WINED3D_FORMAT_CAP_GEN_MIPMAP))
3773 WARN("Format doesn't support mipmaps generation, "
3774 "ignoring WINED3D_TEXTURE_CREATE_GENERATE_MIPMAPS flag.\n");
3775 else
3777 }
3778
3780 {
3781 if (!(texture->dirty_regions = calloc(texture->layer_count, sizeof(*texture->dirty_regions))))
3782 {
3784 return E_OUTOFMEMORY;
3785 }
3786 for (i = 0; i < texture->layer_count; ++i)
3788 }
3789
3790 if (wined3d_texture_use_pbo(texture, d3d_info))
3791 texture->resource.map_binding = WINED3D_LOCATION_BUFFER;
3792
3793 sub_count = level_count * layer_count;
3794 if (sub_count / layer_count != level_count)
3795 {
3797 return E_OUTOFMEMORY;
3798 }
3799
3800 if (desc->usage & WINED3DUSAGE_OVERLAY)
3801 {
3802 if (!(texture->overlay_info = calloc(sub_count, sizeof(*texture->overlay_info))))
3803 {
3805 return E_OUTOFMEMORY;
3806 }
3807
3808 for (i = 0; i < sub_count; ++i)
3809 {
3810 list_init(&texture->overlay_info[i].entry);
3811 list_init(&texture->overlay_info[i].overlays);
3812 }
3813 }
3814
3815 /* Generate all sub-resources. */
3816 for (i = 0; i < sub_count; ++i)
3817 {
3818 struct wined3d_texture_sub_resource *sub_resource;
3819
3820 sub_resource = &texture->sub_resources[i];
3821 sub_resource->locations = WINED3D_LOCATION_CLEARED;
3822
3823 if (FAILED(hr = device_parent->ops->texture_sub_resource_created(device_parent,
3824 desc->resource_type, texture, i, &sub_resource->parent, &sub_resource->parent_ops)))
3825 {
3826 WARN("Failed to create sub-resource parent, hr %#lx.\n", hr);
3827 sub_resource->parent = NULL;
3829 return hr;
3830 }
3831
3832 TRACE("parent %p, parent_ops %p.\n", sub_resource->parent, sub_resource->parent_ops);
3833
3834 TRACE("Created sub-resource %u (level %u, layer %u).\n",
3835 i, i % texture->level_count, i / texture->level_count);
3836
3837 if (desc->usage & WINED3DUSAGE_OWNDC)
3838 {
3839 struct wined3d_texture_idx texture_idx = {texture, i};
3840
3843 if (!texture->dc_info || !texture->dc_info[i].dc)
3844 {
3847 }
3848 }
3849 }
3850
3851 return WINED3D_OK;
3852}
HRESULT resource_init(struct wined3d_resource *resource, struct wined3d_device *device, enum wined3d_resource_type type, const struct wined3d_format *format, enum wined3d_multisample_type multisample_type, unsigned int multisample_quality, uint32_t usage, unsigned int bind_flags, unsigned int access, unsigned int width, unsigned int height, unsigned int depth, unsigned int size, void *parent, const struct wined3d_parent_ops *parent_ops, const struct wined3d_resource_ops *resource_ops)
Definition: resource.c:54
void wined3d_resource_update_draw_binding(struct wined3d_resource *resource)
Definition: resource.c:425
static const struct wined3d_resource_ops texture_resource_ops
Definition: texture.c:3608
static void wined3d_texture_cleanup_sync(struct wined3d_texture *texture)
Definition: texture.c:1599
const char * debug_d3dusage(uint32_t usage)
Definition: utils.c:4895
UINT wined3d_format_calculate_size(const struct wined3d_format *format, UINT alignment, UINT width, UINT height, UINT depth)
Definition: utils.c:4519
GLsizeiptr size
Definition: glext.h:5919
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
#define ERR_(ch,...)
Definition: debug.h:156
struct wined3d_d3d_limits limits
uint32_t unconditional_npot
const struct wined3d_device_parent_ops * ops
Definition: wined3d.h:2246
#define WINED3D_TEXTURE_CREATE_DISCARD
Definition: wined3d.h:1563
#define WINED3DUSAGE_OWNDC
Definition: wined3d.h:935
#define WINED3D_TEXTURE_CREATE_RECORD_DIRTY_REGIONS
Definition: wined3d.h:1567
@ WINED3DFMT_DXT2
Definition: wined3d.h:261
@ WINED3DFMT_DXT1
Definition: wined3d.h:260
@ WINED3DFMT_DXT3
Definition: wined3d.h:262
@ WINED3DFMT_DXT4
Definition: wined3d.h:263
@ WINED3DFMT_DXT5
Definition: wined3d.h:264
#define WINED3DUSAGE_MANAGED
Definition: wined3d.h:938
#define WINED3DUSAGE_SCRATCH
Definition: wined3d.h:932
#define WINED3D_TEXTURE_CREATE_GET_DC
Definition: wined3d.h:1565
#define WINED3D_TEXTURE_CREATE_GET_DC_LENIENT
Definition: wined3d.h:1564
#define WINED3D_TEXTURE_CREATE_GENERATE_MIPMAPS
Definition: wined3d.h:1566
#define WINED3D_TEXTURE_GENERATE_MIPMAPS
#define WINED3D_TEXTURE_DOWNLOADABLE
#define WINED3D_FORMAT_CAP_TEXTURE
#define RESOURCE_ALIGNMENT
#define WINED3D_TEXTURE_DISCARD
#define WINED3D_FORMAT_CAP_GEN_MIPMAP

Referenced by wined3d_texture_gl_init(), wined3d_texture_no3d_init(), and wined3d_texture_vk_init().

◆ wined3d_texture_invalidate_location()

void wined3d_texture_invalidate_location ( struct wined3d_texture *  texture,
unsigned int  sub_resource_idx,
uint32_t  location 
)

Definition at line 702 of file texture.c.

704{
705 struct wined3d_texture_sub_resource *sub_resource;
706 DWORD previous_locations;
707
708 TRACE("texture %p, sub_resource_idx %u, location %s.\n",
709 texture, sub_resource_idx, wined3d_debug_location(location));
710
713
714 sub_resource = &texture->sub_resources[sub_resource_idx];
715 previous_locations = sub_resource->locations;
716 sub_resource->locations &= ~location;
717 if (previous_locations != WINED3D_LOCATION_SYSMEM && sub_resource->locations == WINED3D_LOCATION_SYSMEM)
718 ++texture->sysmem_count;
719
720 TRACE("New locations flags are %s.\n", wined3d_debug_location(sub_resource->locations));
721
722 if (!sub_resource->locations)
723 ERR("Sub-resource %u of texture %p does not have any up to date location.\n",
724 sub_resource_idx, texture);
725}

Referenced by cpu_blitter_clear_texture(), raw_blitter_blit(), surface_convert_format(), surface_cpu_blt(), swapchain_blit(), swapchain_gl_present(), swapchain_vk_present(), texture2d_blt(), texture_resource_sub_resource_map(), texture_resource_unload(), vk_blitter_blit(), wined3d_cs_exec_add_dirty_texture_region(), wined3d_cs_exec_blt_sub_resource(), wined3d_shader_resource_view_gl_generate_mipmap(), wined3d_shader_resource_view_vk_generate_mipmap(), wined3d_swapchain_gl_rotate(), wined3d_swapchain_init(), wined3d_swapchain_resize_buffers(), wined3d_swapchain_vk_rotate(), wined3d_texture_create_dc(), wined3d_texture_destroy_object(), wined3d_texture_download_from_texture(), wined3d_texture_force_reload(), wined3d_texture_load_location(), wined3d_texture_remove_buffer_object(), wined3d_texture_update_desc(), wined3d_texture_update_sub_resource(), wined3d_texture_upload_from_texture(), wined3d_unordered_access_view_gl_clear(), wined3d_unordered_access_view_vk_clear(), and wined3d_view_invalidate_location().

◆ wined3d_texture_load()

void wined3d_texture_load ( struct wined3d_texture *  texture,
struct wined3d_context *  context,
BOOL  srgb 
)

Definition at line 1657 of file texture.c.

1659{
1660 UINT sub_count = texture->level_count * texture->layer_count;
1661 DWORD flag;
1662 UINT i;
1663
1664 TRACE("texture %p, context %p, srgb %#x.\n", texture, context, srgb);
1665
1667 srgb = FALSE;
1668
1669 if (srgb)
1671 else
1673
1674 if (texture->flags & flag)
1675 {
1676 TRACE("Texture %p not dirty, nothing to do.\n", texture);
1677 return;
1678 }
1679
1680 /* Reload the surfaces if the texture is marked dirty. */
1681 for (i = 0; i < sub_count; ++i)
1682 {
1685 ERR("Failed to load location (srgb %#x).\n", srgb);
1686 }
1687 texture->flags |= flag;
1688}
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean flag
Definition: glfuncs.h:52
unsigned int UINT
Definition: sysinfo.c:13
#define WINED3D_TEXTURE_RGB_VALID
#define WINED3D_TEXTURE_SRGB_VALID

Referenced by context_gl_load_shader_resources(), context_gl_load_unordered_access_resources(), glsl_blitter_blit(), texture_resource_preload(), and wined3d_context_vk_load_shader_resources().

◆ wined3d_texture_load_drawable()

static BOOL wined3d_texture_load_drawable ( struct wined3d_texture *  texture,
unsigned int  sub_resource_idx,
struct wined3d_context *  context 
)
static

Definition at line 2865 of file texture.c.

2867{
2868 struct wined3d_device *device;
2869 unsigned int level;
2870 RECT r;
2871
2872 if (texture->resource.bind_flags & WINED3D_BIND_DEPTH_STENCIL)
2873 {
2874 DWORD current = texture->sub_resources[sub_resource_idx].locations;
2875 FIXME("Unimplemented copy from %s for depth/stencil buffers.\n",
2877 return FALSE;
2878 }
2879
2880 if (wined3d_resource_is_offscreen(&texture->resource))
2881 {
2882 ERR("Trying to load offscreen texture into WINED3D_LOCATION_DRAWABLE.\n");
2883 return FALSE;
2884 }
2885
2886 device = texture->resource.device;
2887 level = sub_resource_idx % texture->level_count;
2891 device->blitter->ops->blitter_blit(device->blitter, WINED3D_BLIT_OP_COLOR_BLIT, context,
2892 texture, sub_resource_idx, WINED3D_LOCATION_TEXTURE_RGB, &r,
2893 texture, sub_resource_idx, WINED3D_LOCATION_DRAWABLE, &r,
2895
2896 return TRUE;
2897}
struct task_struct * current
Definition: linux.c:32

Referenced by wined3d_texture_gl_load_location().

◆ wined3d_texture_load_location()

BOOL wined3d_texture_load_location ( struct wined3d_texture *  texture,
unsigned int  sub_resource_idx,
struct wined3d_context *  context,
uint32_t  location 
)

Definition at line 770 of file texture.c.

772{
773 DWORD current = texture->sub_resources[sub_resource_idx].locations;
774 BOOL ret;
775
776 TRACE("texture %p, sub_resource_idx %u, context %p, location %s.\n",
777 texture, sub_resource_idx, context, wined3d_debug_location(location));
778
779 TRACE("Current resource location %s.\n", wined3d_debug_location(current));
780
781 if (current & location)
782 {
783 TRACE("Location %s is already up to date.\n", wined3d_debug_location(location));
784 return TRUE;
785 }
786
787 if (WARN_ON(d3d))
788 {
790 if ((texture->resource.access & required_access) != required_access)
791 WARN("Operation requires %#x access, but texture only has %#x.\n",
792 required_access, texture->resource.access);
793 }
794
796 {
797 TRACE("Sub-resource previously discarded, nothing to do.\n");
799 return FALSE;
802 return TRUE;
803 }
804
805 if (!current)
806 {
807 ERR("Sub-resource %u of texture %p does not have any up to date location.\n",
808 sub_resource_idx, texture);
810 return wined3d_texture_load_location(texture, sub_resource_idx, context, location);
811 }
812
815 {
816 struct wined3d_bo_address source, destination;
817 struct wined3d_range range;
818
820 return FALSE;
821 wined3d_texture_get_bo_address(texture, sub_resource_idx, &destination, location);
822 range.offset = 0;
823 range.size = texture->sub_resources[sub_resource_idx].size;
825 {
826 unsigned int level_idx = sub_resource_idx % texture->level_count;
827 struct wined3d_map_desc map;
828 struct wined3d_box box;
829 struct wined3d_color c;
830
831 if (texture->resource.format->caps[WINED3D_GL_RES_TYPE_TEX_2D]
833 {
834 c.r = texture->sub_resources[sub_resource_idx].clear_value.depth;
835 c.g = texture->sub_resources[sub_resource_idx].clear_value.stencil;
836 c.b = c.a = 0.0f;
837 }
838 else
839 {
840 c = texture->sub_resources[sub_resource_idx].clear_value.colour;
841 }
842
843 wined3d_texture_get_pitch(texture, level_idx, &map.row_pitch, &map.slice_pitch);
844 if (destination.buffer_object)
845 map.data = wined3d_context_map_bo_address(context, &destination, range.size,
847 else
848 map.data = destination.addr;
849
851 wined3d_resource_memory_colour_fill(&texture->resource, &map, &c, &box, true);
852
853 if (destination.buffer_object)
855 }
856 else
857 {
858 wined3d_texture_get_bo_address(texture, sub_resource_idx,
862 }
863 ret = TRUE;
864 }
865 else
866 {
867 ret = texture->texture_ops->texture_load_location(texture, sub_resource_idx, context, location);
868 }
869
870 if (ret)
872
873 return ret;
874}
Definition: _map.h:48
void wined3d_resource_memory_colour_fill(struct wined3d_resource *resource, const struct wined3d_map_desc *map, const struct wined3d_color *colour, const struct wined3d_box *box, bool full_subresource)
Definition: resource.c:601
static uint32_t wined3d_resource_access_from_location(uint32_t location)
Definition: texture.c:141
#define WARN_ON(c)
Definition: module.h:257
static void wined3d_context_copy_bo_address(struct wined3d_context *context, const struct wined3d_bo_address *dst, const struct wined3d_bo_address *src, unsigned int range_count, const struct wined3d_range *ranges, uint32_t map_flags)

Referenced by cpu_blitter_blit(), cpu_blitter_clear_texture(), glsl_blitter_blit(), raw_blitter_blit(), surface_convert_format(), surface_cpu_blt(), swapchain_blit_gdi(), swapchain_frontbuffer_updated(), swapchain_gl_present(), swapchain_vk_present(), texture2d_blt(), texture2d_blt_fbo(), texture2d_depth_blt_fbo(), texture_resource_sub_resource_map(), texture_resource_unload(), vk_blitter_blit(), wined3d_cs_exec_add_dirty_texture_region(), wined3d_cs_exec_blt_sub_resource(), wined3d_shader_resource_view_gl_generate_mipmap(), wined3d_shader_resource_view_vk_generate_mipmap(), wined3d_swapchain_gl_rotate(), wined3d_swapchain_vk_rotate(), wined3d_texture_create_dc(), wined3d_texture_get_memory(), wined3d_texture_gl_load_sysmem(), wined3d_texture_gl_load_texture(), wined3d_texture_load(), wined3d_texture_load_drawable(), wined3d_texture_load_location(), wined3d_texture_update_map_binding(), wined3d_texture_update_sub_resource(), wined3d_texture_upload_from_texture(), and wined3d_view_load_location().

◆ wined3d_texture_load_renderbuffer()

static BOOL wined3d_texture_load_renderbuffer ( struct wined3d_texture *  texture,
unsigned int  sub_resource_idx,
struct wined3d_context *  context,
DWORD  dst_location 
)
static

Definition at line 2899 of file texture.c.

2901{
2902 unsigned int level = sub_resource_idx % texture->level_count;
2903 const RECT rect = {0, 0,
2906 struct wined3d_texture_sub_resource *sub_resource;
2907 DWORD src_location, locations;
2908
2909 sub_resource = &texture->sub_resources[sub_resource_idx];
2910 locations = sub_resource->locations;
2911 if (texture->resource.bind_flags & WINED3D_BIND_DEPTH_STENCIL)
2912 {
2913 FIXME("Unimplemented copy from %s for depth/stencil buffers.\n",
2915 return FALSE;
2916 }
2917
2919 src_location = WINED3D_LOCATION_RB_MULTISAMPLE;
2921 src_location = WINED3D_LOCATION_RB_RESOLVED;
2923 src_location = WINED3D_LOCATION_TEXTURE_SRGB;
2925 src_location = WINED3D_LOCATION_TEXTURE_RGB;
2927 src_location = WINED3D_LOCATION_DRAWABLE;
2928 else /* texture2d_blt_fbo() will load the source location if necessary. */
2929 src_location = WINED3D_LOCATION_TEXTURE_RGB;
2930
2932 sub_resource_idx, src_location, &rect, texture, sub_resource_idx, dst_location, &rect, NULL);
2933
2934 return TRUE;
2935}

Referenced by wined3d_texture_gl_load_location().

◆ wined3d_texture_no3d_download_data()

static void wined3d_texture_no3d_download_data ( struct wined3d_context *  context,
struct wined3d_texture *  src_texture,
unsigned int  src_sub_resource_idx,
unsigned int  src_location,
const struct wined3d_box *  src_box,
const struct wined3d_bo_address *  dst_bo_addr,
const struct wined3d_format *  dst_format,
unsigned int  dst_x,
unsigned int  dst_y,
unsigned int  dst_z,
unsigned int  dst_row_pitch,
unsigned int  dst_slice_pitch 
)
static

Definition at line 4521 of file texture.c.

4526{
4527 FIXME("Not implemented.\n");
4528}

◆ wined3d_texture_no3d_init()

HRESULT wined3d_texture_no3d_init ( struct wined3d_texture *  texture_no3d,
struct wined3d_device *  device,
const struct wined3d_resource_desc *  desc,
unsigned int  layer_count,
unsigned int  level_count,
uint32_t  flags,
void *  parent,
const struct wined3d_parent_ops *  parent_ops 
)

Definition at line 4570 of file texture.c.

4573{
4574 TRACE("texture_no3d %p, device %p, desc %p, layer_count %u, "
4575 "level_count %u, flags %#x, parent %p, parent_ops %p.\n",
4576 texture_no3d, device, desc, layer_count,
4577 level_count, flags, parent, parent_ops);
4578
4579 return wined3d_texture_init(texture_no3d, desc, layer_count, level_count,
4580 flags, device, parent, parent_ops, &texture_no3d[1], &wined3d_texture_no3d_ops);
4581}
static const struct wined3d_texture_ops wined3d_texture_no3d_ops
Definition: texture.c:4561

Referenced by adapter_no3d_create_texture().

◆ wined3d_texture_no3d_load_location()

static BOOL wined3d_texture_no3d_load_location ( struct wined3d_texture *  texture,
unsigned int  sub_resource_idx,
struct wined3d_context *  context,
uint32_t  location 
)
static

Definition at line 4541 of file texture.c.

4543{
4544 TRACE("texture %p, sub_resource_idx %u, context %p, location %s.\n",
4545 texture, sub_resource_idx, context, wined3d_debug_location(location));
4546
4548 return TRUE;
4549
4550 ERR("Unhandled location %s.\n", wined3d_debug_location(location));
4551
4552 return FALSE;
4553}

◆ wined3d_texture_no3d_prepare_location()

static BOOL wined3d_texture_no3d_prepare_location ( struct wined3d_texture *  texture,
unsigned int  sub_resource_idx,
struct wined3d_context *  context,
unsigned int  location 
)
static

Definition at line 4530 of file texture.c.

4532{
4534 return texture->sub_resources[sub_resource_idx].user_memory ? TRUE
4536
4537 FIXME("Unhandled location %s.\n", wined3d_debug_location(location));
4538 return FALSE;
4539}

◆ wined3d_texture_no3d_unload_location()

static void wined3d_texture_no3d_unload_location ( struct wined3d_texture *  texture,
struct wined3d_context *  context,
unsigned int  location 
)
static

Definition at line 4555 of file texture.c.

4557{
4558 TRACE("texture %p, context %p, location %s.\n", texture, context, wined3d_debug_location(location));
4559}

◆ wined3d_texture_no3d_upload_data()

static void wined3d_texture_no3d_upload_data ( struct wined3d_context *  context,
const struct wined3d_const_bo_address *  src_bo_addr,
const struct wined3d_format *  src_format,
const struct wined3d_box *  src_box,
unsigned int  src_row_pitch,
unsigned int  src_slice_pitch,
struct wined3d_texture *  dst_texture,
unsigned int  dst_sub_resource_idx,
unsigned int  dst_location,
unsigned int  dst_x,
unsigned int  dst_y,
unsigned int  dst_z 
)
static

Definition at line 4512 of file texture.c.

4517{
4518 FIXME("Not implemented.\n");
4519}

◆ wined3d_texture_prepare_location()

◆ wined3d_texture_release_dc()

HRESULT CDECL wined3d_texture_release_dc ( struct wined3d_texture *  texture,
unsigned int  sub_resource_idx,
HDC  dc 
)

Definition at line 4291 of file texture.c.

4292{
4293 struct wined3d_device *device = texture->resource.device;
4294 struct wined3d_texture_sub_resource *sub_resource;
4295 struct wined3d_dc_info *dc_info;
4296
4297 TRACE("texture %p, sub_resource_idx %u, dc %p.\n", texture, sub_resource_idx, dc);
4298
4299 if (!(sub_resource = wined3d_texture_get_sub_resource(texture, sub_resource_idx)))
4301
4302 if (texture->resource.type != WINED3D_RTYPE_TEXTURE_2D)
4303 {
4304 WARN("Not supported on %s resources.\n", debug_d3dresourcetype(texture->resource.type));
4306 }
4307
4310
4311 if (!(dc_info = texture->dc_info) || dc_info[sub_resource_idx].dc != dc)
4312 {
4313 WARN("Application tries to release invalid DC %p, sub-resource DC is %p.\n",
4314 dc, dc_info ? dc_info[sub_resource_idx].dc : NULL);
4316 }
4317
4318 if (!(texture->resource.usage & WINED3DUSAGE_OWNDC))
4319 {
4320 struct wined3d_texture_idx texture_idx = {texture, sub_resource_idx};
4321
4324 }
4325
4326 --sub_resource->map_count;
4327 if (!--texture->resource.map_count && texture->update_map_binding)
4330 texture->flags &= ~WINED3D_TEXTURE_DC_IN_USE;
4331
4332 return WINED3D_OK;
4333}

Referenced by d3d9_surface_ReleaseDC(), ddraw_surface7_ReleaseDC(), ddraw_surface_update_frontbuffer(), device_load_logo(), and dxgi_surface_ReleaseDC().

◆ wined3d_texture_remove_buffer_object()

static void wined3d_texture_remove_buffer_object ( struct wined3d_texture *  texture,
unsigned int  sub_resource_idx,
struct wined3d_context_gl *  context_gl 
)
static

Definition at line 913 of file texture.c.

915{
916 struct wined3d_texture_sub_resource *sub_resource = &texture->sub_resources[sub_resource_idx];
917 struct wined3d_bo_gl *bo_gl = wined3d_bo_gl(sub_resource->bo);
918
919 TRACE("texture %p, sub_resource_idx %u, context_gl %p.\n", texture, sub_resource_idx, context_gl);
920
921 wined3d_context_gl_destroy_bo(context_gl, bo_gl);
923 sub_resource->bo = NULL;
924 free(bo_gl);
925}
void wined3d_context_gl_destroy_bo(struct wined3d_context_gl *context_gl, struct wined3d_bo_gl *bo)
Definition: context_gl.c:3097

Referenced by wined3d_texture_gl_unload_location().

◆ wined3d_texture_set_bo()

static void wined3d_texture_set_bo ( struct wined3d_texture *  texture,
unsigned  sub_resource_idx,
struct wined3d_context *  context,
struct wined3d_bo *  bo 
)
static

Definition at line 4415 of file texture.c.

4417{
4418 struct wined3d_texture_sub_resource *sub_resource = &texture->sub_resources[sub_resource_idx];
4419 struct wined3d_bo *prev_bo = sub_resource->bo;
4420
4421 TRACE("texture %p, sub_resource_idx %u, context %p, bo %p.\n", texture, sub_resource_idx, context, bo);
4422
4423 if (prev_bo)
4424 {
4425 struct wined3d_bo_user *bo_user;
4426
4427 LIST_FOR_EACH_ENTRY(bo_user, &prev_bo->users, struct wined3d_bo_user, entry)
4428 bo_user->valid = false;
4429 list_init(&prev_bo->users);
4430
4431 assert(list_empty(&bo->users));
4432
4434 free(prev_bo);
4435 }
4436
4437 sub_resource->bo = bo;
4438}
static int list_empty(struct list_entry *head)
Definition: list.h:58
struct list users
static void wined3d_context_destroy_bo(struct wined3d_context *context, struct wined3d_bo *bo)

Referenced by wined3d_texture_update_sub_resource().

◆ wined3d_texture_set_color_key()

HRESULT CDECL wined3d_texture_set_color_key ( struct wined3d_texture *  texture,
uint32_t  flags,
const struct wined3d_color_key *  color_key 
)

Definition at line 1753 of file texture.c.

1755{
1756 struct wined3d_device *device = texture->resource.device;
1757 static const DWORD all_flags = WINED3D_CKEY_DST_BLT | WINED3D_CKEY_DST_OVERLAY
1759
1760 TRACE("texture %p, flags %#x, color_key %p.\n", texture, flags, color_key);
1761
1762 if (flags & ~all_flags)
1763 {
1764 WARN("Invalid flags passed, returning WINED3DERR_INVALIDCALL.\n");
1766 }
1767
1768 if (color_key)
1769 {
1771 texture->src_blt_color_key = *color_key;
1772 texture->color_key_flags |= flags;
1773 }
1774 else
1775 {
1776 texture->color_key_flags &= ~flags;
1777 }
1778
1780
1781 return WINED3D_OK;
1782}
void wined3d_cs_emit_set_color_key(struct wined3d_cs *cs, struct wined3d_texture *texture, WORD flags, const struct wined3d_color_key *color_key)
Definition: cs.c:2037
#define WINED3D_CKEY_DST_BLT
Definition: wined3d.h:1339
#define WINED3D_CKEY_SRC_OVERLAY
Definition: wined3d.h:1342
#define WINED3D_CKEY_SRC_BLT
Definition: wined3d.h:1341
#define WINED3D_CKEY_DST_OVERLAY
Definition: wined3d.h:1340

Referenced by ddraw_surface_set_wined3d_textures_colour_key(), and device_load_logo().

◆ wined3d_texture_set_dirty()

static void wined3d_texture_set_dirty ( struct wined3d_texture *  texture)
static

◆ wined3d_texture_set_lod()

unsigned int CDECL wined3d_texture_set_lod ( struct wined3d_texture *  texture,
unsigned int  lod 
)

Definition at line 1722 of file texture.c.

1723{
1724 struct wined3d_resource *resource;
1725 unsigned int old = texture->lod;
1726
1727 TRACE("texture %p, returning %u.\n", texture, texture->lod);
1728
1729 /* The d3d9:texture test shows that SetLOD is ignored on non-managed
1730 * textures. The call always returns 0, and GetLOD always returns 0. */
1731 resource = &texture->resource;
1732 if (!(resource->usage & WINED3DUSAGE_MANAGED))
1733 {
1734 TRACE("Ignoring LOD on texture with resource access %s.\n",
1736 return 0;
1737 }
1738
1739 if (lod >= texture->level_count)
1740 lod = texture->level_count - 1;
1741
1742 texture->lod = lod;
1743 return old;
1744}
GLint lod
Definition: glext.h:7795

Referenced by ddraw_surface7_SetLOD(), and wined3d_stateblock_set_texture_lod().

◆ wined3d_texture_set_map_binding()

static void wined3d_texture_set_map_binding ( struct wined3d_texture *  texture,
DWORD  map_binding 
)
static

Definition at line 959 of file texture.c.

960{
961 texture->update_map_binding = map_binding;
962 if (!texture->resource.map_count)
964}

Referenced by wined3d_texture_gl_load_texture().

◆ wined3d_texture_set_overlay_position()

HRESULT CDECL wined3d_texture_set_overlay_position ( struct wined3d_texture *  texture,
unsigned int  sub_resource_idx,
LONG  x,
LONG  y 
)

Definition at line 3943 of file texture.c.

3945{
3946 struct wined3d_overlay_info *overlay;
3947 LONG w, h;
3948
3949 TRACE("texture %p, sub_resource_idx %u, x %ld, y %ld.\n", texture, sub_resource_idx, x, y);
3950
3951 if (!(texture->resource.usage & WINED3DUSAGE_OVERLAY)
3954
3955 overlay = &texture->overlay_info[sub_resource_idx];
3956 w = overlay->dst_rect.right - overlay->dst_rect.left;
3957 h = overlay->dst_rect.bottom - overlay->dst_rect.top;
3958 SetRect(&overlay->dst_rect, x, y, x + w, y + h);
3959
3960 return WINED3D_OK;
3961}
long LONG
Definition: pedump.c:60

Referenced by ddraw_surface7_SetOverlayPosition().

◆ wined3d_texture_set_sub_resource_parent()

void CDECL wined3d_texture_set_sub_resource_parent ( struct wined3d_texture *  texture,
unsigned int  sub_resource_idx,
void *  parent,
const struct wined3d_parent_ops *  parent_ops 
)

Definition at line 4043 of file texture.c.

4045{
4046 TRACE("texture %p, sub_resource_idx %u, parent %p.\n", texture, sub_resource_idx, parent);
4047
4048 if (!wined3d_texture_validate_sub_resource_idx(texture, sub_resource_idx))
4049 return;
4050
4051 texture->sub_resources[sub_resource_idx].parent = parent;
4052 texture->sub_resources[sub_resource_idx].parent_ops = parent_ops;
4053}

Referenced by d3d8_surface_create(), d3d9_surface_create(), ddraw_surface7_SetSurfaceDesc(), ddraw_texture_init(), and ddraw_texture_rename_to().

◆ wined3d_texture_set_swapchain()

void wined3d_texture_set_swapchain ( struct wined3d_texture *  texture,
struct wined3d_swapchain *  swapchain 
)

Definition at line 1263 of file texture.c.

1264{
1265 texture->swapchain = swapchain;
1267}

Referenced by swapchain_create_texture(), wined3d_swapchain_cleanup(), wined3d_swapchain_init(), and wined3d_swapchain_resize_buffers().

◆ wined3d_texture_sub_resources_destroyed()

void wined3d_texture_sub_resources_destroyed ( struct wined3d_texture *  texture)

Definition at line 1111 of file texture.c.

1112{
1113 unsigned int sub_count = texture->level_count * texture->layer_count;
1114 struct wined3d_texture_sub_resource *sub_resource;
1115 unsigned int i;
1116
1117 for (i = 0; i < sub_count; ++i)
1118 {
1119 sub_resource = &texture->sub_resources[i];
1120 if (sub_resource->parent)
1121 {
1122 TRACE("sub-resource %u.\n", i);
1123 sub_resource->parent_ops->wined3d_object_destroyed(sub_resource->parent);
1124 sub_resource->parent = NULL;
1125 }
1126 }
1127}

Referenced by adapter_gl_destroy_texture(), adapter_no3d_destroy_texture(), adapter_vk_destroy_texture(), and wined3d_texture_cleanup_sync().

◆ wined3d_texture_translate_drawable_coords()

void wined3d_texture_translate_drawable_coords ( const struct wined3d_texture *  texture,
HWND  window,
RECT *  rect 
)

Definition at line 91 of file texture.c.

92{
93 unsigned int drawable_height;
94 POINT offset = {0, 0};
95 RECT windowsize;
96
97 if (!texture->swapchain)
98 return;
99
100 if (texture == texture->swapchain->front_buffer)
101 {
104 }
105
106 GetClientRect(window, &windowsize);
107 drawable_height = windowsize.bottom - windowsize.top;
108
109 rect->top = drawable_height - rect->top;
110 rect->bottom = drawable_height - rect->bottom;
111}
static IHTMLWindow2 * window
Definition: events.c:77
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
BOOL WINAPI OffsetRect(_Inout_ LPRECT, _In_ int, _In_ int)
BOOL WINAPI ScreenToClient(_In_ HWND, _Inout_ LPPOINT)

Referenced by glsl_blitter_blit(), and texture2d_blt_fbo().

◆ wined3d_texture_unload_location()

static void wined3d_texture_unload_location ( struct wined3d_texture *  texture,
struct wined3d_context *  context,
unsigned int  location 
)
static

Definition at line 927 of file texture.c.

929{
930 texture->texture_ops->texture_unload_location(texture, context, location);
931}

Referenced by texture_resource_unload(), and wined3d_texture_update_map_binding().

◆ wined3d_texture_update_desc()

HRESULT CDECL wined3d_texture_update_desc ( struct wined3d_texture *  texture,
unsigned int  sub_resource_idx,
void *  mem,
unsigned int  pitch 
)

Definition at line 1868 of file texture.c.

1870{
1871 unsigned int current_row_pitch, current_slice_pitch, width, height;
1872 struct wined3d_texture_sub_resource *sub_resource;
1873 unsigned int i, level, sub_resource_count;
1874 const struct wined3d_format *format;
1875 struct wined3d_device *device;
1876 unsigned int slice_pitch;
1877 bool update_memory_only;
1878 bool create_dib = false;
1879
1880 TRACE("texture %p, sub_resource_idx %u, mem %p, pitch %u.\n", texture, sub_resource_idx, mem, pitch);
1881
1882 device = texture->resource.device;
1883 format = texture->resource.format;
1884 level = sub_resource_idx % texture->level_count;
1885 sub_resource_count = texture->level_count * texture->layer_count;
1886
1889 if (pitch)
1890 slice_pitch = height * pitch;
1891 else
1892 wined3d_format_calculate_pitch(format, 1, width, height, &pitch, &slice_pitch);
1893
1894 wined3d_texture_get_pitch(texture, level, &current_row_pitch, &current_slice_pitch);
1895 update_memory_only = (pitch == current_row_pitch && slice_pitch == current_slice_pitch);
1896
1897 if (sub_resource_count > 1 && !update_memory_only)
1898 {
1899 FIXME("Texture has multiple sub-resources, not supported.\n");
1901 }
1902
1903 if (texture->resource.type != WINED3D_RTYPE_TEXTURE_2D)
1904 {
1905 WARN("Not supported on %s.\n", debug_d3dresourcetype(texture->resource.type));
1907 }
1908
1909 if (texture->resource.map_count)
1910 {
1911 WARN("Texture is mapped.\n");
1913 }
1914
1915 /* We have no way of supporting a pitch that is not a multiple of the pixel
1916 * byte width short of uploading the texture row-by-row.
1917 * Fortunately that's not an issue since D3D9Ex doesn't allow a custom pitch
1918 * for user-memory textures (it always expects packed data) while DirectDraw
1919 * requires a 4-byte aligned pitch and doesn't support texture formats
1920 * larger than 4 bytes per pixel nor any format using 3 bytes per pixel.
1921 * This check is here to verify that the assumption holds. */
1922 if (pitch % format->byte_count)
1923 {
1924 WARN("Pitch unsupported, not a multiple of the texture format byte width.\n");
1926 }
1927
1928 if (device->d3d_initialized)
1931
1932 if (texture->dc_info && texture->dc_info[0].dc)
1933 {
1934 struct wined3d_texture_idx texture_idx = {texture, sub_resource_idx};
1935
1938 create_dib = true;
1939 }
1940
1941 texture->sub_resources[sub_resource_idx].user_memory = mem;
1942
1943 if (update_memory_only)
1944 {
1945 for (i = 0; i < sub_resource_count; ++i)
1946 if (!texture->sub_resources[i].user_memory)
1947 break;
1948
1949 if (i == sub_resource_count)
1951 }
1952 else
1953 {
1955
1956 sub_resource = &texture->sub_resources[sub_resource_idx];
1957
1958 texture->row_pitch = pitch;
1959 texture->slice_pitch = slice_pitch;
1960
1961 if (!(texture->resource.access & WINED3D_RESOURCE_ACCESS_CPU)
1962 && texture->resource.usage & WINED3DUSAGE_VIDMEM_ACCOUNTING)
1963 adapter_adjust_memory(device->adapter, (INT64)texture->slice_pitch - texture->resource.size);
1964 texture->resource.size = texture->slice_pitch;
1965 sub_resource->size = texture->slice_pitch;
1966 sub_resource->locations = WINED3D_LOCATION_DISCARDED;
1967 }
1968
1969 if (!mem && !wined3d_resource_prepare_sysmem(&texture->resource))
1970 ERR("Failed to allocate resource memory.\n");
1971
1974
1975 if (create_dib)
1976 {
1977 struct wined3d_texture_idx texture_idx = {texture, sub_resource_idx};
1978
1981 }
1982
1983 return WINED3D_OK;
1984}
COMPILER_DEPENDENT_INT64 INT64
Definition: actypes.h:132
void wined3d_cs_emit_unload_resource(struct wined3d_cs *cs, struct wined3d_resource *resource)
Definition: cs.c:2440
static void create_dib(STGMEDIUM *med)
Definition: ole2.c:210
uint64_t size
Definition: devices.h:44
UINT64 adapter_adjust_memory(struct wined3d_adapter *adapter, INT64 amount)
Definition: directx.c:158
#define WINED3DUSAGE_VIDMEM_ACCOUNTING
Definition: wined3d.h:939

Referenced by d3d9_device_create_surface(), d3d9_device_CreateTexture(), ddraw_surface7_SetSurfaceDesc(), ddraw_surface_reserve_memory(), and ddraw_texture_init().

◆ wined3d_texture_update_map_binding()

static void wined3d_texture_update_map_binding ( struct wined3d_texture *  texture)
static

Definition at line 933 of file texture.c.

934{
935 unsigned int sub_count = texture->level_count * texture->layer_count;
936 struct wined3d_device *device = texture->resource.device;
937 DWORD map_binding = texture->update_map_binding;
938 struct wined3d_context *context;
939 unsigned int i;
940
942
943 for (i = 0; i < sub_count; ++i)
944 {
945 if (texture->sub_resources[i].locations == texture->resource.map_binding
947 ERR("Failed to load location %s.\n", wined3d_debug_location(map_binding));
948 }
949
950 if (texture->resource.map_binding == WINED3D_LOCATION_BUFFER)
952
954
955 texture->resource.map_binding = map_binding;
956 texture->update_map_binding = 0;
957}

Referenced by texture_resource_sub_resource_unmap(), wined3d_texture_release_dc(), and wined3d_texture_set_map_binding().

◆ wined3d_texture_update_overlay()

HRESULT CDECL wined3d_texture_update_overlay ( struct wined3d_texture *  texture,
unsigned int  sub_resource_idx,
const RECT *  src_rect,
struct wined3d_texture *  dst_texture,
unsigned int  dst_sub_resource_idx,
const RECT *  dst_rect,
uint32_t  flags 
)

Definition at line 3963 of file texture.c.

3966{
3967 struct wined3d_overlay_info *overlay;
3968 unsigned int level, dst_level;
3969
3970 TRACE("texture %p, sub_resource_idx %u, src_rect %s, dst_texture %p, "
3971 "dst_sub_resource_idx %u, dst_rect %s, flags %#x.\n",
3972 texture, sub_resource_idx, wine_dbgstr_rect(src_rect), dst_texture,
3973 dst_sub_resource_idx, wine_dbgstr_rect(dst_rect), flags);
3974
3975 if (!(texture->resource.usage & WINED3DUSAGE_OVERLAY) || texture->resource.type != WINED3D_RTYPE_TEXTURE_2D
3978
3979 if (!dst_texture || dst_texture->resource.type != WINED3D_RTYPE_TEXTURE_2D
3980 || !wined3d_texture_validate_sub_resource_idx(dst_texture, dst_sub_resource_idx))
3982
3983 overlay = &texture->overlay_info[sub_resource_idx];
3984
3985 level = sub_resource_idx % texture->level_count;
3986 if (src_rect)
3987 overlay->src_rect = *src_rect;
3988 else
3989 SetRect(&overlay->src_rect, 0, 0,
3992
3993 dst_level = dst_sub_resource_idx % dst_texture->level_count;
3994 if (dst_rect)
3995 overlay->dst_rect = *dst_rect;
3996 else
3997 SetRect(&overlay->dst_rect, 0, 0,
3998 wined3d_texture_get_level_width(dst_texture, dst_level),
3999 wined3d_texture_get_level_height(dst_texture, dst_level));
4000
4001 if (overlay->dst_texture && (overlay->dst_texture != dst_texture
4002 || overlay->dst_sub_resource_idx != dst_sub_resource_idx || flags & WINEDDOVER_HIDE))
4003 {
4004 overlay->dst_texture = NULL;
4005 list_remove(&overlay->entry);
4006 }
4007
4008 if (flags & WINEDDOVER_SHOW)
4009 {
4010 if (overlay->dst_texture != dst_texture || overlay->dst_sub_resource_idx != dst_sub_resource_idx)
4011 {
4012 overlay->dst_texture = dst_texture;
4013 overlay->dst_sub_resource_idx = dst_sub_resource_idx;
4014 list_add_tail(&texture->overlay_info[dst_sub_resource_idx].overlays, &overlay->entry);
4015 }
4016 }
4017 else if (flags & WINEDDOVER_HIDE)
4018 {
4019 /* Tests show that the rectangles are erased on hide. */
4020 SetRectEmpty(&overlay->src_rect);
4021 SetRectEmpty(&overlay->dst_rect);
4022 overlay->dst_texture = NULL;
4023 }
4024
4025 return WINED3D_OK;
4026}
static void list_add_tail(struct list_entry *head, struct list_entry *entry)
Definition: list.h:83
BOOL WINAPI SetRectEmpty(_Out_ LPRECT)
#define WINEDDOVER_HIDE
Definition: wined3d.h:1404
#define WINEDDOVER_SHOW
Definition: wined3d.h:1409

Referenced by ddraw_surface7_UpdateOverlay().

◆ wined3d_texture_update_sub_resource()

void wined3d_texture_update_sub_resource ( struct wined3d_texture *  texture,
unsigned int  sub_resource_idx,
struct wined3d_context *  context,
const struct upload_bo *  upload_bo,
const struct wined3d_box *  box,
unsigned int  row_pitch,
unsigned int  slice_pitch 
)

Definition at line 4440 of file texture.c.

4443{
4444 unsigned int level = sub_resource_idx % texture->level_count;
4448 struct wined3d_box src_box;
4449
4451 {
4452 wined3d_texture_set_bo(texture, sub_resource_idx, context, upload_bo->addr.buffer_object);
4455 /* Try to free address space if we are not mapping persistently. */
4456 if (upload_bo->addr.buffer_object->map_ptr)
4458 }
4459
4460 /* Only load the sub-resource for partial updates. */
4461 if (!box->left && !box->top && !box->front
4462 && box->right == width && box->bottom == height && box->back == depth)
4464 else
4466
4467 wined3d_box_set(&src_box, 0, 0, box->right - box->left, box->bottom - box->top, 0, box->back - box->front);
4468 texture->texture_ops->texture_upload_data(context, &upload_bo->addr, texture->resource.format,
4469 &src_box, row_pitch, slice_pitch, texture, sub_resource_idx,
4470 WINED3D_LOCATION_TEXTURE_RGB, box->left, box->top, box->front);
4471
4474}
static void wined3d_texture_set_bo(struct wined3d_texture *texture, unsigned sub_resource_idx, struct wined3d_context *context, struct wined3d_bo *bo)
Definition: texture.c:4415
struct wined3d_const_bo_address addr
uint32_t flags
static void wined3d_box_set(struct wined3d_box *box, unsigned int left, unsigned int top, unsigned int right, unsigned int bottom, unsigned int front, unsigned int back)
Definition: wined3d.h:3006
#define UPLOAD_BO_RENAME_ON_UNMAP

Referenced by wined3d_cs_exec_update_sub_resource().

◆ wined3d_texture_upload_from_texture()

void wined3d_texture_upload_from_texture ( struct wined3d_texture *  dst_texture,
unsigned int  dst_sub_resource_idx,
unsigned int  dst_x,
unsigned int  dst_y,
unsigned int  dst_z,
struct wined3d_texture *  src_texture,
unsigned int  src_sub_resource_idx,
const struct wined3d_box *  src_box 
)

Definition at line 4335 of file texture.c.

4338{
4339 unsigned int src_row_pitch, src_slice_pitch;
4340 unsigned int update_w, update_h, update_d;
4341 unsigned int src_level, dst_level;
4342 struct wined3d_context *context;
4343 struct wined3d_bo_address data;
4344
4345 TRACE("dst_texture %p, dst_sub_resource_idx %u, dst_x %u, dst_y %u, dst_z %u, "
4346 "src_texture %p, src_sub_resource_idx %u, src_box %s.\n",
4347 dst_texture, dst_sub_resource_idx, dst_x, dst_y, dst_z,
4348 src_texture, src_sub_resource_idx, debug_box(src_box));
4349
4350 context = context_acquire(dst_texture->resource.device, NULL, 0);
4351
4352 /* Only load the sub-resource for partial updates. For newly allocated
4353 * textures the texture wouldn't be the current location, and we'd upload
4354 * zeroes just to overwrite them again. */
4355 update_w = src_box->right - src_box->left;
4356 update_h = src_box->bottom - src_box->top;
4357 update_d = src_box->back - src_box->front;
4358 dst_level = dst_sub_resource_idx % dst_texture->level_count;
4359 if (update_w == wined3d_texture_get_level_width(dst_texture, dst_level)
4360 && update_h == wined3d_texture_get_level_height(dst_texture, dst_level)
4361 && update_d == wined3d_texture_get_level_depth(dst_texture, dst_level))
4362 wined3d_texture_prepare_location(dst_texture, dst_sub_resource_idx, context, WINED3D_LOCATION_TEXTURE_RGB);
4363 else
4364 wined3d_texture_load_location(dst_texture, dst_sub_resource_idx, context, WINED3D_LOCATION_TEXTURE_RGB);
4365
4366 src_level = src_sub_resource_idx % src_texture->level_count;
4367 wined3d_texture_get_memory(src_texture, src_sub_resource_idx, context, &data);
4368 wined3d_texture_get_pitch(src_texture, src_level, &src_row_pitch, &src_slice_pitch);
4369
4370 dst_texture->texture_ops->texture_upload_data(context, wined3d_const_bo_address(&data),
4371 src_texture->resource.format, src_box, src_row_pitch, src_slice_pitch, dst_texture,
4372 dst_sub_resource_idx, WINED3D_LOCATION_TEXTURE_RGB, dst_x, dst_y, dst_z);
4373
4375
4376 wined3d_texture_validate_location(dst_texture, dst_sub_resource_idx, WINED3D_LOCATION_TEXTURE_RGB);
4377 wined3d_texture_invalidate_location(dst_texture, dst_sub_resource_idx, ~WINED3D_LOCATION_TEXTURE_RGB);
4378}

Referenced by glsl_blitter_blit(), and texture2d_blt().

◆ wined3d_texture_use_immutable_storage()

static BOOL wined3d_texture_use_immutable_storage ( const struct wined3d_texture *  texture,
const struct wined3d_gl_info *  gl_info 
)
static

Definition at line 78 of file texture.c.

80{
81 /* We don't expect to create texture views for textures with height-scaled formats.
82 * Besides, ARB_texture_storage doesn't allow specifying exact sizes for all levels. */
83 return gl_info->supported[ARB_TEXTURE_STORAGE]
84 && !(texture->resource.format_attrs & WINED3D_FORMAT_ATTR_HEIGHT_SCALE);
85}
@ ARB_TEXTURE_STORAGE
Definition: wined3d_gl.h:144

Referenced by wined3d_texture_gl_prepare_texture().

◆ wined3d_texture_use_pbo()

static BOOL wined3d_texture_use_pbo ( const struct wined3d_texture *  texture,
const struct wined3d_d3d_info *  d3d_info 
)
static

Definition at line 67 of file texture.c.

68{
70 return FALSE;
71
72 /* Use a PBO for dynamic textures and read-only staging textures. */
73 return (!(texture->resource.access & WINED3D_RESOURCE_ACCESS_CPU)
74 && texture->resource.usage & WINED3DUSAGE_DYNAMIC)
76}
BOOL wined3d_texture_can_use_pbo(const struct wined3d_texture *texture, const struct wined3d_d3d_info *d3d_info)
Definition: texture.c:59
#define WINED3D_RESOURCE_ACCESS_MAP_R
Definition: wined3d.h:53

Referenced by wined3d_texture_get_memory(), and wined3d_texture_init().

◆ wined3d_texture_validate_location()

void wined3d_texture_validate_location ( struct wined3d_texture *  texture,
unsigned int  sub_resource_idx,
uint32_t  location 
)

Definition at line 678 of file texture.c.

680{
681 struct wined3d_texture_sub_resource *sub_resource;
682 DWORD previous_locations;
683
684 TRACE("texture %p, sub_resource_idx %u, location %s.\n",
685 texture, sub_resource_idx, wined3d_debug_location(location));
686
687 sub_resource = &texture->sub_resources[sub_resource_idx];
688 previous_locations = sub_resource->locations;
689 sub_resource->locations |= location;
690 if (previous_locations == WINED3D_LOCATION_SYSMEM && location != WINED3D_LOCATION_SYSMEM
691 && !--texture->sysmem_count)
693
694 TRACE("New locations flags are %s.\n", wined3d_debug_location(sub_resource->locations));
695}
static void wined3d_texture_evict_sysmem(struct wined3d_texture *texture)
Definition: texture.c:651

Referenced by raw_blitter_blit(), surface_convert_format(), surface_cpu_blt(), swapchain_blit(), swapchain_gl_present(), swapchain_vk_present(), texture2d_blt(), texture_resource_sub_resource_map(), texture_resource_unload(), vk_blitter_blit(), wined3d_cs_exec_blt_sub_resource(), wined3d_cs_exec_present(), wined3d_cs_exec_set_depth_stencil_view(), wined3d_rendertarget_view_validate_location(), wined3d_shader_resource_view_gl_generate_mipmap(), wined3d_shader_resource_view_vk_generate_mipmap(), wined3d_swapchain_gl_rotate(), wined3d_swapchain_init(), wined3d_swapchain_resize_buffers(), wined3d_swapchain_vk_rotate(), wined3d_texture_destroy_object(), wined3d_texture_download_from_texture(), wined3d_texture_gl_clear(), wined3d_texture_load_location(), wined3d_texture_update_desc(), wined3d_texture_update_sub_resource(), wined3d_texture_upload_from_texture(), wined3d_texture_vk_clear(), wined3d_unordered_access_view_gl_clear(), and wined3d_unordered_access_view_vk_clear().

◆ wined3d_texture_validate_sub_resource_idx()

bool wined3d_texture_validate_sub_resource_idx ( const struct wined3d_texture *  texture,
unsigned int  sub_resource_idx 
)

◆ wined3d_texture_vk_barrier()

void wined3d_texture_vk_barrier ( struct wined3d_texture_vk *  texture_vk,
struct wined3d_context_vk *  context_vk,
uint32_t  bind_mask 
)

Definition at line 5524 of file texture.c.

5526{
5527 enum VkImageLayout new_layout;
5528 uint32_t src_bind_mask = 0;
5529
5530 TRACE("texture_vk %p, context_vk %p, bind_mask %s.\n",
5531 texture_vk, context_vk, wined3d_debug_bind_flags(bind_mask));
5532
5533 new_layout = wined3d_layout_from_bind_mask(texture_vk, bind_mask);
5534
5535 /* A layout transition is potentially a read-write operation, so even if we
5536 * prepare the texture to e.g. read only shader resource mode, we have to wait
5537 * for past operations to finish. */
5538 if (bind_mask & ~WINED3D_READ_ONLY_BIND_MASK || new_layout != texture_vk->layout)
5539 {
5540 src_bind_mask = texture_vk->bind_mask & WINED3D_READ_ONLY_BIND_MASK;
5541 if (!src_bind_mask)
5542 src_bind_mask = texture_vk->bind_mask;
5543
5544 texture_vk->bind_mask = bind_mask;
5545 }
5546 else if ((texture_vk->bind_mask & bind_mask) != bind_mask)
5547 {
5548 src_bind_mask = texture_vk->bind_mask & ~WINED3D_READ_ONLY_BIND_MASK;
5549 texture_vk->bind_mask |= bind_mask;
5550 }
5551
5552 if (src_bind_mask)
5553 {
5554 VkImageSubresourceRange vk_range;
5555
5556 TRACE(" %s(%x) -> %s(%x).\n",
5557 wined3d_debug_bind_flags(src_bind_mask), texture_vk->layout,
5558 wined3d_debug_bind_flags(bind_mask), new_layout);
5559
5560 vk_range.aspectMask = vk_aspect_mask_from_format(texture_vk->t.resource.format);
5561 vk_range.baseMipLevel = 0;
5563 vk_range.baseArrayLayer = 0;
5565
5570 texture_vk->layout, new_layout, texture_vk->image.vk_image, &vk_range);
5571
5572 texture_vk->layout = new_layout;
5573 }
5574}
VkPipelineStageFlags vk_pipeline_stage_mask_from_bind_flags(uint32_t bind_flags)
Definition: resource.c:552
enum VkImageLayout wined3d_layout_from_bind_mask(const struct wined3d_texture_vk *texture_vk, const uint32_t bind_mask)
Definition: texture.c:5497
uint32_t bind_mask
Definition: wined3d_vk.h:879
#define VK_REMAINING_MIP_LEVELS
Definition: vulkan.h:50
#define VK_REMAINING_ARRAY_LAYERS
Definition: vulkan.h:51
static const uint32_t WINED3D_READ_ONLY_BIND_MASK

Referenced by wined3d_resource_vk_barrier().

◆ wined3d_texture_vk_clear()

static bool wined3d_texture_vk_clear ( struct wined3d_texture_vk *  texture_vk,
unsigned int  sub_resource_idx,
struct wined3d_context *  context 
)
static

Definition at line 5106 of file texture.c.

5108{
5109 struct wined3d_texture_sub_resource *sub_resource = &texture_vk->t.sub_resources[sub_resource_idx];
5110 struct wined3d_context_vk *context_vk = wined3d_context_vk(context);
5111 const struct wined3d_format *format = texture_vk->t.resource.format;
5112 const struct wined3d_vk_info *vk_info = context_vk->vk_info;
5113 VkClearDepthStencilValue depth_value;
5114 VkCommandBuffer vk_command_buffer;
5115 VkImageSubresourceRange vk_range;
5116 VkClearColorValue colour_value;
5117 VkImageAspectFlags aspect_mask;
5118 VkImage vk_image;
5119
5120 if (texture_vk->t.resource.format_attrs & WINED3D_FORMAT_ATTR_COMPRESSED)
5121 {
5122 struct wined3d_bo_address addr;
5123 struct wined3d_color *c = &sub_resource->clear_value.colour;
5124
5125 if (c->r || c->g || c-> b || c->a)
5126 FIXME("Compressed resource %p is cleared to a non-zero color.\n", &texture_vk->t);
5127
5128 if (!wined3d_texture_prepare_location(&texture_vk->t, sub_resource_idx, context, WINED3D_LOCATION_SYSMEM))
5129 return false;
5130 wined3d_texture_get_bo_address(&texture_vk->t, sub_resource_idx, &addr, WINED3D_LOCATION_SYSMEM);
5131 memset(addr.addr, 0, sub_resource->size);
5132 wined3d_texture_validate_location(&texture_vk->t, sub_resource_idx, WINED3D_LOCATION_SYSMEM);
5133 return true;
5134 }
5135
5136 vk_image = texture_vk->image.vk_image;
5137
5138 if (!(vk_command_buffer = wined3d_context_vk_get_command_buffer(context_vk)))
5139 {
5140 ERR("Failed to get command buffer.\n");
5141 return false;
5142 }
5143
5144 aspect_mask = vk_aspect_mask_from_format(format);
5145
5146 vk_range.aspectMask = aspect_mask;
5147 vk_range.baseMipLevel = sub_resource_idx % texture_vk->t.level_count;
5148 vk_range.levelCount = 1;
5149 vk_range.baseArrayLayer = sub_resource_idx / texture_vk->t.level_count;
5150 vk_range.layerCount = 1;
5151
5153
5154 wined3d_context_vk_image_barrier(context_vk, vk_command_buffer,
5156 vk_access_mask_from_bind_flags(texture_vk->t.resource.bind_flags), VK_ACCESS_TRANSFER_WRITE_BIT,
5157 texture_vk->layout, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, vk_image, &vk_range);
5158
5159 if (format->depth_size || format->stencil_size)
5160 {
5161 depth_value.depth = sub_resource->clear_value.depth;
5162 depth_value.stencil = sub_resource->clear_value.stencil;
5163 VK_CALL(vkCmdClearDepthStencilImage(vk_command_buffer, vk_image,
5164 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &depth_value, 1, &vk_range));
5165 }
5166 else
5167 {
5168 wined3d_format_colour_to_vk(format, &sub_resource->clear_value.colour, &colour_value);
5169 VK_CALL(vkCmdClearColorImage(vk_command_buffer, vk_image,
5170 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &colour_value, 1, &vk_range));
5171 }
5172
5173 wined3d_context_vk_image_barrier(context_vk, vk_command_buffer,
5175 VK_ACCESS_TRANSFER_WRITE_BIT, vk_access_mask_from_bind_flags(texture_vk->t.resource.bind_flags),
5176 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, texture_vk->layout, vk_image, &vk_range);
5177 wined3d_context_vk_reference_texture(context_vk, texture_vk);
5178
5179 wined3d_texture_validate_location(&texture_vk->t, sub_resource_idx, WINED3D_LOCATION_TEXTURE_RGB);
5180 return true;
5181}
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
VkFlags VkImageAspectFlags
Definition: vulkan.h:1043
void VKAPI_CALL vkCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, const VkClearColorValue *pColor, uint32_t rangeCount, const VkImageSubresourceRange *pRanges)
void VKAPI_CALL vkCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, const VkClearDepthStencilValue *pDepthStencil, uint32_t rangeCount, const VkImageSubresourceRange *pRanges)

Referenced by wined3d_texture_vk_load_texture().

◆ wined3d_texture_vk_download_data()

static void wined3d_texture_vk_download_data ( struct wined3d_context *  context,
struct wined3d_texture *  src_texture,
unsigned int  src_sub_resource_idx,
unsigned int  src_location,
const struct wined3d_box *  src_box,
const struct wined3d_bo_address *  dst_bo_addr,
const struct wined3d_format *  dst_format,
unsigned int  dst_x,
unsigned int  dst_y,
unsigned int  dst_z,
unsigned int  dst_row_pitch,
unsigned int  dst_slice_pitch 
)
static

Definition at line 4871 of file texture.c.

4876{
4877 struct wined3d_texture_vk *src_texture_vk = wined3d_texture_vk(src_texture);
4878 struct wined3d_context_vk *context_vk = wined3d_context_vk(context);
4879 unsigned int src_level, src_width, src_height, src_depth;
4880 struct wined3d_texture_sub_resource *sub_resource;
4881 unsigned int src_row_pitch, src_slice_pitch;
4882 struct wined3d_bo_address staging_bo_addr;
4883 VkPipelineStageFlags bo_stage_flags = 0;
4884 const struct wined3d_vk_info *vk_info;
4885 VkCommandBuffer vk_command_buffer;
4886 VkImageSubresourceRange vk_range;
4887 VkBufferMemoryBarrier vk_barrier;
4888 struct wined3d_bo_vk staging_bo;
4889 VkImageAspectFlags aspect_mask;
4890 struct wined3d_bo_vk *dst_bo;
4892 size_t dst_offset = 0;
4893 void *map_ptr;
4894
4895 TRACE("context %p, src_texture %p, src_sub_resource_idx %u, src_location %s, src_box %s, dst_bo_addr %s, "
4896 "dst_format %s, dst_x %u, dst_y %u, dst_z %u, dst_row_pitch %u, dst_slice_pitch %u.\n",
4897 context, src_texture, src_sub_resource_idx, wined3d_debug_location(src_location),
4898 debug_box(src_box), debug_bo_address(dst_bo_addr), debug_d3dformat(dst_format->id),
4899 dst_x, dst_y, dst_z, dst_row_pitch, dst_slice_pitch);
4900
4901 if (src_location != WINED3D_LOCATION_TEXTURE_RGB)
4902 {
4903 FIXME("Unhandled location %s.\n", wined3d_debug_location(src_location));
4904 return;
4905 }
4906
4907 src_level = src_sub_resource_idx % src_texture->level_count;
4908 src_width = wined3d_texture_get_level_width(src_texture, src_level);
4909 src_height = wined3d_texture_get_level_height(src_texture, src_level);
4910 src_depth = wined3d_texture_get_level_depth(src_texture, src_level);
4911 if (src_box->left || src_box->top || src_box->right != src_width || src_box->bottom != src_height
4912 || src_box->front || src_box->back != src_depth)
4913 {
4914 FIXME("Unhandled source box %s.\n", debug_box(src_box));
4915 return;
4916 }
4917
4918 if (dst_format->id != src_texture->resource.format->id)
4919 {
4920 FIXME("Unhandled format conversion (%s -> %s).\n",
4921 debug_d3dformat(src_texture->resource.format->id),
4923 return;
4924 }
4925
4926 if (dst_x || dst_y || dst_z)
4927 {
4928 FIXME("Unhandled destination (%u, %u, %u).\n", dst_x, dst_y, dst_z);
4929 return;
4930 }
4931
4932 if (wined3d_resource_get_sample_count(&src_texture_vk->t.resource) > 1)
4933 {
4934 FIXME("Not supported for multisample textures.\n");
4935 return;
4936 }
4937
4938 aspect_mask = vk_aspect_mask_from_format(src_texture->resource.format);
4939 if (wined3d_popcount(aspect_mask) > 1)
4940 {
4941 FIXME("Unhandled multi-aspect format %s.\n", debug_d3dformat(src_texture->resource.format->id));
4942 return;
4943 }
4944
4945 wined3d_texture_get_pitch(src_texture, src_level, &src_row_pitch, &src_slice_pitch);
4946 if (src_texture->resource.type == WINED3D_RTYPE_TEXTURE_1D)
4947 src_row_pitch = dst_row_pitch = 0;
4948 if (src_texture->resource.type != WINED3D_RTYPE_TEXTURE_3D)
4949 src_slice_pitch = dst_slice_pitch = 0;
4950
4951 sub_resource = &src_texture_vk->t.sub_resources[src_sub_resource_idx];
4952 vk_info = context_vk->vk_info;
4953 if (!(vk_command_buffer = wined3d_context_vk_get_command_buffer(context_vk)))
4954 {
4955 ERR("Failed to get command buffer.\n");
4956 return;
4957 }
4958
4959 /* We need to be outside of a render pass for vkCmdPipelineBarrier() and vkCmdCopyImageToBuffer() calls below. */
4961
4962 if (!dst_bo_addr->buffer_object)
4963 {
4964 if (!wined3d_context_vk_create_bo(context_vk, sub_resource->size,
4966 {
4967 ERR("Failed to create staging bo.\n");
4968 return;
4969 }
4970
4971 dst_bo = &staging_bo;
4972
4973 region.bufferRowLength = (src_row_pitch / dst_format->block_byte_count) * dst_format->block_width;
4974 if (src_row_pitch)
4975 region.bufferImageHeight = (src_slice_pitch / src_row_pitch) * dst_format->block_height;
4976 else
4977 region.bufferImageHeight = 1;
4978
4979 if (src_row_pitch % dst_format->byte_count)
4980 {
4981 FIXME("Row pitch %u is not a multiple of byte count %u.\n", src_row_pitch, dst_format->byte_count);
4982 return;
4983 }
4984 if (src_row_pitch && src_slice_pitch % src_row_pitch)
4985 {
4986 FIXME("Slice pitch %u is not a multiple of row pitch %u.\n", src_slice_pitch, src_row_pitch);
4987 return;
4988 }
4989 }
4990 else
4991 {
4992 dst_bo = wined3d_bo_vk(dst_bo_addr->buffer_object);
4993
4994 region.bufferRowLength = (dst_row_pitch / dst_format->block_byte_count) * dst_format->block_width;
4995 if (dst_row_pitch)
4996 region.bufferImageHeight = (dst_slice_pitch / dst_row_pitch) * dst_format->block_height;
4997 else
4998 region.bufferImageHeight = 1;
4999
5000 if (dst_row_pitch % dst_format->byte_count)
5001 {
5002 FIXME("Row pitch %u is not a multiple of byte count %u.\n", dst_row_pitch, dst_format->byte_count);
5003 return;
5004 }
5005 if (dst_row_pitch && dst_slice_pitch % dst_row_pitch)
5006 {
5007 FIXME("Slice pitch %u is not a multiple of row pitch %u.\n", dst_slice_pitch, dst_row_pitch);
5008 return;
5009 }
5010
5012 vk_barrier.pNext = NULL;
5017 vk_barrier.buffer = dst_bo->vk_buffer;
5018 vk_barrier.offset = dst_bo->b.buffer_offset + (size_t)dst_bo_addr->addr;
5019 vk_barrier.size = sub_resource->size;
5020
5021 bo_stage_flags = vk_pipeline_stage_mask_from_buffer_usage(dst_bo->usage);
5022 dst_offset = (size_t)dst_bo_addr->addr;
5023
5024 VK_CALL(vkCmdPipelineBarrier(vk_command_buffer, bo_stage_flags,
5025 VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, NULL, 1, &vk_barrier, 0, NULL));
5026 }
5027
5028 vk_range.aspectMask = aspect_mask;
5029 vk_range.baseMipLevel = src_level;
5030 vk_range.levelCount = 1;
5031 vk_range.baseArrayLayer = src_sub_resource_idx / src_texture_vk->t.level_count;
5032 vk_range.layerCount = 1;
5033
5034 wined3d_context_vk_image_barrier(context_vk, vk_command_buffer,
5036 vk_access_mask_from_bind_flags(src_texture_vk->t.resource.bind_flags),
5039 src_texture_vk->image.vk_image, &vk_range);
5040
5041 region.bufferOffset = dst_bo->b.buffer_offset + dst_offset;
5042 region.imageSubresource.aspectMask = vk_range.aspectMask;
5043 region.imageSubresource.mipLevel = vk_range.baseMipLevel;
5044 region.imageSubresource.baseArrayLayer = vk_range.baseArrayLayer;
5045 region.imageSubresource.layerCount = vk_range.layerCount;
5046 region.imageOffset.x = 0;
5047 region.imageOffset.y = 0;
5048 region.imageOffset.z = 0;
5049 region.imageExtent.width = src_width;
5050 region.imageExtent.height = src_height;
5051 region.imageExtent.depth = src_depth;
5052
5053 VK_CALL(vkCmdCopyImageToBuffer(vk_command_buffer, src_texture_vk->image.vk_image,
5055
5056 wined3d_context_vk_image_barrier(context_vk, vk_command_buffer,
5059 vk_access_mask_from_bind_flags(src_texture_vk->t.resource.bind_flags),
5061 src_texture_vk->image.vk_image, &vk_range);
5062
5063 wined3d_context_vk_reference_texture(context_vk, src_texture_vk);
5064 wined3d_context_vk_reference_bo(context_vk, dst_bo);
5065
5066 if (dst_bo == &staging_bo)
5067 {
5069 wined3d_context_vk_wait_command_buffer(context_vk, src_texture_vk->image.command_buffer_id);
5070
5071 staging_bo_addr.buffer_object = &staging_bo.b;
5072 staging_bo_addr.addr = NULL;
5073 if (!(map_ptr = wined3d_context_map_bo_address(context, &staging_bo_addr,
5074 sub_resource->size, WINED3D_MAP_READ)))
5075 {
5076 ERR("Failed to map staging bo.\n");
5077 wined3d_context_vk_destroy_bo(context_vk, &staging_bo);
5078 return;
5079 }
5080
5081 wined3d_format_copy_data(dst_format, map_ptr, src_row_pitch, src_slice_pitch,
5082 dst_bo_addr->addr, dst_row_pitch, dst_slice_pitch, src_box->right - src_box->left,
5083 src_box->bottom - src_box->top, src_box->back - src_box->front);
5084
5085 wined3d_context_unmap_bo_address(context, &staging_bo_addr, 0, NULL);
5086 wined3d_context_vk_destroy_bo(context_vk, &staging_bo);
5087 }
5088 else
5089 {
5090 vk_barrier.dstAccessMask = vk_barrier.srcAccessMask;
5092
5093 if (dst_bo->host_synced)
5094 {
5096 bo_stage_flags |= VK_PIPELINE_STAGE_HOST_BIT;
5097 }
5098
5100 bo_stage_flags, 0, 0, NULL, 1, &vk_barrier, 0, NULL));
5101 /* Start the download so we don't stall waiting for the result. */
5103 }
5104}
VkAccessFlags vk_access_mask_from_buffer_usage(VkBufferUsageFlags usage)
Definition: adapter_vk.c:835
VkPipelineStageFlags vk_pipeline_stage_mask_from_buffer_usage(VkBufferUsageFlags usage)
Definition: adapter_vk.c:864
BOOL wined3d_context_vk_create_bo(struct wined3d_context_vk *context_vk, VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags memory_type, struct wined3d_bo_vk *bo)
Definition: context_vk.c:528
void wined3d_context_vk_destroy_bo(struct wined3d_context_vk *context_vk, const struct wined3d_bo_vk *bo)
Definition: context_vk.c:1106
void wined3d_context_vk_submit_command_buffer(struct wined3d_context_vk *context_vk, unsigned int wait_semaphore_count, const VkSemaphore *wait_semaphores, const VkPipelineStageFlags *wait_stages, unsigned int signal_semaphore_count, const VkSemaphore *signal_semaphores)
Definition: context_vk.c:1896
void wined3d_context_vk_wait_command_buffer(struct wined3d_context_vk *context_vk, uint64_t id)
Definition: context_vk.c:1990
void wined3d_format_copy_data(const struct wined3d_format *format, const uint8_t *src, unsigned int src_row_pitch, unsigned int src_slice_pitch, uint8_t *dst, unsigned int dst_row_pitch, unsigned int dst_slice_pitch, unsigned int w, unsigned int h, unsigned int d)
Definition: utils.c:6080
unsigned int size_t
Definition: corecrt.h:203
VkAccessFlags srcAccessMask
Definition: vulkan.h:7632
VkAccessFlags dstAccessMask
Definition: vulkan.h:7633
uint32_t srcQueueFamilyIndex
Definition: vulkan.h:7634
const void * pNext
Definition: vulkan.h:7631
VkStructureType sType
Definition: vulkan.h:7630
uint32_t dstQueueFamilyIndex
Definition: vulkan.h:7635
struct wined3d_bo b
Definition: wined3d_vk.h:310
VkBufferUsageFlags usage
Definition: wined3d_vk.h:319
VkBuffer vk_buffer
Definition: wined3d_vk.h:312
bool host_synced
Definition: wined3d_vk.h:323
VkFlags VkPipelineStageFlags
Definition: vulkan.h:1101
@ VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Definition: vulkan.h:3771
void VKAPI_CALL vkCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkBuffer dstBuffer, uint32_t regionCount, const VkBufferImageCopy *pRegions)
@ VK_BUFFER_USAGE_TRANSFER_DST_BIT
Definition: vulkan.h:1916
@ VK_ACCESS_HOST_READ_BIT
Definition: vulkan.h:1642
@ VK_PIPELINE_STAGE_HOST_BIT
Definition: vulkan.h:4286
void VKAPI_CALL vkCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier *pBufferMemoryBarriers, uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier *pImageMemoryBarriers)
#define VK_QUEUE_FAMILY_IGNORED
Definition: vulkan.h:57
@ VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER
Definition: vulkan.h:5008
static void wined3d_context_vk_reference_bo(const struct wined3d_context_vk *context_vk, struct wined3d_bo_vk *bo)
Definition: wined3d_vk.h:1091

Referenced by wined3d_texture_vk_load_sysmem().

◆ wined3d_texture_vk_get_default_image_info()

const VkDescriptorImageInfo * wined3d_texture_vk_get_default_image_info ( struct wined3d_texture_vk *  texture_vk,
struct wined3d_context_vk *  context_vk 
)

Definition at line 4601 of file texture.c.

4603{
4604 const struct wined3d_format_vk *format_vk;
4605 const struct wined3d_vk_info *vk_info;
4606 struct wined3d_device_vk *device_vk;
4607 VkImageViewCreateInfo create_info;
4608 struct color_fixup_desc fixup;
4609 uint32_t flags = 0;
4610 VkResult vr;
4611
4612 if (texture_vk->default_image_info.imageView)
4613 return &texture_vk->default_image_info;
4614
4615 format_vk = wined3d_format_vk(texture_vk->t.resource.format);
4616 device_vk = wined3d_device_vk(texture_vk->t.resource.device);
4617 vk_info = context_vk->vk_info;
4618
4619 if (texture_vk->t.layer_count > 1)
4621
4622 wined3d_texture_vk_prepare_texture(texture_vk, context_vk);
4624 create_info.pNext = NULL;
4625 create_info.flags = 0;
4626 create_info.image = texture_vk->image.vk_image;
4627 create_info.viewType = vk_image_view_type_from_wined3d(texture_vk->t.resource.type, flags);
4628 create_info.format = format_vk->vk_format;
4629 fixup = format_vk->f.color_fixup;
4630 if (is_identity_fixup(fixup) || !can_use_texture_swizzle(context_vk->c.d3d_info, &format_vk->f))
4631 {
4636 }
4637 else
4638 {
4640 }
4641 create_info.subresourceRange.aspectMask = vk_aspect_mask_from_format(&format_vk->f);
4642 create_info.subresourceRange.baseMipLevel = 0;
4643 create_info.subresourceRange.levelCount = texture_vk->t.level_count;
4644 create_info.subresourceRange.baseArrayLayer = 0;
4645 create_info.subresourceRange.layerCount = texture_vk->t.layer_count;
4646 if ((vr = VK_CALL(vkCreateImageView(device_vk->vk_device, &create_info,
4647 NULL, &texture_vk->default_image_info.imageView))) < 0)
4648 {
4649 ERR("Failed to create Vulkan image view, vr %s.\n", wined3d_debug_vkresult(vr));
4650 return NULL;
4651 }
4652
4653 TRACE("Created image view 0x%s.\n", wine_dbgstr_longlong(texture_vk->default_image_info.imageView));
4654
4655 texture_vk->default_image_info.sampler = VK_NULL_HANDLE;
4656
4657 /* The default image view is used for SRVs, UAVs and RTVs when the d3d view encompasses the entire
4658 * resource. Any UAV capable resource will always use VK_IMAGE_LAYOUT_GENERAL, so we can use the
4659 * same image info for SRVs and UAVs. For render targets wined3d_rendertarget_view_vk_get_image_view
4660 * only cares about the VkImageView, not entire image info. So using SHADER_READ_ONLY_OPTIMAL works,
4661 * but relies on what the callers of the function do and don't do with the descriptor we return.
4662 *
4663 * Note that VkWriteDescriptorSet for SRV/UAV use takes a VkDescriptorImageInfo *, so we need a
4664 * place to store the VkDescriptorImageInfo. So returning onlky a VkImageView from this function
4665 * would bring its own problems. */
4666 if (texture_vk->layout == VK_IMAGE_LAYOUT_GENERAL)
4668 else
4670
4671 return &texture_vk->default_image_info;
4672}
void wined3d_vk_swizzle_from_color_fixup(VkComponentMapping *mapping, struct color_fixup_desc fixup)
Definition: texture.c:4583
BOOL wined3d_texture_vk_prepare_texture(struct wined3d_texture_vk *texture_vk, struct wined3d_context_vk *context_vk)
Definition: texture.c:5244
VkImageViewType vk_image_view_type_from_wined3d(enum wined3d_resource_type type, uint32_t flags)
Definition: view.c:676
static __inline const char * wine_dbgstr_longlong(ULONGLONG ll)
Definition: compat.h:49
VkComponentSwizzle r
Definition: vulkan.h:7880
VkComponentSwizzle a
Definition: vulkan.h:7883
VkComponentSwizzle g
Definition: vulkan.h:7881
VkComponentSwizzle b
Definition: vulkan.h:7882
VkImageLayout imageLayout
Definition: vulkan.h:8266
VkImageSubresourceRange subresourceRange
Definition: vulkan.h:9118
VkComponentMapping components
Definition: vulkan.h:9117
VkImageViewType viewType
Definition: vulkan.h:9115
VkStructureType sType
Definition: vulkan.h:9111
const void * pNext
Definition: vulkan.h:9112
VkImageViewCreateFlags flags
Definition: vulkan.h:9113
struct wined3d_format f
Definition: wined3d_vk.h:1081
VkDescriptorImageInfo default_image_info
Definition: wined3d_vk.h:881
@ VK_COMPONENT_SWIZZLE_IDENTITY
Definition: vulkan.h:2188
VkResult VKAPI_CALL vkCreateImageView(VkDevice device, const VkImageViewCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkImageView *pView)
#define VK_NULL_HANDLE
Definition: vulkan.h:861
@ VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
Definition: vulkan.h:4979
#define WINED3D_VIEW_TEXTURE_ARRAY
Definition: wined3d.h:1583

Referenced by wined3d_rendertarget_view_vk_get_image_view(), wined3d_shader_descriptor_writes_vk_add_srv_write(), wined3d_shader_descriptor_writes_vk_add_uav_write(), and wined3d_unordered_access_view_vk_clear().

◆ wined3d_texture_vk_init()

HRESULT wined3d_texture_vk_init ( struct wined3d_texture_vk *  texture_vk,
struct wined3d_device *  device,
const struct wined3d_resource_desc *  desc,
unsigned int  layer_count,
unsigned int  level_count,
uint32_t  flags,
void *  parent,
const struct wined3d_parent_ops *  parent_ops 
)

Definition at line 5484 of file texture.c.

5487{
5488 TRACE("texture_vk %p, device %p, desc %p, layer_count %u, "
5489 "level_count %u, flags %#x, parent %p, parent_ops %p.\n",
5490 texture_vk, device, desc, layer_count,
5491 level_count, flags, parent, parent_ops);
5492
5493 return wined3d_texture_init(&texture_vk->t, desc, layer_count, level_count,
5494 flags, device, parent, parent_ops, &texture_vk[1], &wined3d_texture_vk_ops);
5495}
static const struct wined3d_texture_ops wined3d_texture_vk_ops
Definition: texture.c:5475

Referenced by adapter_vk_create_texture().

◆ wined3d_texture_vk_load_location()

static BOOL wined3d_texture_vk_load_location ( struct wined3d_texture *  texture,
unsigned int  sub_resource_idx,
struct wined3d_context *  context,
uint32_t  location 
)
static

Definition at line 5403 of file texture.c.

5405{
5407 return FALSE;
5408
5409 switch (location)
5410 {
5413
5417
5418 default:
5419 FIXME("Unimplemented location %s.\n", wined3d_debug_location(location));
5420 return FALSE;
5421 }
5422}
static BOOL wined3d_texture_vk_load_sysmem(struct wined3d_texture_vk *texture_vk, unsigned int sub_resource_idx, struct wined3d_context *context, unsigned int location)
Definition: texture.c:5219
static BOOL wined3d_texture_vk_prepare_location(struct wined3d_texture *texture, unsigned int sub_resource_idx, struct wined3d_context *context, unsigned int location)
Definition: texture.c:5381
static BOOL wined3d_texture_vk_load_texture(struct wined3d_texture_vk *texture_vk, unsigned int sub_resource_idx, struct wined3d_context *context)
Definition: texture.c:5183

◆ wined3d_texture_vk_load_sysmem()

static BOOL wined3d_texture_vk_load_sysmem ( struct wined3d_texture_vk *  texture_vk,
unsigned int  sub_resource_idx,
struct wined3d_context *  context,
unsigned int  location 
)
static

Definition at line 5219 of file texture.c.

5221{
5222 struct wined3d_texture_sub_resource *sub_resource;
5223 unsigned int level, row_pitch, slice_pitch;
5224 struct wined3d_bo_address data;
5225 struct wined3d_box src_box;
5226
5227 sub_resource = &texture_vk->t.sub_resources[sub_resource_idx];
5228 if (!(sub_resource->locations & WINED3D_LOCATION_TEXTURE_RGB))
5229 {
5230 ERR("Unimplemented load from %s.\n", wined3d_debug_location(sub_resource->locations));
5231 return FALSE;
5232 }
5233
5234 level = sub_resource_idx % texture_vk->t.level_count;
5235 wined3d_texture_get_bo_address(&texture_vk->t, sub_resource_idx, &data, location);
5236 wined3d_texture_get_level_box(&texture_vk->t, level, &src_box);
5237 wined3d_texture_get_pitch(&texture_vk->t, level, &row_pitch, &slice_pitch);
5239 &src_box, &data, texture_vk->t.resource.format, 0, 0, 0, row_pitch, slice_pitch);
5240
5241 return TRUE;
5242}
static void wined3d_texture_vk_download_data(struct wined3d_context *context, struct wined3d_texture *src_texture, unsigned int src_sub_resource_idx, unsigned int src_location, const struct wined3d_box *src_box, const struct wined3d_bo_address *dst_bo_addr, const struct wined3d_format *dst_format, unsigned int dst_x, unsigned int dst_y, unsigned int dst_z, unsigned int dst_row_pitch, unsigned int dst_slice_pitch)
Definition: texture.c:4871

Referenced by wined3d_texture_vk_load_location().

◆ wined3d_texture_vk_load_texture()

static BOOL wined3d_texture_vk_load_texture ( struct wined3d_texture_vk *  texture_vk,
unsigned int  sub_resource_idx,
struct wined3d_context *  context 
)
static

Definition at line 5183 of file texture.c.

5185{
5186 struct wined3d_texture_sub_resource *sub_resource;
5187 unsigned int level, row_pitch, slice_pitch;
5188 struct wined3d_bo_address data;
5189 struct wined3d_box src_box;
5190
5191 sub_resource = &texture_vk->t.sub_resources[sub_resource_idx];
5192
5193 if (sub_resource->locations & WINED3D_LOCATION_CLEARED)
5194 {
5195 if (!wined3d_texture_vk_clear(texture_vk, sub_resource_idx, context))
5196 return FALSE;
5197
5198 if (sub_resource->locations & WINED3D_LOCATION_TEXTURE_RGB)
5199 return TRUE;
5200 }
5201
5202 if (!(sub_resource->locations & wined3d_texture_sysmem_locations))
5203 {
5204 ERR("Unimplemented load from %s.\n", wined3d_debug_location(sub_resource->locations));
5205 return FALSE;
5206 }
5207
5208 level = sub_resource_idx % texture_vk->t.level_count;
5209 wined3d_texture_get_memory(&texture_vk->t, sub_resource_idx, context, &data);
5210 wined3d_texture_get_level_box(&texture_vk->t, level, &src_box);
5211 wined3d_texture_get_pitch(&texture_vk->t, level, &row_pitch, &slice_pitch);
5213 &src_box, row_pitch, slice_pitch, &texture_vk->t, sub_resource_idx,
5215
5216 return TRUE;
5217}
static void wined3d_texture_vk_upload_data(struct wined3d_context *context, const struct wined3d_const_bo_address *src_bo_addr, const struct wined3d_format *src_format, const struct wined3d_box *src_box, unsigned int src_row_pitch, unsigned int src_slice_pitch, struct wined3d_texture *dst_texture, unsigned int dst_sub_resource_idx, unsigned int dst_location, unsigned int dst_x, unsigned int dst_y, unsigned int dst_z)
Definition: texture.c:4674
static bool wined3d_texture_vk_clear(struct wined3d_texture_vk *texture_vk, unsigned int sub_resource_idx, struct wined3d_context *context)
Definition: texture.c:5106

Referenced by wined3d_texture_vk_load_location().

◆ wined3d_texture_vk_make_generic()

void wined3d_texture_vk_make_generic ( struct wined3d_texture_vk *  texture_vk,
struct wined3d_context_vk *  context_vk 
)

Definition at line 5581 of file texture.c.

5583{
5584 VkImageSubresourceRange vk_range;
5585
5586 if (texture_vk->layout == VK_IMAGE_LAYOUT_GENERAL)
5587 return;
5588
5589 vk_range.aspectMask = vk_aspect_mask_from_format(texture_vk->t.resource.format);
5590 vk_range.baseMipLevel = 0;
5592 vk_range.baseArrayLayer = 0;
5594
5598 0, 0,
5599 texture_vk->layout, VK_IMAGE_LAYOUT_GENERAL, texture_vk->image.vk_image, &vk_range);
5600
5601 texture_vk->layout = VK_IMAGE_LAYOUT_GENERAL;
5603}
@ VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT
Definition: vulkan.h:4285

Referenced by wined3d_context_vk_begin_render_pass().

◆ wined3d_texture_vk_prepare_buffer_object()

static BOOL wined3d_texture_vk_prepare_buffer_object ( struct wined3d_texture_vk *  texture_vk,
unsigned int  sub_resource_idx,
struct wined3d_context_vk *  context_vk 
)
static

Definition at line 5352 of file texture.c.

5354{
5355 struct wined3d_texture_sub_resource *sub_resource;
5356 struct wined3d_bo_vk *bo;
5357
5358 sub_resource = &texture_vk->t.sub_resources[sub_resource_idx];
5359 if (sub_resource->bo)
5360 return TRUE;
5361
5362 if (!(bo = malloc(sizeof(*bo))))
5363 return FALSE;
5364
5365 if (!wined3d_context_vk_create_bo(context_vk, sub_resource->size,
5368 {
5369 free(bo);
5370 return FALSE;
5371 }
5372
5373 /* Texture buffer objects receive a barrier to HOST_READ in wined3d_texture_vk_download_data(),
5374 * so they don't need it when they are mapped for reading. */
5375 bo->host_synced = true;
5376 sub_resource->bo = &bo->b;
5377 TRACE("Created buffer object %p for texture %p, sub-resource %u.\n", bo, texture_vk, sub_resource_idx);
5378 return TRUE;
5379}
@ VK_BUFFER_USAGE_TRANSFER_SRC_BIT
Definition: vulkan.h:1915

Referenced by wined3d_texture_vk_prepare_location().

◆ wined3d_texture_vk_prepare_location()

static BOOL wined3d_texture_vk_prepare_location ( struct wined3d_texture *  texture,
unsigned int  sub_resource_idx,
struct wined3d_context *  context,
unsigned int  location 
)
static

Definition at line 5381 of file texture.c.

5383{
5384 switch (location)
5385 {
5387 return texture->sub_resources[sub_resource_idx].user_memory ? TRUE
5389
5392
5396
5397 default:
5398 FIXME("Unhandled location %s.\n", wined3d_debug_location(location));
5399 return FALSE;
5400 }
5401}
static BOOL wined3d_texture_vk_prepare_buffer_object(struct wined3d_texture_vk *texture_vk, unsigned int sub_resource_idx, struct wined3d_context_vk *context_vk)
Definition: texture.c:5352

Referenced by wined3d_texture_vk_load_location().

◆ wined3d_texture_vk_prepare_texture()

BOOL wined3d_texture_vk_prepare_texture ( struct wined3d_texture_vk *  texture_vk,
struct wined3d_context_vk *  context_vk 
)

Definition at line 5244 of file texture.c.

5246{
5247 const struct wined3d_format_vk *format_vk;
5248 struct wined3d_resource *resource;
5249 VkCommandBuffer vk_command_buffer;
5250 VkImageSubresourceRange vk_range;
5251 VkImageUsageFlags vk_usage;
5252 VkImageType vk_image_type;
5253 unsigned int flags = 0;
5254
5255 if (texture_vk->t.flags & WINED3D_TEXTURE_RGB_ALLOCATED)
5256 return TRUE;
5257
5258 if (!(vk_command_buffer = wined3d_context_vk_get_command_buffer(context_vk)))
5259 {
5260 ERR("Failed to get command buffer.\n");
5261 return FALSE;
5262 }
5263
5264 resource = &texture_vk->t.resource;
5265 format_vk = wined3d_format_vk(resource->format);
5266
5267 if (wined3d_format_is_typeless(&format_vk->f) || texture_vk->t.swapchain
5268 || (texture_vk->t.resource.bind_flags & WINED3D_BIND_UNORDERED_ACCESS))
5269 {
5270 /* For UAVs, we need this in case a clear necessitates creation of a new view
5271 * with a different format. */
5273 }
5274
5275 switch (resource->type)
5276 {
5278 vk_image_type = VK_IMAGE_TYPE_1D;
5279 break;
5281 vk_image_type = VK_IMAGE_TYPE_2D;
5282 if (texture_vk->t.layer_count >= 6 && resource->width == resource->height)
5284 break;
5286 vk_image_type = VK_IMAGE_TYPE_3D;
5289 break;
5290 default:
5291 ERR("Invalid resource type %s.\n", debug_d3dresourcetype(resource->type));
5292 vk_image_type = VK_IMAGE_TYPE_2D;
5293 break;
5294 }
5295
5297 if (resource->bind_flags & WINED3D_BIND_SHADER_RESOURCE)
5298 vk_usage |= VK_IMAGE_USAGE_SAMPLED_BIT;
5299 if (resource->bind_flags & WINED3D_BIND_RENDER_TARGET)
5301 if (resource->bind_flags & WINED3D_BIND_DEPTH_STENCIL)
5303 if (resource->bind_flags & WINED3D_BIND_UNORDERED_ACCESS)
5304 vk_usage |= VK_IMAGE_USAGE_STORAGE_BIT;
5305
5306 if (resource->bind_flags & WINED3D_BIND_UNORDERED_ACCESS)
5307 texture_vk->layout = VK_IMAGE_LAYOUT_GENERAL;
5308 else if (resource->bind_flags & WINED3D_BIND_RENDER_TARGET)
5310 else if (resource->bind_flags & WINED3D_BIND_DEPTH_STENCIL)
5312 else if (resource->bind_flags & WINED3D_BIND_SHADER_RESOURCE)
5314 else
5315 {
5316 FIXME("unexpected bind flags %s, using VK_IMAGE_LAYOUT_GENERAL\n", wined3d_debug_bind_flags(resource->bind_flags));
5317 texture_vk->layout = VK_IMAGE_LAYOUT_GENERAL;
5318 }
5319
5320 if (!wined3d_context_vk_create_image(context_vk, vk_image_type, vk_usage, format_vk->vk_format,
5322 texture_vk->t.level_count, texture_vk->t.layer_count, flags, &texture_vk->image))
5323 {
5324 return FALSE;
5325 }
5326
5327 /* We can't use a zero src access mask without synchronization2. Set the last-used bind mask to something
5328 * non-zero to avoid this. */
5329 texture_vk->bind_mask = resource->bind_flags;
5330
5331 vk_range.aspectMask = vk_aspect_mask_from_format(&format_vk->f);
5332 vk_range.baseMipLevel = 0;
5334 vk_range.baseArrayLayer = 0;
5336
5337 wined3d_context_vk_reference_texture(context_vk, texture_vk);
5338 wined3d_context_vk_image_barrier(context_vk, vk_command_buffer,
5340 0, 0,
5341 VK_IMAGE_LAYOUT_UNDEFINED, texture_vk->layout,
5342 texture_vk->image.vk_image, &vk_range);
5343
5344 texture_vk->t.flags |= WINED3D_TEXTURE_RGB_ALLOCATED;
5345
5346 TRACE("Created image 0x%s, memory 0x%s for texture %p.\n",
5347 wine_dbgstr_longlong(texture_vk->image.vk_image), wine_dbgstr_longlong(texture_vk->image.vk_memory), texture_vk);
5348
5349 return TRUE;
5350}
VkFlags VkImageUsageFlags
Definition: vulkan.h:1050
@ VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT
Definition: vulkan.h:3425
@ VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT
Definition: vulkan.h:3424
@ VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT
Definition: vulkan.h:3423
@ VK_IMAGE_USAGE_SAMPLED_BIT
Definition: vulkan.h:3512
@ VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
Definition: vulkan.h:3515
@ VK_IMAGE_USAGE_STORAGE_BIT
Definition: vulkan.h:3513
#define WINED3D_BIND_UNORDERED_ACCESS
Definition: wined3d.h:916

Referenced by wined3d_texture_vk_get_default_image_info(), wined3d_texture_vk_prepare_location(), and wined3d_view_vk_create_vk_image_view().

◆ wined3d_texture_vk_unload_location()

static void wined3d_texture_vk_unload_location ( struct wined3d_texture *  texture,
struct wined3d_context *  context,
unsigned int  location 
)
static

Definition at line 5424 of file texture.c.

5426{
5427 struct wined3d_texture_vk *texture_vk = wined3d_texture_vk(texture);
5428 struct wined3d_context_vk *context_vk = wined3d_context_vk(context);
5429 unsigned int i, sub_count;
5430
5431 TRACE("texture %p, context %p, location %s.\n", texture, context, wined3d_debug_location(location));
5432
5433 switch (location)
5434 {
5436 if (texture_vk->default_image_info.imageView)
5437 {
5439 texture_vk->default_image_info.imageView, texture_vk->image.command_buffer_id);
5440 texture_vk->default_image_info.imageView = VK_NULL_HANDLE;
5441 }
5442
5443 if (texture_vk->image.vk_image)
5444 wined3d_context_vk_destroy_image(context_vk, &texture_vk->image);
5445 break;
5446
5448 sub_count = texture->level_count * texture->layer_count;
5449 for (i = 0; i < sub_count; ++i)
5450 {
5451 struct wined3d_texture_sub_resource *sub_resource = &texture->sub_resources[i];
5452
5453 if (sub_resource->bo)
5454 {
5455 struct wined3d_bo_vk *bo_vk = wined3d_bo_vk(sub_resource->bo);
5456
5457 wined3d_context_vk_destroy_bo(context_vk, bo_vk);
5458 free(bo_vk);
5459 sub_resource->bo = NULL;
5460 }
5461 }
5462 break;
5463
5467 break;
5468
5469 default:
5470 ERR("Unhandled location %s.\n", wined3d_debug_location(location));
5471 break;
5472 }
5473}
void wined3d_context_vk_destroy_vk_image_view(struct wined3d_context_vk *context_vk, VkImageView vk_view, uint64_t command_buffer_id)
Definition: context_vk.c:956

◆ wined3d_texture_vk_upload_data()

static void wined3d_texture_vk_upload_data ( struct wined3d_context *  context,
const struct wined3d_const_bo_address *  src_bo_addr,
const struct wined3d_format *  src_format,
const struct wined3d_box *  src_box,
unsigned int  src_row_pitch,
unsigned int  src_slice_pitch,
struct wined3d_texture *  dst_texture,
unsigned int  dst_sub_resource_idx,
unsigned int  dst_location,
unsigned int  dst_x,
unsigned int  dst_y,
unsigned int  dst_z 
)
static

Definition at line 4674 of file texture.c.

4679{
4680 struct wined3d_texture_vk *dst_texture_vk = wined3d_texture_vk(dst_texture);
4681 struct wined3d_context_vk *context_vk = wined3d_context_vk(context);
4682 unsigned int dst_level, dst_row_pitch, dst_slice_pitch;
4683 struct wined3d_texture_sub_resource *sub_resource;
4684 unsigned int src_width, src_height, src_depth;
4685 struct wined3d_bo_address staging_bo_addr;
4686 VkPipelineStageFlags bo_stage_flags = 0;
4687 const struct wined3d_vk_info *vk_info;
4688 VkCommandBuffer vk_command_buffer;
4689 VkBufferMemoryBarrier vk_barrier;
4690 VkImageSubresourceRange vk_range;
4691 struct wined3d_bo_vk staging_bo;
4692 VkImageAspectFlags aspect_mask;
4693 struct wined3d_bo_vk *src_bo;
4694 struct wined3d_range range;
4696 size_t src_offset;
4697 void *map_ptr;
4698
4699 TRACE("context %p, src_bo_addr %s, src_format %s, src_box %s, src_row_pitch %u, src_slice_pitch %u, "
4700 "dst_texture %p, dst_sub_resource_idx %u, dst_location %s, dst_x %u, dst_y %u, dst_z %u.\n",
4701 context, debug_const_bo_address(src_bo_addr), debug_d3dformat(src_format->id), debug_box(src_box),
4702 src_row_pitch, src_slice_pitch, dst_texture, dst_sub_resource_idx,
4703 wined3d_debug_location(dst_location), dst_x, dst_y, dst_z);
4704
4705 if (src_format->id != dst_texture->resource.format->id)
4706 {
4707 FIXME("Unhandled format conversion (%s -> %s).\n",
4708 debug_d3dformat(src_format->id),
4709 debug_d3dformat(dst_texture->resource.format->id));
4710 return;
4711 }
4712
4713 dst_level = dst_sub_resource_idx % dst_texture->level_count;
4714 wined3d_texture_get_pitch(dst_texture, dst_level, &dst_row_pitch, &dst_slice_pitch);
4715 if (dst_texture->resource.type == WINED3D_RTYPE_TEXTURE_1D)
4716 src_row_pitch = dst_row_pitch = 0;
4717 if (dst_texture->resource.type != WINED3D_RTYPE_TEXTURE_3D)
4718 src_slice_pitch = dst_slice_pitch = 0;
4719
4720 if (dst_location != WINED3D_LOCATION_TEXTURE_RGB)
4721 {
4722 FIXME("Unhandled location %s.\n", wined3d_debug_location(dst_location));
4723 return;
4724 }
4725
4726 if (wined3d_resource_get_sample_count(&dst_texture_vk->t.resource) > 1)
4727 {
4728 FIXME("Not supported for multisample textures.\n");
4729 return;
4730 }
4731
4732 aspect_mask = vk_aspect_mask_from_format(dst_texture->resource.format);
4733 if (wined3d_popcount(aspect_mask) > 1)
4734 {
4735 FIXME("Unhandled multi-aspect format %s.\n", debug_d3dformat(dst_texture->resource.format->id));
4736 return;
4737 }
4738
4739 sub_resource = &dst_texture_vk->t.sub_resources[dst_sub_resource_idx];
4740 vk_info = context_vk->vk_info;
4741
4742 src_width = src_box->right - src_box->left;
4743 src_height = src_box->bottom - src_box->top;
4744 src_depth = src_box->back - src_box->front;
4745
4746 src_offset = src_box->front * src_slice_pitch
4747 + (src_box->top / src_format->block_height) * src_row_pitch
4748 + (src_box->left / src_format->block_width) * src_format->block_byte_count;
4749
4750 if (!(vk_command_buffer = wined3d_context_vk_get_command_buffer(context_vk)))
4751 {
4752 ERR("Failed to get command buffer.\n");
4753 return;
4754 }
4755
4756 /* We need to be outside of a render pass for vkCmdPipelineBarrier() and vkCmdCopyBufferToImage() calls below. */
4758 if (!src_bo_addr->buffer_object)
4759 {
4760 unsigned int staging_row_pitch, staging_slice_pitch, staging_size;
4761
4762 wined3d_format_calculate_pitch(src_format, context->device->surface_alignment, src_width, src_height,
4763 &staging_row_pitch, &staging_slice_pitch);
4764 staging_size = staging_slice_pitch * src_depth;
4765
4766 if (!wined3d_context_vk_create_bo(context_vk, staging_size,
4768 {
4769 ERR("Failed to create staging bo.\n");
4770 return;
4771 }
4772
4773 staging_bo_addr.buffer_object = &staging_bo.b;
4774 staging_bo_addr.addr = NULL;
4775 if (!(map_ptr = wined3d_context_map_bo_address(context, &staging_bo_addr,
4776 staging_size, WINED3D_MAP_DISCARD | WINED3D_MAP_WRITE)))
4777 {
4778 ERR("Failed to map staging bo.\n");
4779 wined3d_context_vk_destroy_bo(context_vk, &staging_bo);
4780 return;
4781 }
4782
4783 wined3d_format_copy_data(src_format, src_bo_addr->addr + src_offset, src_row_pitch, src_slice_pitch,
4784 map_ptr, staging_row_pitch, staging_slice_pitch, src_width, src_height, src_depth);
4785
4786 range.offset = 0;
4787 range.size = staging_size;
4788 wined3d_context_unmap_bo_address(context, &staging_bo_addr, 1, &range);
4789
4790 src_bo = &staging_bo;
4791
4792 src_offset = 0;
4793 src_row_pitch = staging_row_pitch;
4794 src_slice_pitch = staging_slice_pitch;
4795 }
4796 else
4797 {
4798 src_bo = wined3d_bo_vk(src_bo_addr->buffer_object);
4799
4801 vk_barrier.pNext = NULL;
4802 vk_barrier.srcAccessMask = vk_access_mask_from_buffer_usage(src_bo->usage) & ~WINED3D_READ_ONLY_ACCESS_FLAGS;
4806 vk_barrier.buffer = src_bo->vk_buffer;
4807 vk_barrier.offset = src_bo->b.buffer_offset + (size_t)src_bo_addr->addr;
4808 vk_barrier.size = sub_resource->size;
4809
4810 src_offset += (size_t)src_bo_addr->addr;
4811
4812 bo_stage_flags = vk_pipeline_stage_mask_from_buffer_usage(src_bo->usage);
4813 if (vk_barrier.srcAccessMask)
4814 VK_CALL(vkCmdPipelineBarrier(vk_command_buffer, bo_stage_flags,
4815 VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, NULL, 1, &vk_barrier, 0, NULL));
4816 }
4817
4818 vk_range.aspectMask = aspect_mask;
4819 vk_range.baseMipLevel = dst_level;
4820 vk_range.levelCount = 1;
4821 vk_range.baseArrayLayer = dst_sub_resource_idx / dst_texture_vk->t.level_count;
4822 vk_range.layerCount = 1;
4823
4824 wined3d_context_vk_image_barrier(context_vk, vk_command_buffer,
4826 vk_access_mask_from_bind_flags(dst_texture_vk->t.resource.bind_flags),
4829 dst_texture_vk->image.vk_image, &vk_range);
4830
4831 region.bufferOffset = src_bo->b.buffer_offset + src_offset;
4832 region.bufferRowLength = (src_row_pitch / src_format->block_byte_count) * src_format->block_width;
4833 if (src_row_pitch)
4834 region.bufferImageHeight = (src_slice_pitch / src_row_pitch) * src_format->block_height;
4835 else
4836 region.bufferImageHeight = 1;
4837 region.imageSubresource.aspectMask = vk_range.aspectMask;
4838 region.imageSubresource.mipLevel = vk_range.baseMipLevel;
4839 region.imageSubresource.baseArrayLayer = vk_range.baseArrayLayer;
4840 region.imageSubresource.layerCount = vk_range.layerCount;
4841 region.imageOffset.x = dst_x;
4842 region.imageOffset.y = dst_y;
4843 region.imageOffset.z = dst_z;
4844 region.imageExtent.width = src_width;
4845 region.imageExtent.height = src_height;
4846 region.imageExtent.depth = src_depth;
4847
4848 VK_CALL(vkCmdCopyBufferToImage(vk_command_buffer, src_bo->vk_buffer,
4849 dst_texture_vk->image.vk_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region));
4850
4851 wined3d_context_vk_image_barrier(context_vk, vk_command_buffer,
4854 vk_access_mask_from_bind_flags(dst_texture_vk->t.resource.bind_flags),
4856 dst_texture_vk->image.vk_image, &vk_range);
4857 wined3d_context_vk_reference_texture(context_vk, dst_texture_vk);
4858 wined3d_context_vk_reference_bo(context_vk, src_bo);
4859
4860 if (src_bo == &staging_bo)
4861 {
4862 wined3d_context_vk_destroy_bo(context_vk, &staging_bo);
4863 }
4864 else if (vk_barrier.srcAccessMask)
4865 {
4867 bo_stage_flags, 0, 0, NULL, 0, NULL, 0, NULL));
4868 }
4869}
void VKAPI_CALL vkCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, VkImageLayout dstImageLayout, uint32_t regionCount, const VkBufferImageCopy *pRegions)

Referenced by wined3d_texture_vk_load_texture().

◆ wined3d_vk_blitter_create()

void wined3d_vk_blitter_create ( struct wined3d_blitter **  next)

Definition at line 7048 of file texture.c.

7049{
7050 struct wined3d_blitter *blitter;
7051
7052 if (!(blitter = malloc(sizeof(*blitter))))
7053 return;
7054
7055 TRACE("Created blitter %p.\n", blitter);
7056
7057 blitter->ops = &vk_blitter_ops;
7058 blitter->next = *next;
7059 *next = blitter;
7060}
static const struct wined3d_blitter_ops vk_blitter_ops
Definition: texture.c:7041

Referenced by adapter_vk_init_3d().

◆ wined3d_vk_swizzle_from_color_fixup()

void wined3d_vk_swizzle_from_color_fixup ( VkComponentMapping *  mapping,
struct color_fixup_desc  fixup 
)

Definition at line 4583 of file texture.c.

4584{
4585 static const VkComponentSwizzle swizzle_source[] =
4586 {
4587 VK_COMPONENT_SWIZZLE_ZERO, /* CHANNEL_SOURCE_ZERO */
4588 VK_COMPONENT_SWIZZLE_ONE, /* CHANNEL_SOURCE_ONE */
4589 VK_COMPONENT_SWIZZLE_R, /* CHANNEL_SOURCE_X */
4590 VK_COMPONENT_SWIZZLE_G, /* CHANNEL_SOURCE_Y */
4591 VK_COMPONENT_SWIZZLE_B, /* CHANNEL_SOURCE_Z */
4592 VK_COMPONENT_SWIZZLE_A, /* CHANNEL_SOURCE_W */
4593 };
4594
4595 mapping->r = swizzle_source[fixup.x_source];
4596 mapping->g = swizzle_source[fixup.y_source];
4597 mapping->b = swizzle_source[fixup.z_source];
4598 mapping->a = swizzle_source[fixup.w_source];
4599}
GLenum GLenum GLenum GLenum mapping
Definition: glext.h:9031
VkComponentSwizzle
Definition: vulkan.h:2187
@ VK_COMPONENT_SWIZZLE_G
Definition: vulkan.h:2192
@ VK_COMPONENT_SWIZZLE_B
Definition: vulkan.h:2193
@ VK_COMPONENT_SWIZZLE_ONE
Definition: vulkan.h:2190
@ VK_COMPONENT_SWIZZLE_A
Definition: vulkan.h:2194
@ VK_COMPONENT_SWIZZLE_R
Definition: vulkan.h:2191
@ VK_COMPONENT_SWIZZLE_ZERO
Definition: vulkan.h:2189

Referenced by wined3d_texture_vk_get_default_image_info(), and wined3d_view_vk_create_vk_image_view().

Variable Documentation

◆ fbo_blitter_ops

const struct wined3d_blitter_ops fbo_blitter_ops
static
Initial value:
=
{
}
static DWORD fbo_blitter_blit(struct wined3d_blitter *blitter, enum wined3d_blit_op op, struct wined3d_context *context, struct wined3d_texture *src_texture, unsigned int src_sub_resource_idx, DWORD src_location, const RECT *src_rect, struct wined3d_texture *dst_texture, unsigned int dst_sub_resource_idx, DWORD dst_location, const RECT *dst_rect, const struct wined3d_color_key *colour_key, enum wined3d_texture_filter_type filter, const struct wined3d_format *resolve_format)
Definition: texture.c:6030
static void fbo_blitter_destroy(struct wined3d_blitter *blitter, struct wined3d_context *context)
Definition: texture.c:6009
static void fbo_blitter_clear(struct wined3d_blitter *blitter, struct wined3d_device *device, unsigned int rt_count, const struct wined3d_fb_state *fb, unsigned int rect_count, const RECT *clear_rects, const RECT *draw_rect, uint32_t flags, const struct wined3d_color *colour, float depth, unsigned int stencil)
Definition: texture.c:6019

Definition at line 6098 of file texture.c.

Referenced by wined3d_fbo_blitter_create().

◆ ffp_blitter_ops

const struct wined3d_blitter_ops ffp_blitter_ops
static
Initial value:
=
{
}
static void ffp_blitter_clear(struct wined3d_blitter *blitter, struct wined3d_device *device, unsigned int rt_count, const struct wined3d_fb_state *fb, unsigned int rect_count, const RECT *clear_rects, const RECT *draw_rect, uint32_t flags, const struct wined3d_color *colour, float depth, unsigned int stencil)
Definition: texture.c:5873
static DWORD ffp_blitter_blit(struct wined3d_blitter *blitter, enum wined3d_blit_op op, struct wined3d_context *context, struct wined3d_texture *src_texture, unsigned int src_sub_resource_idx, DWORD src_location, const RECT *src_rect, struct wined3d_texture *dst_texture, unsigned int dst_sub_resource_idx, DWORD dst_location, const RECT *dst_rect, const struct wined3d_color_key *colour_key, enum wined3d_texture_filter_type filter, const struct wined3d_format *resolve_format)
Definition: texture.c:5968
static void ffp_blitter_destroy(struct wined3d_blitter *blitter, struct wined3d_context *context)
Definition: texture.c:5605

Definition at line 5988 of file texture.c.

Referenced by wined3d_ffp_blitter_create().

◆ formats_src_alpha_fixup

const struct d3dfmt_alpha_fixup formats_src_alpha_fixup[]
static
Initial value:
=
{
}
@ WINED3DFMT_B4G4R4A4_UNORM
Definition: wined3d.h:130
@ WINED3DFMT_B8G8R8A8_UNORM
Definition: wined3d.h:244
@ WINED3DFMT_B8G8R8X8_UNORM
Definition: wined3d.h:245
@ WINED3DFMT_B5G5R5X1_UNORM
Definition: wined3d.h:129
@ WINED3DFMT_B5G5R5A1_UNORM
Definition: wined3d.h:243
@ WINED3DFMT_B4G4R4X4_UNORM
Definition: wined3d.h:133

Referenced by wined3d_get_alpha_fixup_format().

◆ raw_blitter_ops

const struct wined3d_blitter_ops raw_blitter_ops
static
Initial value:
=
{
}
static void raw_blitter_clear(struct wined3d_blitter *blitter, struct wined3d_device *device, unsigned int rt_count, const struct wined3d_fb_state *fb, unsigned int rect_count, const RECT *clear_rects, const RECT *draw_rect, uint32_t flags, const struct wined3d_color *colour, float depth, unsigned int stencil)
Definition: texture.c:6129
static DWORD raw_blitter_blit(struct wined3d_blitter *blitter, enum wined3d_blit_op op, struct wined3d_context *context, struct wined3d_texture *src_texture, unsigned int src_sub_resource_idx, DWORD src_location, const RECT *src_rect, struct wined3d_texture *dst_texture, unsigned int dst_sub_resource_idx, DWORD dst_location, const RECT *dst_rect, const struct wined3d_color_key *colour_key, enum wined3d_texture_filter_type filter, const struct wined3d_format *resolve_format)
Definition: texture.c:6166
static void raw_blitter_destroy(struct wined3d_blitter *blitter, struct wined3d_context *context)
Definition: texture.c:6119

Definition at line 6255 of file texture.c.

Referenced by wined3d_raw_blitter_create().

◆ texture_gl_ops

static const struct wined3d_texture_ops texture_gl_ops
static
Initial value:
=
{
}
static BOOL wined3d_texture_gl_load_location(struct wined3d_texture *texture, unsigned int sub_resource_idx, struct wined3d_context *context, uint32_t location)
Definition: texture.c:3219
static void wined3d_texture_gl_unload_location(struct wined3d_texture *texture, struct wined3d_context *context, unsigned int location)
Definition: texture.c:3266

Definition at line 34 of file texture.c.

Referenced by wined3d_texture_gl_init().

◆ texture_resource_ops

const struct wined3d_resource_ops texture_resource_ops
static
Initial value:
=
{
}
static HRESULT texture_resource_sub_resource_unmap(struct wined3d_resource *resource, unsigned int sub_resource_idx)
Definition: texture.c:3563
static HRESULT texture_resource_sub_resource_map(struct wined3d_resource *resource, unsigned int sub_resource_idx, void **map_ptr, const struct wined3d_box *box, uint32_t flags)
Definition: texture.c:3450
static void texture_resource_preload(struct wined3d_resource *resource)
Definition: texture.c:3358
static void texture_resource_sub_resource_get_map_pitch(struct wined3d_resource *resource, unsigned int sub_resource_idx, unsigned int *row_pitch, unsigned int *slice_pitch)
Definition: texture.c:3433
static ULONG texture_resource_decref(struct wined3d_resource *resource)
Definition: texture.c:3353
static ULONG texture_resource_incref(struct wined3d_resource *resource)
Definition: texture.c:3348
static HRESULT texture_resource_sub_resource_get_desc(struct wined3d_resource *resource, unsigned int sub_resource_idx, struct wined3d_sub_resource_desc *desc)
Definition: texture.c:3425
static void texture_resource_unload(struct wined3d_resource *resource)
Definition: texture.c:3368

Definition at line 3608 of file texture.c.

Referenced by wined3d_texture_init().

◆ vk_blitter_ops

const struct wined3d_blitter_ops vk_blitter_ops
static
Initial value:
=
{
.blitter_destroy = vk_blitter_destroy,
.blitter_clear = vk_blitter_clear,
.blitter_blit = vk_blitter_blit,
}
static DWORD vk_blitter_blit(struct wined3d_blitter *blitter, enum wined3d_blit_op op, struct wined3d_context *context, struct wined3d_texture *src_texture, unsigned int src_sub_resource_idx, DWORD src_location, const RECT *src_rect, struct wined3d_texture *dst_texture, unsigned int dst_sub_resource_idx, DWORD dst_location, const RECT *dst_rect, const struct wined3d_color_key *colour_key, enum wined3d_texture_filter_type filter, const struct wined3d_format *resolve_format)
Definition: texture.c:6678
static void vk_blitter_clear(struct wined3d_blitter *blitter, struct wined3d_device *device, unsigned int rt_count, const struct wined3d_fb_state *fb, unsigned int rect_count, const RECT *clear_rects, const RECT *draw_rect, uint32_t flags, const struct wined3d_color *colour, float depth, unsigned int stencil)
Definition: texture.c:6494
static void vk_blitter_destroy(struct wined3d_blitter *blitter, struct wined3d_context *context)
Definition: texture.c:6279

Definition at line 7041 of file texture.c.

Referenced by wined3d_vk_blitter_create().

◆ wined3d_texture_no3d_ops

const struct wined3d_texture_ops wined3d_texture_no3d_ops
static
Initial value:
=
{
}
static void wined3d_texture_no3d_upload_data(struct wined3d_context *context, const struct wined3d_const_bo_address *src_bo_addr, const struct wined3d_format *src_format, const struct wined3d_box *src_box, unsigned int src_row_pitch, unsigned int src_slice_pitch, struct wined3d_texture *dst_texture, unsigned int dst_sub_resource_idx, unsigned int dst_location, unsigned int dst_x, unsigned int dst_y, unsigned int dst_z)
Definition: texture.c:4512
static void wined3d_texture_no3d_download_data(struct wined3d_context *context, struct wined3d_texture *src_texture, unsigned int src_sub_resource_idx, unsigned int src_location, const struct wined3d_box *src_box, const struct wined3d_bo_address *dst_bo_addr, const struct wined3d_format *dst_format, unsigned int dst_x, unsigned int dst_y, unsigned int dst_z, unsigned int dst_row_pitch, unsigned int dst_slice_pitch)
Definition: texture.c:4521
static BOOL wined3d_texture_no3d_prepare_location(struct wined3d_texture *texture, unsigned int sub_resource_idx, struct wined3d_context *context, unsigned int location)
Definition: texture.c:4530
static void wined3d_texture_no3d_unload_location(struct wined3d_texture *texture, struct wined3d_context *context, unsigned int location)
Definition: texture.c:4555
static BOOL wined3d_texture_no3d_load_location(struct wined3d_texture *texture, unsigned int sub_resource_idx, struct wined3d_context *context, uint32_t location)
Definition: texture.c:4541

Definition at line 4561 of file texture.c.

Referenced by wined3d_texture_no3d_init().

◆ wined3d_texture_sysmem_locations

◆ wined3d_texture_vk_ops

const struct wined3d_texture_ops wined3d_texture_vk_ops
static
Initial value:
=
{
}
static BOOL wined3d_texture_vk_load_location(struct wined3d_texture *texture, unsigned int sub_resource_idx, struct wined3d_context *context, uint32_t location)
Definition: texture.c:5403
static void wined3d_texture_vk_unload_location(struct wined3d_texture *texture, struct wined3d_context *context, unsigned int location)
Definition: texture.c:5424

Definition at line 5475 of file texture.c.

Referenced by wined3d_texture_vk_init().