ReactOS  0.4.13-dev-241-g63286c6
resource.c File Reference
#include "config.h"
#include "wine/port.h"
#include "wined3d_private.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 (DWORD usage)
 
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, unsigned int usage, 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)
 
DWORD CDECL wined3d_resource_set_priority (struct wined3d_resource *resource, DWORD priority)
 
DWORD 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)
 
void CDECL wined3d_resource_get_desc (const struct wined3d_resource *resource, struct wined3d_resource_desc *desc)
 
static DWORD wined3d_resource_sanitise_map_flags (const struct wined3d_resource *resource, DWORD flags)
 
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, DWORD flags)
 
HRESULT CDECL wined3d_resource_map_info (struct wined3d_resource *resource, unsigned int sub_resource_idx, struct wined3d_map_info *info, DWORD flags)
 
HRESULT CDECL wined3d_resource_unmap (struct wined3d_resource *resource, unsigned int sub_resource_idx)
 
UINT CDECL wined3d_resource_update_info (struct wined3d_resource *resource, unsigned int sub_resource_idx, const struct wined3d_box *box, unsigned int row_pitch, unsigned int depth_pitch)
 
void CDECL wined3d_resource_preload (struct wined3d_resource *resource)
 
BOOL wined3d_resource_allocate_sysmem (struct wined3d_resource *resource)
 
void wined3d_resource_free_sysmem (struct wined3d_resource *resource)
 
GLbitfield wined3d_resource_gl_map_flags (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)
 

Function Documentation

◆ resource_check_usage()

static void resource_check_usage ( DWORD  usage)
static

Definition at line 31 of file resource.c.

32 {
33  static DWORD handled = WINED3DUSAGE_RENDERTARGET
43 
44  /* WINED3DUSAGE_WRITEONLY is supposed to result in write-combined mappings
45  * being returned. OpenGL doesn't give us explicit control over that, but
46  * the hints and access flags we set for typical access patterns on
47  * dynamic resources should in theory have the same effect on the OpenGL
48  * driver. */
49 
50  if (usage & ~handled)
51  {
52  FIXME("Unhandled usage flags %#x.\n", usage & ~handled);
53  handled |= usage;
54  }
56  WARN_(d3d_perf)("WINED3DUSAGE_DYNAMIC used without WINED3DUSAGE_WRITEONLY.\n");
57 }
#define WINED3DUSAGE_OVERLAY
Definition: wined3d.h:930
#define WINED3DUSAGE_DYNAMIC
Definition: wined3d.h:916
#define WINED3DUSAGE_DEPTHSTENCIL
Definition: wined3d.h:909
#define FIXME(fmt,...)
Definition: debug.h:110
#define WINED3DUSAGE_STATICDECL
Definition: wined3d.h:929
#define WINED3DUSAGE_LEGACY_CUBEMAP
Definition: wined3d.h:926
#define WINED3DUSAGE_WRITEONLY
Definition: wined3d.h:910
#define WINED3DUSAGE_RENDERTARGET
Definition: wined3d.h:908
unsigned long DWORD
Definition: ntddk_ex.h:95
GLsizeiptr const GLvoid GLenum usage
Definition: glext.h:5919
#define WINED3DUSAGE_PRIVATE
Definition: wined3d.h:925
#define WINED3DUSAGE_TEXTURE
Definition: wined3d.h:927
#define WINED3DUSAGE_SCRATCH
Definition: wined3d.h:924
#define WARN_(ch,...)
Definition: debug.h:157

Referenced by resource_init().

◆ resource_cleanup()

void resource_cleanup ( struct wined3d_resource resource)

Definition at line 227 of file resource.c.

