winhttp: Convert connect_t's address type from a struct sockaddr_in to a struct socka...
[wine] / dlls / d3dx9_36 / shader.c
1 /*
2  * Copyright 2008 Luis Busquets
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 #include "config.h"
20 #include "wine/port.h"
21 #include "wine/debug.h"
22 #include "windef.h"
23 #include "wingdi.h"
24 #include "d3dx9.h"
25
26 WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
27
28 LPCSTR WINAPI D3DXGetPixelShaderProfile(LPDIRECT3DDEVICE9 device)
29 {
30     D3DCAPS9 caps;
31
32     TRACE("device %p\n", device);
33
34     if (!device) return NULL;
35
36     IDirect3DDevice9_GetDeviceCaps(device,&caps);
37
38     switch (caps.PixelShaderVersion)
39     {
40     case D3DPS_VERSION(1, 1):
41         return "ps_1_1";
42
43     case D3DPS_VERSION(1, 2):
44         return "ps_1_2";
45
46     case D3DPS_VERSION(1, 3):
47         return "ps_1_3";
48
49     case D3DPS_VERSION(1, 4):
50         return "ps_1_4";
51
52     case D3DPS_VERSION(2, 0):
53         if ((caps.PS20Caps.NumTemps>=22)                          &&
54             (caps.PS20Caps.Caps&D3DPS20CAPS_ARBITRARYSWIZZLE)     &&
55             (caps.PS20Caps.Caps&D3DPS20CAPS_GRADIENTINSTRUCTIONS) &&
56             (caps.PS20Caps.Caps&D3DPS20CAPS_PREDICATION)          &&
57             (caps.PS20Caps.Caps&D3DPS20CAPS_NODEPENDENTREADLIMIT) &&
58             (caps.PS20Caps.Caps&D3DPS20CAPS_NOTEXINSTRUCTIONLIMIT))
59         {
60             return "ps_2_a";
61         }
62         if ((caps.PS20Caps.NumTemps>=32)                          &&
63             (caps.PS20Caps.Caps&D3DPS20CAPS_NOTEXINSTRUCTIONLIMIT))
64         {
65             return "ps_2_b";
66         }
67         return "ps_2_0";
68
69     case D3DPS_VERSION(3, 0):
70         return "ps_3_0";
71     }
72
73     return NULL;
74 }
75
76 UINT WINAPI D3DXGetShaderSize(const DWORD *byte_code)
77 {
78     const DWORD *ptr = byte_code;
79
80     TRACE("byte_code %p\n", byte_code);
81
82     if (!ptr) return 0;
83
84     /* Look for the END token, skipping the VERSION token */
85     while (*++ptr != D3DSIO_END)
86     {
87         /* Skip comments */
88         if ((*ptr & D3DSI_OPCODE_MASK) == D3DSIO_COMMENT)
89         {
90             ptr += ((*ptr & D3DSI_COMMENTSIZE_MASK) >> D3DSI_COMMENTSIZE_SHIFT);
91         }
92     }
93     ++ptr;
94
95     /* Return the shader size in bytes */
96     return (ptr - byte_code) * sizeof(*ptr);
97 }
98
99 DWORD WINAPI D3DXGetShaderVersion(const DWORD *byte_code)
100 {
101     TRACE("byte_code %p\n", byte_code);
102
103     return byte_code ? *byte_code : 0;
104 }
105
106 LPCSTR WINAPI D3DXGetVertexShaderProfile(LPDIRECT3DDEVICE9 device)
107 {
108     D3DCAPS9 caps;
109
110     TRACE("device %p\n", device);
111
112     if (!device) return NULL;
113
114     IDirect3DDevice9_GetDeviceCaps(device,&caps);
115
116     switch (caps.VertexShaderVersion)
117     {
118     case D3DVS_VERSION(1, 1):
119         return "vs_1_1";
120     case D3DVS_VERSION(2, 0):
121         if ((caps.VS20Caps.NumTemps>=13) &&
122             (caps.VS20Caps.DynamicFlowControlDepth==24) &&
123             (caps.VS20Caps.Caps&D3DPS20CAPS_PREDICATION))
124         {
125             return "vs_2_a";
126         }
127         return "vs_2_0";
128     case D3DVS_VERSION(3, 0):
129         return "vs_3_0";
130     }
131
132     return NULL;
133 }