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

Go to the source code of this file.

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (d3d)
 
 WINE_DECLARE_DEBUG_CHANNEL (d3d_perf)
 
static void resource_check_usage (uint32_t usage, unsigned int access)
 
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)
 
static void wined3d_resource_destroy_object (void *object)
 
void resource_cleanup (struct wined3d_resource *resource)
 
void resource_unload (struct wined3d_resource *resource)
 
unsigned int CDECL wined3d_resource_set_priority (struct wined3d_resource *resource, unsigned int priority)
 
unsigned int CDECL wined3d_resource_get_priority (const struct wined3d_resource *resource)
 
void *CDECL wined3d_resource_get_parent (const struct wined3d_resource *resource)
 
void CDECL wined3d_resource_set_parent (struct wined3d_resource *resource, void *parent, const struct wined3d_parent_ops *parent_ops)
 
void CDECL wined3d_resource_get_desc (const struct wined3d_resource *resource, struct wined3d_resource_desc *desc)
 
HRESULT CDECL wined3d_resource_map (struct wined3d_resource *resource, unsigned int sub_resource_idx, struct wined3d_map_desc *map_desc, const struct wined3d_box *box, uint32_t flags)
 
HRESULT CDECL wined3d_resource_unmap (struct wined3d_resource *resource, unsigned int sub_resource_idx)
 
void CDECL wined3d_resource_preload (struct wined3d_resource *resource)
 
static BOOL wined3d_resource_allocate_sysmem (struct wined3d_resource *resource)
 
BOOL wined3d_resource_prepare_sysmem (struct wined3d_resource *resource)
 
void wined3d_resource_free_sysmem (struct wined3d_resource *resource)
 
GLbitfield wined3d_resource_gl_storage_flags (const struct wined3d_resource *resource)
 
GLbitfield wined3d_resource_gl_map_flags (const struct wined3d_bo_gl *bo, DWORD d3d_flags)
 
GLenum wined3d_resource_gl_legacy_map_flags (DWORD d3d_flags)
 
BOOL wined3d_resource_is_offscreen (struct wined3d_resource *resource)
 
void wined3d_resource_update_draw_binding (struct wined3d_resource *resource)
 
const struct wined3d_format * wined3d_resource_get_decompress_format (const struct wined3d_resource *resource)
 
unsigned int wined3d_resource_get_sample_count (const struct wined3d_resource *resource)
 
HRESULT wined3d_resource_check_box_dimensions (struct wined3d_resource *resource, unsigned int sub_resource_idx, const struct wined3d_box *box)
 
VkAccessFlags vk_access_mask_from_bind_flags (uint32_t bind_flags)
 
VkPipelineStageFlags vk_pipeline_stage_mask_from_bind_flags (uint32_t bind_flags)
 
void * resource_offset_map_pointer (struct wined3d_resource *resource, unsigned int sub_resource_idx, uint8_t *base_memory, const struct wined3d_box *box)
 
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)
 

Function Documentation

◆ resource_check_usage()

static void resource_check_usage ( uint32_t  usage,
unsigned int  access 
)
static

Definition at line 31 of file resource.c.

32{
33 static const uint32_t handled = WINED3DUSAGE_DYNAMIC
40 | ~WINED3DUSAGE_MASK;
41
42 /* Write-only CPU access is supposed to result in write-combined mappings
43 * being returned. OpenGL doesn't give us explicit control over that, but
44 * the hints and access flags we set for typical access patterns on
45 * dynamic resources should in theory have the same effect on the OpenGL
46 * driver. */
47
48 if (usage & ~handled)
49 FIXME("Unhandled usage flags %#x.\n", usage & ~handled);
51 WARN_(d3d_perf)("WINED3DUSAGE_DYNAMIC used with WINED3D_RESOURCE_ACCESS_MAP_R.\n");
52}
#define FIXME(fmt,...)
Definition: precomp.h:53
UINT32 uint32_t
Definition: types.h:75
GLuint GLint GLboolean GLint GLenum access
Definition: glext.h:7866
GLsizeiptr const GLvoid GLenum usage
Definition: glext.h:5919
#define WARN_(ch,...)
Definition: debug.h:157
#define WINED3DUSAGE_LEGACY_CUBEMAP
Definition: wined3d.h:934
#define WINED3DUSAGE_OVERLAY
Definition: wined3d.h:937
#define WINED3D_RESOURCE_ACCESS_MAP_R
Definition: wined3d.h:53
#define WINED3DUSAGE_MANAGED
Definition: wined3d.h:938
#define WINED3DUSAGE_SCRATCH
Definition: wined3d.h:932
#define WINED3DUSAGE_CS
Definition: wined3d.h:933
#define WINED3DUSAGE_DYNAMIC
Definition: wined3d.h:924
#define WINED3DUSAGE_STATICDECL
Definition: wined3d.h:936