228 {
229  const struct wined3d *d3d = resource->device->wined3d;
230 
231  TRACE("Cleaning up resource %p.\n", resource);
232 
233  if (!(resource->usage & WINED3DUSAGE_PRIVATE))
234  {
236  {
237  TRACE("Decrementing device memory pool by %u.\n", resource->size);
238  adapter_adjust_memory(resource->device->adapter, (INT64)0 - resource->size);
239  }
240 
242  }
245 }
static void wined3d_resource_destroy_object(void *object)
Definition: resource.c:218
static void wined3d_resource_acquire(struct wined3d_resource *resource)
void wined3d_cs_destroy_object(struct wined3d_cs *cs, void(*callback)(void *object), void *object)
Definition: cs.c:1907
#define WINED3D_RESOURCE_ACCESS_CPU
Definition: wined3d.h:56
void device_resource_released(struct wined3d_device *device, struct wined3d_resource *resource)
Definition: device.c:5133
size_t size
Definition: utils.c:259
#define TRACE(s)
Definition: solgame.cpp:4
signed long long INT64
#define WINED3DUSAGE_PRIVATE
Definition: wined3d.h:925
UINT64 adapter_adjust_memory(struct wined3d_adapter *adapter, INT64 amount)
Definition: directx.c:442
#define WINED3D_VIDMEM_ACCOUNTING
Definition: wined3d.h:1319

Referenced by buffer_init(), wined3d_buffer_decref(), wined3d_texture_cleanup_sync(), and wined3d_texture_decref().

◆ 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,
unsigned int  usage,
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 59 of file resource.c.

