~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/dlls/d3d10core/shader.c

Version: ~ [ wine-1.1.33 ] ~ [ wine-1.1.32 ] ~ [ wine-1.1.31 ] ~ [ wine-1.1.30 ] ~ [ wine-1.1.29 ] ~ [ wine-1.1.28 ] ~ [ wine-1.1.27 ] ~ [ wine-1.1.26 ] ~ [ wine-1.1.25 ] ~ [ wine-1.1.24 ] ~ [ wine-1.1.23 ] ~ [ wine-1.1.22 ] ~ [ wine-1.1.21 ] ~ [ wine-1.1.20 ] ~ [ wine-1.1.19 ] ~ [ wine-1.1.18 ] ~ [ wine-1.1.17 ] ~ [ wine-1.1.16 ] ~ [ wine-1.1.15 ] ~ [ wine-1.1.14 ] ~ [ wine-1.1.13 ] ~ [ wine-1.1.12 ] ~ [ wine-1.1.11 ] ~ [ wine-1.1.10 ] ~ [ wine-1.1.9 ] ~ [ wine-1.1.8 ] ~ [ wine-1.1.7 ] ~ [ wine-1.0.1 ] ~ [ wine-1.1.6 ] ~ [ wine-1.1.5 ] ~ [ wine-1.1.4 ] ~ [ wine-1.1.3 ] ~ [ wine-1.1.2 ] ~ [ wine-1.1.1 ] ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~

  1 /*
  2  * Copyright 2009 Henri Verbeet for CodeWeavers
  3  *
  4  * This library is free software; you can redistribute it and/or
  5  * modify it under the terms of the GNU Lesser General Public
  6  * License as published by the Free Software Foundation; either
  7  * version 2.1 of the License, or (at your option) any later version.
  8  *
  9  * This library is distributed in the hope that it will be useful,
 10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 12  * Lesser General Public License for more details.
 13  *
 14  * You should have received a copy of the GNU Lesser General Public
 15  * License along with this library; if not, write to the Free Software
 16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 17  *
 18  */
 19 
 20 #include "config.h"
 21 #include "wine/port.h"
 22 
 23 #include "d3d10core_private.h"
 24 
 25 WINE_DEFAULT_DEBUG_CHANNEL(d3d10core);
 26 
 27 static HRESULT shdr_handler(const char *data, DWORD data_size, DWORD tag, void *ctx)
 28 {
 29     struct d3d10_shader_info *shader_info = ctx;
 30     HRESULT hr;
 31 
 32     switch(tag)
 33     {
 34         case TAG_OSGN:
 35             hr = shader_parse_signature(data, data_size, shader_info->output_signature);
 36             if (FAILED(hr)) return hr;
 37             break;
 38 
 39         case TAG_SHDR:
 40             shader_info->shader_code = (const DWORD *)data;
 41             break;
 42 
 43         default:
 44             FIXME("Unhandled chunk %s\n", debugstr_an((const char *)&tag, 4));
 45             break;
 46     }
 47 
 48     return S_OK;
 49 }
 50 
 51 static HRESULT shader_extract_from_dxbc(const void *dxbc, SIZE_T dxbc_length, struct d3d10_shader_info *shader_info)
 52 {
 53     HRESULT hr;
 54 
 55     shader_info->shader_code = NULL;
 56     memset(shader_info->output_signature, 0, sizeof(*shader_info->output_signature));
 57 
 58     hr = parse_dxbc(dxbc, dxbc_length, shdr_handler, shader_info);
 59     if (!shader_info->shader_code) hr = E_FAIL;
 60 
 61     if (FAILED(hr))
 62     {
 63         ERR("Failed to parse shader, hr %#x\n", hr);
 64         shader_free_signature(shader_info->output_signature);
 65     }
 66 
 67     return hr;
 68 }
 69 
 70 HRESULT shader_parse_signature(const char *data, DWORD data_size, struct wined3d_shader_signature *s)
 71 {
 72     struct wined3d_shader_signature_element *e;
 73     unsigned int string_data_offset;
 74     unsigned int string_data_size;
 75     const char *ptr = data;
 76     char *string_data;
 77     unsigned int i;
 78     DWORD count;
 79 
 80     read_dword(&ptr, &count);
 81     TRACE("%u elements\n", count);
 82 
 83     skip_dword_unknown(&ptr, 1);
 84 
 85     e = HeapAlloc(GetProcessHeap(), 0, count * sizeof(*e));
 86     if (!e)
 87     {
 88         ERR("Failed to allocate input signature memory.\n");
 89         return E_OUTOFMEMORY;
 90     }
 91 
 92     /* 2 DWORDs for the header, 6 for each element. */
 93     string_data_offset = 2 * sizeof(DWORD) + count * 6 * sizeof(DWORD);
 94     string_data_size = data_size - string_data_offset;
 95     string_data = HeapAlloc(GetProcessHeap(), 0, string_data_size);
 96     if (!string_data)
 97     {
 98         ERR("Failed to allocate string data memory.\n");
 99         HeapFree(GetProcessHeap(), 0, e);
100         return E_OUTOFMEMORY;
101     }
102     memcpy(string_data, data + string_data_offset, string_data_size);
103 
104     for (i = 0; i < count; ++i)
105     {
106         UINT name_offset;
107 
108         read_dword(&ptr, &name_offset);
109         e[i].semantic_name = string_data + (name_offset - string_data_offset);
110         read_dword(&ptr, &e[i].semantic_idx);
111         read_dword(&ptr, &e[i].sysval_semantic);
112         read_dword(&ptr, &e[i].component_type);
113         read_dword(&ptr, &e[i].register_idx);
114         read_dword(&ptr, &e[i].mask);
115 
116         TRACE("semantic: %s, semantic idx: %u, sysval_semantic %#x, "
117                 "type %u, register idx: %u, use_mask %#x, input_mask %#x\n",
118                 debugstr_a(e[i].semantic_name), e[i].semantic_idx, e[i].sysval_semantic,
119                 e[i].component_type, e[i].register_idx, (e[i].mask >> 8) & 0xff, e[i].mask & 0xff);
120     }
121 
122     s->elements = e;
123     s->element_count = count;
124     s->string_data = string_data;
125 
126     return S_OK;
127 }
128 
129 void shader_free_signature(struct wined3d_shader_signature *s)
130 {
131     HeapFree(GetProcessHeap(), 0, s->string_data);
132     HeapFree(GetProcessHeap(), 0, s->elements);
133 }
134 
135 /* IUnknown methods */
136 
137 static HRESULT STDMETHODCALLTYPE d3d10_vertex_shader_QueryInterface(ID3D10VertexShader *iface,
138         REFIID riid, void **object)
139 {
140     TRACE("iface %p, riid %s, object %p\n", iface, debugstr_guid(riid), object);
141 
142     if (IsEqualGUID(riid, &IID_ID3D10VertexShader)
143             || IsEqualGUID(riid, &IID_ID3D10DeviceChild)
144             || IsEqualGUID(riid, &IID_IUnknown))
145     {
146         IUnknown_AddRef(iface);
147         *object = iface;
148         return S_OK;
149     }
150 
151     WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
152 
153     *object = NULL;
154     return E_NOINTERFACE;
155 }
156 
157 static ULONG STDMETHODCALLTYPE d3d10_vertex_shader_AddRef(ID3D10VertexShader *iface)
158 {
159     struct d3d10_vertex_shader *This = (struct d3d10_vertex_shader *)iface;
160     ULONG refcount = InterlockedIncrement(&This->refcount);
161 
162     TRACE("%p increasing refcount to %u\n", This, refcount);
163 
164     if (refcount == 1)
165     {
166         IWineD3DVertexShader_AddRef(This->wined3d_shader);
167     }
168 
169     return refcount;
170 }
171 
172 static ULONG STDMETHODCALLTYPE d3d10_vertex_shader_Release(ID3D10VertexShader *iface)
173 {
174     struct d3d10_vertex_shader *This = (struct d3d10_vertex_shader *)iface;
175     ULONG refcount = InterlockedDecrement(&This->refcount);
176 
177     TRACE("%p decreasing refcount to %u\n", This, refcount);
178 
179     if (!refcount)
180     {
181         IWineD3DVertexShader_Release(This->wined3d_shader);
182     }
183 
184     return refcount;
185 }
186 
187 /* ID3D10DeviceChild methods */
188 
189 static void STDMETHODCALLTYPE d3d10_vertex_shader_GetDevice(ID3D10VertexShader *iface, ID3D10Device **device)
190 {
191     FIXME("iface %p, device %p stub!\n", iface, device);
192 }
193 
194 static HRESULT STDMETHODCALLTYPE d3d10_vertex_shader_GetPrivateData(ID3D10VertexShader *iface,
195         REFGUID guid, UINT *data_size, void *data)
196 {
197     FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
198             iface, debugstr_guid(guid), data_size, data);
199 
200     return E_NOTIMPL;
201 }
202 
203 static HRESULT STDMETHODCALLTYPE d3d10_vertex_shader_SetPrivateData(ID3D10VertexShader *iface,
204         REFGUID guid, UINT data_size, const void *data)
205 {
206     FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
207             iface, debugstr_guid(guid), data_size, data);
208 
209     return E_NOTIMPL;
210 }
211 
212 static HRESULT STDMETHODCALLTYPE d3d10_vertex_shader_SetPrivateDataInterface(ID3D10VertexShader *iface,
213         REFGUID guid, const IUnknown *data)
214 {
215     FIXME("iface %p, guid %s, data %p stub!\n", iface, debugstr_guid(guid), data);
216 
217     return E_NOTIMPL;
218 }
219 
220 static const struct ID3D10VertexShaderVtbl d3d10_vertex_shader_vtbl =
221 {
222     /* IUnknown methods */
223     d3d10_vertex_shader_QueryInterface,
224     d3d10_vertex_shader_AddRef,
225     d3d10_vertex_shader_Release,
226     /* ID3D10DeviceChild methods */
227     d3d10_vertex_shader_GetDevice,
228     d3d10_vertex_shader_GetPrivateData,
229     d3d10_vertex_shader_SetPrivateData,
230     d3d10_vertex_shader_SetPrivateDataInterface,
231 };
232 
233 static void STDMETHODCALLTYPE d3d10_vertex_shader_wined3d_object_destroyed(void *parent)
234 {
235     struct d3d10_vertex_shader *shader = parent;
236     shader_free_signature(&shader->output_signature);
237     HeapFree(GetProcessHeap(), 0, shader);
238 }
239 
240 static const struct wined3d_parent_ops d3d10_vertex_shader_wined3d_parent_ops =
241 {
242     d3d10_vertex_shader_wined3d_object_destroyed,
243 };
244 
245 HRESULT d3d10_vertex_shader_init(struct d3d10_vertex_shader *shader, struct d3d10_device *device,
246         const void *byte_code, SIZE_T byte_code_length)
247 {
248     struct d3d10_shader_info shader_info;
249     HRESULT hr;
250 
251     shader->vtbl = &d3d10_vertex_shader_vtbl;
252     shader->refcount = 1;
253 
254     shader_info.output_signature = &shader->output_signature;
255     hr = shader_extract_from_dxbc(byte_code, byte_code_length, &shader_info);
256     if (FAILED(hr))
257     {
258         ERR("Failed to extract shader, hr %#x.\n", hr);
259         return hr;
260     }
261 
262     hr = IWineD3DDevice_CreateVertexShader(device->wined3d_device,
263             shader_info.shader_code, &shader->output_signature, &shader->wined3d_shader,
264             (IUnknown *)shader, &d3d10_vertex_shader_wined3d_parent_ops);
265     if (FAILED(hr))
266     {
267         WARN("Failed to create wined3d vertex shader, hr %#x.\n", hr);
268         shader_free_signature(&shader->output_signature);
269         return hr;
270     }
271 
272     return S_OK;
273 }
274 
275 /* IUnknown methods */
276 
277 static HRESULT STDMETHODCALLTYPE d3d10_geometry_shader_QueryInterface(ID3D10GeometryShader *iface,
278         REFIID riid, void **object)
279 {
280     TRACE("iface %p, riid %s, object %p\n", iface, debugstr_guid(riid), object);
281 
282     if (IsEqualGUID(riid, &IID_ID3D10GeometryShader)
283             || IsEqualGUID(riid, &IID_ID3D10DeviceChild)
284             || IsEqualGUID(riid, &IID_IUnknown))
285     {
286         IUnknown_AddRef(iface);
287         *object = iface;
288         return S_OK;
289     }
290 
291     WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
292 
293     *object = NULL;
294     return E_NOINTERFACE;
295 }
296 
297 static ULONG STDMETHODCALLTYPE d3d10_geometry_shader_AddRef(ID3D10GeometryShader *iface)
298 {
299     struct d3d10_geometry_shader *This = (struct d3d10_geometry_shader *)iface;
300     ULONG refcount = InterlockedIncrement(&This->refcount);
301 
302     TRACE("%p increasing refcount to %u\n", This, refcount);
303 
304     return refcount;
305 }
306 
307 static ULONG STDMETHODCALLTYPE d3d10_geometry_shader_Release(ID3D10GeometryShader *iface)
308 {
309     struct d3d10_geometry_shader *This = (struct d3d10_geometry_shader *)iface;
310     ULONG refcount = InterlockedDecrement(&This->refcount);
311 
312     TRACE("%p decreasing refcount to %u\n", This, refcount);
313 
314     if (!refcount)
315     {
316         HeapFree(GetProcessHeap(), 0, This);
317     }
318 
319     return refcount;
320 }
321 
322 /* ID3D10DeviceChild methods */
323 
324 static void STDMETHODCALLTYPE d3d10_geometry_shader_GetDevice(ID3D10GeometryShader *iface, ID3D10Device **device)
325 {
326     FIXME("iface %p, device %p stub!\n", iface, device);
327 }
328 
329 static HRESULT STDMETHODCALLTYPE d3d10_geometry_shader_GetPrivateData(ID3D10GeometryShader *iface,
330         REFGUID guid, UINT *data_size, void *data)
331 {
332     FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
333             iface, debugstr_guid(guid), data_size, data);
334 
335     return E_NOTIMPL;
336 }
337 
338 static HRESULT STDMETHODCALLTYPE d3d10_geometry_shader_SetPrivateData(ID3D10GeometryShader *iface,
339         REFGUID guid, UINT data_size, const void *data)
340 {
341     FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
342             iface, debugstr_guid(guid), data_size, data);
343 
344     return E_NOTIMPL;
345 }
346 
347 static HRESULT STDMETHODCALLTYPE d3d10_geometry_shader_SetPrivateDataInterface(ID3D10GeometryShader *iface,
348         REFGUID guid, const IUnknown *data)
349 {
350     FIXME("iface %p, guid %s, data %p stub!\n", iface, debugstr_guid(guid), data);
351 
352     return E_NOTIMPL;
353 }
354 
355 static const struct ID3D10GeometryShaderVtbl d3d10_geometry_shader_vtbl =
356 {
357     /* IUnknown methods */
358     d3d10_geometry_shader_QueryInterface,
359     d3d10_geometry_shader_AddRef,
360     d3d10_geometry_shader_Release,
361     /* ID3D10DeviceChild methods */
362     d3d10_geometry_shader_GetDevice,
363     d3d10_geometry_shader_GetPrivateData,
364     d3d10_geometry_shader_SetPrivateData,
365     d3d10_geometry_shader_SetPrivateDataInterface,
366 };
367 
368 HRESULT d3d10_geometry_shader_init(struct d3d10_geometry_shader *shader)
369 {
370     shader->vtbl = &d3d10_geometry_shader_vtbl;
371     shader->refcount = 1;
372 
373     return S_OK;
374 }
375 
376 /* IUnknown methods */
377 
378 static HRESULT STDMETHODCALLTYPE d3d10_pixel_shader_QueryInterface(ID3D10PixelShader *iface,
379         REFIID riid, void **object)
380 {
381     TRACE("iface %p, riid %s, object %p\n", iface, debugstr_guid(riid), object);
382 
383     if (IsEqualGUID(riid, &IID_ID3D10PixelShader)
384             || IsEqualGUID(riid, &IID_ID3D10DeviceChild)
385             || IsEqualGUID(riid, &IID_IUnknown))
386     {
387         IUnknown_AddRef(iface);
388         *object = iface;
389         return S_OK;
390     }
391 
392     WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
393 
394     *object = NULL;
395     return E_NOINTERFACE;
396 }
397 
398 static ULONG STDMETHODCALLTYPE d3d10_pixel_shader_AddRef(ID3D10PixelShader *iface)
399 {
400     struct d3d10_pixel_shader *This = (struct d3d10_pixel_shader *)iface;
401     ULONG refcount = InterlockedIncrement(&This->refcount);
402 
403     TRACE("%p increasing refcount to %u\n", This, refcount);
404 
405     if (refcount == 1)
406     {
407         IWineD3DPixelShader_AddRef(This->wined3d_shader);
408     }
409 
410     return refcount;
411 }
412 
413 static ULONG STDMETHODCALLTYPE d3d10_pixel_shader_Release(ID3D10PixelShader *iface)
414 {
415     struct d3d10_pixel_shader *This = (struct d3d10_pixel_shader *)iface;
416     ULONG refcount = InterlockedDecrement(&This->refcount);
417 
418     TRACE("%p decreasing refcount to %u\n", This, refcount);
419 
420     if (!refcount)
421     {
422         IWineD3DPixelShader_Release(This->wined3d_shader);
423     }
424 
425     return refcount;
426 }
427 
428 /* ID3D10DeviceChild methods */
429 
430 static void STDMETHODCALLTYPE d3d10_pixel_shader_GetDevice(ID3D10PixelShader *iface, ID3D10Device **device)
431 {
432     FIXME("iface %p, device %p stub!\n", iface, device);
433 }
434 
435 static HRESULT STDMETHODCALLTYPE d3d10_pixel_shader_GetPrivateData(ID3D10PixelShader *iface,
436         REFGUID guid, UINT *data_size, void *data)
437 {
438     FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
439             iface, debugstr_guid(guid), data_size, data);
440 
441     return E_NOTIMPL;
442 }
443 
444 static HRESULT STDMETHODCALLTYPE d3d10_pixel_shader_SetPrivateData(ID3D10PixelShader *iface,
445         REFGUID guid, UINT data_size, const void *data)
446 {
447     FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
448             iface, debugstr_guid(guid), data_size, data);
449 
450     return E_NOTIMPL;
451 }
452 
453 static HRESULT STDMETHODCALLTYPE d3d10_pixel_shader_SetPrivateDataInterface(ID3D10PixelShader *iface,
454         REFGUID guid, const IUnknown *data)
455 {
456     FIXME("iface %p, guid %s, data %p stub!\n", iface, debugstr_guid(guid), data);
457 
458     return E_NOTIMPL;
459 }
460 
461 static const struct ID3D10PixelShaderVtbl d3d10_pixel_shader_vtbl =
462 {
463     /* IUnknown methods */
464     d3d10_pixel_shader_QueryInterface,
465     d3d10_pixel_shader_AddRef,
466     d3d10_pixel_shader_Release,
467     /* ID3D10DeviceChild methods */
468     d3d10_pixel_shader_GetDevice,
469     d3d10_pixel_shader_GetPrivateData,
470     d3d10_pixel_shader_SetPrivateData,
471     d3d10_pixel_shader_SetPrivateDataInterface,
472 };
473 
474 static void STDMETHODCALLTYPE d3d10_pixel_shader_wined3d_object_destroyed(void *parent)
475 {
476     struct d3d10_pixel_shader *shader = parent;
477     shader_free_signature(&shader->output_signature);
478     HeapFree(GetProcessHeap(), 0, shader);
479 }
480 
481 static const struct wined3d_parent_ops d3d10_pixel_shader_wined3d_parent_ops =
482 {
483     d3d10_pixel_shader_wined3d_object_destroyed,
484 };
485 
486 HRESULT d3d10_pixel_shader_init(struct d3d10_pixel_shader *shader, struct d3d10_device *device,
487         const void *byte_code, SIZE_T byte_code_length)
488 {
489     struct d3d10_shader_info shader_info;
490     HRESULT hr;
491 
492     shader->vtbl = &d3d10_pixel_shader_vtbl;
493     shader->refcount = 1;
494 
495     shader_info.output_signature = &shader->output_signature;
496     hr = shader_extract_from_dxbc(byte_code, byte_code_length, &shader_info);
497     if (FAILED(hr))
498     {
499         ERR("Failed to extract shader, hr %#x.\n", hr);
500         return hr;
501     }
502 
503     hr = IWineD3DDevice_CreatePixelShader(device->wined3d_device,
504             shader_info.shader_code, &shader->output_signature, &shader->wined3d_shader,
505             (IUnknown *)shader, &d3d10_pixel_shader_wined3d_parent_ops);
506     if (FAILED(hr))
507     {
508         WARN("Failed to create wined3d pixel shader, hr %#x.\n", hr);
509         shader_free_signature(&shader->output_signature);
510         return hr;
511     }
512 
513     return S_OK;
514 }
515 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.