Referenced by resource_init().

◆ resource_cleanup()

void resource_cleanup ( struct wined3d_resource *  resource)

Definition at line 224 of file resource.c.

225{
226 TRACE("Cleaning up resource %p.\n", resource);
227
229 {
230 TRACE("Decrementing device memory pool by %u.\n", resource->size);
231 adapter_adjust_memory(resource->device->adapter, (INT64)0 - resource->size);
232 }
233
234 if (!(resource->usage & WINED3DUSAGE_CS))
236
239}
COMPILER_DEPENDENT_INT64 INT64
Definition: actypes.h:132
void wined3d_cs_destroy_object(struct wined3d_cs *cs, void(*callback)(void *object), void *object)
Definition: cs.c:2299
void device_resource_released(struct wined3d_device *device, struct wined3d_resource *resource)
Definition: device.c:5358
static void wined3d_resource_destroy_object(void *object)
Definition: resource.c:214
#define TRACE(s)
Definition: solgame.cpp:4
size_t size
Definition: utils.c:170
UINT64 adapter_adjust_memory(struct wined3d_adapter *adapter, INT64 amount)
Definition: directx.c:158
#define WINED3D_RESOURCE_ACCESS_CPU
Definition: wined3d.h:52
#define WINED3DUSAGE_VIDMEM_ACCOUNTING
Definition: wined3d.h:939
static void wined3d_resource_reference(struct wined3d_resource *resource)

Referenced by wined3d_buffer_cleanup(), wined3d_buffer_init(), and wined3d_texture_cleanup().

◆ resource_init()

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 at line 54 of file resource.c.