65 {
68  const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
69  BOOL tex_2d_ok = FALSE;
70  unsigned int i;
71 
72  static const struct
73  {
75  DWORD cube_usage;
76  enum wined3d_gl_resource_type gl_type;
77  }
78  resource_types[] =
79  {
87  };
88 
90 
92  {
93  ERR("Trying to create a scratch resource with access flags %s.\n",
96  }
97 
98  if (!size)
99  ERR("Attempting to create a zero-sized resource.\n");
100 
101  for (i = 0; i < ARRAY_SIZE(resource_types); ++i)
102  {
103  if (resource_types[i].type != type
104  || resource_types[i].cube_usage != (usage & WINED3DUSAGE_LEGACY_CUBEMAP))
105  continue;
106 
107  gl_type = resource_types[i].gl_type;
108  if (base_type == WINED3D_GL_RES_TYPE_COUNT)
109  base_type = gl_type;
110 
111  if ((usage & WINED3DUSAGE_RENDERTARGET) && !(format->flags[gl_type] & WINED3DFMT_FLAG_RENDERTARGET))
112  {
113  WARN("Format %s cannot be used for render targets.\n", debug_d3dformat(format->id));
114  continue;
115  }
117  && !(format->flags[gl_type] & (WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL)))
118  {
119  WARN("Format %s cannot be used for depth/stencil buffers.\n", debug_d3dformat(format->id));
120  continue;
121  }
124  && !(format->flags[gl_type] & WINED3DFMT_FLAG_FBO_ATTACHABLE))
125  {
126  WARN("Render target or depth stencil is not FBO attachable.\n");
127  continue;
128  }
129  if ((usage & WINED3DUSAGE_TEXTURE) && !(format->flags[gl_type] & WINED3DFMT_FLAG_TEXTURE))
130  {
131  WARN("Format %s cannot be used for texturing.\n", debug_d3dformat(format->id));
132  continue;
133  }
134  if (((width & (width - 1)) || (height & (height - 1)))
137  && gl_type == WINED3D_GL_RES_TYPE_TEX_2D)
138  {
139  TRACE("Skipping 2D texture type to try texture rectangle.\n");
140  tex_2d_ok = TRUE;
141  continue;
142  }
143  break;
144  }
145 
146  if (base_type != WINED3D_GL_RES_TYPE_COUNT && i == ARRAY_SIZE(resource_types))
147  {
148  if (tex_2d_ok)
149  {
150  /* Non power of 2 texture and rectangle textures or renderbuffers do not work.
151  * Use 2D textures, the texture code will pad to a power of 2 size. */
152  gl_type = WINED3D_GL_RES_TYPE_TEX_2D;
153  }
154  else if (usage & WINED3DUSAGE_SCRATCH)
155  {
156  /* Needed for proper format information. */
157  gl_type = base_type;
158  }
159  else
160  {
161  WARN("Did not find a suitable GL resource type for resource type %s.\n",
163  return WINED3DERR_INVALIDCALL;
164  }
165  }
166 
167  if (base_type != WINED3D_GL_RES_TYPE_COUNT
170  {
171  UINT width_mask = format->block_width - 1;
172  UINT height_mask = format->block_height - 1;
173  if (width & width_mask || height & height_mask)
174  return WINED3DERR_INVALIDCALL;
175  }
176 
177  resource->ref = 1;
178  resource->device = device;
179  resource->type = type;
180  resource->gl_type = gl_type;
181  resource->format = format;
182  if (gl_type < WINED3D_GL_RES_TYPE_COUNT)
183  resource->format_flags = format->flags[gl_type];
184  resource->multisample_type = multisample_type;
185  resource->multisample_quality = multisample_quality;
186  resource->usage = usage;
187  resource->access = access;
188  resource->width = width;
189  resource->height = height;
190  resource->depth = depth;
191  resource->size = size;
192  resource->priority = 0;
193  resource->parent = parent;
194  resource->parent_ops = parent_ops;
195  resource->resource_ops = resource_ops;
196  resource->map_binding = WINED3D_LOCATION_SYSMEM;
197  resource->heap_memory = NULL;
198 
199  if (!(usage & WINED3DUSAGE_PRIVATE))
200  {
201  /* Check that we have enough video ram left */
203  {
205  {
206  ERR("Out of adapter memory.\n");
208  }
209  adapter_adjust_memory(device->adapter, size);
210  }
211 
213  }
214 
215  return WINED3D_OK;
216 }
#define ORM_FBO
#define WINED3DFMT_FLAG_STENCIL
#define WINED3DERR_INVALIDCALL
Definition: wined3d.h:48
GLint GLint GLsizei width
Definition: gl.h:1546
wined3d_resource_type
Definition: wined3d.h:704
#define TRUE
Definition: types.h:120
#define WINED3DERR_OUTOFVIDEOMEMORY
Definition: wined3d.h:47
#define WARN(fmt,...)
Definition: debug.h:111
UINT CDECL wined3d_device_get_available_texture_mem(const struct wined3d_device *device)
Definition: device.c:1301
#define WINED3DFMT_FLAG_BLOCKS
void device_resource_add(struct wined3d_device *device, struct wined3d_resource *resource)
Definition: device.c:5115
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
#define WINED3DUSAGE_DEPTHSTENCIL
Definition: wined3d.h:909
wined3d_gl_resource_type
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
#define WINED3D_RESOURCE_ACCESS_CPU
Definition: wined3d.h:56
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 BOOL
Definition: ntddk_ex.h:94
Definition: devices.h:37
#define WINED3DFMT_FLAG_BLOCKS_NO_VERIFY
#define WINED3DFMT_FLAG_TEXTURE
size_t size
Definition: utils.c:259
BOOL supported[WINED3D_GL_EXT_COUNT]
smooth NULL
Definition: ftsmooth.c:416
#define WINED3DUSAGE_LEGACY_CUBEMAP
Definition: wined3d.h:926
#define TRACE(s)
Definition: solgame.cpp:4
GLsizeiptr size
Definition: glext.h:5919
r parent
Definition: btrfs.c:2677
#define WINED3DUSAGE_RENDERTARGET
Definition: wined3d.h:908
#define WINED3D_OK
Definition: wined3d.h:37
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLint GLsizei GLsizei GLsizei depth
Definition: gl.h:1546
#define WINED3D_LOCATION_SYSMEM
#define WINED3DFMT_FLAG_FBO_ATTACHABLE
GLsizeiptr const GLvoid GLenum usage
Definition: glext.h:5919
#define WINED3DUSAGE_PRIVATE
Definition: wined3d.h:925
#define WINED3DFMT_FLAG_RENDERTARGET
#define WINED3D_RESOURCE_ACCESS_GPU
Definition: wined3d.h:55
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
#define ERR(fmt,...)
Definition: debug.h:109
GLuint GLint GLboolean GLint GLenum access
Definition: glext.h:7866
#define ARRAY_SIZE(a)
Definition: main.h:24
#define WINED3DUSAGE_TEXTURE
Definition: wined3d.h:927
unsigned int UINT
Definition: ndis.h:50
#define WINED3DUSAGE_SCRATCH
Definition: wined3d.h:924
const char * debug_d3dresourcetype(enum wined3d_resource_type resource_type)
Definition: utils.c:4271
#define WINED3DFMT_FLAG_DEPTH
const char * wined3d_debug_resource_access(DWORD access)
Definition: utils.c:4142
const char * debug_d3dformat(enum wined3d_format_id format_id)
Definition: utils.c:3922
UINT64 adapter_adjust_memory(struct wined3d_adapter *adapter, INT64 amount)
Definition: directx.c:442
static void resource_check_usage(DWORD usage)
Definition: resource.c:31
#define WINED3D_VIDMEM_ACCOUNTING
Definition: wined3d.h:1319

Referenced by buffer_init(), and wined3d_texture_init().

◆ resource_unload()

void resource_unload ( struct wined3d_resource resource)

Definition at line 247 of file resource.c.

248 {
249  if (resource->map_count)
250  ERR("Resource %p is being unloaded while mapped.\n", resource);
251 }
#define ERR(fmt,...)
Definition: debug.h:109

Referenced by buffer_unload(), and wined3d_texture_unload_gl_texture().

◆ WINE_DECLARE_DEBUG_CHANNEL()

WINE_DECLARE_DEBUG_CHANNEL ( d3d_perf  )

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( d3d  )

◆ wined3d_resource_allocate_sysmem()

BOOL wined3d_resource_allocate_sysmem ( struct wined3d_resource resource)

Definition at line 477 of file resource.c.

478 {
479  void **p;
480  SIZE_T align = RESOURCE_ALIGNMENT - 1 + sizeof(*p);
481  void *mem;
482 
483  if (!(mem = heap_alloc_zero(resource->size + align)))
484  {
485  ERR("Failed to allocate system memory.\n");
486  return FALSE;
487  }
488 
489  p = (void **)(((ULONG_PTR)mem + align) & ~(RESOURCE_ALIGNMENT - 1)) - 1;
490  *p = mem;
491 
492  resource->heap_memory = ++p;
493 
494  return TRUE;
495 }
#define TRUE
Definition: types.h:120
#define RESOURCE_ALIGNMENT
int align(int length, int align)
Definition: dsound8.c:36
uint32_t ULONG_PTR
Definition: typedefs.h:63
size_t size
Definition: utils.c:259
#define ERR(fmt,...)
Definition: debug.h:109
ULONG_PTR SIZE_T
Definition: typedefs.h:78
Definition: mem.c:156
GLfloat GLfloat p
Definition: glext.h:8902

Referenced by buffer_init(), wined3d_buffer_prepare_location(), wined3d_texture_init(), and wined3d_texture_prepare_location().

◆ wined3d_resource_destroy_object()

static void wined3d_resource_destroy_object ( void object)
static

Definition at line 218 of file resource.c.

219 {
220  struct wined3d_resource *resource = object;
221 
225 }
void context_resource_released(const struct wined3d_device *device, struct wined3d_resource *resource)
Definition: context.c:1070
static void wined3d_resource_release(struct wined3d_resource *resource)
void * object
Definition: jmemsys.h:48
void wined3d_resource_free_sysmem(struct wined3d_resource *resource)
Definition: resource.c:497

Referenced by resource_cleanup().

◆ wined3d_resource_free_sysmem()

void wined3d_resource_free_sysmem ( struct wined3d_resource resource)

Definition at line 497 of file resource.c.

498 {
499  void **p = resource->heap_memory;
500 
501  if (!p)
502  return;
503 
504  heap_free(*(--p));
505  resource->heap_memory = NULL;
506 }
smooth NULL
Definition: ftsmooth.c:416
GLfloat GLfloat p
Definition: glext.h:8902
static BOOL heap_free(void *mem)
Definition: appwiz.h:75

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

◆ wined3d_resource_get_desc()

void CDECL wined3d_resource_get_desc ( const struct wined3d_resource resource,
struct wined3d_resource_desc desc 
)

Definition at line 285 of file resource.c.

286 {
287  desc->resource_type = resource->type;
288  desc->format = resource->format->id;
289  desc->multisample_type = resource->multisample_type;
290  desc->multisample_quality = resource->multisample_quality;
291  desc->usage = resource->usage;
292  desc->access = resource->access;
293  desc->width = resource->width;
294  desc->height = resource->height;
295  desc->depth = resource->depth;
296  desc->size = resource->size;
297 }
size_t size
Definition: utils.c:259
const struct builtin_class_descr * desc
Definition: regcontrol.c:48

Referenced by d3d8_indexbuffer_GetDesc(), d3d8_vertexbuffer_GetDesc(), d3d9_indexbuffer_GetDesc(), d3d9_vertexbuffer_GetDesc(), d3d_device3_GetRenderState(), d3d_device3_SetRenderState(), d3d_device3_SetTexture(), d3d_vertex_buffer7_GetVertexBufferDesc(), d3d_vertex_buffer7_Lock(), and reset_enum_callback().

◆ wined3d_resource_get_parent()

void* CDECL wined3d_resource_get_parent ( const struct wined3d_resource resource)

Definition at line 275 of file resource.c.

276 {
277  return resource->parent;
278 }

Referenced by reset_enum_callback().

◆ wined3d_resource_get_priority()

◆ wined3d_resource_gl_legacy_map_flags()

GLenum wined3d_resource_gl_legacy_map_flags ( DWORD  d3d_flags)

Definition at line 525 of file resource.c.

526 {
527  switch (d3d_flags & (WINED3D_MAP_READ | WINED3D_MAP_WRITE))
528  {
529  case WINED3D_MAP_READ:
530  return GL_READ_ONLY_ARB;
531 
532  case WINED3D_MAP_WRITE:
533  return GL_WRITE_ONLY_ARB;
534 
535  default:
536  return GL_READ_WRITE_ARB;
537  }
538 }
#define GL_READ_ONLY_ARB
Definition: glext.h:1500
#define GL_READ_WRITE_ARB
Definition: glext.h:1502
#define WINED3D_MAP_READ
Definition: wined3d.h:948
#define WINED3D_MAP_WRITE
Definition: wined3d.h:947
#define GL_WRITE_ONLY_ARB
Definition: glext.h:1501

Referenced by context_map_bo_address().

◆ wined3d_resource_gl_map_flags()

GLbitfield wined3d_resource_gl_map_flags ( DWORD  d3d_flags)

Definition at line 508 of file resource.c.

509 {
510  GLbitfield ret = 0;
511 
512  if (d3d_flags & WINED3D_MAP_WRITE)
514  if (d3d_flags & WINED3D_MAP_READ)
515  ret |= GL_MAP_READ_BIT;
516 
517  if (d3d_flags & WINED3D_MAP_DISCARD)
519  if (d3d_flags & WINED3D_MAP_NOOVERWRITE)
521 
522  return ret;
523 }
#define GL_MAP_READ_BIT
Definition: glext.h:1793
#define GL_MAP_INVALIDATE_BUFFER_BIT
Definition: glext.h:1796
#define GL_MAP_WRITE_BIT
Definition: glext.h:1794
#define WINED3D_MAP_DISCARD
Definition: wined3d.h:944
#define WINED3D_MAP_READ
Definition: wined3d.h:948
int ret
#define WINED3D_MAP_WRITE
Definition: wined3d.h:947
unsigned int GLbitfield
Definition: gl.h:152
#define WINED3D_MAP_NOOVERWRITE
Definition: wined3d.h:943
#define GL_MAP_UNSYNCHRONIZED_BIT
Definition: glext.h:1798
#define GL_MAP_FLUSH_EXPLICIT_BIT
Definition: glext.h:1797

Referenced by context_map_bo_address(), and wined3d_buffer_map().

◆ wined3d_resource_is_offscreen()

BOOL wined3d_resource_is_offscreen ( struct wined3d_resource resource)

Definition at line 540 of file resource.c.

541 {
542  struct wined3d_swapchain *swapchain;
543 
544  /* Only 2D texture resources can be onscreen. */
545  if (resource->type != WINED3D_RTYPE_TEXTURE_2D)
546  return TRUE;
547 
548  /* Not on a swapchain - must be offscreen */
549  if (!(swapchain = texture_from_resource(resource)->swapchain))
550  return TRUE;
551 
552  /* The front buffer is always onscreen */
553  if (resource == &swapchain->front_buffer->resource)
554  return FALSE;
555 
556  /* If the swapchain is rendered to an FBO, the backbuffer is
557  * offscreen, otherwise onscreen */
558  return swapchain->render_to_fbo;
559 }
struct wined3d_texture * front_buffer
#define TRUE
Definition: types.h:120
static struct wined3d_texture * texture_from_resource(struct wined3d_resource *resource)

Referenced by arbfp_blitter_blit(), context_apply_clear_state(), context_create(), context_setup_target(), fb_copy_to_texture_direct(), fb_copy_to_texture_hwstretch(), glsl_blitter_blit(), texture2d_blt(), texture2d_load_drawable(), texture2d_load_fb_texture(), texture2d_load_texture(), texture2d_read_from_framebuffer(), wined3d_resource_update_draw_binding(), wined3d_texture_prepare_texture(), and wined3d_texture_upload_data().

◆ 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,
DWORD  flags 
)

Definition at line 334 of file resource.c.

336 {
337  TRACE("resource %p, sub_resource_idx %u, map_desc %p, box %s, flags %#x.\n",
338  resource, sub_resource_idx, map_desc, debug_box(box), flags);
339 
341  {
342  WARN("No read/write flags specified.\n");
343  return E_INVALIDARG;
344  }
345 
347  {
348  WARN("Resource does not have MAP_R access.\n");
349  return E_INVALIDARG;
350  }
351 
353  {
354  WARN("Resource does not have MAP_W access.\n");
355  return E_INVALIDARG;
356  }
357 
360 
361  return wined3d_cs_map(resource->device->cs, resource, sub_resource_idx, map_desc, box, flags);
362 }
static DWORD wined3d_resource_sanitise_map_flags(const struct wined3d_resource *resource, DWORD flags)
Definition: resource.c:299
#define WARN(fmt,...)
Definition: debug.h:111
const char * debug_box(const struct wined3d_box *box)
Definition: utils.c:3881
#define WINED3D_RESOURCE_ACCESS_MAP_W
Definition: wined3d.h:58
static void wined3d_resource_wait_idle(struct wined3d_resource *resource)
#define E_INVALIDARG
Definition: ddrawi.h:101
#define TRACE(s)
Definition: solgame.cpp:4
#define WINED3D_MAP_READ
Definition: wined3d.h:948
#define WINED3D_RESOURCE_ACCESS_MAP_R
Definition: wined3d.h:57
HRESULT wined3d_cs_map(struct wined3d_cs *cs, struct wined3d_resource *resource, unsigned int sub_resource_idx, struct wined3d_map_desc *map_desc, const struct wined3d_box *box, unsigned int flags)
Definition: cs.c:2022
GLbitfield flags
Definition: glext.h:7161
#define WINED3D_MAP_WRITE
Definition: wined3d.h:947
Definition: palette.c:467

