Advertisement
Guest User

Untitled

a guest
Feb 10th, 2014
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 11.67 KB | None | 0 0
  1. diff --git a/dlls/wined3d/buffer.c b/dlls/wined3d/buffer.c
  2. index c53021b..5b4ef8e 100644
  3. --- a/dlls/wined3d/buffer.c
  4. +++ b/dlls/wined3d/buffer.c
  5. @@ -1147,7 +1147,7 @@ static HRESULT buffer_init(struct wined3d_buffer *buffer, struct wined3d_device
  6.  
  7.      hr = resource_init(&buffer->resource, device, WINED3D_RTYPE_BUFFER, format,
  8.              WINED3D_MULTISAMPLE_NONE, 0, usage, pool, size, 1, 1, size,
  9. -            parent, parent_ops, &buffer_resource_ops);
  10. +            parent, parent_ops, &buffer_resource_ops, 0);
  11.      if (FAILED(hr))
  12.      {
  13.          WARN("Failed to initialize resource, hr %#x\n", hr);
  14. diff --git a/dlls/wined3d/resource.c b/dlls/wined3d/resource.c
  15. index 177d23e..87157b2 100644
  16. --- a/dlls/wined3d/resource.c
  17. +++ b/dlls/wined3d/resource.c
  18. @@ -82,7 +82,7 @@ HRESULT resource_init(struct wined3d_resource *resource, struct wined3d_device *
  19.          enum wined3d_multisample_type multisample_type, UINT multisample_quality,
  20.          DWORD usage, enum wined3d_pool pool, UINT width, UINT height, UINT depth, UINT size,
  21.          void *parent, const struct wined3d_parent_ops *parent_ops,
  22. -        const struct wined3d_resource_ops *resource_ops)
  23. +        const struct wined3d_resource_ops *resource_ops, void *have_alloc)
  24.  {
  25.      const struct wined3d *d3d = device->wined3d;
  26.  
  27. @@ -113,6 +113,7 @@ HRESULT resource_init(struct wined3d_resource *resource, struct wined3d_device *
  28.      resource->depth = depth;
  29.      resource->size = size;
  30.      resource->priority = 0;
  31. +    resource->alloc_managed = have_alloc == NULL ? 0 : 1;
  32.      resource->parent = parent;
  33.      resource->parent_ops = parent_ops;
  34.      resource->resource_ops = resource_ops;
  35. @@ -120,7 +121,9 @@ HRESULT resource_init(struct wined3d_resource *resource, struct wined3d_device *
  36.  
  37.      if (size)
  38.      {
  39. -        if (!wined3d_resource_allocate_sysmem(resource))
  40. +        if (have_alloc) {
  41. +            resource->heap_memory = have_alloc;
  42. +        } else if (!wined3d_resource_allocate_sysmem(resource))
  43.          {
  44.              ERR("Failed to allocate system memory.\n");
  45.              return E_OUTOFMEMORY;
  46. @@ -171,7 +174,8 @@ void resource_cleanup(struct wined3d_resource *resource)
  47.              ERR("Failed to free private data when destroying resource %p, hr = %#x.\n", resource, hr);
  48.      }
  49.  
  50. -    wined3d_resource_free_sysmem(resource);
  51. +    if (!resource->alloc_managed)
  52. +        wined3d_resource_free_sysmem(resource);
  53.  
  54.      device_resource_released(resource->device, resource);
  55.  }
  56. diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c
  57. index 628a4a5..3ab9878 100644
  58. --- a/dlls/wined3d/surface.c
  59. +++ b/dlls/wined3d/surface.c
  60. @@ -6307,7 +6307,7 @@ cpu:
  61.  }
  62.  
  63.  static HRESULT surface_init(struct wined3d_surface *surface, struct wined3d_texture *container,
  64. -        const struct wined3d_resource_desc *desc, DWORD flags)
  65. +        const struct wined3d_resource_desc *desc, DWORD flags, void *have_alloc)
  66.  {
  67.      struct wined3d_device *device = container->resource.device;
  68.      const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
  69. @@ -6365,7 +6365,7 @@ static HRESULT surface_init(struct wined3d_surface *surface, struct wined3d_text
  70.  
  71.      if (FAILED(hr = resource_init(&surface->resource, device, WINED3D_RTYPE_SURFACE, format,
  72.              desc->multisample_type, multisample_quality, desc->usage, desc->pool, desc->width, desc->height, 1,
  73. -            resource_size, NULL, &wined3d_null_parent_ops, &surface_resource_ops)))
  74. +            resource_size, NULL, &wined3d_null_parent_ops, &surface_resource_ops, have_alloc)))
  75.      {
  76.          WARN("Failed to initialize resource, returning %#x.\n", hr);
  77.          return hr;
  78. @@ -6415,7 +6415,7 @@ static HRESULT surface_init(struct wined3d_surface *surface, struct wined3d_text
  79.  }
  80.  
  81.  HRESULT CDECL wined3d_surface_create(struct wined3d_texture *container,
  82. -        const struct wined3d_resource_desc *desc, DWORD flags, struct wined3d_surface **surface)
  83. +        const struct wined3d_resource_desc *desc, DWORD flags, struct wined3d_surface **surface, void *have_alloc)
  84.  {
  85.      struct wined3d_device_parent *device_parent = container->resource.device->device_parent;
  86.      const struct wined3d_parent_ops *parent_ops;
  87. @@ -6432,7 +6432,7 @@ HRESULT CDECL wined3d_surface_create(struct wined3d_texture *container,
  88.      if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
  89.          return E_OUTOFMEMORY;
  90.  
  91. -    if (FAILED(hr = surface_init(object, container, desc, flags)))
  92. +    if (FAILED(hr = surface_init(object, container, desc, flags, have_alloc)))
  93.      {
  94.          WARN("Failed to initialize surface, returning %#x.\n", hr);
  95.          HeapFree(GetProcessHeap(), 0, object);
  96. diff --git a/dlls/wined3d/texture.c b/dlls/wined3d/texture.c
  97. index 897af19..e94179c 100644
  98. --- a/dlls/wined3d/texture.c
  99. +++ b/dlls/wined3d/texture.c
  100. @@ -51,7 +51,7 @@ static HRESULT wined3d_texture_init(struct wined3d_texture *texture, const struc
  101.  
  102.      if (FAILED(hr = resource_init(&texture->resource, device, desc->resource_type, format,
  103.              desc->multisample_type, desc->multisample_quality, desc->usage, desc->pool,
  104. -            desc->width, desc->height, desc->depth, 0, parent, parent_ops, resource_ops)))
  105. +            desc->width, desc->height, desc->depth, 0, parent, parent_ops, resource_ops, 0)))
  106.      {
  107.          WARN("Failed to initialize resource, returning %#x\n", hr);
  108.          return hr;
  109. @@ -128,8 +128,11 @@ static void wined3d_texture_cleanup(struct wined3d_texture *texture)
  110.      {
  111.          struct wined3d_resource *sub_resource = texture->sub_resources[i];
  112.  
  113. -        if (sub_resource)
  114. +        if (sub_resource) {
  115. +            if (sub_resource->alloc_managed && i == 0)
  116. +                sub_resource->alloc_managed = 0;
  117.              texture->texture_ops->texture_sub_resource_cleanup(sub_resource);
  118. +        }
  119.      }
  120.  
  121.      wined3d_texture_unload_gl_texture(texture);
  122. @@ -879,7 +882,7 @@ static HRESULT cubetexture_init(struct wined3d_texture *texture, const struct wi
  123.              UINT idx = j * texture->level_count + i;
  124.              struct wined3d_surface *surface;
  125.  
  126. -            if (FAILED(hr = wined3d_surface_create(texture, &surface_desc, surface_flags, &surface)))
  127. +            if (FAILED(hr = wined3d_surface_create(texture, &surface_desc, surface_flags, &surface, 0)))
  128.              {
  129.                  WARN("Failed to create surface, hr %#x.\n", hr);
  130.                  wined3d_texture_cleanup(texture);
  131. @@ -897,6 +900,21 @@ static HRESULT cubetexture_init(struct wined3d_texture *texture, const struct wi
  132.      return WINED3D_OK;
  133.  }
  134.  
  135. +void* wined3d_resource_allocate_sysmem_from_size(SIZE_T size)
  136. +{
  137. +    void **p;
  138. +    SIZE_T align = RESOURCE_ALIGNMENT - 1 + sizeof(*p);
  139. +    void *mem;
  140. +
  141. +    if (!(mem = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size + align)))
  142. +        return FALSE;
  143. +
  144. +    p = (void **)(((ULONG_PTR)mem + align) & ~(RESOURCE_ALIGNMENT - 1)) - 1;
  145. +    *p = mem;
  146. +
  147. +    return ++p;
  148. +}
  149. +
  150.  static HRESULT texture_init(struct wined3d_texture *texture, const struct wined3d_resource_desc *desc,
  151.          UINT levels, DWORD surface_flags, struct wined3d_device *device, void *parent,
  152.          const struct wined3d_parent_ops *parent_ops)
  153. @@ -1029,25 +1047,42 @@ static HRESULT texture_init(struct wined3d_texture *texture, const struct wined3
  154.      /* Generate all the surfaces. */
  155.      surface_desc = *desc;
  156.      surface_desc.resource_type = WINED3D_RTYPE_SURFACE;
  157. +    SIZE_T resource_size = 0;
  158. +    // compute the needed space for all mipmaps
  159. +    UINT pw = surface_desc.width;
  160. +    UINT ph = surface_desc.height;
  161. +    const struct wined3d_format *format = wined3d_get_format(gl_info, desc->format);
  162. +
  163. +    for (i = 0; i < texture->level_count; ++i)
  164. +    {
  165. +        resource_size += wined3d_format_calculate_size(format, device->surface_alignment, pw, ph, 1);
  166. +        // next mipmap
  167. +        pw = max(1, pw >> 1);
  168. +        ph = max(1, ph >> 1);
  169. +    }
  170. +    // alloc
  171. +    void *base_surface_alloc = wined3d_resource_allocate_sysmem_from_size(resource_size);
  172. +    void *last_alloc = base_surface_alloc;
  173.      for (i = 0; i < texture->level_count; ++i)
  174.      {
  175.          struct wined3d_surface *surface;
  176.  
  177. -        if (FAILED(hr = wined3d_surface_create(texture, &surface_desc, surface_flags, &surface)))
  178. +        if (FAILED(hr = wined3d_surface_create(texture, &surface_desc, surface_flags, &surface, last_alloc)))
  179.          {
  180.              WARN("Failed to create surface, hr %#x.\n", hr);
  181.              wined3d_texture_cleanup(texture);
  182.              return hr;
  183.          }
  184. +        last_alloc += wined3d_format_calculate_size(format, device->surface_alignment, surface_desc.width, surface_desc.height, 1);
  185.  
  186.          surface_set_texture_target(surface, texture->target, i);
  187.          texture->sub_resources[i] = &surface->resource;
  188. +
  189.          TRACE("Created surface level %u @ %p.\n", i, surface);
  190.          /* Calculate the next mipmap level. */
  191.          surface_desc.width = max(1, surface_desc.width >> 1);
  192.          surface_desc.height = max(1, surface_desc.height >> 1);
  193.      }
  194. -
  195.      return WINED3D_OK;
  196.  }
  197.  
  198. diff --git a/dlls/wined3d/volume.c b/dlls/wined3d/volume.c
  199. index 817fe7e..335c65e 100644
  200. --- a/dlls/wined3d/volume.c
  201. +++ b/dlls/wined3d/volume.c
  202. @@ -839,7 +839,7 @@ static HRESULT volume_init(struct wined3d_volume *volume, struct wined3d_texture
  203.  
  204.      if (FAILED(hr = resource_init(&volume->resource, device, WINED3D_RTYPE_VOLUME, format,
  205.              WINED3D_MULTISAMPLE_NONE, 0, desc->usage, desc->pool, desc->width, desc->height, desc->depth,
  206. -            size, NULL, &wined3d_null_parent_ops, &volume_resource_ops)))
  207. +            size, NULL, &wined3d_null_parent_ops, &volume_resource_ops, 0)))
  208.      {
  209.          WARN("Failed to initialize resource, returning %#x.\n", hr);
  210.          return hr;
  211. diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
  212. index 991db87..b873d48 100644
  213. --- a/dlls/wined3d/wined3d_private.h
  214. +++ b/dlls/wined3d/wined3d_private.h
  215. @@ -2002,6 +2002,7 @@ struct wined3d_resource
  216.      void *heap_memory;
  217.      struct list privateData;
  218.      struct list resource_list_entry;
  219. +    DWORD alloc_managed;
  220.  
  221.      void *parent;
  222.      const struct wined3d_parent_ops *parent_ops;
  223. @@ -2015,7 +2016,7 @@ HRESULT resource_init(struct wined3d_resource *resource, struct wined3d_device *
  224.          enum wined3d_multisample_type multisample_type, UINT multisample_quality,
  225.          DWORD usage, enum wined3d_pool pool, UINT width, UINT height, UINT depth, UINT size,
  226.          void *parent, const struct wined3d_parent_ops *parent_ops,
  227. -        const struct wined3d_resource_ops *resource_ops) DECLSPEC_HIDDEN;
  228. +        const struct wined3d_resource_ops *resource_ops, void *have_alloc) DECLSPEC_HIDDEN;
  229.  DWORD resource_set_priority(struct wined3d_resource *resource, DWORD priority) DECLSPEC_HIDDEN;
  230.  void resource_unload(struct wined3d_resource *resource) DECLSPEC_HIDDEN;
  231.  BOOL wined3d_resource_allocate_sysmem(struct wined3d_resource *resource) DECLSPEC_HIDDEN;
  232. @@ -2275,7 +2276,7 @@ HRESULT surface_upload_from_surface(struct wined3d_surface *dst_surface, const P
  233.          struct wined3d_surface *src_surface, const RECT *src_rect) DECLSPEC_HIDDEN;
  234.  void surface_validate_location(struct wined3d_surface *surface, DWORD location) DECLSPEC_HIDDEN;
  235.  HRESULT CDECL wined3d_surface_create(struct wined3d_texture *container,
  236. -        const struct wined3d_resource_desc *desc, DWORD flags, struct wined3d_surface **surface) DECLSPEC_HIDDEN;
  237. +        const struct wined3d_resource_desc *desc, DWORD flags, struct wined3d_surface **surface, void *last_alloc) DECLSPEC_HIDDEN;
  238.  void surface_prepare_map_memory(struct wined3d_surface *surface) DECLSPEC_HIDDEN;
  239.  
  240.  void get_drawable_size_swapchain(const struct wined3d_context *context, UINT *width, UINT *height) DECLSPEC_HIDDEN;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement