[D3D8][D3D9][DDRAW][WINED3D] Sync with Wine Staging 3.3. CORE-14434
[reactos.git] / dll / directx / wine / wined3d / shader.c
index a42f35d..0513c9e 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
+#include "config.h"
+#include "wine/port.h"
+
+#include <stdio.h>
+#include <string.h>
+
 #include "wined3d_private.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(d3d_shader);
@@ -422,7 +428,7 @@ void string_buffer_clear(struct wined3d_string_buffer *buffer)
 BOOL string_buffer_init(struct wined3d_string_buffer *buffer)
 {
     buffer->buffer_size = 32;
-    if (!(buffer->buffer = HeapAlloc(GetProcessHeap(), 0, buffer->buffer_size)))
+    if (!(buffer->buffer = heap_alloc(buffer->buffer_size)))
     {
         ERR("Failed to allocate shader buffer memory.\n");
         return FALSE;
@@ -434,7 +440,7 @@ BOOL string_buffer_init(struct wined3d_string_buffer *buffer)
 
 void string_buffer_free(struct wined3d_string_buffer *buffer)
 {
-    HeapFree(GetProcessHeap(), 0, buffer->buffer);
+    heap_free(buffer->buffer);
 }
 
 BOOL string_buffer_resize(struct wined3d_string_buffer *buffer, int rc)
@@ -444,7 +450,7 @@ BOOL string_buffer_resize(struct wined3d_string_buffer *buffer, int rc)
 
     while (rc > 0 && (unsigned int)rc >= new_buffer_size - buffer->content_size)
         new_buffer_size *= 2;
-    if (!(new_buffer = HeapReAlloc(GetProcessHeap(), 0, buffer->buffer, new_buffer_size)))
+    if (!(new_buffer = heap_realloc(buffer->buffer, new_buffer_size)))
     {
         ERR("Failed to grow buffer.\n");
         buffer->buffer[buffer->content_size] = '\0';
@@ -492,11 +498,11 @@ struct wined3d_string_buffer *string_buffer_get(struct wined3d_string_buffer_lis
 
     if (list_empty(&list->list))
     {
-        buffer = HeapAlloc(GetProcessHeap(), 0, sizeof(*buffer));
+        buffer = heap_alloc(sizeof(*buffer));
         if (!buffer || !string_buffer_init(buffer))
         {
             ERR("Couldn't allocate buffer for temporary string.\n");
-            HeapFree(GetProcessHeap(), 0, buffer);
+            heap_free(buffer);
             return NULL;
         }
     }
@@ -553,7 +559,7 @@ void string_buffer_list_cleanup(struct wined3d_string_buffer_list *list)
     LIST_FOR_EACH_ENTRY_SAFE(buffer, buffer_next, &list->list, struct wined3d_string_buffer, entry)
     {
         string_buffer_free(buffer);
-        HeapFree(GetProcessHeap(), 0, buffer);
+        heap_free(buffer);
     }
     list_init(&list->list);
 }
@@ -579,7 +585,7 @@ static void shader_delete_constant_list(struct list *clist)
     struct wined3d_shader_lconst *constant, *constant_next;
 
     LIST_FOR_EACH_ENTRY_SAFE(constant, constant_next, clist, struct wined3d_shader_lconst, entry)
-        HeapFree(GetProcessHeap(), 0, constant);
+        heap_free(constant);
     list_init(clist);
 }
 
@@ -820,7 +826,7 @@ static void shader_record_sample(struct wined3d_shader_reg_maps *reg_maps,
 
     if (!map->size)
     {
-        if (!(entries = wined3d_calloc(4, sizeof(*entries))))
+        if (!(entries = heap_calloc(4, sizeof(*entries))))
         {
             ERR("Failed to allocate sampler map entries.\n");
             return;
@@ -833,7 +839,7 @@ static void shader_record_sample(struct wined3d_shader_reg_maps *reg_maps,
         size_t new_size = map->size * 2;
 
         if (sizeof(*entries) * new_size <= sizeof(*entries) * map->size
-                || !(entries = HeapReAlloc(GetProcessHeap(), 0, entries, sizeof(*entries) * new_size)))
+                || !(entries = heap_realloc(entries, sizeof(*entries) * new_size)))
         {
             ERR("Failed to resize sampler map entries.\n");
             return;
@@ -919,10 +925,9 @@ static HRESULT shader_record_shader_phase(struct wined3d_shader *shader,
             if (shader->u.hs.phases.control_point)
             {
                 FIXME("Multiple control point phases.\n");
-                HeapFree(GetProcessHeap(), 0, shader->u.hs.phases.control_point);
+                heap_free(shader->u.hs.phases.control_point);
             }
-            if (!(shader->u.hs.phases.control_point = HeapAlloc(GetProcessHeap(),
-                    HEAP_ZERO_MEMORY, sizeof(*shader->u.hs.phases.control_point))))
+            if (!(shader->u.hs.phases.control_point = heap_alloc_zero(sizeof(*shader->u.hs.phases.control_point))))
                 return E_OUTOFMEMORY;
             phase = shader->u.hs.phases.control_point;
             break;
@@ -952,27 +957,19 @@ static HRESULT shader_record_shader_phase(struct wined3d_shader *shader,
 }
 
 static HRESULT shader_calculate_clip_or_cull_distance_mask(
-        const struct wined3d_shader_signature_element *e, DWORD *mask)
+        const struct wined3d_shader_signature_element *e, unsigned int *mask)
 {
-    unsigned int i;
-
-    *mask = 0;
-
-    /* Cull and clip distances are packed in 4 component registers. 0 and 1 are
+    /* Clip and cull distances are packed in 4 component registers. 0 and 1 are
      * the only allowed semantic indices.
      */
     if (e->semantic_idx >= MAX_CLIP_DISTANCES / 4)
     {
+        *mask = 0;
         WARN("Invalid clip/cull distance index %u.\n", e->semantic_idx);
         return WINED3DERR_INVALIDCALL;
     }
 
-    for (i = 0; i < 4; ++i)
-    {
-        if (e->mask & (WINED3DSP_WRITEMASK_0 << i))
-            *mask |= 1u << (4 * e->semantic_idx + i);
-    }
-
+    *mask = (e->mask & WINED3DSP_WRITEMASK_ALL) << (4 * e->semantic_idx);
     return WINED3D_OK;
 }
 
@@ -1013,7 +1010,7 @@ static HRESULT shader_get_registers_used(struct wined3d_shader *shader, const st
 
     shader_set_limits(shader);
 
-    if (!(reg_maps->constf = wined3d_calloc(((min(shader->limits->constant_float, constf_size) + 31) / 32),
+    if (!(reg_maps->constf = heap_calloc(((min(shader->limits->constant_float, constf_size) + 31) / 32),
             sizeof(*reg_maps->constf))))
     {
         ERR("Failed to allocate constant map memory.\n");
@@ -1158,7 +1155,7 @@ static HRESULT shader_get_registers_used(struct wined3d_shader *shader, const st
             {
                 struct wined3d_shader_indexable_temp *reg;
 
-                if (!(reg = HeapAlloc(GetProcessHeap(), 0, sizeof(*reg))))
+                if (!(reg = heap_alloc(sizeof(*reg))))
                     return E_OUTOFMEMORY;
 
                 *reg = ins.declaration.indexable_temp;
@@ -1338,9 +1335,11 @@ static HRESULT shader_get_registers_used(struct wined3d_shader *shader, const st
         }
         else if (ins.handler_idx == WINED3DSIH_DEF)
         {
-            struct wined3d_shader_lconst *lconst = HeapAlloc(GetProcessHeap(), 0, sizeof(*lconst));
+            struct wined3d_shader_lconst *lconst;
             float *value;
-            if (!lconst) return E_OUTOFMEMORY;
+
+            if (!(lconst = heap_alloc(sizeof(*lconst))))
+                return E_OUTOFMEMORY;
 
             lconst->idx = ins.dst[0].reg.idx[0].offset;
             memcpy(lconst->value, ins.src[0].reg.u.immconst_data, 4 * sizeof(DWORD));
@@ -1369,8 +1368,10 @@ static HRESULT shader_get_registers_used(struct wined3d_shader *shader, const st
         }
         else if (ins.handler_idx == WINED3DSIH_DEFI)
         {
-            struct wined3d_shader_lconst *lconst = HeapAlloc(GetProcessHeap(), 0, sizeof(*lconst));
-            if (!lconst) return E_OUTOFMEMORY;
+            struct wined3d_shader_lconst *lconst;
+
+            if (!(lconst = heap_alloc(sizeof(*lconst))))
+                return E_OUTOFMEMORY;
 
             lconst->idx = ins.dst[0].reg.idx[0].offset;
             memcpy(lconst->value, ins.src[0].reg.u.immconst_data, 4 * sizeof(DWORD));
@@ -1380,8 +1381,10 @@ static HRESULT shader_get_registers_used(struct wined3d_shader *shader, const st
         }
         else if (ins.handler_idx == WINED3DSIH_DEFB)
         {
-            struct wined3d_shader_lconst *lconst = HeapAlloc(GetProcessHeap(), 0, sizeof(*lconst));
-            if (!lconst) return E_OUTOFMEMORY;
+            struct wined3d_shader_lconst *lconst;
+
+            if (!(lconst = heap_alloc(sizeof(*lconst))))
+                return E_OUTOFMEMORY;
 
             lconst->idx = ins.dst[0].reg.idx[0].offset;
             memcpy(lconst->value, ins.src[0].reg.u.immconst_data, sizeof(DWORD));
@@ -1670,6 +1673,7 @@ static HRESULT shader_get_registers_used(struct wined3d_shader *shader, const st
                         WINED3D_SAMPLER_DEFAULT, reg_maps->sampler_map.count);
             }
             else if (ins.handler_idx == WINED3DSIH_LD
+                    || ins.handler_idx == WINED3DSIH_LD2DMS
                     || (ins.handler_idx == WINED3DSIH_LD_RAW && ins.src[1].reg.type == WINED3DSPR_RESOURCE)
                     || (ins.handler_idx == WINED3DSIH_RESINFO && ins.src[1].reg.type == WINED3DSPR_RESOURCE))
             {
@@ -1760,7 +1764,7 @@ static HRESULT shader_get_registers_used(struct wined3d_shader *shader, const st
         struct wined3d_shader_signature_element *e;
         unsigned int i;
 
-        if (!(input_signature->elements = wined3d_calloc(count, sizeof(*input_signature->elements))))
+        if (!(input_signature->elements = heap_calloc(count, sizeof(*input_signature->elements))))
             return E_OUTOFMEMORY;
         input_signature->element_count = count;
 
@@ -1779,7 +1783,7 @@ static HRESULT shader_get_registers_used(struct wined3d_shader *shader, const st
         for (i = 0; i < output_signature->element_count; ++i)
         {
             const struct wined3d_shader_signature_element *e = &output_signature->elements[i];
-            DWORD mask;
+            unsigned int mask;
 
             reg_maps->output_registers |= 1u << e->register_idx;
             if (e->sysval_semantic == WINED3D_SV_CLIP_DISTANCE)
@@ -1801,7 +1805,7 @@ static HRESULT shader_get_registers_used(struct wined3d_shader *shader, const st
         unsigned int count = wined3d_popcount(reg_maps->output_registers);
         struct wined3d_shader_signature_element *e;
 
-        if (!(output_signature->elements = wined3d_calloc(count, sizeof(*output_signature->elements))))
+        if (!(output_signature->elements = heap_calloc(count, sizeof(*output_signature->elements))))
             return E_OUTOFMEMORY;
         output_signature->element_count = count;
 
@@ -1821,14 +1825,14 @@ static void shader_cleanup_reg_maps(struct wined3d_shader_reg_maps *reg_maps)
 {
     struct wined3d_shader_indexable_temp *reg, *reg_next;
 
-    HeapFree(GetProcessHeap(), 0, reg_maps->constf);
-    HeapFree(GetProcessHeap(), 0, reg_maps->sampler_map.entries);
+    heap_free(reg_maps->constf);
+    heap_free(reg_maps->sampler_map.entries);
 
     LIST_FOR_EACH_ENTRY_SAFE(reg, reg_next, &reg_maps->indexable_temps, struct wined3d_shader_indexable_temp, entry)
-        HeapFree(GetProcessHeap(), 0, reg);
+        heap_free(reg);
     list_init(&reg_maps->indexable_temps);
 
-    HeapFree(GetProcessHeap(), 0, reg_maps->tgsm);
+    heap_free(reg_maps->tgsm);
 }
 
 unsigned int shader_find_free_input_register(const struct wined3d_shader_reg_maps *reg_maps, unsigned int max)
@@ -3085,22 +3089,22 @@ static void shader_cleanup(struct wined3d_shader *shader)
 {
     if (shader->reg_maps.shader_version.type == WINED3D_SHADER_TYPE_HULL)
     {
-        HeapFree(GetProcessHeap(), 0, shader->u.hs.phases.control_point);
-        HeapFree(GetProcessHeap(), 0, shader->u.hs.phases.fork);
-        HeapFree(GetProcessHeap(), 0, shader->u.hs.phases.join);
+        heap_free(shader->u.hs.phases.control_point);
+        heap_free(shader->u.hs.phases.fork);
+        heap_free(shader->u.hs.phases.join);
     }
     else if (shader->reg_maps.shader_version.type == WINED3D_SHADER_TYPE_GEOMETRY)
     {
-        HeapFree(GetProcessHeap(), 0, shader->u.gs.so_desc.elements);
+        heap_free(shader->u.gs.so_desc.elements);
     }
 
-    HeapFree(GetProcessHeap(), 0, shader->patch_constant_signature.elements);
-    HeapFree(GetProcessHeap(), 0, shader->output_signature.elements);
-    HeapFree(GetProcessHeap(), 0, shader->input_signature.elements);
-    HeapFree(GetProcessHeap(), 0, shader->signature_strings);
+    heap_free(shader->patch_constant_signature.elements);
+    heap_free(shader->output_signature.elements);
+    heap_free(shader->input_signature.elements);
+    heap_free(shader->signature_strings);
     shader->device->shader_backend->shader_destroy(shader);
     shader_cleanup_reg_maps(&shader->reg_maps);
-    HeapFree(GetProcessHeap(), 0, shader->function);
+    heap_free(shader->function);
     shader_delete_constant_list(&shader->constantsF);
     shader_delete_constant_list(&shader->constantsB);
     shader_delete_constant_list(&shader->constantsI);
@@ -3164,13 +3168,13 @@ static HRESULT shader_none_alloc(struct wined3d_device *device, const struct win
     void *vertex_priv, *fragment_priv;
     struct shader_none_priv *priv;
 
-    if (!(priv = HeapAlloc(GetProcessHeap(), 0, sizeof(*priv))))
+    if (!(priv = heap_alloc(sizeof(*priv))))
         return E_OUTOFMEMORY;
 
     if (!(vertex_priv = vertex_pipe->vp_alloc(&none_shader_backend, priv)))
     {
         ERR("Failed to initialize vertex pipe.\n");
-        HeapFree(GetProcessHeap(), 0, priv);
+        heap_free(priv);
         return E_FAIL;
     }
 
@@ -3178,7 +3182,7 @@ static HRESULT shader_none_alloc(struct wined3d_device *device, const struct win
     {
         ERR("Failed to initialize fragment pipe.\n");
         vertex_pipe->vp_free(device);
-        HeapFree(GetProcessHeap(), 0, priv);
+        heap_free(priv);
         return E_FAIL;
     }
 
@@ -3200,7 +3204,7 @@ static void shader_none_free(struct wined3d_device *device)
 
     priv->fragment_pipe->free_private(device);
     priv->vertex_pipe->vp_free(device);
-    HeapFree(GetProcessHeap(), 0, priv);
+    heap_free(priv);
 }
 
 static BOOL shader_none_allocate_context_data(struct wined3d_context *context)
@@ -3354,7 +3358,7 @@ static void wined3d_shader_init_object(void *object)
 static void wined3d_shader_destroy_object(void *object)
 {
     shader_cleanup(object);
-    HeapFree(GetProcessHeap(), 0, object);
+    heap_free(object);
 }
 
 ULONG CDECL wined3d_shader_decref(struct wined3d_shader *shader)
@@ -3421,9 +3425,10 @@ HRESULT CDECL wined3d_shader_set_local_constants_float(struct wined3d_shader *sh
 
     for (i = start_idx; i < end_idx; ++i)
     {
-        struct wined3d_shader_lconst *lconst = HeapAlloc(GetProcessHeap(), 0, sizeof(*lconst));
+        struct wined3d_shader_lconst *lconst;
         float *value;
-        if (!lconst)
+
+        if (!(lconst = heap_alloc(sizeof(*lconst))))
             return E_OUTOFMEMORY;
 
         lconst->idx = i;
@@ -3555,7 +3560,7 @@ static HRESULT shader_signature_copy(struct wined3d_shader_signature *dst,
     ptr = *signature_strings;
 
     dst->element_count = src->element_count;
-    if (!(dst->elements = wined3d_calloc(dst->element_count, sizeof(*dst->elements))))
+    if (!(dst->elements = heap_calloc(dst->element_count, sizeof(*dst->elements))))
         return E_OUTOFMEMORY;
 
     for (i = 0; i < src->element_count; ++i)
@@ -3607,26 +3612,26 @@ static HRESULT shader_init(struct wined3d_shader *shader, struct wined3d_device
         return hr;
     if (FAILED(hr = shader_signature_calculate_strings_length(&desc->patch_constant_signature, &total)))
         return hr;
-    if (total && !(shader->signature_strings = HeapAlloc(GetProcessHeap(), 0, total)))
+    if (total && !(shader->signature_strings = heap_alloc(total)))
         return E_OUTOFMEMORY;
     ptr = shader->signature_strings;
 
     if (FAILED(hr = shader_signature_copy(&shader->input_signature, &desc->input_signature, &ptr)))
     {
-        HeapFree(GetProcessHeap(), 0, shader->signature_strings);
+        heap_free(shader->signature_strings);
         return hr;
     }
     if (FAILED(hr = shader_signature_copy(&shader->output_signature, &desc->output_signature, &ptr)))
     {
-        HeapFree(GetProcessHeap(), 0, shader->input_signature.elements);
-        HeapFree(GetProcessHeap(), 0, shader->signature_strings);
+        heap_free(shader->input_signature.elements);
+        heap_free(shader->signature_strings);
         return hr;
     }
     if (FAILED(hr = shader_signature_copy(&shader->patch_constant_signature, &desc->patch_constant_signature, &ptr)))
     {
-        HeapFree(GetProcessHeap(), 0, shader->output_signature.elements);
-        HeapFree(GetProcessHeap(), 0, shader->input_signature.elements);
-        HeapFree(GetProcessHeap(), 0, shader->signature_strings);
+        heap_free(shader->output_signature.elements);
+        heap_free(shader->input_signature.elements);
+        heap_free(shader->signature_strings);
         return hr;
     }
 
@@ -3663,7 +3668,7 @@ static HRESULT shader_init(struct wined3d_shader *shader, struct wined3d_device
         byte_code_size = (ptr - desc->byte_code) * sizeof(*ptr);
     }
 
-    if (!(shader->function = HeapAlloc(GetProcessHeap(), 0, byte_code_size)))
+    if (!(shader->function = heap_alloc(byte_code_size)))
     {
         shader_cleanup(shader);
         return E_OUTOFMEMORY;
@@ -3721,12 +3726,12 @@ static HRESULT geometry_shader_init(struct wined3d_shader *shader, struct wined3
     struct wined3d_stream_output_element *elements = NULL;
     HRESULT hr;
 
-    if (so_desc && !(elements = wined3d_calloc(so_desc->element_count, sizeof(*elements))))
+    if (so_desc && !(elements = heap_calloc(so_desc->element_count, sizeof(*elements))))
         return E_OUTOFMEMORY;
 
     if (FAILED(hr = shader_init(shader, device, desc, 0, WINED3D_SHADER_TYPE_GEOMETRY, parent, parent_ops)))
     {
-        HeapFree(GetProcessHeap(), 0, elements);
+        heap_free(elements);
         return hr;
     }
 
@@ -4006,6 +4011,8 @@ void find_ps_compile_args(const struct wined3d_state *state, const struct wined3
 
     args->render_offscreen = shader->reg_maps.vpos && gl_info->supported[ARB_FRAGMENT_COORD_CONVENTIONS]
             ? context->render_offscreen : 0;
+
+    args->dual_source_blend = wined3d_dualblend_enabled(state, gl_info);
 }
 
 static HRESULT pixel_shader_init(struct wined3d_shader *shader, struct wined3d_device *device,
@@ -4103,13 +4110,13 @@ HRESULT CDECL wined3d_shader_create_cs(struct wined3d_device *device, const stru
     TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
             device, desc, parent, parent_ops, shader);
 
-    if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
+    if (!(object = heap_alloc_zero(sizeof(*object))))
         return E_OUTOFMEMORY;
 
     if (FAILED(hr = shader_init(object, device, desc, 0, WINED3D_SHADER_TYPE_COMPUTE, parent, parent_ops)))
     {
         WARN("Failed to initialize compute shader, hr %#x.\n", hr);
-        HeapFree(GetProcessHeap(), 0, object);
+        heap_free(object);
         return hr;
     }
 
@@ -4128,13 +4135,13 @@ HRESULT CDECL wined3d_shader_create_ds(struct wined3d_device *device, const stru
     TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
             device, desc, parent, parent_ops, shader);
 
-    if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
+    if (!(object = heap_alloc_zero(sizeof(*object))))
         return E_OUTOFMEMORY;
 
     if (FAILED(hr = shader_init(object, device, desc, 0, WINED3D_SHADER_TYPE_DOMAIN, parent, parent_ops)))
     {
         WARN("Failed to initialize domain shader, hr %#x.\n", hr);
-        HeapFree(GetProcessHeap(), 0, object);
+        heap_free(object);
         return hr;
     }
 
@@ -4154,13 +4161,13 @@ HRESULT CDECL wined3d_shader_create_gs(struct wined3d_device *device, const stru
     TRACE("device %p, desc %p, so_desc %p, parent %p, parent_ops %p, shader %p.\n",
             device, desc, so_desc, parent, parent_ops, shader);
 
-    if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
+    if (!(object = heap_alloc_zero(sizeof(*object))))
         return E_OUTOFMEMORY;
 
     if (FAILED(hr = geometry_shader_init(object, device, desc, so_desc, parent, parent_ops)))
     {
         WARN("Failed to initialize geometry shader, hr %#x.\n", hr);
-        HeapFree(GetProcessHeap(), 0, object);
+        heap_free(object);
         return hr;
     }
 
@@ -4179,13 +4186,13 @@ HRESULT CDECL wined3d_shader_create_hs(struct wined3d_device *device, const stru
     TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
             device, desc, parent, parent_ops, shader);
 
-    if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
+    if (!(object = heap_alloc_zero(sizeof(*object))))
         return E_OUTOFMEMORY;
 
     if (FAILED(hr = shader_init(object, device, desc, 0, WINED3D_SHADER_TYPE_HULL, parent, parent_ops)))
     {
         WARN("Failed to initialize hull shader, hr %#x.\n", hr);
-        HeapFree(GetProcessHeap(), 0, object);
+        heap_free(object);
         return hr;
     }
 
@@ -4204,14 +4211,13 @@ HRESULT CDECL wined3d_shader_create_ps(struct wined3d_device *device, const stru
     TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
             device, desc, parent, parent_ops, shader);
 
-    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
-    if (!object)
+    if (!(object = heap_alloc_zero(sizeof(*object))))
         return E_OUTOFMEMORY;
 
     if (FAILED(hr = pixel_shader_init(object, device, desc, parent, parent_ops)))
     {
         WARN("Failed to initialize pixel shader, hr %#x.\n", hr);
-        HeapFree(GetProcessHeap(), 0, object);
+        heap_free(object);
         return hr;
     }
 
@@ -4230,14 +4236,13 @@ HRESULT CDECL wined3d_shader_create_vs(struct wined3d_device *device, const stru
     TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
             device, desc, parent, parent_ops, shader);
 
-    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
-    if (!object)
+    if (!(object = heap_alloc_zero(sizeof(*object))))
         return E_OUTOFMEMORY;
 
     if (FAILED(hr = vertex_shader_init(object, device, desc, parent, parent_ops)))
     {
         WARN("Failed to initialize vertex shader, hr %#x.\n", hr);
-        HeapFree(GetProcessHeap(), 0, object);
+        heap_free(object);
         return hr;
     }