Referenced by d3d8_device_DrawIndexedPrimitiveUP(), d3d8_device_DrawPrimitiveUP(), d3d8_indexbuffer_Lock(), d3d8_surface_LockRect(), d3d8_vertexbuffer_Lock(), d3d8_volume_LockBox(), d3d9_device_DrawIndexedPrimitiveUP(), d3d9_device_DrawPrimitiveUP(), d3d9_indexbuffer_Lock(), d3d9_surface_LockRect(), d3d9_vertexbuffer_Lock(), d3d9_volume_LockBox(), d3d_device7_DrawIndexedPrimitive(), d3d_device7_DrawIndexedPrimitiveStrided(), d3d_device7_DrawIndexedPrimitiveVB(), d3d_device7_DrawPrimitive(), d3d_device7_DrawPrimitiveStrided(), d3d_execute_buffer_SetExecuteData(), d3d_vertex_buffer7_Lock(), process_vertices_strided(), surface_lock(), wined3d_device_create_cursor_texture(), wined3d_device_process_vertices(), and wined3d_device_set_cursor_properties().

◆ wined3d_resource_map_info()

HRESULT CDECL wined3d_resource_map_info ( struct wined3d_resource resource,
unsigned int  sub_resource_idx,
struct wined3d_map_info info,
DWORD  flags 
)