60{
63 unsigned int i;
64
65 static const struct
66 {
68 DWORD cube_usage;
69 enum wined3d_gl_resource_type gl_type;
70 }
71 resource_types[] =
72 {
79 };
80
82
84 {
85 ERR("Trying to create a scratch resource with access flags %s.\n",
88 }
89
91 {
93 {
94 WARN("Bind flags %s are incompatible with resource access %s.\n",
97 }
98
99 /* Dynamic and managed usages are incompatible with GPU writes. */
101 {
102 WARN("Bind flags %s are incompatible with resource usage %s.\n",
105 }
106 }
107
108 if (!size)
109 ERR("Attempting to create a zero-sized resource.\n");
110
111 for (i = 0; i < ARRAY_SIZE(resource_types); ++i)
112 {
113 if (resource_types[i].type != type
114 || resource_types[i].cube_usage != (usage & WINED3DUSAGE_LEGACY_CUBEMAP))
115 continue;
116
117 gl_type = resource_types[i].gl_type;
118 if (base_type == WINED3D_GL_RES_TYPE_COUNT)
119 base_type = gl_type;
120
122 break;
123
124 if ((bind_flags & WINED3D_BIND_RENDER_TARGET)
125 && !(format->caps[gl_type] & WINED3D_FORMAT_CAP_RENDERTARGET))
126 {
127 WARN("Format %s cannot be used for render targets.\n", debug_d3dformat(format->id));
128 continue;
129 }
130 if ((bind_flags & WINED3D_BIND_DEPTH_STENCIL)
131 && !(format->caps[gl_type] & WINED3D_FORMAT_CAP_DEPTH_STENCIL))
132 {
133 WARN("Format %s cannot be used for depth/stencil buffers.\n", debug_d3dformat(format->id));
134 continue;
135 }
136 if ((bind_flags & WINED3D_BIND_SHADER_RESOURCE)
137 && !(format->caps[gl_type] & WINED3D_FORMAT_CAP_TEXTURE))
138 {
139 WARN("Format %s cannot be used for texturing.\n", debug_d3dformat(format->id));
140 continue;
141 }
142 break;
143 }
144
145 if (base_type != WINED3D_GL_RES_TYPE_COUNT && i == ARRAY_SIZE(resource_types))
146 {
148 {
149 /* Needed for proper format information. */
150 gl_type = base_type;
151 }
152 else
153 {
154 WARN("Did not find a suitable GL resource type for resource type %s.\n",
157 }
158 }
159
160 if (base_type != WINED3D_GL_RES_TYPE_COUNT
163 {
164 UINT width_mask = format->block_width - 1;
165 UINT height_mask = format->block_height - 1;
166 if (width & width_mask || height & height_mask)
168 }
169
170 resource->ref = 1;
171 resource->device = device;
172 resource->type = type;
173 resource->gl_type = gl_type;
174 resource->format = format;
175 resource->format_attrs = format->attrs;
176 if (gl_type < WINED3D_GL_RES_TYPE_COUNT)
177 resource->format_caps = format->caps[gl_type];
178 resource->multisample_type = multisample_type;
179 resource->multisample_quality = multisample_quality;
180 resource->usage = usage;
181 resource->bind_flags = bind_flags;
182 if (resource->format_attrs & WINED3D_FORMAT_ATTR_MAPPABLE)
184 resource->access = access;
185 resource->width = width;
186 resource->height = height;
187 resource->depth = depth;
188 resource->size = size;
189 resource->priority = 0;
190 resource->parent = parent;
191 resource->parent_ops = parent_ops;
192 resource->resource_ops = resource_ops;
193 resource->map_binding = WINED3D_LOCATION_SYSMEM;
194 resource->heap_pointer = NULL;
195 resource->heap_memory = NULL;
196
197 /* Check that we have enough video ram left */
199 {
201 {
202 ERR("Out of adapter memory.\n");
204 }
206 }
207
208 if (!(usage & WINED3DUSAGE_CS))
210
211 return WINED3D_OK;
212}
#define ARRAY_SIZE(A)
Definition: main.h:20
#define WARN(fmt,...)
Definition: precomp.h:61
#define ERR(fmt,...)
Definition: precomp.h:57
#define NULL
Definition: types.h:112
UINT CDECL wined3d_device_get_available_texture_mem(const struct wined3d_device *device)
Definition: device.c:1754
void device_resource_add(struct wined3d_device *device, struct wined3d_resource *resource)
Definition: device.c:5340
static void resource_check_usage(uint32_t usage, unsigned int access)
Definition: resource.c:31
const char * debug_d3dusage(uint32_t usage)
Definition: utils.c:4895
const char * wined3d_debug_bind_flags(uint32_t bind_flags)
Definition: utils.c:4845
const char * debug_d3dformat(enum wined3d_format_id format_id)
Definition: utils.c:4605
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
r parent
Definition: btrfs.c:3010
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLint GLsizei GLsizei GLsizei depth
Definition: gl.h:1546
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLint GLint GLsizei width
Definition: gl.h:1546
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 i
Definition: glfuncs.h:248
unsigned int UINT
Definition: sysinfo.c:13
Definition: devices.h:37
#define WINED3D_OK
Definition: wined3d.h:33
#define WINED3D_RESOURCE_ACCESS_GPU
Definition: wined3d.h:51
wined3d_resource_type
Definition: wined3d.h:716
@ WINED3D_RTYPE_TEXTURE_2D
Definition: wined3d.h:720
@ WINED3D_RTYPE_TEXTURE_1D
Definition: wined3d.h:719
@ WINED3D_RTYPE_BUFFER
Definition: wined3d.h:718
@ WINED3D_RTYPE_TEXTURE_3D
Definition: wined3d.h:721
#define WINED3D_BIND_SHADER_RESOURCE
Definition: wined3d.h:912
#define WINED3D_BIND_DEPTH_STENCIL
Definition: wined3d.h:915
#define WINED3D_BIND_RENDER_TARGET
Definition: wined3d.h:914
#define WINED3DERR_INVALIDCALL
Definition: wined3d.h:44
#define WINED3DERR_OUTOFVIDEOMEMORY
Definition: wined3d.h:43
#define WINED3D_RESOURCE_ACCESS_MAP_W
Definition: wined3d.h:54
#define WINED3D_FORMAT_ATTR_BLOCKS_NO_VERIFY
#define WINED3D_LOCATION_SYSMEM
#define WINED3D_FORMAT_CAP_TEXTURE
#define WINED3D_FORMAT_ATTR_MAPPABLE
wined3d_gl_resource_type
@ WINED3D_GL_RES_TYPE_TEX_3D
@ WINED3D_GL_RES_TYPE_TEX_CUBE
@ WINED3D_GL_RES_TYPE_BUFFER
@ WINED3D_GL_RES_TYPE_TEX_2D
@ WINED3D_GL_RES_TYPE_RB
@ WINED3D_GL_RES_TYPE_TEX_1D
@ WINED3D_GL_RES_TYPE_COUNT
#define WINED3D_FORMAT_CAP_DEPTH_STENCIL
#define WINED3D_FORMAT_CAP_RENDERTARGET
#define WINED3D_FORMAT_ATTR_BLOCKS

Referenced by wined3d_buffer_init(), and wined3d_texture_init().

◆ resource_offset_map_pointer()

void * resource_offset_map_pointer ( struct wined3d_resource *  resource,
unsigned int  sub_resource_idx,
uint8_t *  base_memory,
const struct wined3d_box *  box 
)

Definition at line 574 of file resource.c.

576{
577 const struct wined3d_format *format = resource->format;
578 unsigned int row_pitch, slice_pitch;
579
580 wined3d_resource_get_sub_resource_map_pitch(resource, sub_resource_idx, &row_pitch, &slice_pitch);
581
584 {
585 /* Compressed textures are block based, so calculate the offset of
586 * the block that contains the top-left pixel of the mapped box. */
587 return base_memory
588 + (box->front * slice_pitch)
589 + ((box->top / format->block_height) * row_pitch)
590 + ((box->left / format->block_width) * format->block_byte_count);
591 }
592 else
593 {
594 return base_memory
595 + (box->front * slice_pitch)
596 + (box->top * row_pitch)
597 + (box->left * format->byte_count);
598 }
599}
Definition: palette.c:466
static void wined3d_resource_get_sub_resource_map_pitch(struct wined3d_resource *resource, unsigned int sub_resource_idx, unsigned int *row_pitch, unsigned int *slice_pitch)
#define WINED3D_FORMAT_ATTR_BROKEN_PITCH

Referenced by texture_resource_sub_resource_map(), and wined3d_cs_map_upload_bo().

◆ resource_unload()

void resource_unload ( struct wined3d_resource *  resource)

Definition at line 241 of file resource.c.

242{
243 if (resource->map_count)
244 ERR("Resource %p is being unloaded while mapped.\n", resource);
245}

Referenced by buffer_resource_unload(), and texture_resource_unload().

◆ vk_access_mask_from_bind_flags()

VkAccessFlags vk_access_mask_from_bind_flags ( uint32_t  bind_flags)

Definition at line 526 of file resource.c.

527{
529
530 if (bind_flags & WINED3D_BIND_VERTEX_BUFFER)
532 if (bind_flags & WINED3D_BIND_INDEX_BUFFER)
534 if (bind_flags & WINED3D_BIND_CONSTANT_BUFFER)
536 if (bind_flags & WINED3D_BIND_SHADER_RESOURCE)
538 if (bind_flags & WINED3D_BIND_UNORDERED_ACCESS)
540 if (bind_flags & WINED3D_BIND_INDIRECT_BUFFER)
542 if (bind_flags & WINED3D_BIND_RENDER_TARGET)
544 if (bind_flags & WINED3D_BIND_DEPTH_STENCIL)
546 if (bind_flags & WINED3D_BIND_STREAM_OUTPUT)
548
549 return flags;
550}
GLbitfield flags
Definition: glext.h:7161
VkFlags VkAccessFlags
Definition: vulkan.h:957
@ VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT
Definition: vulkan.h:1639
@ VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT
Definition: vulkan.h:1631
@ VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT
Definition: vulkan.h:1637
@ VK_ACCESS_INDIRECT_COMMAND_READ_BIT
Definition: vulkan.h:1629
@ VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT
Definition: vulkan.h:1638
@ VK_ACCESS_SHADER_WRITE_BIT
Definition: vulkan.h:1635
@ VK_ACCESS_SHADER_READ_BIT
Definition: vulkan.h:1634
@ VK_ACCESS_UNIFORM_READ_BIT
Definition: vulkan.h:1632
@ VK_ACCESS_INDEX_READ_BIT
Definition: vulkan.h:1630
@ VK_ACCESS_TRANSFORM_FEEDBACK_WRITE_BIT_EXT
Definition: vulkan.h:1654
@ VK_ACCESS_COLOR_ATTACHMENT_READ_BIT
Definition: vulkan.h:1636
#define WINED3D_BIND_VERTEX_BUFFER
Definition: wined3d.h:909
#define WINED3D_BIND_UNORDERED_ACCESS
Definition: wined3d.h:916
#define WINED3D_BIND_INDIRECT_BUFFER
Definition: wined3d.h:917
#define WINED3D_BIND_CONSTANT_BUFFER
Definition: wined3d.h:911
#define WINED3D_BIND_STREAM_OUTPUT
Definition: wined3d.h:913
#define WINED3D_BIND_INDEX_BUFFER
Definition: wined3d.h:910

Referenced by vk_blitter_blit(), wined3d_buffer_vk_barrier(), wined3d_shader_resource_view_vk_generate_mipmap(), wined3d_swapchain_vk_blit(), wined3d_texture_vk_barrier(), wined3d_texture_vk_clear(), wined3d_texture_vk_download_data(), wined3d_texture_vk_upload_data(), and wined3d_unordered_access_view_vk_clear().

◆ vk_pipeline_stage_mask_from_bind_flags()

VkPipelineStageFlags vk_pipeline_stage_mask_from_bind_flags ( uint32_t  bind_flags)

Definition at line 552 of file resource.c.

553{
555
562 if (bind_flags & WINED3D_BIND_INDIRECT_BUFFER)
564 if (bind_flags & WINED3D_BIND_RENDER_TARGET)
566 if (bind_flags & WINED3D_BIND_DEPTH_STENCIL)
568 if (bind_flags & WINED3D_BIND_STREAM_OUTPUT)
570
571 return flags;
572}
VkFlags VkPipelineStageFlags
Definition: vulkan.h:1101
@ VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT
Definition: vulkan.h:4278
@ VK_PIPELINE_STAGE_VERTEX_INPUT_BIT
Definition: vulkan.h:4274
@ VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT
Definition: vulkan.h:4283
@ VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
Definition: vulkan.h:4279
@ VK_PIPELINE_STAGE_TESSELLATION_EVALUATION_SHADER_BIT
Definition: vulkan.h:4277
@ VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
Definition: vulkan.h:4282
@ VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT
Definition: vulkan.h:4281
@ VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT
Definition: vulkan.h:4273
@ VK_PIPELINE_STAGE_VERTEX_SHADER_BIT
Definition: vulkan.h:4275
@ VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT
Definition: vulkan.h:4276
@ VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
Definition: vulkan.h:4280
@ VK_PIPELINE_STAGE_TRANSFORM_FEEDBACK_BIT_EXT
Definition: vulkan.h:4296

Referenced by wined3d_buffer_vk_barrier(), wined3d_texture_vk_barrier(), and wined3d_unordered_access_view_vk_clear().

◆ WINE_DECLARE_DEBUG_CHANNEL()

WINE_DECLARE_DEBUG_CHANNEL ( d3d_perf  )

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( d3d  )

◆ wined3d_resource_allocate_sysmem()

static BOOL wined3d_resource_allocate_sysmem ( struct wined3d_resource *  resource)
static

Definition at line 316 of file resource.c.

317{
318 /* Overallocate and add padding to the allocated pointer, to guard against
319 * games (for instance Railroad Tycoon 2) writing before the locked resource
320 * memory pointer.
321 */
322 static const SIZE_T align = RESOURCE_ALIGNMENT;
323 void *mem;
324
325 if (!(mem = calloc(1, resource->size + align)))
326 {
327 ERR("Failed to allocate system memory.\n");
328 return FALSE;
329 }
330
331 resource->heap_memory = (void *)(((ULONG_PTR)mem + align) & ~(RESOURCE_ALIGNMENT - 1));
332 resource->heap_pointer = mem;
333
334 return TRUE;
335}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define calloc
Definition: rosglue.h:14
Definition: mem.c:349
ULONG_PTR SIZE_T
Definition: typedefs.h:80
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define RESOURCE_ALIGNMENT
static size_t align(size_t addr, size_t alignment)

Referenced by wined3d_resource_prepare_sysmem().

◆ wined3d_resource_check_box_dimensions()

HRESULT wined3d_resource_check_box_dimensions ( struct wined3d_resource *  resource,
unsigned int  sub_resource_idx,
const struct wined3d_box *  box 
)

Definition at line 488 of file resource.c.

490{
491 const struct wined3d_format *format = resource->format;
493 unsigned int width_mask, height_mask;
494
496
497 if (box->left >= box->right || box->right > desc.width
498 || box->top >= box->bottom || box->bottom > desc.height
499 || box->front >= box->back || box->back > desc.depth)
500 {
501 WARN("Box %s is invalid.\n", debug_box(box));
503 }
504
505 if (resource->format_attrs & WINED3D_FORMAT_ATTR_BLOCKS)
506 {
507 /* This assumes power of two block sizes, but NPOT block sizes would
508 * be silly anyway.
509 *
510 * This also assumes that the format's block depth is 1. */
511 width_mask = format->block_width - 1;
512 height_mask = format->block_height - 1;
513
514 if ((box->left & width_mask) || (box->top & height_mask)
515 || (box->right & width_mask && box->right != desc.width)
516 || (box->bottom & height_mask && box->bottom != desc.height))
517 {
518 WARN("Box %s is misaligned for %ux%u blocks.\n", debug_box(box), format->block_width, format->block_height);
520 }
521 }
522
523 return WINED3D_OK;
524}
const char * debug_box(const struct wined3d_box *box)
Definition: utils.c:4552
D3D11_SHADER_VARIABLE_DESC desc
Definition: reflection.c:1683
#define WINEDDERR_INVALIDRECT
Definition: wined3d.h:48
static HRESULT wined3d_resource_get_sub_resource_desc(struct wined3d_resource *resource, unsigned int sub_resource_idx, struct wined3d_sub_resource_desc *desc)

Referenced by wined3d_device_context_blt(), wined3d_device_context_clear_rendertarget_view(), wined3d_device_context_clear_sysmem_texture(), wined3d_device_context_copy_sub_resource_region(), wined3d_device_context_map(), and wined3d_texture_add_dirty_region().

◆ wined3d_resource_destroy_object()

static void wined3d_resource_destroy_object ( void *  object)
static

Definition at line 214 of file resource.c.

215{
217
218 TRACE("resource %p.\n", resource);
219
222}
void context_resource_released(const struct wined3d_device *device, struct wined3d_resource *resource)
Definition: context.c:32
void wined3d_resource_free_sysmem(struct wined3d_resource *resource)
Definition: resource.c:345

Referenced by resource_cleanup().

◆ wined3d_resource_free_sysmem()

void wined3d_resource_free_sysmem ( struct wined3d_resource *  resource)

Definition at line 345 of file resource.c.

346{
347 if (!resource->heap_memory)
348 return;
349 resource->heap_memory = NULL;
350
351 free(resource->heap_pointer);
352 resource->heap_pointer = NULL;
353}
#define free
Definition: debug_ros.c:5

Referenced by wined3d_buffer_evict_sysmem(), wined3d_resource_destroy_object(), wined3d_texture_evict_sysmem(), and wined3d_texture_update_desc().

◆ wined3d_resource_get_decompress_format()

const struct wined3d_format * wined3d_resource_get_decompress_format ( const struct wined3d_resource *  resource)

Definition at line 447 of file resource.c.

448{
449 const struct wined3d_adapter *adapter = resource->device->adapter;
451 && !(adapter->d3d_info.wined3d_creation_flags & WINED3D_SRGB_READ_WRITE_CONTROL))
454}
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
return adapter
@ WINED3DFMT_B8G8R8A8_UNORM
Definition: wined3d.h:244
@ WINED3DFMT_B8G8R8A8_UNORM_SRGB
Definition: wined3d.h:247
#define WINED3D_SRGB_READ_WRITE_CONTROL
Definition: wined3d.h:1330
#define WINED3D_FORMAT_CAP_SRGB_WRITE
#define WINED3D_FORMAT_CAP_SRGB_READ

Referenced by wined3d_texture_gl_prepare_texture(), and wined3d_texture_gl_upload_data().

◆ wined3d_resource_get_desc()

◆ wined3d_resource_get_parent()

void *CDECL wined3d_resource_get_parent ( const struct wined3d_resource *  resource)

Definition at line 269 of file resource.c.

270{
271 return resource->parent;
272}

Referenced by reset_enum_callback().

◆ wined3d_resource_get_priority()

◆ wined3d_resource_get_sample_count()

unsigned int wined3d_resource_get_sample_count ( const struct wined3d_resource *  resource)

Definition at line 456 of file resource.c.

457{
458 const struct wined3d_format *format = resource->format;
459
460 /* TODO: NVIDIA expose their Coverage Sample Anti-Aliasing (CSAA)
461 * feature through type == MULTISAMPLE_XX and quality != 0. This could
462 * be mapped to GL_NV_framebuffer_multisample_coverage.
463 *
464 * AMD have a similar feature called Enhanced Quality Anti-Aliasing
465 * (EQAA), but it does not have an equivalent OpenGL extension. */
466
467 /* We advertise as many WINED3D_MULTISAMPLE_NON_MASKABLE quality
468 * levels as the count of advertised multisample types for the texture
469 * format. */
470 if (resource->multisample_type == WINED3D_MULTISAMPLE_NON_MASKABLE)
471 {
472 unsigned int i, count = 0;
473
474 for (i = 0; i < sizeof(format->multisample_types) * CHAR_BIT; ++i)
475 {
476 if (format->multisample_types & 1u << i)
477 {
478 if (resource->multisample_quality == count++)
479 break;
480 }
481 }
482 return i + 1;
483 }
484
485 return resource->multisample_type;
486}
#define CHAR_BIT
Definition: cabinet.h:45
GLuint GLuint GLsizei count
Definition: gl.h:1545
@ WINED3D_MULTISAMPLE_NON_MASKABLE
Definition: wined3d.h:574

Referenced by vk_blitter_blit(), vk_blitter_blit_supported(), wined3d_context_vk_apply_draw_state(), wined3d_render_pass_key_vk_init(), wined3d_shader_resource_view_vk_generate_mipmap(), wined3d_texture_gl_allocate_immutable_storage(), wined3d_texture_gl_prepare_rb(), wined3d_texture_vk_download_data(), wined3d_texture_vk_prepare_texture(), and wined3d_texture_vk_upload_data().

◆ wined3d_resource_gl_legacy_map_flags()

GLenum wined3d_resource_gl_legacy_map_flags ( DWORD  d3d_flags)

Definition at line 391 of file resource.c.

392{
393 switch (d3d_flags & (WINED3D_MAP_READ | WINED3D_MAP_WRITE))
394 {
395 case WINED3D_MAP_READ:
396 return GL_READ_ONLY_ARB;
397
399 return GL_WRITE_ONLY_ARB;
400
401 default:
402 return GL_READ_WRITE_ARB;
403 }
404}
#define GL_WRITE_ONLY_ARB
Definition: glext.h:1501
#define GL_READ_WRITE_ARB
Definition: glext.h:1502
#define GL_READ_ONLY_ARB
Definition: glext.h:1500
#define WINED3D_MAP_READ
Definition: wined3d.h:957
#define WINED3D_MAP_WRITE
Definition: wined3d.h:956

Referenced by wined3d_bo_gl_map().

◆ wined3d_resource_gl_map_flags()

GLbitfield wined3d_resource_gl_map_flags ( const struct wined3d_bo_gl *  bo,
DWORD  d3d_flags 
)

Definition at line 373 of file resource.c.

374{
375 GLbitfield ret = 0;
376
377 if (d3d_flags & WINED3D_MAP_WRITE)
378 {
380 if (!bo->b.coherent)
382 }
383 if (d3d_flags & WINED3D_MAP_READ)
385 else
387
388 return ret;
389}
return ret
Definition: mutex.c:147
unsigned int GLbitfield
Definition: gl.h:152
#define GL_MAP_READ_BIT
Definition: glext.h:1793
#define GL_MAP_FLUSH_EXPLICIT_BIT
Definition: glext.h:1797
#define GL_MAP_UNSYNCHRONIZED_BIT
Definition: glext.h:1798
#define GL_MAP_WRITE_BIT
Definition: glext.h:1794
struct wined3d_bo b
Definition: wined3d_gl.h:415

Referenced by wined3d_bo_gl_map().

◆ wined3d_resource_gl_storage_flags()

GLbitfield wined3d_resource_gl_storage_flags ( const struct wined3d_resource *  resource)

Definition at line 355 of file resource.c.

356{
357 uint32_t access = resource->access;
358 GLbitfield flags = 0;
359
360 if (resource->usage & WINED3DUSAGE_DYNAMIC)
363 {
368 }
369
370 return flags;
371}
#define GL_CLIENT_STORAGE_BIT
Definition: wgl.h:399

Referenced by adapter_gl_alloc_bo(), and wined3d_buffer_gl_create_buffer_object().

◆ wined3d_resource_is_offscreen()

BOOL wined3d_resource_is_offscreen ( struct wined3d_resource *  resource)

Definition at line 406 of file resource.c.

407{
408 struct wined3d_swapchain *swapchain;
409
410 /* Only 2D texture resources can be onscreen. */
412 return TRUE;
413
414 /* Not on a swapchain - must be offscreen */
415 if (!(swapchain = texture_from_resource(resource)->swapchain))
416 return TRUE;
417
418 /* The front buffer is always onscreen */
419 if (resource == &swapchain->front_buffer->resource)
420 return FALSE;
421
422 return TRUE;
423}
struct wined3d_texture * front_buffer
static struct wined3d_texture * texture_from_resource(struct wined3d_resource *resource)

Referenced by ffp_blitter_clear_rendertargets(), texture2d_blt(), texture2d_read_from_framebuffer(), wined3d_context_gl_acquire(), wined3d_context_gl_apply_clear_state(), wined3d_gl_get_internal_format(), wined3d_resource_update_draw_binding(), and wined3d_texture_load_drawable().

◆ wined3d_resource_map()

HRESULT CDECL wined3d_resource_map ( struct wined3d_resource *  resource,
unsigned int  sub_resource_idx,
struct wined3d_map_desc *  map_desc,
const struct wined3d_box *  box,
uint32_t  flags 
)

◆ wined3d_resource_memory_colour_fill()

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 at line 601 of file resource.c.

604{
605 const struct wined3d_format *format = resource->format;
606 unsigned int w, h, d, x, y, z, bpp;
607 uint8_t *dst, *dst2;
608 uint32_t c[4];
609
610 /* Fast and simple path for setting everything to zero. The C library's memset is
611 * more sophisticated than our code below. Also this works for block formats, which
612 * we still need to zero-initialize for newly created resources. */
613 if (full_subresource && !colour->r && !colour->g && !colour->b && !colour->a)
614 {
615 memset(map->data, 0, map->slice_pitch * box->back);
616 return;
617 }
618
619 w = box->right - box->left;
620 h = box->bottom - box->top;
621 d = box->back - box->front;
622
623 dst = (uint8_t *)map->data
624 + (box->front * map->slice_pitch)
625 + ((box->top / format->block_height) * map->row_pitch)
626 + ((box->left / format->block_width) * format->block_byte_count);
627
629 bpp = format->byte_count;
630
631 switch (bpp)
632 {
633 case 1:
634 for (x = 0; x < w; ++x)
635 {
636 dst[x] = c[0];
637 }
638 break;
639
640 case 2:
641 for (x = 0; x < w; ++x)
642 {
643 ((uint16_t *)dst)[x] = c[0];
644 }
645 break;
646
647 case 3:
648 {
649 dst2 = dst;
650 for (x = 0; x < w; ++x, dst2 += 3)
651 {
652 dst2[0] = (c[0] ) & 0xff;
653 dst2[1] = (c[0] >> 8) & 0xff;
654 dst2[2] = (c[0] >> 16) & 0xff;
655 }
656 break;
657 }
658 case 4:
659 for (x = 0; x < w; ++x)
660 {
661 ((uint32_t *)dst)[x] = c[0];
662 }
663 break;
664
665 case 8:
666 case 12:
667 case 16:
668 for (x = 0; x < w; ++x)
669 memcpy(((uint8_t *)map->data) + x * bpp, c, bpp);
670 break;
671
672 default:
673 FIXME("Not implemented for bpp %u.\n", bpp);
674 return;
675 }
676
677 dst2 = dst;
678 for (y = 1; y < h; ++y)
679 {
680 dst2 += map->row_pitch;
681 memcpy(dst2, dst, w * bpp);
682 }
683
684 dst2 = dst;
685 for (z = 1; z < d; ++z)
686 {
687 dst2 += map->slice_pitch;
688 memcpy(dst2, dst, w * h * bpp);
689 }
690
691}
Definition: _map.h:48
void wined3d_format_convert_from_float(const struct wined3d_format *format, const struct wined3d_color *color, void *ret)
Definition: utils.c:5817
unsigned short uint16_t
Definition: stdint.h:35
unsigned char uint8_t
Definition: stdint.h:33
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
const GLubyte * c
Definition: glext.h:8905
GLenum GLenum dst
Definition: glext.h:6340
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:6102
GLdouble GLdouble z
Definition: glext.h:5874
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
#define d
Definition: ke_i.h:81
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define memset(x, y, z)
Definition: compat.h:39
ULONG bpp[]
Definition: xlate.c:19

Referenced by cpu_blitter_clear_texture(), and wined3d_texture_load_location().

◆ wined3d_resource_preload()

void CDECL wined3d_resource_preload ( struct wined3d_resource *  resource)

Definition at line 311 of file resource.c.

312{
314}
void wined3d_cs_emit_preload_resource(struct wined3d_cs *cs, struct wined3d_resource *resource)
Definition: cs.c:2419

Referenced by d3d8_indexbuffer_PreLoad(), d3d8_texture_preload(), d3d8_vertexbuffer_PreLoad(), d3d9_indexbuffer_PreLoad(), d3d9_surface_PreLoad(), d3d9_texture_preload(), d3d9_vertexbuffer_PreLoad(), and d3d_device7_PreLoad().

◆ wined3d_resource_prepare_sysmem()

◆ wined3d_resource_set_parent()

void CDECL wined3d_resource_set_parent ( struct wined3d_resource *  resource,
void *  parent,
const struct wined3d_parent_ops *  parent_ops 
)

Definition at line 274 of file resource.c.

275{
276 resource->parent = parent;
277 resource->parent_ops = parent_ops;
278}

Referenced by d3d_texture2d_create(), ddraw_surface7_SetSurfaceDesc(), ddraw_texture_init(), and ddraw_texture_rename_to().

◆ wined3d_resource_set_priority()

unsigned int CDECL wined3d_resource_set_priority ( struct wined3d_resource *  resource,
unsigned int  priority 
)

Definition at line 247 of file resource.c.

248{
249 unsigned int prev;
250
251 if (!(resource->usage & WINED3DUSAGE_MANAGED))
252 {
253 WARN("Called on non-managed resource %p, ignoring.\n", resource);
254 return 0;
255 }
256
257 prev = resource->priority;
258 resource->priority = priority;
259 TRACE("resource %p, new priority %u, returning old priority %u.\n", resource, priority, prev);
260 return prev;
261}
static int priority
Definition: timer.c:163

Referenced by d3d8_indexbuffer_SetPriority(), d3d8_texture_2d_SetPriority(), d3d8_texture_3d_SetPriority(), d3d8_texture_cube_SetPriority(), d3d8_vertexbuffer_SetPriority(), d3d9_indexbuffer_SetPriority(), d3d9_texture_2d_SetPriority(), d3d9_texture_3d_SetPriority(), d3d9_texture_cube_SetPriority(), d3d9_vertexbuffer_SetPriority(), and ddraw_surface7_SetPriority().

◆ wined3d_resource_unmap()

◆ wined3d_resource_update_draw_binding()

void wined3d_resource_update_draw_binding ( struct wined3d_resource *  resource)

Definition at line 425 of file resource.c.

426{
427 const struct wined3d_d3d_info *d3d_info = &resource->device->adapter->d3d_info;
428
430 {
431 resource->draw_binding = WINED3D_LOCATION_DRAWABLE;
432 }
433 else if (resource->multisample_type)
434 {
435 resource->draw_binding = d3d_info->multisample_draw_location;
436 }
437 else if (resource->gl_type == WINED3D_GL_RES_TYPE_RB)
438 {
440 }
441 else
442 {
444 }
445}
BOOL wined3d_resource_is_offscreen(struct wined3d_resource *resource)
Definition: resource.c:406
DWORD multisample_draw_location
#define WINED3D_LOCATION_RB_RESOLVED
#define WINED3D_LOCATION_TEXTURE_RGB
#define WINED3D_LOCATION_DRAWABLE

Referenced by swapchain_update_draw_bindings(), wined3d_texture_init(), and wined3d_texture_set_swapchain().