windowscodecs: Add locking to the PNG encoder.
[wine] / dlls / d3dx9_36 / asmparser.c
1 /*
2  * Direct3D asm shader parser
3  *
4  * Copyright 2008 Stefan Dösinger
5  * Copyright 2009 Matteo Bruni
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  *
21  */
22
23 #include "config.h"
24 #include "wine/port.h"
25 #include "wine/debug.h"
26
27 #include "d3dx9_36_private.h"
28
29 WINE_DEFAULT_DEBUG_CHANNEL(asmshader);
30 WINE_DECLARE_DEBUG_CHANNEL(parsed_shader);
31
32
33 /****************************************************************
34  * Common(non-version specific) shader parser control code      *
35  ****************************************************************/
36
37 static void asmparser_end(struct asm_parser *This) {
38     TRACE("Finalizing shader\n");
39 }
40
41 static void asmparser_instr(struct asm_parser *This, DWORD opcode,
42                             DWORD mod, DWORD shift,
43                             BWRITER_COMPARISON_TYPE comp,
44                             const struct shader_reg *dst,
45                             const struct src_regs *srcs, int expectednsrcs) {
46     struct instruction *instr;
47     unsigned int i;
48     BOOL firstreg = TRUE;
49     unsigned int src_count = srcs ? srcs->count : 0;
50
51     if(!This->shader) return;
52
53     TRACE_(parsed_shader)("%s ", debug_print_opcode(opcode));
54     if(dst) {
55         TRACE_(parsed_shader)("%s", debug_print_dstreg(dst, This->shader->type));
56         firstreg = FALSE;
57     }
58     for(i = 0; i < src_count; i++) {
59         if(!firstreg) TRACE_(parsed_shader)(", ");
60         else firstreg = FALSE;
61         TRACE_(parsed_shader)("%s", debug_print_srcreg(&srcs->reg[i],
62                                                        This->shader->type));
63     }
64     TRACE_(parsed_shader)("\n");
65
66     if(src_count != expectednsrcs) {
67         asmparser_message(This, "Line %u: Wrong number of source registers\n", This->line_no);
68         set_parse_status(This, PARSE_ERR);
69         return;
70     }
71
72     instr = alloc_instr(src_count);
73     if(!instr) {
74         ERR("Error allocating memory for the instruction\n");
75         set_parse_status(This, PARSE_ERR);
76         return;
77     }
78
79     instr->opcode = opcode;
80     instr->dstmod = mod;
81     instr->shift = shift;
82     instr->comptype = comp;
83     if(dst) This->funcs->dstreg(This, instr, dst);
84     for(i = 0; i < src_count; i++) {
85         This->funcs->srcreg(This, instr, i, &srcs->reg[i]);
86     }
87
88     if(!add_instruction(This->shader, instr)) {
89         ERR("Out of memory\n");
90         set_parse_status(This, PARSE_ERR);
91     }
92 }
93
94 static void asmparser_srcreg_vs_3(struct asm_parser *This,
95                                   struct instruction *instr, int num,
96                                   const struct shader_reg *src) {
97     memcpy(&instr->src[num], src, sizeof(*src));
98 }
99
100 static void asmparser_dstreg_vs_3(struct asm_parser *This,
101                                   struct instruction *instr,
102                                   const struct shader_reg *dst) {
103     memcpy(&instr->dst, dst, sizeof(*dst));
104     instr->has_dst = TRUE;
105 }
106
107 static void asmparser_predicate_unsupported(struct asm_parser *This,
108                                             const struct shader_reg *predicate) {
109     asmparser_message(This, "Line %u: Predicate not supported in < VS 2.0 or PS 2.x\n", This->line_no);
110     set_parse_status(This, PARSE_ERR);
111 }
112
113 static void asmparser_coissue_unsupported(struct asm_parser *This) {
114     asmparser_message(This, "Line %u: Coissue is only supported in pixel shaders versions <= 1.4\n", This->line_no);
115     set_parse_status(This, PARSE_ERR);
116 }
117
118 static const struct asmparser_backend parser_vs_3 = {
119     asmparser_dstreg_vs_3,
120     asmparser_srcreg_vs_3,
121
122     asmparser_predicate_unsupported,
123     asmparser_coissue_unsupported,
124
125     asmparser_end,
126
127     asmparser_instr,
128 };
129
130 void create_vs30_parser(struct asm_parser *ret) {
131     TRACE_(parsed_shader)("vs_3_0\n");
132
133     ret->shader = asm_alloc(sizeof(*ret->shader));
134     if(!ret->shader) {
135         ERR("Failed to allocate memory for the shader\n");
136         set_parse_status(ret, PARSE_ERR);
137         return;
138     }
139
140     ret->shader->type = ST_VERTEX;
141     ret->shader->version = BWRITERVS_VERSION(3, 0);
142     ret->funcs = &parser_vs_3;
143 }