Definition at line 364 of file resource.c.

366 {
367  TRACE("resource %p, sub_resource_idx %u.\n", resource, sub_resource_idx);
368 
369  return resource->resource_ops->resource_map_info(resource, sub_resource_idx, info, flags);
370 }
#define TRACE(s)
Definition: solgame.cpp:4
GLbitfield flags
Definition: glext.h:7161

◆ wined3d_resource_preload()

◆ wined3d_resource_sanitise_map_flags()

static DWORD wined3d_resource_sanitise_map_flags ( const struct wined3d_resource resource,
DWORD  flags 
)
static

Definition at line 299 of file resource.c.

300 {
301  /* Not all flags make sense together, but Windows never returns an error.
302  * Catch the cases that could cause issues. */
303  if (flags & WINED3D_MAP_READ)
304  {
306  {
307  WARN("WINED3D_MAP_READ combined with WINED3D_MAP_DISCARD, ignoring flags.\n");
309  }
311  {
312  WARN("WINED3D_MAP_READ combined with WINED3D_MAP_NOOVERWRITE, ignoring flags.\n");
314  }
315  }
317  {
318  if (!(resource->usage & WINED3DUSAGE_DYNAMIC))
319  {
320  WARN("DISCARD or NOOVERWRITE map on non-dynamic buffer, ignoring.\n");
322  }
325  {
326  WARN("WINED3D_MAP_NOOVERWRITE used with WINED3D_MAP_DISCARD, ignoring WINED3D_MAP_DISCARD.\n");
328  }
329  }
330 
331  return flags;
332 }
#define WINED3DUSAGE_DYNAMIC
Definition: wined3d.h:916
#define WARN(fmt,...)
Definition: debug.h:111
#define WINED3D_MAP_DISCARD
Definition: wined3d.h:944
#define WINED3D_MAP_READ
Definition: wined3d.h:948
GLbitfield flags
Definition: glext.h:7161
#define WINED3D_MAP_WRITE
Definition: wined3d.h:947
#define WINED3D_MAP_NOOVERWRITE
Definition: wined3d.h:943

Referenced by wined3d_resource_map().

◆ wined3d_resource_set_parent()

void CDECL wined3d_resource_set_parent ( struct wined3d_resource resource,
void parent 
)

Definition at line 280 of file resource.c.

281 {
282  resource->parent = parent;
283 }
r parent
Definition: btrfs.c:2677

Referenced by ddraw_surface7_Flip().

◆ wined3d_resource_set_priority()

DWORD CDECL wined3d_resource_set_priority ( struct wined3d_resource resource,
DWORD  priority 
)

Definition at line 253 of file resource.c.

254 {
255  DWORD prev;
256 
258  {
259  WARN("Called on non-managed resource %p, ignoring.\n", resource);
260  return 0;
261  }
262 
263  prev = resource->priority;
264  resource->priority = priority;
265  TRACE("resource %p, new priority %u, returning old priority %u.\n", resource, priority, prev);
266  return prev;
267 }
#define WARN(fmt,...)
Definition: debug.h:111
static BOOL wined3d_resource_access_is_managed(unsigned int access)
#define TRACE(s)
Definition: solgame.cpp:4
unsigned long DWORD
Definition: ntddk_ex.h:95
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 561 of file resource.c.

562 {
564  {
565  resource->draw_binding = WINED3D_LOCATION_DRAWABLE;
566  }
567  else if (resource->multisample_type)
568  {
569  const struct wined3d_gl_info *gl_info = &resource->device->adapter->gl_info;
570  if (gl_info->supported[ARB_TEXTURE_MULTISAMPLE])
571  resource->draw_binding = WINED3D_LOCATION_TEXTURE_RGB;
572  else
574  }
575  else if (resource->gl_type == WINED3D_GL_RES_TYPE_RB)
576  {
577  resource->draw_binding = WINED3D_LOCATION_RB_RESOLVED;
578  }
579  else
580  {
581  resource->draw_binding = WINED3D_LOCATION_TEXTURE_RGB;
582  }
583 }
#define ORM_FBO
#define WINED3D_LOCATION_RB_MULTISAMPLE
BOOL supported[WINED3D_GL_EXT_COUNT]
#define WINED3D_LOCATION_RB_RESOLVED
#define WINED3D_LOCATION_DRAWABLE
BOOL wined3d_resource_is_offscreen(struct wined3d_resource *resource)
Definition: resource.c:540
#define WINED3D_LOCATION_TEXTURE_RGB

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

◆ wined3d_resource_update_info()

UINT CDECL wined3d_resource_update_info ( struct wined3d_resource resource,
unsigned int  sub_resource_idx,
const struct wined3d_box box,
unsigned int  row_pitch,
unsigned int  depth_pitch 
)

Definition at line 379 of file resource.c.

381 {
382  unsigned int width, height, depth;
383  struct wined3d_box b;
384  UINT data_size;
385 
386  TRACE("resource %p, sub_resource_idx %u, box %s, row_pitch %u, depth_pitch %u.\n",
387  resource, sub_resource_idx, debug_box(box), row_pitch, depth_pitch);
388 
389  if (resource->type == WINED3D_RTYPE_BUFFER)
390  {
391  if (sub_resource_idx > 0)
392  {
393  WARN("Invalid sub_resource_idx %u.\n", sub_resource_idx);
394  return 0;
395  }
396 
397  width = resource->size;
398  height = 1;
399  depth = 1;
400  }
401  else if (resource->type == WINED3D_RTYPE_TEXTURE_1D ||
403  {
405  unsigned int level;
406 
407  if (sub_resource_idx >= texture->level_count * texture->layer_count)
408  {
409  WARN("Invalid sub_resource_idx %u.\n", sub_resource_idx);
410  return 0;
411  }
412 
413  level = sub_resource_idx % texture->level_count;
417  }
418  else
419  {
420  FIXME("Not implemented for %s resources.\n", debug_d3dresourcetype(resource->type));
421  return 0;
422  }
423 
424  if (!box)
425  {
426  wined3d_box_set(&b, 0, 0, width, height, 0, depth);
427  box = &b;
428  }
429  else if (box->left >= box->right || box->right > width
430  || box->top >= box->bottom || box->bottom > height
431  || box->front >= box->back || box->back > depth)
432  {
433  WARN("Invalid box %s specified.\n", debug_box(box));
434  return 0;
435  }
436 
437  if (resource->format_flags & WINED3DFMT_FLAG_BLOCKS)
438  {
439  if (resource->type != WINED3D_RTYPE_TEXTURE_2D)
440  {
441  FIXME("Calculation of block formats not implemented for %s resources.\n", debug_d3dresourcetype(resource->type));
442  return 0;
443  }
444 
445  height = (box->bottom - box->top + resource->format->block_height - 1) / resource->format->block_height;
446  width = (box->right - box->left + resource->format->block_width - 1) / resource->format->block_width;
447  return (height - 1) * row_pitch + width * resource->format->block_byte_count;
448  }
449 
450  data_size = 0;
451  switch (resource->type)
452  {
454  data_size += (box->back - box->front - 1) * depth_pitch;
455  /* fall-through */
457  data_size += (box->bottom - box->top - 1) * row_pitch;
458  /* fall-through */
460  data_size += (box->right - box->left) * resource->format->byte_count;
461  break;
463  data_size = box->right - box->left;
464  break;
465  case WINED3D_RTYPE_NONE:
466  break;
467  }
468 
469  return data_size;
470 }
GLint level
Definition: gl.h:1546
GLint GLint GLsizei width
Definition: gl.h:1546
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)
#define WARN(fmt,...)
Definition: debug.h:111
#define WINED3DFMT_FLAG_BLOCKS
static unsigned int wined3d_texture_get_level_depth(const struct wined3d_texture *texture, unsigned int level)
const char * debug_box(const struct wined3d_box *box)
Definition: utils.c:3881
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:2793
unsigned int row_pitch
#define FIXME(fmt,...)
Definition: debug.h:110
size_t size
Definition: utils.c:259
#define b
Definition: ke_i.h:79
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
#define TRACE(s)
Definition: solgame.cpp:4
GLenum GLuint texture
Definition: glext.h:6295
static struct wined3d_texture * texture_from_resource(struct wined3d_resource *resource)
GLint GLint GLsizei GLsizei GLsizei depth
Definition: gl.h:1546
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
unsigned int UINT
Definition: ndis.h:50
const char * debug_d3dresourcetype(enum wined3d_resource_type resource_type)
Definition: utils.c:4271
Definition: palette.c:467