ReactOS 0.4.17-dev-966-gf06eace
hlsl.c
Go to the documentation of this file.
1/*
2 * HLSL utility functions
3 *
4 * Copyright 2012 Matteo Bruni for CodeWeavers
5 * Copyright 2019-2020 Zebediah Figura for CodeWeavers
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#include "hlsl.h"
23#include <stdio.h>
24
25void hlsl_note(struct hlsl_ctx *ctx, const struct vkd3d_shader_location *loc,
26 enum vkd3d_shader_log_level level, const char *fmt, ...)
27{
29
31 vkd3d_shader_vnote(ctx->message_context, loc, level, fmt, args);
32 va_end(args);
33}
34
35void hlsl_error(struct hlsl_ctx *ctx, const struct vkd3d_shader_location *loc,
36 enum vkd3d_shader_error error, const char *fmt, ...)
37{
39
41 vkd3d_shader_verror(ctx->message_context, loc, error, fmt, args);
42 va_end(args);
43
44 if (!ctx->result)
46}
47
48void hlsl_warning(struct hlsl_ctx *ctx, const struct vkd3d_shader_location *loc,
49 enum vkd3d_shader_error error, const char *fmt, ...)
50{
52
54 vkd3d_shader_vwarning(ctx->message_context, loc, error, fmt, args);
55 va_end(args);
56}
57
58void hlsl_fixme(struct hlsl_ctx *ctx, const struct vkd3d_shader_location *loc, const char *fmt, ...)
59{
62
65 vkd3d_string_buffer_printf(string, "Aborting due to not yet implemented feature: ");
67 vkd3d_shader_error(ctx->message_context, loc, VKD3D_SHADER_ERROR_HLSL_NOT_IMPLEMENTED, "%s", string->buffer);
69 va_end(args);
70
71 if (!ctx->result)
73}
74
75char *hlsl_sprintf_alloc(struct hlsl_ctx *ctx, const char *fmt, ...)
76{
79 char *ret;
80
81 if (!(string = hlsl_get_string_buffer(ctx)))
82 return NULL;
84 if (vkd3d_string_buffer_vprintf(string, fmt, args) < 0)
85 {
86 va_end(args);
88 return NULL;
89 }
90 va_end(args);
91 ret = hlsl_strdup(ctx, string->buffer);
93 return ret;
94}
95
96bool hlsl_add_var(struct hlsl_ctx *ctx, struct hlsl_ir_var *decl, bool local_var)
97{
98 struct hlsl_scope *scope = ctx->cur_scope;
99 struct hlsl_ir_var *var;
100
101 if (decl->name)
102 {
104 {
105 if (var->name && !strcmp(decl->name, var->name))
106 return false;
107 }
108 if (local_var && scope->upper->upper == ctx->globals)
109 {
110 /* Check whether the variable redefines a function parameter. */
111 LIST_FOR_EACH_ENTRY(var, &scope->upper->vars, struct hlsl_ir_var, scope_entry)
112 {
113 if (var->name && !strcmp(decl->name, var->name))
114 return false;
115 }
116 }
117 }
118
119 list_add_tail(&scope->vars, &decl->scope_entry);
120 return true;
121}
122
123struct hlsl_ir_var *hlsl_get_var(struct hlsl_scope *scope, const char *name)
124{
125 struct hlsl_ir_var *var;
126
128 {
129 if (var->name && !strcmp(name, var->name))
130 return var;
131 }
132 if (!scope->upper)
133 return NULL;
134 return hlsl_get_var(scope->upper, name);
135}
136
138{
139 unsigned int i;
140
141 vkd3d_free(entry->name);
142 for (i = 0; i < entry->args_count; ++i)
143 hlsl_src_remove(&entry->args[i]);
144 vkd3d_free(entry->args);
145 hlsl_block_cleanup(entry->instrs);
146 vkd3d_free(entry->instrs);
148}
149
151{
152 unsigned int k;
153
154 VKD3D_ASSERT(state_block);
155 for (k = 0; k < state_block->count; ++k)
157 vkd3d_free(state_block->entries);
158 vkd3d_free(state_block);
159}
160
161void hlsl_free_var(struct hlsl_ir_var *decl)
162{
163 unsigned int k, i;
164
165 vkd3d_free((void *)decl->name);
167 for (k = 0; k <= HLSL_REGSET_LAST_OBJECT; ++k)
168 vkd3d_free((void *)decl->objects_usage[k]);
169
170 if (decl->default_values)
171 {
173
174 for (k = 0; k < component_count; ++k)
175 vkd3d_free((void *)decl->default_values[k].string);
177 }
178
179 for (i = 0; i < decl->state_block_count; ++i)
182
183 vkd3d_free(decl);
184}
185
187{
188 /* Default to column-major if the majority isn't explicitly set, which can
189 * happen for anonymous nodes. */
190 return !!(type->modifiers & HLSL_MODIFIER_ROW_MAJOR);
191}
192
193unsigned int hlsl_type_minor_size(const struct hlsl_type *type)
194{
196 return type->dimx;
197 else
198 return type->dimy;
199}
200
201unsigned int hlsl_type_major_size(const struct hlsl_type *type)
202{
204 return type->dimy;
205 else
206 return type->dimx;
207}
208
209unsigned int hlsl_type_element_count(const struct hlsl_type *type)
210{
211 switch (type->class)
212 {
214 return type->dimx;
217 case HLSL_CLASS_ARRAY:
218 return type->e.array.elements_count;
220 return type->e.record.field_count;
221 default:
222 return 0;
223 }
224}
225
227{
228 if (type->class == HLSL_CLASS_ARRAY)
229 return hlsl_get_multiarray_element_type(type->e.array.type);
230 return type;
231}
232
233unsigned int hlsl_get_multiarray_size(const struct hlsl_type *type)
234{
235 if (type->class == HLSL_CLASS_ARRAY)
236 return hlsl_get_multiarray_size(type->e.array.type) * type->e.array.elements_count;
237 return 1;
238}
239
241{
242 switch (type->class)
243 {
244 case HLSL_CLASS_ARRAY:
245 return hlsl_type_is_resource(type->e.array.type);
246
249 case HLSL_CLASS_UAV:
250 return true;
251
252 default:
253 return false;
254 }
255}
256
258{
259 switch (type->class)
260 {
261 case HLSL_CLASS_ARRAY:
262 return hlsl_type_is_shader(type->e.array.type);
263
270 return true;
271
279 case HLSL_CLASS_ERROR:
280 case HLSL_CLASS_PASS:
287 case HLSL_CLASS_UAV:
290 case HLSL_CLASS_VOID:
291 case HLSL_CLASS_NULL:
292 return false;
293 }
294 return false;
295}
296
297/* Only intended to be used for derefs (after copies have been lowered to components or vectors) or
298 * resources, since for both their data types span across a single regset. */
299static enum hlsl_regset type_get_regset(const struct hlsl_type *type)
300{
301 switch (type->class)
302 {
306 return HLSL_REGSET_NUMERIC;
307
308 case HLSL_CLASS_ARRAY:
309 return type_get_regset(type->e.array.type);
310
313
316
317 case HLSL_CLASS_UAV:
318 return HLSL_REGSET_UAVS;
319
320 default:
321 break;
322 }
323
325}
326
327enum hlsl_regset hlsl_deref_get_regset(struct hlsl_ctx *ctx, const struct hlsl_deref *deref)
328{
330}
331
332unsigned int hlsl_type_get_sm4_offset(const struct hlsl_type *type, unsigned int offset)
333{
334 /* Align to the next vec4 boundary if:
335 * (a) the type is a struct or array type, or
336 * (b) the type would cross a vec4 boundary; i.e. a vec3 and a
337 * vec1 can be packed together, but not a vec3 and a vec2.
338 */
339 if (type->class == HLSL_CLASS_STRUCT || type->class == HLSL_CLASS_ARRAY
340 || (offset & 3) + type->reg_size[HLSL_REGSET_NUMERIC] > 4)
341 return align(offset, 4);
342 return offset;
343}
344
346{
347 bool is_sm4 = (ctx->profile->major_version >= 4);
348 unsigned int k;
349
350 for (k = 0; k <= HLSL_REGSET_LAST; ++k)
351 type->reg_size[k] = 0;
352
353 switch (type->class)
354 {
357 type->reg_size[HLSL_REGSET_NUMERIC] = is_sm4 ? type->dimx : 4;
358 break;
359
362 type->reg_size[HLSL_REGSET_NUMERIC] = is_sm4 ? (4 * (type->dimy - 1) + type->dimx) : (4 * type->dimy);
363 else
364 type->reg_size[HLSL_REGSET_NUMERIC] = is_sm4 ? (4 * (type->dimx - 1) + type->dimy) : (4 * type->dimx);
365 break;
366
367 case HLSL_CLASS_ARRAY:
368 {
369 if (type->e.array.elements_count == HLSL_ARRAY_ELEMENTS_COUNT_IMPLICIT)
370 break;
371
372 for (k = 0; k <= HLSL_REGSET_LAST; ++k)
373 {
374 unsigned int element_size = type->e.array.type->reg_size[k];
375
376 if (is_sm4 && k == HLSL_REGSET_NUMERIC)
377 type->reg_size[k] = (type->e.array.elements_count - 1) * align(element_size, 4) + element_size;
378 else
379 type->reg_size[k] = type->e.array.elements_count * element_size;
380 }
381
382 break;
383 }
384
386 {
387 unsigned int i;
388
389 type->dimx = 0;
390 for (i = 0; i < type->e.record.field_count; ++i)
391 {
392 struct hlsl_struct_field *field = &type->e.record.fields[i];
393
394 for (k = 0; k <= HLSL_REGSET_LAST; ++k)
395 {
396 if (k == HLSL_REGSET_NUMERIC)
397 type->reg_size[k] = hlsl_type_get_sm4_offset(field->type, type->reg_size[k]);
398 field->reg_offset[k] = type->reg_size[k];
399 type->reg_size[k] += field->type->reg_size[k];
400 }
401
402 type->dimx += field->type->dimx * field->type->dimy * hlsl_get_multiarray_size(field->type);
403 }
404 break;
405 }
406
408 type->reg_size[HLSL_REGSET_SAMPLERS] = 1;
409 break;
410
412 type->reg_size[HLSL_REGSET_TEXTURES] = 1;
413 break;
414
415 case HLSL_CLASS_UAV:
416 type->reg_size[HLSL_REGSET_UAVS] = 1;
417 break;
418
422 case HLSL_CLASS_ERROR:
423 case HLSL_CLASS_PASS:
430 case HLSL_CLASS_VOID:
437 case HLSL_CLASS_NULL:
438 break;
439 }
440}
441
442/* Returns the size of a type, considered as part of an array of that type, within a specific
443 * register set. As such it includes padding after the type, when applicable. */
445{
447 return align(type->reg_size[regset], 4);
448 return type->reg_size[regset];
449}
450
451static struct hlsl_type *hlsl_new_simple_type(struct hlsl_ctx *ctx, const char *name, enum hlsl_type_class class)
452{
453 struct hlsl_type *type;
454
455 if (!(type = hlsl_alloc(ctx, sizeof(*type))))
456 return NULL;
457 if (!(type->name = hlsl_strdup(ctx, name)))
458 {
460 return NULL;
461 }
462 type->class = class;
464
465 list_add_tail(&ctx->types, &type->entry);
466
467 return type;
468}
469
470static struct hlsl_type *hlsl_new_type(struct hlsl_ctx *ctx, const char *name, enum hlsl_type_class type_class,
471 enum hlsl_base_type base_type, unsigned dimx, unsigned dimy)
472{
473 struct hlsl_type *type;
474
475 if (!(type = hlsl_alloc(ctx, sizeof(*type))))
476 return NULL;
477 if (!(type->name = hlsl_strdup(ctx, name)))
478 {
480 return NULL;
481 }
482 type->class = type_class;
483 type->e.numeric.type = base_type;
484 type->dimx = dimx;
485 type->dimy = dimy;
487
488 list_add_tail(&ctx->types, &type->entry);
489
490 return type;
491}
492
493static bool type_is_single_component(const struct hlsl_type *type)
494{
495 switch (type->class)
496 {
499 case HLSL_CLASS_ERROR:
507 case HLSL_CLASS_UAV:
514 case HLSL_CLASS_NULL:
515 return true;
516
520 case HLSL_CLASS_ARRAY:
522 return false;
523
525 case HLSL_CLASS_PASS:
527 case HLSL_CLASS_VOID:
528 break;
529 }
531}
532
533/* Given a type and a component index, this function moves one step through the path required to
534 * reach that component within the type.
535 * It returns the first index of this path.
536 * It sets *type_ptr to the (outermost) type within the original type that contains the component.
537 * It sets *index_ptr to the index of the component within *type_ptr.
538 * So, this function can be called several times in sequence to obtain all the path's indexes until
539 * the component is finally reached. */
541 struct hlsl_type **type_ptr, unsigned int *index_ptr)
542{
543 struct hlsl_type *type = *type_ptr;
544 unsigned int index = *index_ptr;
545
548
549 switch (type->class)
550 {
552 VKD3D_ASSERT(index < type->dimx);
553 *type_ptr = hlsl_get_scalar_type(ctx, type->e.numeric.type);
554 *index_ptr = 0;
555 return index;
556
558 {
559 unsigned int y = index / type->dimx, x = index % type->dimx;
560 bool row_major = hlsl_type_is_row_major(type);
561
562 VKD3D_ASSERT(index < type->dimx * type->dimy);
563 *type_ptr = hlsl_get_vector_type(ctx, type->e.numeric.type, row_major ? type->dimx : type->dimy);
564 *index_ptr = row_major ? x : y;
565 return row_major ? y : x;
566 }
567
568 case HLSL_CLASS_ARRAY:
569 {
570 unsigned int elem_comp_count = hlsl_type_component_count(type->e.array.type);
571 unsigned int array_index;
572
573 *type_ptr = type->e.array.type;
574 *index_ptr = index % elem_comp_count;
575 array_index = index / elem_comp_count;
576 VKD3D_ASSERT(array_index < type->e.array.elements_count);
577 return array_index;
578 }
579
581 {
582 struct hlsl_struct_field *field;
583 unsigned int field_comp_count, i;
584
585 for (i = 0; i < type->e.record.field_count; ++i)
586 {
587 field = &type->e.record.fields[i];
588 field_comp_count = hlsl_type_component_count(field->type);
589 if (index < field_comp_count)
590 {
591 *type_ptr = field->type;
592 *index_ptr = index;
593 return i;
594 }
595 index -= field_comp_count;
596 }
598 }
599
601 {
602 *type_ptr = type->e.resource.format;
603 return traverse_path_from_component_index(ctx, type_ptr, index_ptr);
604 }
605
606 default:
608 }
609}
610
612 unsigned int index)
613{
616
617 return type;
618}
619
621 unsigned int index, enum hlsl_regset *regset)
622{
623 unsigned int offset[HLSL_REGSET_LAST + 1] = {0};
624 struct hlsl_type *next_type;
625 unsigned int idx, r;
626
628 {
629 next_type = type;
631
632 switch (type->class)
633 {
636 break;
637
640 break;
641
643 for (r = 0; r <= HLSL_REGSET_LAST; ++r)
644 offset[r] += type->e.record.fields[idx].reg_offset[r];
645 break;
646
647 case HLSL_CLASS_ARRAY:
648 for (r = 0; r <= HLSL_REGSET_LAST; ++r)
649 {
650 if (r == HLSL_REGSET_NUMERIC)
651 offset[r] += idx * align(type->e.array.type->reg_size[r], 4);
652 else
653 offset[r] += idx * type->e.array.type->reg_size[r];
654 }
655 break;
656
665 case HLSL_CLASS_UAV:
672 VKD3D_ASSERT(idx == 0);
673 break;
674
676 case HLSL_CLASS_ERROR:
677 case HLSL_CLASS_PASS:
679 case HLSL_CLASS_VOID:
682 case HLSL_CLASS_NULL:
684 }
685 type = next_type;
686 }
687
689 return offset[*regset];
690}
691
692static bool init_deref(struct hlsl_ctx *ctx, struct hlsl_deref *deref, struct hlsl_ir_var *var,
693 unsigned int path_len)
694{
695 deref->var = var;
696 deref->path_len = path_len;
697 deref->rel_offset.node = NULL;
698 deref->const_offset = 0;
699 deref->data_type = NULL;
700
701 if (path_len == 0)
702 {
703 deref->path = NULL;
704 return true;
705 }
706
707 if (!(deref->path = hlsl_calloc(ctx, deref->path_len, sizeof(*deref->path))))
708 {
709 deref->var = NULL;
710 deref->path_len = 0;
711 return false;
712 }
713
714 return true;
715}
716
718{
719 struct hlsl_ir_index *index;
720 struct hlsl_ir_load *load;
721 unsigned int chain_len, i;
722 struct hlsl_ir_node *ptr;
723
724 deref->path = NULL;
725 deref->path_len = 0;
726 deref->rel_offset.node = NULL;
727 deref->const_offset = 0;
728
730 if (chain->type == HLSL_IR_INDEX)
732
733 /* Find the length of the index chain */
734 chain_len = 0;
735 ptr = chain;
736 while (ptr->type == HLSL_IR_INDEX)
737 {
739
740 chain_len++;
741 ptr = index->val.node;
742 }
743
744 if (ptr->type != HLSL_IR_LOAD)
745 {
746 hlsl_error(ctx, &chain->loc, VKD3D_SHADER_ERROR_HLSL_INVALID_LVALUE, "Invalid l-value.");
747 return false;
748 }
750
751 if (!init_deref(ctx, deref, load->src.var, load->src.path_len + chain_len))
752 return false;
753
754 for (i = 0; i < load->src.path_len; ++i)
755 hlsl_src_from_node(&deref->path[i], load->src.path[i].node);
756
757 chain_len = 0;
758 ptr = chain;
759 while (ptr->type == HLSL_IR_INDEX)
760 {
761 unsigned int p = deref->path_len - 1 - chain_len;
762
765 {
766 hlsl_src_from_node(&deref->path[p], deref->path[p + 1].node);
767 hlsl_src_remove(&deref->path[p + 1]);
768 hlsl_src_from_node(&deref->path[p + 1], index->idx.node);
769 }
770 else
771 {
772 hlsl_src_from_node(&deref->path[p], index->idx.node);
773 }
774
775 chain_len++;
776 ptr = index->val.node;
777 }
778 VKD3D_ASSERT(deref->path_len == load->src.path_len + chain_len);
779
780 return true;
781}
782
783struct hlsl_type *hlsl_deref_get_type(struct hlsl_ctx *ctx, const struct hlsl_deref *deref)
784{
785 struct hlsl_type *type;
786 unsigned int i;
787
788 VKD3D_ASSERT(deref);
789
790 if (hlsl_deref_is_lowered(deref))
791 return deref->data_type;
792
793 type = deref->var->data_type;
794 for (i = 0; i < deref->path_len; ++i)
796 return type;
797}
798
799/* Initializes a deref from another deref (prefix) and a component index.
800 * *block is initialized to contain the new constant node instructions used by the deref's path. */
802 struct hlsl_deref *deref, const struct hlsl_deref *prefix, unsigned int index,
803 const struct vkd3d_shader_location *loc)
804{
805 unsigned int path_len, path_index, deref_path_len, i;
806 struct hlsl_type *path_type;
807 struct hlsl_ir_node *c;
808
810
811 path_len = 0;
812 path_type = hlsl_deref_get_type(ctx, prefix);
813 path_index = index;
814 while (!type_is_single_component(path_type))
815 {
816 traverse_path_from_component_index(ctx, &path_type, &path_index);
817 ++path_len;
818 }
819
820 if (!init_deref(ctx, deref, prefix->var, prefix->path_len + path_len))
821 return false;
822
823 deref_path_len = 0;
824 for (i = 0; i < prefix->path_len; ++i)
825 hlsl_src_from_node(&deref->path[deref_path_len++], prefix->path[i].node);
826
827 path_type = hlsl_deref_get_type(ctx, prefix);
828 path_index = index;
829 while (!type_is_single_component(path_type))
830 {
831 unsigned int next_index = traverse_path_from_component_index(ctx, &path_type, &path_index);
832
833 if (!(c = hlsl_new_uint_constant(ctx, next_index, loc)))
834 {
836 return false;
837 }
839
840 hlsl_src_from_node(&deref->path[deref_path_len++], c);
841 }
842
843 VKD3D_ASSERT(deref_path_len == deref->path_len);
844
845 return true;
846}
847
849 struct hlsl_ir_node *idx)
850{
852
853 switch (type->class)
854 {
856 return hlsl_get_scalar_type(ctx, type->e.numeric.type);
857
860 return hlsl_get_vector_type(ctx, type->e.numeric.type, type->dimx);
861 else
862 return hlsl_get_vector_type(ctx, type->e.numeric.type, type->dimy);
863
864 case HLSL_CLASS_ARRAY:
865 return type->e.array.type;
866
868 {
870
871 VKD3D_ASSERT(c->value.u[0].u < type->e.record.field_count);
872 return type->e.record.fields[c->value.u[0].u].type;
873 }
874
875 default:
877 }
878}
879
880struct hlsl_type *hlsl_new_array_type(struct hlsl_ctx *ctx, struct hlsl_type *basic_type, unsigned int array_size)
881{
882 struct hlsl_type *type;
883
884 if (!(type = hlsl_alloc(ctx, sizeof(*type))))
885 return NULL;
886
887 type->class = HLSL_CLASS_ARRAY;
888 type->modifiers = basic_type->modifiers;
889 type->e.array.elements_count = array_size;
890 type->e.array.type = basic_type;
891 type->dimx = basic_type->dimx;
892 type->dimy = basic_type->dimy;
893 type->sampler_dim = basic_type->sampler_dim;
895
896 list_add_tail(&ctx->types, &type->entry);
897
898 return type;
899}
900
901struct hlsl_type *hlsl_new_struct_type(struct hlsl_ctx *ctx, const char *name,
902 struct hlsl_struct_field *fields, size_t field_count)
903{
904 struct hlsl_type *type;
905
906 if (!(type = hlsl_alloc(ctx, sizeof(*type))))
907 return NULL;
908 type->class = HLSL_CLASS_STRUCT;
909 type->name = name;
910 type->dimy = 1;
911 type->e.record.fields = fields;
912 type->e.record.field_count = field_count;
914
915 list_add_tail(&ctx->types, &type->entry);
916
917 return type;
918}
919
921 struct hlsl_type *format, unsigned int sample_count)
922{
923 struct hlsl_type *type;
924
925 if (!(type = hlsl_alloc(ctx, sizeof(*type))))
926 return NULL;
927 type->class = HLSL_CLASS_TEXTURE;
928 type->dimx = 4;
929 type->dimy = 1;
930 type->sampler_dim = dim;
931 type->e.resource.format = format;
932 type->sample_count = sample_count;
934 list_add_tail(&ctx->types, &type->entry);
935 return type;
936}
937
939 struct hlsl_type *format, bool rasteriser_ordered)
940{
941 struct hlsl_type *type;
942
943 if (!(type = hlsl_alloc(ctx, sizeof(*type))))
944 return NULL;
945 type->class = HLSL_CLASS_UAV;
946 type->dimx = format->dimx;
947 type->dimy = 1;
948 type->sampler_dim = dim;
949 type->e.resource.format = format;
950 type->e.resource.rasteriser_ordered = rasteriser_ordered;
952 list_add_tail(&ctx->types, &type->entry);
953 return type;
954}
955
957{
958 struct hlsl_type *type;
959
960 if (!(type = hlsl_alloc(ctx, sizeof(*type))))
961 return NULL;
963 type->dimy = 1;
964 type->e.resource.format = format;
966 list_add_tail(&ctx->types, &type->entry);
967 return type;
968}
969
970static const char * get_case_insensitive_typename(const char *name)
971{
972 static const char *const names[] =
973 {
974 "dword",
975 "float",
976 "geometryshader",
977 "matrix",
978 "pixelshader",
979 "texture",
980 "vector",
981 "vertexshader",
982 "string",
983 };
984 unsigned int i;
985
986 for (i = 0; i < ARRAY_SIZE(names); ++i)
987 {
989 return names[i];
990 }
991
992 return NULL;
993}
994
995struct hlsl_type *hlsl_get_type(struct hlsl_scope *scope, const char *name, bool recursive, bool case_insensitive)
996{
997 struct rb_entry *entry = rb_get(&scope->types, name);
998
999 if (entry)
1000 return RB_ENTRY_VALUE(entry, struct hlsl_type, scope_entry);
1001
1002 if (scope->upper)
1003 {
1004 if (recursive)
1005 return hlsl_get_type(scope->upper, name, recursive, case_insensitive);
1006 }
1007 else
1008 {
1009 if (case_insensitive && (name = get_case_insensitive_typename(name)))
1010 {
1011 if ((entry = rb_get(&scope->types, name)))
1012 return RB_ENTRY_VALUE(entry, struct hlsl_type, scope_entry);
1013 }
1014 }
1015
1016 return NULL;
1017}
1018
1020{
1021 struct rb_entry *entry;
1022
1023 if ((entry = rb_get(&ctx->functions, name)))
1024 return RB_ENTRY_VALUE(entry, struct hlsl_ir_function, entry);
1025 return NULL;
1026}
1027
1029{
1030 struct hlsl_ir_function *func;
1031 struct rb_entry *entry;
1032
1033 if ((entry = rb_get(&ctx->functions, name)))
1034 {
1036 return LIST_ENTRY(list_head(&func->overloads), struct hlsl_ir_function_decl, entry);
1037 }
1038
1039 return NULL;
1040}
1041
1042unsigned int hlsl_type_component_count(const struct hlsl_type *type)
1043{
1044 switch (type->class)
1045 {
1046 case HLSL_CLASS_SCALAR:
1047 case HLSL_CLASS_VECTOR:
1048 case HLSL_CLASS_MATRIX:
1049 return type->dimx * type->dimy;
1050
1051 case HLSL_CLASS_STRUCT:
1052 {
1053 unsigned int count = 0, i;
1054
1055 for (i = 0; i < type->e.record.field_count; ++i)
1056 count += hlsl_type_component_count(type->e.record.fields[i].type);
1057 return count;
1058 }
1059
1060 case HLSL_CLASS_ARRAY:
1061 return hlsl_type_component_count(type->e.array.type) * type->e.array.elements_count;
1062
1064 return hlsl_type_component_count(type->e.resource.format);
1065
1068 case HLSL_CLASS_ERROR:
1072 case HLSL_CLASS_SAMPLER:
1073 case HLSL_CLASS_STRING:
1074 case HLSL_CLASS_TEXTURE:
1075 case HLSL_CLASS_UAV:
1082 case HLSL_CLASS_NULL:
1083 return 1;
1084
1086 case HLSL_CLASS_PASS:
1088 case HLSL_CLASS_VOID:
1089 break;
1090 }
1091
1093}
1094
1095bool hlsl_types_are_equal(const struct hlsl_type *t1, const struct hlsl_type *t2)
1096{
1097 if (t1 == t2)
1098 return true;
1099
1100 if (t1->class != t2->class)
1101 return false;
1102
1103 switch (t1->class)
1104 {
1105 case HLSL_CLASS_SCALAR:
1106 case HLSL_CLASS_VECTOR:
1107 case HLSL_CLASS_MATRIX:
1108 if (t1->e.numeric.type != t2->e.numeric.type)
1109 return false;
1112 return false;
1113 if (t1->dimx != t2->dimx)
1114 return false;
1115 if (t1->dimy != t2->dimy)
1116 return false;
1117 return true;
1118
1119 case HLSL_CLASS_UAV:
1120 if (t1->e.resource.rasteriser_ordered != t2->e.resource.rasteriser_ordered)
1121 return false;
1122 /* fall through */
1123 case HLSL_CLASS_TEXTURE:
1125 && !hlsl_types_are_equal(t1->e.resource.format, t2->e.resource.format))
1126 return false;
1127 /* fall through */
1128 case HLSL_CLASS_SAMPLER:
1129 if (t1->sampler_dim != t2->sampler_dim)
1130 return false;
1131 return true;
1132
1133 case HLSL_CLASS_STRUCT:
1134 if (t1->e.record.field_count != t2->e.record.field_count)
1135 return false;
1136
1137 for (size_t i = 0; i < t1->e.record.field_count; ++i)
1138 {
1139 const struct hlsl_struct_field *field1 = &t1->e.record.fields[i];
1140 const struct hlsl_struct_field *field2 = &t2->e.record.fields[i];
1141
1142 if (!hlsl_types_are_equal(field1->type, field2->type))
1143 return false;
1144
1145 if (strcmp(field1->name, field2->name))
1146 return false;
1147 }
1148 return true;
1149
1150 case HLSL_CLASS_ARRAY:
1151 return t1->e.array.elements_count == t2->e.array.elements_count
1152 && hlsl_types_are_equal(t1->e.array.type, t2->e.array.type);
1153
1155 return t1->e.version == t2->e.version;
1156
1158 return hlsl_types_are_equal(t1->e.resource.format, t2->e.resource.format);
1159
1163 case HLSL_CLASS_ERROR:
1164 case HLSL_CLASS_PASS:
1168 case HLSL_CLASS_STRING:
1170 case HLSL_CLASS_VOID:
1176 case HLSL_CLASS_NULL:
1177 return true;
1178 }
1179
1181}
1182
1183struct hlsl_type *hlsl_type_clone(struct hlsl_ctx *ctx, struct hlsl_type *old,
1184 unsigned int default_majority, uint32_t modifiers)
1185{
1186 struct hlsl_type *type;
1187
1188 if (!(type = hlsl_alloc(ctx, sizeof(*type))))
1189 return NULL;
1190
1191 if (old->name)
1192 {
1193 type->name = hlsl_strdup(ctx, old->name);
1194 if (!type->name)
1195 {
1197 return NULL;
1198 }
1199 }
1200 type->class = old->class;
1201 type->dimx = old->dimx;
1202 type->dimy = old->dimy;
1203 type->modifiers = old->modifiers | modifiers;
1204 if (!(type->modifiers & HLSL_MODIFIERS_MAJORITY_MASK))
1205 type->modifiers |= default_majority;
1206 type->sampler_dim = old->sampler_dim;
1207 type->is_minimum_precision = old->is_minimum_precision;
1208 type->sample_count = old->sample_count;
1209
1210 switch (old->class)
1211 {
1212 case HLSL_CLASS_SCALAR:
1213 case HLSL_CLASS_VECTOR:
1214 case HLSL_CLASS_MATRIX:
1215 type->e.numeric.type = old->e.numeric.type;
1216 break;
1217
1218 case HLSL_CLASS_ARRAY:
1219 if (!(type->e.array.type = hlsl_type_clone(ctx, old->e.array.type, default_majority, modifiers)))
1220 {
1221 vkd3d_free((void *)type->name);
1223 return NULL;
1224 }
1225 type->e.array.elements_count = old->e.array.elements_count;
1226 break;
1227
1228 case HLSL_CLASS_STRUCT:
1229 {
1230 size_t field_count = old->e.record.field_count, i;
1231
1232 type->e.record.field_count = field_count;
1233
1234 if (!(type->e.record.fields = hlsl_calloc(ctx, field_count, sizeof(*type->e.record.fields))))
1235 {
1236 vkd3d_free((void *)type->name);
1238 return NULL;
1239 }
1240
1241 for (i = 0; i < field_count; ++i)
1242 {
1243 const struct hlsl_struct_field *src_field = &old->e.record.fields[i];
1244 struct hlsl_struct_field *dst_field = &type->e.record.fields[i];
1245
1246 dst_field->loc = src_field->loc;
1247 if (!(dst_field->type = hlsl_type_clone(ctx, src_field->type, default_majority, modifiers)))
1248 {
1249 vkd3d_free(type->e.record.fields);
1250 vkd3d_free((void *)type->name);
1252 return NULL;
1253 }
1254 dst_field->name = hlsl_strdup(ctx, src_field->name);
1255 if (src_field->semantic.name)
1256 {
1257 dst_field->semantic.name = hlsl_strdup(ctx, src_field->semantic.name);
1258 dst_field->semantic.index = src_field->semantic.index;
1259 }
1260 }
1261 break;
1262 }
1263
1264 case HLSL_CLASS_UAV:
1265 type->e.resource.rasteriser_ordered = old->e.resource.rasteriser_ordered;
1266 /* fall through */
1267 case HLSL_CLASS_TEXTURE:
1268 type->e.resource.format = old->e.resource.format;
1269 break;
1270
1272 type->e.version = old->e.version;
1273 break;
1274
1275 default:
1276 break;
1277 }
1278
1280
1281 list_add_tail(&ctx->types, &type->entry);
1282 return type;
1283}
1284
1285bool hlsl_scope_add_type(struct hlsl_scope *scope, struct hlsl_type *type)
1286{
1287 if (hlsl_get_type(scope, type->name, false, false))
1288 return false;
1289
1290 rb_put(&scope->types, type->name, &type->scope_entry);
1291 return true;
1292}
1293
1295 const struct vkd3d_shader_location *loc)
1296{
1297 struct hlsl_ir_node *cast;
1298
1300 if (cast)
1301 cast->data_type = type;
1302 return cast;
1303}
1304
1306{
1307 /* Use a cast to the same type as a makeshift identity expression. */
1308 return hlsl_new_cast(ctx, node, node->data_type, &node->loc);
1309}
1310
1311struct hlsl_ir_var *hlsl_new_var(struct hlsl_ctx *ctx, const char *name, struct hlsl_type *type,
1312 const struct vkd3d_shader_location *loc, const struct hlsl_semantic *semantic, uint32_t modifiers,
1314{
1315 struct hlsl_ir_var *var;
1316 unsigned int k;
1317
1318 if (!(var = hlsl_alloc(ctx, sizeof(*var))))
1319 return NULL;
1320
1321 var->name = name;
1322 var->data_type = type;
1323 var->loc = *loc;
1324 if (semantic)
1325 var->semantic = *semantic;
1326 var->storage_modifiers = modifiers;
1327 if (reg_reservation)
1328 var->reg_reservation = *reg_reservation;
1329
1330 for (k = 0; k <= HLSL_REGSET_LAST_OBJECT; ++k)
1331 {
1332 unsigned int i, obj_count = type->reg_size[k];
1333
1334 if (obj_count == 0)
1335 continue;
1336
1337 if (!(var->objects_usage[k] = hlsl_calloc(ctx, obj_count, sizeof(*var->objects_usage[0]))))
1338 {
1339 for (i = 0; i < k; ++i)
1340 vkd3d_free(var->objects_usage[i]);
1341 vkd3d_free(var);
1342 return NULL;
1343 }
1344 }
1345
1346 return var;
1347}
1348
1349struct hlsl_ir_var *hlsl_new_synthetic_var(struct hlsl_ctx *ctx, const char *template,
1350 struct hlsl_type *type, const struct vkd3d_shader_location *loc)
1351{
1353 struct hlsl_ir_var *var;
1354
1355 if (!(string = hlsl_get_string_buffer(ctx)))
1356 return NULL;
1357 vkd3d_string_buffer_printf(string, "<%s-%u>", template, ctx->internal_name_counter++);
1358 var = hlsl_new_synthetic_var_named(ctx, string->buffer, type, loc, true);
1360 return var;
1361}
1362
1364 struct hlsl_type *type, const struct vkd3d_shader_location *loc, bool dummy_scope)
1365{
1366 struct hlsl_ir_var *var;
1367 const char *name_copy;
1368
1369 if (!(name_copy = hlsl_strdup(ctx, name)))
1370 return NULL;
1371 var = hlsl_new_var(ctx, name_copy, type, loc, NULL, 0, NULL);
1372 if (var)
1373 {
1374 if (dummy_scope)
1375 list_add_tail(&ctx->dummy_scope->vars, &var->scope_entry);
1376 else
1377 list_add_tail(&ctx->globals->vars, &var->scope_entry);
1378 var->is_synthetic = true;
1379 }
1380 return var;
1381}
1382
1383static bool type_is_single_reg(const struct hlsl_type *type)
1384{
1385 return type->class == HLSL_CLASS_SCALAR || type->class == HLSL_CLASS_VECTOR;
1386}
1387
1388bool hlsl_copy_deref(struct hlsl_ctx *ctx, struct hlsl_deref *deref, const struct hlsl_deref *other)
1389{
1390 unsigned int i;
1391
1392 memset(deref, 0, sizeof(*deref));
1393
1394 if (!other)
1395 return true;
1396
1398
1399 if (!init_deref(ctx, deref, other->var, other->path_len))
1400 return false;
1401
1402 for (i = 0; i < deref->path_len; ++i)
1403 hlsl_src_from_node(&deref->path[i], other->path[i].node);
1404
1405 return true;
1406}
1407
1409{
1410 unsigned int i;
1411
1412 for (i = 0; i < deref->path_len; ++i)
1413 hlsl_src_remove(&deref->path[i]);
1414 vkd3d_free(deref->path);
1415
1416 deref->path = NULL;
1417 deref->path_len = 0;
1418
1419 hlsl_src_remove(&deref->rel_offset);
1420 deref->const_offset = 0;
1421}
1422
1423/* Initializes a simple variable dereference, so that it can be passed to load/store functions. */
1425{
1426 memset(deref, 0, sizeof(*deref));
1427 deref->var = var;
1428}
1429
1431 struct hlsl_type *data_type, const struct vkd3d_shader_location *loc)
1432{
1433 memset(node, 0, sizeof(*node));
1434 node->type = type;
1435 node->data_type = data_type;
1436 node->loc = *loc;
1437 list_init(&node->uses);
1438}
1439
1440struct hlsl_ir_node *hlsl_new_simple_store(struct hlsl_ctx *ctx, struct hlsl_ir_var *lhs, struct hlsl_ir_node *rhs)
1441{
1442 struct hlsl_deref lhs_deref;
1443
1444 hlsl_init_simple_deref_from_var(&lhs_deref, lhs);
1445 return hlsl_new_store_index(ctx, &lhs_deref, NULL, rhs, 0, &rhs->loc);
1446}
1447
1448struct hlsl_ir_node *hlsl_new_store_index(struct hlsl_ctx *ctx, const struct hlsl_deref *lhs,
1449 struct hlsl_ir_node *idx, struct hlsl_ir_node *rhs, unsigned int writemask, const struct vkd3d_shader_location *loc)
1450{
1451 struct hlsl_ir_store *store;
1452 unsigned int i;
1453
1456
1457 if (!(store = hlsl_alloc(ctx, sizeof(*store))))
1458 return NULL;
1459 init_node(&store->node, HLSL_IR_STORE, NULL, loc);
1460
1461 if (!init_deref(ctx, &store->lhs, lhs->var, lhs->path_len + !!idx))
1462 {
1463 vkd3d_free(store);
1464 return NULL;
1465 }
1466 for (i = 0; i < lhs->path_len; ++i)
1467 hlsl_src_from_node(&store->lhs.path[i], lhs->path[i].node);
1468 if (idx)
1469 hlsl_src_from_node(&store->lhs.path[lhs->path_len], idx);
1470
1471 hlsl_src_from_node(&store->rhs, rhs);
1472
1473 if (!writemask && type_is_single_reg(rhs->data_type))
1474 writemask = (1 << rhs->data_type->dimx) - 1;
1475 store->writemask = writemask;
1476
1477 return &store->node;
1478}
1479
1481 const struct hlsl_deref *lhs, unsigned int comp, struct hlsl_ir_node *rhs)
1482{
1483 struct hlsl_block comp_path_block;
1484 struct hlsl_ir_store *store;
1485
1487
1488 if (!(store = hlsl_alloc(ctx, sizeof(*store))))
1489 return false;
1490 init_node(&store->node, HLSL_IR_STORE, NULL, &rhs->loc);
1491
1492 if (!init_deref_from_component_index(ctx, &comp_path_block, &store->lhs, lhs, comp, &rhs->loc))
1493 {
1494 vkd3d_free(store);
1495 return false;
1496 }
1497 hlsl_block_add_block(block, &comp_path_block);
1498 hlsl_src_from_node(&store->rhs, rhs);
1499
1500 if (type_is_single_reg(rhs->data_type))
1501 store->writemask = (1 << rhs->data_type->dimx) - 1;
1502
1504
1505 return true;
1506}
1507
1509 const struct vkd3d_shader_location *loc)
1510{
1511 struct hlsl_ir_call *call;
1512
1513 if (!(call = hlsl_alloc(ctx, sizeof(*call))))
1514 return NULL;
1515
1516 init_node(&call->node, HLSL_IR_CALL, NULL, loc);
1517 call->decl = decl;
1518 return &call->node;
1519}
1520
1522 const struct hlsl_constant_value *value, const struct vkd3d_shader_location *loc)
1523{
1524 struct hlsl_ir_constant *c;
1525
1526 VKD3D_ASSERT(type->class <= HLSL_CLASS_VECTOR || type->class == HLSL_CLASS_NULL);
1527
1528 if (!(c = hlsl_alloc(ctx, sizeof(*c))))
1529 return NULL;
1530
1531 init_node(&c->node, HLSL_IR_CONSTANT, type, loc);
1532 c->value = *value;
1533
1534 return &c->node;
1535}
1536
1538{
1539 struct hlsl_constant_value value;
1540
1541 value.u[0].u = b ? ~0u : 0;
1543}
1544
1546 const struct vkd3d_shader_location *loc)
1547{
1548 struct hlsl_constant_value value;
1549
1550 value.u[0].f = f;
1552}
1553
1555{
1556 struct hlsl_constant_value value;
1557
1558 value.u[0].i = n;
1560}
1561
1562struct hlsl_ir_node *hlsl_new_uint_constant(struct hlsl_ctx *ctx, unsigned int n,
1563 const struct vkd3d_shader_location *loc)
1564{
1565 struct hlsl_constant_value value;
1566
1567 value.u[0].u = n;
1569}
1570
1572 const struct vkd3d_shader_location *loc)
1573{
1574 struct hlsl_ir_string_constant *s;
1575
1576 if (!(s = hlsl_alloc(ctx, sizeof(*s))))
1577 return NULL;
1578
1579 init_node(&s->node, HLSL_IR_STRING_CONSTANT, ctx->builtin_types.string, loc);
1580
1581 if (!(s->string = hlsl_strdup(ctx, str)))
1582 {
1583 hlsl_free_instr(&s->node);
1584 return NULL;
1585 }
1586 return &s->node;
1587}
1588
1590{
1591 struct hlsl_constant_value value = { 0 };
1592 return hlsl_new_constant(ctx, ctx->builtin_types.null, &value, loc);
1593}
1594
1596 struct hlsl_ir_node *operands[HLSL_MAX_OPERANDS],
1597 struct hlsl_type *data_type, const struct vkd3d_shader_location *loc)
1598{
1599 struct hlsl_ir_expr *expr;
1600 unsigned int i;
1601
1602 if (!(expr = hlsl_alloc(ctx, sizeof(*expr))))
1603 return NULL;
1604 init_node(&expr->node, HLSL_IR_EXPR, data_type, loc);
1605 expr->op = op;
1606 for (i = 0; i < HLSL_MAX_OPERANDS; ++i)
1607 hlsl_src_from_node(&expr->operands[i], operands[i]);
1608 return &expr->node;
1609}
1610
1612 struct hlsl_ir_node *arg, const struct vkd3d_shader_location *loc)
1613{
1614 struct hlsl_ir_node *operands[HLSL_MAX_OPERANDS] = {arg};
1615
1616 return hlsl_new_expr(ctx, op, operands, arg->data_type, loc);
1617}
1618
1620 struct hlsl_ir_node *arg1, struct hlsl_ir_node *arg2)
1621{
1622 struct hlsl_ir_node *operands[HLSL_MAX_OPERANDS] = {arg1, arg2};
1623
1624 return hlsl_new_expr(ctx, op, operands, arg1->data_type, &arg1->loc);
1625}
1626
1628 struct hlsl_ir_node *arg1, struct hlsl_ir_node *arg2, struct hlsl_ir_node *arg3)
1629{
1630 struct hlsl_ir_node *operands[HLSL_MAX_OPERANDS] = {arg1, arg2, arg3};
1631
1632 VKD3D_ASSERT(hlsl_types_are_equal(arg1->data_type, arg2->data_type));
1633 VKD3D_ASSERT(hlsl_types_are_equal(arg1->data_type, arg3->data_type));
1634 return hlsl_new_expr(ctx, op, operands, arg1->data_type, &arg1->loc);
1635}
1636
1638{
1639 static const struct vkd3d_shader_location loc = {.source_name = "<error>"};
1640 struct hlsl_ir_node *operands[HLSL_MAX_OPERANDS] = {0};
1641
1642 /* Use a dummy location; we should never report any messages related to
1643 * this expression. */
1644 return hlsl_new_expr(ctx, HLSL_OP0_ERROR, operands, ctx->builtin_types.error, &loc);
1645}
1646
1648 struct hlsl_block *then_block, struct hlsl_block *else_block, const struct vkd3d_shader_location *loc)
1649{
1650 struct hlsl_ir_if *iff;
1651
1652 if (!(iff = hlsl_alloc(ctx, sizeof(*iff))))
1653 return NULL;
1654 init_node(&iff->node, HLSL_IR_IF, NULL, loc);
1659 if (else_block)
1661 return &iff->node;
1662}
1663
1665 bool is_default, struct hlsl_block *body, const struct vkd3d_shader_location *loc)
1666{
1667 struct hlsl_ir_switch_case *c;
1668
1669 if (!(c = hlsl_alloc(ctx, sizeof(*c))))
1670 return NULL;
1671
1672 c->value = value;
1673 c->is_default = is_default;
1674 hlsl_block_init(&c->body);
1675 if (body)
1676 hlsl_block_add_block(&c->body, body);
1677 c->loc = *loc;
1678
1679 return c;
1680}
1681
1682struct hlsl_ir_node *hlsl_new_switch(struct hlsl_ctx *ctx, struct hlsl_ir_node *selector,
1683 struct list *cases, const struct vkd3d_shader_location *loc)
1684{
1685 struct hlsl_ir_switch *s;
1686
1687 if (!(s = hlsl_alloc(ctx, sizeof(*s))))
1688 return NULL;
1689 init_node(&s->node, HLSL_IR_SWITCH, NULL, loc);
1690 hlsl_src_from_node(&s->selector, selector);
1691 list_init(&s->cases);
1692 if (cases)
1693 list_move_head(&s->cases, cases);
1694
1695 return &s->node;
1696}
1697
1698struct hlsl_ir_node *hlsl_new_vsir_instruction_ref(struct hlsl_ctx *ctx, unsigned int vsir_instr_idx,
1699 struct hlsl_type *type, const struct hlsl_reg *reg, const struct vkd3d_shader_location *loc)
1700{
1701 struct hlsl_ir_vsir_instruction_ref *vsir_instr;
1702
1703 if (!(vsir_instr = hlsl_alloc(ctx, sizeof(*vsir_instr))))
1704 return NULL;
1705 init_node(&vsir_instr->node, HLSL_IR_VSIR_INSTRUCTION_REF, type, loc);
1706 vsir_instr->vsir_instr_idx = vsir_instr_idx;
1707
1708 if (reg)
1709 vsir_instr->node.reg = *reg;
1710
1711 return &vsir_instr->node;
1712}
1713
1714struct hlsl_ir_load *hlsl_new_load_index(struct hlsl_ctx *ctx, const struct hlsl_deref *deref,
1715 struct hlsl_ir_node *idx, const struct vkd3d_shader_location *loc)
1716{
1717 struct hlsl_ir_load *load;
1718 struct hlsl_type *type;
1719 unsigned int i;
1720
1722
1723 type = hlsl_deref_get_type(ctx, deref);
1724 if (idx)
1726
1727 if (!(load = hlsl_alloc(ctx, sizeof(*load))))
1728 return NULL;
1729 init_node(&load->node, HLSL_IR_LOAD, type, loc);
1730
1731 if (!init_deref(ctx, &load->src, deref->var, deref->path_len + !!idx))
1732 {
1734 return NULL;
1735 }
1736 for (i = 0; i < deref->path_len; ++i)
1737 hlsl_src_from_node(&load->src.path[i], deref->path[i].node);
1738 if (idx)
1739 hlsl_src_from_node(&load->src.path[deref->path_len], idx);
1740
1741 return load;
1742}
1743
1744struct hlsl_ir_load *hlsl_new_load_parent(struct hlsl_ctx *ctx, const struct hlsl_deref *deref,
1745 const struct vkd3d_shader_location *loc)
1746{
1747 /* This deref can only exists temporarily because it is not the real owner of its members. */
1748 struct hlsl_deref tmp_deref;
1749
1750 VKD3D_ASSERT(deref->path_len >= 1);
1751
1752 tmp_deref = *deref;
1753 tmp_deref.path_len = deref->path_len - 1;
1754 return hlsl_new_load_index(ctx, &tmp_deref, NULL, loc);
1755}
1756
1758 const struct vkd3d_shader_location *loc)
1759{
1760 struct hlsl_deref var_deref;
1761
1763 return hlsl_new_load_index(ctx, &var_deref, NULL, loc);
1764}
1765
1767 const struct hlsl_deref *deref, unsigned int comp, const struct vkd3d_shader_location *loc)
1768{
1769 struct hlsl_type *type, *comp_type;
1770 struct hlsl_block comp_path_block;
1771 struct hlsl_ir_load *load;
1772
1774
1775 if (!(load = hlsl_alloc(ctx, sizeof(*load))))
1776 return NULL;
1777
1778 type = hlsl_deref_get_type(ctx, deref);
1779 comp_type = hlsl_type_get_component_type(ctx, type, comp);
1780 init_node(&load->node, HLSL_IR_LOAD, comp_type, loc);
1781
1782 if (!init_deref_from_component_index(ctx, &comp_path_block, &load->src, deref, comp, loc))
1783 {
1785 return NULL;
1786 }
1787 hlsl_block_add_block(block, &comp_path_block);
1788
1790
1791 return &load->node;
1792}
1793
1795 const struct hlsl_resource_load_params *params, const struct vkd3d_shader_location *loc)
1796{
1798
1799 if (!(load = hlsl_alloc(ctx, sizeof(*load))))
1800 return NULL;
1801 init_node(&load->node, HLSL_IR_RESOURCE_LOAD, params->format, loc);
1802 load->load_type = params->type;
1803
1804 if (!hlsl_init_deref_from_index_chain(ctx, &load->resource, params->resource))
1805 {
1807 return NULL;
1808 }
1809
1810 if (params->sampler)
1811 {
1812 if (!hlsl_init_deref_from_index_chain(ctx, &load->sampler, params->sampler))
1813 {
1814 hlsl_cleanup_deref(&load->resource);
1816 return NULL;
1817 }
1818 }
1819
1820 hlsl_src_from_node(&load->coords, params->coords);
1821 hlsl_src_from_node(&load->sample_index, params->sample_index);
1822 hlsl_src_from_node(&load->texel_offset, params->texel_offset);
1823 hlsl_src_from_node(&load->lod, params->lod);
1824 hlsl_src_from_node(&load->ddx, params->ddx);
1825 hlsl_src_from_node(&load->ddy, params->ddy);
1826 hlsl_src_from_node(&load->cmp, params->cmp);
1827 load->sampling_dim = params->sampling_dim;
1828 if (load->sampling_dim == HLSL_SAMPLER_DIM_GENERIC)
1829 load->sampling_dim = hlsl_deref_get_type(ctx, &load->resource)->sampler_dim;
1830 return &load->node;
1831}
1832
1834 struct hlsl_ir_node *coords, struct hlsl_ir_node *value, const struct vkd3d_shader_location *loc)
1835{
1836 struct hlsl_ir_resource_store *store;
1837
1838 if (!(store = hlsl_alloc(ctx, sizeof(*store))))
1839 return NULL;
1840 init_node(&store->node, HLSL_IR_RESOURCE_STORE, NULL, loc);
1842 hlsl_src_from_node(&store->coords, coords);
1843 hlsl_src_from_node(&store->value, value);
1844 return &store->node;
1845}
1846
1848 struct hlsl_ir_node *val, const struct vkd3d_shader_location *loc)
1849{
1850 struct hlsl_ir_swizzle *swizzle;
1851 struct hlsl_type *type;
1852
1853 if (!(swizzle = hlsl_alloc(ctx, sizeof(*swizzle))))
1854 return NULL;
1856 if (components == 1)
1857 type = hlsl_get_scalar_type(ctx, val->data_type->e.numeric.type);
1858 else
1859 type = hlsl_get_vector_type(ctx, val->data_type->e.numeric.type, components);
1860 init_node(&swizzle->node, HLSL_IR_SWIZZLE, type, loc);
1862 swizzle->swizzle = s;
1863 return &swizzle->node;
1864}
1865
1866struct hlsl_ir_node *hlsl_new_compile(struct hlsl_ctx *ctx, enum hlsl_compile_type compile_type,
1867 const char *profile_name, struct hlsl_ir_node **args, unsigned int args_count,
1868 struct hlsl_block *args_instrs, const struct vkd3d_shader_location *loc)
1869{
1870 const struct hlsl_profile_info *profile_info = NULL;
1871 struct hlsl_ir_compile *compile;
1872 struct hlsl_type *type = NULL;
1873 unsigned int i;
1874
1875 switch (compile_type)
1876 {
1877 case HLSL_COMPILE_TYPE_COMPILE:
1878 if (!(profile_info = hlsl_get_target_info(profile_name)))
1879 {
1880 hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_INVALID_PROFILE, "Unknown profile \"%s\".", profile_name);
1881 return NULL;
1882 }
1883
1884 if (profile_info->type == VKD3D_SHADER_TYPE_PIXEL)
1885 type = hlsl_get_type(ctx->cur_scope, "PixelShader", true, true);
1886 else if (profile_info->type == VKD3D_SHADER_TYPE_VERTEX)
1887 type = hlsl_get_type(ctx->cur_scope, "VertexShader", true, true);
1888
1889 if (!type)
1890 {
1891 hlsl_error(ctx, loc, VKD3D_SHADER_ERROR_HLSL_INVALID_PROFILE, "Invalid profile \"%s\".", profile_name);
1892 return NULL;
1893 }
1894
1895 break;
1896
1897 case HLSL_COMPILE_TYPE_CONSTRUCTGSWITHSO:
1898 type = hlsl_get_type(ctx->cur_scope, "GeometryShader", true, true);
1899 break;
1900 }
1901
1902 if (!(compile = hlsl_alloc(ctx, sizeof(*compile))))
1903 return NULL;
1904
1905 init_node(&compile->node, HLSL_IR_COMPILE, type, loc);
1906
1907 compile->compile_type = compile_type;
1908 compile->profile = profile_info;
1909
1910 hlsl_block_init(&compile->instrs);
1911 hlsl_block_add_block(&compile->instrs, args_instrs);
1912
1913 compile->args_count = args_count;
1914 if (!(compile->args = hlsl_alloc(ctx, sizeof(*compile->args) * args_count)))
1915 {
1916 vkd3d_free(compile);
1917 return NULL;
1918 }
1919 for (i = 0; i < compile->args_count; ++i)
1920 hlsl_src_from_node(&compile->args[i], args[i]);
1921
1922 return &compile->node;
1923}
1924
1927{
1928 if (!vkd3d_array_reserve((void **)&state_block->entries,
1929 &state_block->capacity, state_block->count + 1,
1930 sizeof(*state_block->entries)))
1931 return false;
1932
1933 state_block->entries[state_block->count++] = entry;
1934 return true;
1935}
1936
1938 const struct hlsl_state_block *state_block, struct vkd3d_shader_location *loc)
1939{
1940 struct hlsl_ir_sampler_state *sampler_state;
1941 struct hlsl_type *type = ctx->builtin_types.sampler[HLSL_SAMPLER_DIM_GENERIC];
1942
1943 if (!(sampler_state = hlsl_alloc(ctx, sizeof(*sampler_state))))
1944 return NULL;
1945
1946 init_node(&sampler_state->node, HLSL_IR_SAMPLER_STATE, type, loc);
1947
1948 if (!(sampler_state->state_block = hlsl_alloc(ctx, sizeof(*sampler_state->state_block))))
1949 {
1950 vkd3d_free(sampler_state);
1951 return NULL;
1952 }
1953
1954 if (state_block)
1955 {
1956 for (unsigned int i = 0; i < state_block->count; ++i)
1957 {
1958 const struct hlsl_state_block_entry *src = state_block->entries[i];
1960
1961 if (!(entry = clone_stateblock_entry(ctx, src, src->name, src->lhs_has_index, src->lhs_index, false, 0)))
1962 {
1963 hlsl_free_instr(&sampler_state->node);
1964 return NULL;
1965 }
1966
1967 if (!hlsl_state_block_add_entry(sampler_state->state_block, entry))
1968 {
1969 hlsl_free_instr(&sampler_state->node);
1970 return NULL;
1971 }
1972 }
1973 }
1974
1975 return &sampler_state->node;
1976}
1977
1979 struct vkd3d_shader_location *loc)
1980{
1983
1984 if (!(constant = hlsl_alloc(ctx, sizeof(*constant))))
1985 return NULL;
1986
1988
1989 if (!(constant->name = hlsl_alloc(ctx, strlen(name) + 1)))
1990 {
1992 return NULL;
1993 }
1994 strcpy(constant->name, name);
1995
1996 return &constant->node;
1997}
1998
2000{
2001 struct hlsl_type *type = index->val.node->data_type;
2002
2004}
2005
2007{
2008 const struct hlsl_type *type = index->val.node->data_type;
2009
2010 return type->class == HLSL_CLASS_TEXTURE || type->class == HLSL_CLASS_UAV;
2011}
2012
2014{
2016 return true;
2017 if (index->val.node->type == HLSL_IR_INDEX)
2019 return false;
2020}
2021
2023 struct hlsl_ir_node *idx, const struct vkd3d_shader_location *loc)
2024{
2025 struct hlsl_type *type = val->data_type;
2026 struct hlsl_ir_index *index;
2027
2028 if (!(index = hlsl_alloc(ctx, sizeof(*index))))
2029 return NULL;
2030
2031 if (type->class == HLSL_CLASS_TEXTURE || type->class == HLSL_CLASS_UAV)
2032 type = type->e.resource.format;
2033 else if (type->class == HLSL_CLASS_MATRIX)
2034 type = hlsl_get_vector_type(ctx, type->e.numeric.type, type->dimx);
2035 else
2037
2038 init_node(&index->node, HLSL_IR_INDEX, type, loc);
2041 return &index->node;
2042}
2043
2045 struct hlsl_ir_node *condition, const struct vkd3d_shader_location *loc)
2046{
2047 struct hlsl_ir_jump *jump;
2048
2049 if (!(jump = hlsl_alloc(ctx, sizeof(*jump))))
2050 return NULL;
2051 init_node(&jump->node, HLSL_IR_JUMP, NULL, loc);
2052 jump->type = type;
2054 return &jump->node;
2055}
2056
2058 struct hlsl_block *block, enum hlsl_ir_loop_unroll_type unroll_type,
2059 unsigned int unroll_limit, const struct vkd3d_shader_location *loc)
2060{
2061 struct hlsl_ir_loop *loop;
2062
2063 if (!(loop = hlsl_alloc(ctx, sizeof(*loop))))
2064 return NULL;
2065 init_node(&loop->node, HLSL_IR_LOOP, NULL, loc);
2066 hlsl_block_init(&loop->body);
2068
2069 loop->unroll_type = unroll_type;
2070 loop->unroll_limit = unroll_limit;
2071 return &loop->node;
2072}
2073
2075{
2076 struct
2077 {
2078 const struct hlsl_ir_node *src;
2082};
2083
2084static struct hlsl_ir_node *clone_instr(struct hlsl_ctx *ctx,
2085 struct clone_instr_map *map, const struct hlsl_ir_node *instr);
2086
2087static bool clone_block(struct hlsl_ctx *ctx, struct hlsl_block *dst_block,
2088 const struct hlsl_block *src_block, struct clone_instr_map *map)
2089{
2090 const struct hlsl_ir_node *src;
2091 struct hlsl_ir_node *dst;
2092
2093 hlsl_block_init(dst_block);
2094
2095 LIST_FOR_EACH_ENTRY(src, &src_block->instrs, struct hlsl_ir_node, entry)
2096 {
2097 if (!(dst = clone_instr(ctx, map, src)))
2098 {
2099 hlsl_block_cleanup(dst_block);
2100 return false;
2101 }
2102 hlsl_block_add_instr(dst_block, dst);
2103
2104 if (!list_empty(&src->uses))
2105 {
2106 if (!hlsl_array_reserve(ctx, (void **)&map->instrs, &map->capacity, map->count + 1, sizeof(*map->instrs)))
2107 {
2108 hlsl_block_cleanup(dst_block);
2109 return false;
2110 }
2111
2112 map->instrs[map->count].dst = dst;
2113 map->instrs[map->count].src = src;
2114 ++map->count;
2115 }
2116 }
2117 return true;
2118}
2119
2120static struct hlsl_ir_node *map_instr(const struct clone_instr_map *map, struct hlsl_ir_node *src)
2121{
2122 size_t i;
2123
2124 if (!src)
2125 return NULL;
2126
2127 for (i = 0; i < map->count; ++i)
2128 {
2129 if (map->instrs[i].src == src)
2130 return map->instrs[i].dst;
2131 }
2132
2133 return src;
2134}
2135
2136static bool clone_deref(struct hlsl_ctx *ctx, struct clone_instr_map *map,
2137 struct hlsl_deref *dst, const struct hlsl_deref *src)
2138{
2139 unsigned int i;
2140
2142
2143 if (!init_deref(ctx, dst, src->var, src->path_len))
2144 return false;
2145
2146 for (i = 0; i < src->path_len; ++i)
2147 hlsl_src_from_node(&dst->path[i], map_instr(map, src->path[i].node));
2148
2149 return true;
2150}
2151
2152static void clone_src(struct clone_instr_map *map, struct hlsl_src *dst, const struct hlsl_src *src)
2153{
2155}
2156
2157static struct hlsl_ir_node *clone_call(struct hlsl_ctx *ctx, struct hlsl_ir_call *src)
2158{
2159 return hlsl_new_call(ctx, src->decl, &src->node.loc);
2160}
2161
2163{
2164 return hlsl_new_constant(ctx, src->node.data_type, &src->value, &src->node.loc);
2165}
2166
2167static struct hlsl_ir_node *clone_expr(struct hlsl_ctx *ctx, struct clone_instr_map *map, struct hlsl_ir_expr *src)
2168{
2169 struct hlsl_ir_node *operands[HLSL_MAX_OPERANDS];
2170 unsigned int i;
2171
2172 for (i = 0; i < ARRAY_SIZE(operands); ++i)
2173 operands[i] = map_instr(map, src->operands[i].node);
2174
2175 return hlsl_new_expr(ctx, src->op, operands, src->node.data_type, &src->node.loc);
2176}
2177
2178static struct hlsl_ir_node *clone_if(struct hlsl_ctx *ctx, struct clone_instr_map *map, struct hlsl_ir_if *src)
2179{
2180 struct hlsl_block then_block, else_block;
2181 struct hlsl_ir_node *dst;
2182
2183 if (!clone_block(ctx, &then_block, &src->then_block, map))
2184 return NULL;
2185 if (!clone_block(ctx, &else_block, &src->else_block, map))
2186 {
2187 hlsl_block_cleanup(&then_block);
2188 return NULL;
2189 }
2190
2191 if (!(dst = hlsl_new_if(ctx, map_instr(map, src->condition.node), &then_block, &else_block, &src->node.loc)))
2192 {
2193 hlsl_block_cleanup(&then_block);
2194 hlsl_block_cleanup(&else_block);
2195 return NULL;
2196 }
2197
2198 return dst;
2199}
2200
2201static struct hlsl_ir_node *clone_jump(struct hlsl_ctx *ctx, struct clone_instr_map *map, struct hlsl_ir_jump *src)
2202{
2203 return hlsl_new_jump(ctx, src->type, map_instr(map, src->condition.node), &src->node.loc);
2204}
2205
2206static struct hlsl_ir_node *clone_load(struct hlsl_ctx *ctx, struct clone_instr_map *map, struct hlsl_ir_load *src)
2207{
2208 struct hlsl_ir_load *dst;
2209
2210 if (!(dst = hlsl_alloc(ctx, sizeof(*dst))))
2211 return NULL;
2212 init_node(&dst->node, HLSL_IR_LOAD, src->node.data_type, &src->node.loc);
2213
2214 if (!clone_deref(ctx, map, &dst->src, &src->src))
2215 {
2216 vkd3d_free(dst);
2217 return NULL;
2218 }
2219 return &dst->node;
2220}
2221
2222static struct hlsl_ir_node *clone_loop(struct hlsl_ctx *ctx, struct clone_instr_map *map, struct hlsl_ir_loop *src)
2223{
2224 struct hlsl_ir_node *dst;
2225 struct hlsl_block body;
2226
2227 if (!clone_block(ctx, &body, &src->body, map))
2228 return NULL;
2229
2230 if (!(dst = hlsl_new_loop(ctx, &body, src->unroll_type, src->unroll_limit, &src->node.loc)))
2231 {
2233 return NULL;
2234 }
2235 return dst;
2236}
2237
2240{
2241 struct hlsl_ir_resource_load *dst;
2242
2243 if (!(dst = hlsl_alloc(ctx, sizeof(*dst))))
2244 return NULL;
2245 init_node(&dst->node, HLSL_IR_RESOURCE_LOAD, src->node.data_type, &src->node.loc);
2246 dst->load_type = src->load_type;
2247 if (!clone_deref(ctx, map, &dst->resource, &src->resource))
2248 {
2249 vkd3d_free(dst);
2250 return NULL;
2251 }
2252 if (!clone_deref(ctx, map, &dst->sampler, &src->sampler))
2253 {
2254 hlsl_cleanup_deref(&dst->resource);
2255 vkd3d_free(dst);
2256 return NULL;
2257 }
2258 clone_src(map, &dst->coords, &src->coords);
2259 clone_src(map, &dst->lod, &src->lod);
2260 clone_src(map, &dst->ddx, &src->ddx);
2261 clone_src(map, &dst->ddy, &src->ddy);
2262 clone_src(map, &dst->sample_index, &src->sample_index);
2263 clone_src(map, &dst->cmp, &src->cmp);
2264 clone_src(map, &dst->texel_offset, &src->texel_offset);
2265 dst->sampling_dim = src->sampling_dim;
2266 return &dst->node;
2267}
2268
2271{
2273
2274 if (!(dst = hlsl_alloc(ctx, sizeof(*dst))))
2275 return NULL;
2276 init_node(&dst->node, HLSL_IR_RESOURCE_STORE, NULL, &src->node.loc);
2277 if (!clone_deref(ctx, map, &dst->resource, &src->resource))
2278 {
2279 vkd3d_free(dst);
2280 return NULL;
2281 }
2282 clone_src(map, &dst->coords, &src->coords);
2283 clone_src(map, &dst->value, &src->value);
2284 return &dst->node;
2285}
2286
2288{
2289 return hlsl_new_string_constant(ctx, src->string, &src->node.loc);
2290}
2291
2292static struct hlsl_ir_node *clone_store(struct hlsl_ctx *ctx, struct clone_instr_map *map, struct hlsl_ir_store *src)
2293{
2294 struct hlsl_ir_store *dst;
2295
2296 if (!(dst = hlsl_alloc(ctx, sizeof(*dst))))
2297 return NULL;
2298 init_node(&dst->node, HLSL_IR_STORE, NULL, &src->node.loc);
2299
2300 if (!clone_deref(ctx, map, &dst->lhs, &src->lhs))
2301 {
2302 vkd3d_free(dst);
2303 return NULL;
2304 }
2305 clone_src(map, &dst->rhs, &src->rhs);
2306 dst->writemask = src->writemask;
2307 return &dst->node;
2308}
2309
2311 struct clone_instr_map *map, struct hlsl_ir_swizzle *src)
2312{
2313 return hlsl_new_swizzle(ctx, src->swizzle, src->node.data_type->dimx,
2314 map_instr(map, src->val.node), &src->node.loc);
2315}
2316
2317static struct hlsl_ir_node *clone_index(struct hlsl_ctx *ctx, struct clone_instr_map *map,
2318 struct hlsl_ir_index *src)
2319{
2320 struct hlsl_ir_node *dst;
2321
2322 if (!(dst = hlsl_new_index(ctx, map_instr(map, src->val.node), map_instr(map, src->idx.node),
2323 &src->node.loc)))
2324 return NULL;
2325 return dst;
2326}
2327
2329 struct clone_instr_map *map, struct hlsl_ir_compile *compile)
2330{
2331 const char *profile_name = NULL;
2332 struct hlsl_ir_node **args;
2333 struct hlsl_ir_node *node;
2334 struct hlsl_block block;
2335 unsigned int i;
2336
2337 if (!(clone_block(ctx, &block, &compile->instrs, map)))
2338 return NULL;
2339
2340 if (!(args = hlsl_alloc(ctx, sizeof(*args) * compile->args_count)))
2341 {
2343 return NULL;
2344 }
2345 for (i = 0; i < compile->args_count; ++i)
2346 {
2347 args[i] = map_instr(map, compile->args[i].node);
2349 }
2350
2351 if (compile->profile)
2352 profile_name = compile->profile->name;
2353
2354 if (!(node = hlsl_new_compile(ctx, compile->compile_type, profile_name,
2355 args, compile->args_count, &block, &compile->node.loc)))
2356 {
2359 return NULL;
2360 }
2361
2363 return node;
2364}
2365
2367 struct clone_instr_map *map, struct hlsl_ir_sampler_state *sampler_state)
2368{
2369 return hlsl_new_sampler_state(ctx, sampler_state->state_block,
2370 &sampler_state->node.loc);
2371}
2372
2375{
2376 return hlsl_new_stateblock_constant(ctx, constant->name, &constant->node.loc);
2377}
2378
2380 const struct hlsl_state_block_entry *src, const char *name, bool lhs_has_index,
2381 unsigned int lhs_index, bool single_arg, unsigned int arg_index)
2382{
2384 struct clone_instr_map map = { 0 };
2385
2386 if (!(entry = hlsl_alloc(ctx, sizeof(*entry))))
2387 return NULL;
2388 entry->name = hlsl_strdup(ctx, name);
2389 entry->lhs_has_index = lhs_has_index;
2390 entry->lhs_index = lhs_index;
2391 if (!(entry->instrs = hlsl_alloc(ctx, sizeof(*entry->instrs))))
2392 {
2394 return NULL;
2395 }
2396
2397 if (single_arg)
2398 entry->args_count = 1;
2399 else
2400 entry->args_count = src->args_count;
2401
2402 if (!(entry->args = hlsl_alloc(ctx, sizeof(*entry->args) * entry->args_count)))
2403 {
2405 return NULL;
2406 }
2407
2408 hlsl_block_init(entry->instrs);
2409 if (!clone_block(ctx, entry->instrs, src->instrs, &map))
2410 {
2412 return NULL;
2413 }
2414
2415 if (single_arg)
2416 {
2417 clone_src(&map, entry->args, &src->args[arg_index]);
2418 }
2419 else
2420 {
2421 for (unsigned int i = 0; i < src->args_count; ++i)
2422 clone_src(&map, &entry->args[i], &src->args[i]);
2423 }
2424 vkd3d_free(map.instrs);
2425
2426 return entry;
2427}
2428
2430{
2431 hlsl_block_cleanup(&c->body);
2432 list_remove(&c->entry);
2433 vkd3d_free(c);
2434}
2435
2437{
2438 struct hlsl_ir_switch_case *c, *next;
2439
2441 {
2443 }
2444}
2445
2446static struct hlsl_ir_node *clone_switch(struct hlsl_ctx *ctx,
2447 struct clone_instr_map *map, struct hlsl_ir_switch *s)
2448{
2449 struct hlsl_ir_switch_case *c, *d;
2450 struct hlsl_ir_node *ret;
2451 struct hlsl_block body;
2452 struct list cases;
2453
2454 list_init(&cases);
2455
2457 {
2458 if (!(clone_block(ctx, &body, &c->body, map)))
2459 {
2461 return NULL;
2462 }
2463
2464 d = hlsl_new_switch_case(ctx, c->value, c->is_default, &body, &c->loc);
2466 if (!d)
2467 {
2469 return NULL;
2470 }
2471
2472 list_add_tail(&cases, &d->entry);
2473 }
2474
2475 ret = hlsl_new_switch(ctx, map_instr(map, s->selector.node), &cases, &s->node.loc);
2477
2478 return ret;
2479}
2480
2481static struct hlsl_ir_node *clone_instr(struct hlsl_ctx *ctx,
2482 struct clone_instr_map *map, const struct hlsl_ir_node *instr)
2483{
2484 switch (instr->type)
2485 {
2486 case HLSL_IR_CALL:
2487 return clone_call(ctx, hlsl_ir_call(instr));
2488
2489 case HLSL_IR_CONSTANT:
2490 return clone_constant(ctx, hlsl_ir_constant(instr));
2491
2492 case HLSL_IR_EXPR:
2493 return clone_expr(ctx, map, hlsl_ir_expr(instr));
2494
2495 case HLSL_IR_IF:
2496 return clone_if(ctx, map, hlsl_ir_if(instr));
2497
2498 case HLSL_IR_INDEX:
2499 return clone_index(ctx, map, hlsl_ir_index(instr));
2500
2501 case HLSL_IR_JUMP:
2502 return clone_jump(ctx, map, hlsl_ir_jump(instr));
2503
2504 case HLSL_IR_LOAD:
2505 return clone_load(ctx, map, hlsl_ir_load(instr));
2506
2507 case HLSL_IR_LOOP:
2508 return clone_loop(ctx, map, hlsl_ir_loop(instr));
2509
2512
2515
2518
2519 case HLSL_IR_STORE:
2520 return clone_store(ctx, map, hlsl_ir_store(instr));
2521
2522 case HLSL_IR_SWITCH:
2523 return clone_switch(ctx, map, hlsl_ir_switch(instr));
2524
2525 case HLSL_IR_SWIZZLE:
2526 return clone_swizzle(ctx, map, hlsl_ir_swizzle(instr));
2527
2528 case HLSL_IR_COMPILE:
2529 return clone_compile(ctx, map, hlsl_ir_compile(instr));
2530
2533
2536
2539 }
2540
2542}
2543
2544bool hlsl_clone_block(struct hlsl_ctx *ctx, struct hlsl_block *dst_block, const struct hlsl_block *src_block)
2545{
2546 struct clone_instr_map map = {0};
2547 bool ret;
2548
2549 ret = clone_block(ctx, dst_block, src_block, &map);
2550 vkd3d_free(map.instrs);
2551 return ret;
2552}
2553
2556 const struct hlsl_semantic *semantic, const struct vkd3d_shader_location *loc)
2557{
2558 struct hlsl_ir_node *constant, *store;
2559 struct hlsl_ir_function_decl *decl;
2560
2561 if (!(decl = hlsl_alloc(ctx, sizeof(*decl))))
2562 return NULL;
2563 hlsl_block_init(&decl->body);
2564 decl->return_type = return_type;
2565 decl->parameters = *parameters;
2566 decl->loc = *loc;
2567 list_init(&decl->extern_vars);
2568
2569 if (!hlsl_types_are_equal(return_type, ctx->builtin_types.Void))
2570 {
2571 if (!(decl->return_var = hlsl_new_synthetic_var(ctx, "retval", return_type, loc)))
2572 {
2573 vkd3d_free(decl);
2574 return NULL;
2575 }
2576 decl->return_var->semantic = *semantic;
2577 }
2578
2579 if (!(decl->early_return_var = hlsl_new_synthetic_var(ctx, "early_return",
2581 return decl;
2582
2583 if (!(constant = hlsl_new_bool_constant(ctx, false, loc)))
2584 return decl;
2586
2587 if (!(store = hlsl_new_simple_store(ctx, decl->early_return_var, constant)))
2588 return decl;
2589 hlsl_block_add_instr(&decl->body, store);
2590
2591 return decl;
2592}
2593
2596 const struct vkd3d_shader_location *loc)
2597{
2598 struct hlsl_buffer *buffer;
2599
2600 if (!(buffer = hlsl_alloc(ctx, sizeof(*buffer))))
2601 return NULL;
2602 buffer->type = type;
2603 buffer->name = name;
2604 buffer->modifiers = modifiers;
2605 if (reservation)
2606 buffer->reservation = *reservation;
2607 buffer->annotations = annotations;
2608 buffer->loc = *loc;
2609 list_add_tail(&ctx->buffers, &buffer->entry);
2610 return buffer;
2611}
2612
2613static int compare_hlsl_types_rb(const void *key, const struct rb_entry *entry)
2614{
2615 const struct hlsl_type *type = RB_ENTRY_VALUE(entry, const struct hlsl_type, scope_entry);
2616 const char *name = key;
2617
2618 if (name == type->name)
2619 return 0;
2620
2621 if (!name || !type->name)
2622 {
2623 ERR("hlsl_type without a name in a scope?\n");
2624 return -1;
2625 }
2626 return strcmp(name, type->name);
2627}
2628
2629static struct hlsl_scope *hlsl_new_scope(struct hlsl_ctx *ctx, struct hlsl_scope *upper)
2630{
2631 struct hlsl_scope *scope;
2632
2633 if (!(scope = hlsl_alloc(ctx, sizeof(*scope))))
2634 return NULL;
2635 list_init(&scope->vars);
2637 scope->upper = upper;
2638 list_add_tail(&ctx->scopes, &scope->entry);
2639 return scope;
2640}
2641
2643{
2644 struct hlsl_scope *new_scope;
2645
2646 if (!(new_scope = hlsl_new_scope(ctx, ctx->cur_scope)))
2647 return;
2648
2649 TRACE("Pushing a new scope.\n");
2650 ctx->cur_scope = new_scope;
2651}
2652
2654{
2655 struct hlsl_scope *prev_scope = ctx->cur_scope->upper;
2656
2657 VKD3D_ASSERT(prev_scope);
2658 TRACE("Popping current scope.\n");
2659 ctx->cur_scope = prev_scope;
2660}
2661
2662static bool func_decl_matches(const struct hlsl_ir_function_decl *decl,
2663 const struct hlsl_func_parameters *parameters)
2664{
2665 size_t i;
2666
2667 if (parameters->count != decl->parameters.count)
2668 return false;
2669
2670 for (i = 0; i < parameters->count; ++i)
2671 {
2672 if (!hlsl_types_are_equal(parameters->vars[i]->data_type, decl->parameters.vars[i]->data_type))
2673 return false;
2674 }
2675 return true;
2676}
2677
2679 const struct hlsl_func_parameters *parameters)
2680{
2681 struct hlsl_ir_function_decl *decl;
2682 struct hlsl_ir_function *func;
2683
2684 if (!(func = hlsl_get_function(ctx, name)))
2685 return NULL;
2686
2687 LIST_FOR_EACH_ENTRY(decl, &func->overloads, struct hlsl_ir_function_decl, entry)
2688 {
2689 if (func_decl_matches(decl, parameters))
2690 return decl;
2691 }
2692
2693 return NULL;
2694}
2695
2697{
2698 struct vkd3d_string_buffer *string, *inner_string;
2699
2700 static const char *const base_types[] =
2701 {
2702 [HLSL_TYPE_FLOAT] = "float",
2703 [HLSL_TYPE_HALF] = "half",
2704 [HLSL_TYPE_DOUBLE] = "double",
2705 [HLSL_TYPE_INT] = "int",
2706 [HLSL_TYPE_UINT] = "uint",
2707 [HLSL_TYPE_BOOL] = "bool",
2708 };
2709
2710 static const char *const dimensions[] =
2711 {
2712 [HLSL_SAMPLER_DIM_1D] = "1D",
2713 [HLSL_SAMPLER_DIM_2D] = "2D",
2714 [HLSL_SAMPLER_DIM_3D] = "3D",
2715 [HLSL_SAMPLER_DIM_CUBE] = "Cube",
2716 [HLSL_SAMPLER_DIM_1DARRAY] = "1DArray",
2717 [HLSL_SAMPLER_DIM_2DARRAY] = "2DArray",
2718 [HLSL_SAMPLER_DIM_2DMS] = "2DMS",
2719 [HLSL_SAMPLER_DIM_2DMSARRAY] = "2DMSArray",
2720 [HLSL_SAMPLER_DIM_CUBEARRAY] = "CubeArray",
2721 };
2722
2723 if (!(string = hlsl_get_string_buffer(ctx)))
2724 return NULL;
2725
2726 if (type->name)
2727 {
2728 vkd3d_string_buffer_printf(string, "%s", type->name);
2729 return string;
2730 }
2731
2732 switch (type->class)
2733 {
2734 case HLSL_CLASS_SCALAR:
2735 VKD3D_ASSERT(type->e.numeric.type < ARRAY_SIZE(base_types));
2736 vkd3d_string_buffer_printf(string, "%s", base_types[type->e.numeric.type]);
2737 return string;
2738
2739 case HLSL_CLASS_VECTOR:
2740 VKD3D_ASSERT(type->e.numeric.type < ARRAY_SIZE(base_types));
2741 vkd3d_string_buffer_printf(string, "%s%u", base_types[type->e.numeric.type], type->dimx);
2742 return string;
2743
2744 case HLSL_CLASS_MATRIX:
2745 VKD3D_ASSERT(type->e.numeric.type < ARRAY_SIZE(base_types));
2746 vkd3d_string_buffer_printf(string, "%s%ux%u", base_types[type->e.numeric.type], type->dimy, type->dimx);
2747 return string;
2748
2749 case HLSL_CLASS_ARRAY:
2750 {
2751 const struct hlsl_type *t;
2752
2753 for (t = type; t->class == HLSL_CLASS_ARRAY; t = t->e.array.type)
2754 ;
2755
2756 if ((inner_string = hlsl_type_to_string(ctx, t)))
2757 {
2758 vkd3d_string_buffer_printf(string, "%s", inner_string->buffer);
2759 hlsl_release_string_buffer(ctx, inner_string);
2760 }
2761
2762 for (t = type; t->class == HLSL_CLASS_ARRAY; t = t->e.array.type)
2763 {
2764 if (t->e.array.elements_count == HLSL_ARRAY_ELEMENTS_COUNT_IMPLICIT)
2765 vkd3d_string_buffer_printf(string, "[]");
2766 else
2767 vkd3d_string_buffer_printf(string, "[%u]", t->e.array.elements_count);
2768 }
2769 return string;
2770 }
2771
2772 case HLSL_CLASS_STRUCT:
2773 vkd3d_string_buffer_printf(string, "<anonymous struct>");
2774 return string;
2775
2776 case HLSL_CLASS_TEXTURE:
2777 if (type->sampler_dim == HLSL_SAMPLER_DIM_RAW_BUFFER)
2778 {
2779 vkd3d_string_buffer_printf(string, "ByteAddressBuffer");
2780 return string;
2781 }
2782
2783 if (type->sampler_dim == HLSL_SAMPLER_DIM_GENERIC)
2784 {
2785 vkd3d_string_buffer_printf(string, "Texture");
2786 return string;
2787 }
2788
2789 VKD3D_ASSERT(hlsl_is_numeric_type(type->e.resource.format));
2790 VKD3D_ASSERT(type->e.resource.format->e.numeric.type < ARRAY_SIZE(base_types));
2791 if (type->sampler_dim == HLSL_SAMPLER_DIM_BUFFER)
2792 {
2793 vkd3d_string_buffer_printf(string, "Buffer");
2794 }
2795 else
2796 {
2797 VKD3D_ASSERT(type->sampler_dim < ARRAY_SIZE(dimensions));
2798 vkd3d_string_buffer_printf(string, "Texture%s", dimensions[type->sampler_dim]);
2799 }
2800 if ((inner_string = hlsl_type_to_string(ctx, type->e.resource.format)))
2801 {
2802 vkd3d_string_buffer_printf(string, "<%s>", inner_string->buffer);
2803 hlsl_release_string_buffer(ctx, inner_string);
2804 }
2805 return string;
2806
2807 case HLSL_CLASS_UAV:
2808 if (type->sampler_dim == HLSL_SAMPLER_DIM_RAW_BUFFER)
2809 {
2810 vkd3d_string_buffer_printf(string, "RWByteAddressBuffer");
2811 return string;
2812 }
2813 if (type->sampler_dim == HLSL_SAMPLER_DIM_BUFFER)
2814 vkd3d_string_buffer_printf(string, "RWBuffer");
2815 else if (type->sampler_dim == HLSL_SAMPLER_DIM_STRUCTURED_BUFFER)
2816 vkd3d_string_buffer_printf(string, "RWStructuredBuffer");
2817 else
2818 vkd3d_string_buffer_printf(string, "RWTexture%s", dimensions[type->sampler_dim]);
2819 if ((inner_string = hlsl_type_to_string(ctx, type->e.resource.format)))
2820 {
2821 vkd3d_string_buffer_printf(string, "<%s>", inner_string->buffer);
2822 hlsl_release_string_buffer(ctx, inner_string);
2823 }
2824 return string;
2825
2827 vkd3d_string_buffer_printf(string, "ConstantBuffer");
2828 if ((inner_string = hlsl_type_to_string(ctx, type->e.resource.format)))
2829 {
2830 vkd3d_string_buffer_printf(string, "<%s>", inner_string->buffer);
2831 hlsl_release_string_buffer(ctx, inner_string);
2832 }
2833 return string;
2834
2835 case HLSL_CLASS_ERROR:
2836 vkd3d_string_buffer_printf(string, "<error type>");
2837 return string;
2838
2842 case HLSL_CLASS_PASS:
2846 case HLSL_CLASS_SAMPLER:
2847 case HLSL_CLASS_STRING:
2850 case HLSL_CLASS_VOID:
2856 case HLSL_CLASS_NULL:
2857 break;
2858 }
2859
2860 vkd3d_string_buffer_printf(string, "<unexpected type>");
2861 return string;
2862}
2863
2865 unsigned int index)
2866{
2867 struct hlsl_type *type = var->data_type, *current_type;
2869 unsigned int element_index;
2870
2872 return NULL;
2873
2875
2877 {
2878 current_type = type;
2879 element_index = traverse_path_from_component_index(ctx, &type, &index);
2880 if (current_type->class == HLSL_CLASS_STRUCT)
2881 vkd3d_string_buffer_printf(buffer, ".%s", current_type->e.record.fields[element_index].name);
2882 else
2883 vkd3d_string_buffer_printf(buffer, "[%u]", element_index);
2884 }
2885
2886 return buffer;
2887}
2888
2889const char *debug_hlsl_type(struct hlsl_ctx *ctx, const struct hlsl_type *type)
2890{
2892 const char *ret;
2893
2894 if (!(string = hlsl_type_to_string(ctx, type)))
2895 return NULL;
2896 ret = vkd3d_dbg_sprintf("%s", string->buffer);
2898 return ret;
2899}
2900
2902{
2904
2905 if (!(string = hlsl_get_string_buffer(ctx)))
2906 return NULL;
2907
2908 if (modifiers & HLSL_STORAGE_EXTERN)
2909 vkd3d_string_buffer_printf(string, "extern ");
2910 if (modifiers & HLSL_STORAGE_LINEAR)
2911 vkd3d_string_buffer_printf(string, "linear ");
2912 if (modifiers & HLSL_STORAGE_NOINTERPOLATION)
2913 vkd3d_string_buffer_printf(string, "nointerpolation ");
2914 if (modifiers & HLSL_STORAGE_CENTROID)
2915 vkd3d_string_buffer_printf(string, "centroid ");
2916 if (modifiers & HLSL_STORAGE_NOPERSPECTIVE)
2917 vkd3d_string_buffer_printf(string, "noperspective ");
2918 if (modifiers & HLSL_MODIFIER_PRECISE)
2919 vkd3d_string_buffer_printf(string, "precise ");
2920 if (modifiers & HLSL_STORAGE_SHARED)
2921 vkd3d_string_buffer_printf(string, "shared ");
2922 if (modifiers & HLSL_STORAGE_GROUPSHARED)
2923 vkd3d_string_buffer_printf(string, "groupshared ");
2924 if (modifiers & HLSL_STORAGE_STATIC)
2925 vkd3d_string_buffer_printf(string, "static ");
2926 if (modifiers & HLSL_STORAGE_UNIFORM)
2927 vkd3d_string_buffer_printf(string, "uniform ");
2928 if (modifiers & HLSL_MODIFIER_VOLATILE)
2929 vkd3d_string_buffer_printf(string, "volatile ");
2930 if (modifiers & HLSL_MODIFIER_CONST)
2931 vkd3d_string_buffer_printf(string, "const ");
2932 if (modifiers & HLSL_MODIFIER_ROW_MAJOR)
2933 vkd3d_string_buffer_printf(string, "row_major ");
2934 if (modifiers & HLSL_MODIFIER_COLUMN_MAJOR)
2935 vkd3d_string_buffer_printf(string, "column_major ");
2937 vkd3d_string_buffer_printf(string, "inout ");
2938 else if (modifiers & HLSL_STORAGE_IN)
2939 vkd3d_string_buffer_printf(string, "in ");
2940 else if (modifiers & HLSL_STORAGE_OUT)
2941 vkd3d_string_buffer_printf(string, "out ");
2942
2943 if (string->content_size)
2944 string->buffer[--string->content_size] = 0;
2945
2946 return string;
2947}
2948
2950{
2951 static const char * const names[] =
2952 {
2953 [HLSL_IR_CALL ] = "HLSL_IR_CALL",
2954 [HLSL_IR_CONSTANT ] = "HLSL_IR_CONSTANT",
2955 [HLSL_IR_EXPR ] = "HLSL_IR_EXPR",
2956 [HLSL_IR_IF ] = "HLSL_IR_IF",
2957 [HLSL_IR_INDEX ] = "HLSL_IR_INDEX",
2958 [HLSL_IR_LOAD ] = "HLSL_IR_LOAD",
2959 [HLSL_IR_LOOP ] = "HLSL_IR_LOOP",
2960 [HLSL_IR_JUMP ] = "HLSL_IR_JUMP",
2961 [HLSL_IR_RESOURCE_LOAD ] = "HLSL_IR_RESOURCE_LOAD",
2962 [HLSL_IR_RESOURCE_STORE ] = "HLSL_IR_RESOURCE_STORE",
2963 [HLSL_IR_STRING_CONSTANT] = "HLSL_IR_STRING_CONSTANT",
2964 [HLSL_IR_STORE ] = "HLSL_IR_STORE",
2965 [HLSL_IR_SWITCH ] = "HLSL_IR_SWITCH",
2966 [HLSL_IR_SWIZZLE ] = "HLSL_IR_SWIZZLE",
2967
2968 [HLSL_IR_COMPILE] = "HLSL_IR_COMPILE",
2969 [HLSL_IR_SAMPLER_STATE] = "HLSL_IR_SAMPLER_STATE",
2970 [HLSL_IR_STATEBLOCK_CONSTANT] = "HLSL_IR_STATEBLOCK_CONSTANT",
2971 [HLSL_IR_VSIR_INSTRUCTION_REF] = "HLSL_IR_VSIR_INSTRUCTION_REF",
2972 };
2973
2974 if (type >= ARRAY_SIZE(names))
2975 return "Unexpected node type";
2976 return names[type];
2977}
2978
2980{
2981 static const char * const names[] =
2982 {
2983 [HLSL_IR_JUMP_BREAK] = "HLSL_IR_JUMP_BREAK",
2984 [HLSL_IR_JUMP_CONTINUE] = "HLSL_IR_JUMP_CONTINUE",
2985 [HLSL_IR_JUMP_DISCARD_NEG] = "HLSL_IR_JUMP_DISCARD_NEG",
2986 [HLSL_IR_JUMP_DISCARD_NZ] = "HLSL_IR_JUMP_DISCARD_NZ",
2987 [HLSL_IR_JUMP_RETURN] = "HLSL_IR_JUMP_RETURN",
2988 };
2989
2991 return names[type];
2992}
2993
2994static void dump_instr(struct hlsl_ctx *ctx, struct vkd3d_string_buffer *buffer, const struct hlsl_ir_node *instr);
2995
2996static void dump_block(struct hlsl_ctx *ctx, struct vkd3d_string_buffer *buffer, const struct hlsl_block *block)
2997{
2998 struct hlsl_ir_node *instr;
2999
3000 LIST_FOR_EACH_ENTRY(instr, &block->instrs, struct hlsl_ir_node, entry)
3001 {
3002 dump_instr(ctx, buffer, instr);
3004 }
3005}
3006
3007static void dump_src(struct vkd3d_string_buffer *buffer, const struct hlsl_src *src)
3008{
3009 if (src->node->index)
3010 vkd3d_string_buffer_printf(buffer, "@%u", src->node->index);
3011 else
3013}
3014
3015static void dump_ir_var(struct hlsl_ctx *ctx, struct vkd3d_string_buffer *buffer, const struct hlsl_ir_var *var)
3016{
3017 if (var->storage_modifiers)
3018 {
3020
3021 if ((string = hlsl_modifiers_to_string(ctx, var->storage_modifiers)))
3022 vkd3d_string_buffer_printf(buffer, "%s ", string->buffer);
3024 }
3025 vkd3d_string_buffer_printf(buffer, "%s %s", debug_hlsl_type(ctx, var->data_type), var->name);
3026 if (var->semantic.name)
3027 vkd3d_string_buffer_printf(buffer, " : %s%u", var->semantic.name, var->semantic.index);
3028}
3029
3030static void dump_deref(struct vkd3d_string_buffer *buffer, const struct hlsl_deref *deref)
3031{
3032 unsigned int i;
3033
3034 if (deref->var)
3035 {
3036 vkd3d_string_buffer_printf(buffer, "%s", deref->var->name);
3037 if (!hlsl_deref_is_lowered(deref))
3038 {
3039 if (deref->path_len)
3040 {
3042 for (i = 0; i < deref->path_len; ++i)
3043 {
3045 dump_src(buffer, &deref->path[i]);
3047 }
3049 }
3050 }
3051 else
3052 {
3053 bool show_rel, show_const;
3054
3055 show_rel = deref->rel_offset.node;
3056 show_const = deref->const_offset != 0 || !show_rel;
3057
3059 if (show_rel)
3060 dump_src(buffer, &deref->rel_offset);
3061 if (show_rel && show_const)
3063 if (show_const)
3066 }
3067 }
3068 else
3069 {
3071 }
3072}
3073
3074const char *debug_hlsl_writemask(unsigned int writemask)
3075{
3076 static const char components[] = {'x', 'y', 'z', 'w'};
3077 char string[5];
3078 unsigned int i = 0, pos = 0;
3079
3080 VKD3D_ASSERT(!(writemask & ~VKD3DSP_WRITEMASK_ALL));
3081
3082 while (writemask)
3083 {
3084 if (writemask & 1)
3085 string[pos++] = components[i];
3086 writemask >>= 1;
3087 i++;
3088 }
3089 string[pos] = '\0';
3090 return vkd3d_dbg_sprintf(".%s", string);
3091}
3092
3093const char *debug_hlsl_swizzle(uint32_t swizzle, unsigned int size)
3094{
3095 static const char components[] = {'x', 'y', 'z', 'w'};
3096 char string[5];
3097 unsigned int i;
3098
3100 for (i = 0; i < size; ++i)
3102 string[size] = 0;
3103 return vkd3d_dbg_sprintf(".%s", string);
3104}
3105
3106static void dump_ir_call(struct hlsl_ctx *ctx, struct vkd3d_string_buffer *buffer, const struct hlsl_ir_call *call)
3107{
3108 const struct hlsl_ir_function_decl *decl = call->decl;
3110 size_t i;
3111
3112 if (!(string = hlsl_type_to_string(ctx, decl->return_type)))
3113 return;
3114
3115 vkd3d_string_buffer_printf(buffer, "call %s %s(", string->buffer, decl->func->name);
3117
3118 for (i = 0; i < decl->parameters.count; ++i)
3119 {
3120 const struct hlsl_ir_var *param = decl->parameters.vars[i];
3121
3122 if (!(string = hlsl_type_to_string(ctx, param->data_type)))
3123 return;
3124
3125 if (i)
3128
3130 }
3132}
3133
3135{
3136 struct hlsl_type *type = constant->node.data_type;
3137 unsigned int x;
3138
3139 if (type->dimx != 1)
3141 for (x = 0; x < type->dimx; ++x)
3142 {
3144
3145 switch (type->e.numeric.type)
3146 {
3147 case HLSL_TYPE_BOOL:
3148 vkd3d_string_buffer_printf(buffer, "%s ", value->u ? "true" : "false");
3149 break;
3150
3151 case HLSL_TYPE_DOUBLE:
3153 break;
3154
3155 case HLSL_TYPE_FLOAT:
3156 case HLSL_TYPE_HALF:
3158 break;
3159
3160 case HLSL_TYPE_INT:
3162 break;
3163
3164 case HLSL_TYPE_UINT:
3166 break;
3167
3168 default:
3170 }
3171 }
3172 if (type->dimx != 1)
3174}
3175
3177{
3178 static const char *const op_names[] =
3179 {
3180 [HLSL_OP0_ERROR] = "error",
3181 [HLSL_OP0_VOID] = "void",
3182 [HLSL_OP0_RASTERIZER_SAMPLE_COUNT] = "GetRenderTargetSampleCount",
3183
3184 [HLSL_OP1_ABS] = "abs",
3185 [HLSL_OP1_BIT_NOT] = "~",
3186 [HLSL_OP1_CAST] = "cast",
3187 [HLSL_OP1_CEIL] = "ceil",
3188 [HLSL_OP1_COS] = "cos",
3189 [HLSL_OP1_COS_REDUCED] = "cos_reduced",
3190 [HLSL_OP1_DSX] = "dsx",
3191 [HLSL_OP1_DSX_COARSE] = "dsx_coarse",
3192 [HLSL_OP1_DSX_FINE] = "dsx_fine",
3193 [HLSL_OP1_DSY] = "dsy",
3194 [HLSL_OP1_DSY_COARSE] = "dsy_coarse",
3195 [HLSL_OP1_DSY_FINE] = "dsy_fine",
3196 [HLSL_OP1_EXP2] = "exp2",
3197 [HLSL_OP1_F16TOF32] = "f16tof32",
3198 [HLSL_OP1_F32TOF16] = "f32tof16",
3199 [HLSL_OP1_FLOOR] = "floor",
3200 [HLSL_OP1_FRACT] = "fract",
3201 [HLSL_OP1_LOG2] = "log2",
3202 [HLSL_OP1_LOGIC_NOT] = "!",
3203 [HLSL_OP1_NEG] = "-",
3204 [HLSL_OP1_NRM] = "nrm",
3205 [HLSL_OP1_RCP] = "rcp",
3206 [HLSL_OP1_REINTERPRET] = "reinterpret",
3207 [HLSL_OP1_ROUND] = "round",
3208 [HLSL_OP1_RSQ] = "rsq",
3209 [HLSL_OP1_SAT] = "sat",
3210 [HLSL_OP1_SIGN] = "sign",
3211 [HLSL_OP1_SIN] = "sin",
3212 [HLSL_OP1_SIN_REDUCED] = "sin_reduced",
3213 [HLSL_OP1_SQRT] = "sqrt",
3214 [HLSL_OP1_TRUNC] = "trunc",
3215
3216 [HLSL_OP2_ADD] = "+",
3217 [HLSL_OP2_BIT_AND] = "&",
3218 [HLSL_OP2_BIT_OR] = "|",
3219 [HLSL_OP2_BIT_XOR] = "^",
3220 [HLSL_OP2_CRS] = "crs",
3221 [HLSL_OP2_DIV] = "/",
3222 [HLSL_OP2_DOT] = "dot",
3223 [HLSL_OP2_EQUAL] = "==",
3224 [HLSL_OP2_GEQUAL] = ">=",
3225 [HLSL_OP2_LESS] = "<",
3226 [HLSL_OP2_LOGIC_AND] = "&&",
3227 [HLSL_OP2_LOGIC_OR] = "||",
3228 [HLSL_OP2_LSHIFT] = "<<",
3229 [HLSL_OP2_MAX] = "max",
3230 [HLSL_OP2_MIN] = "min",
3231 [HLSL_OP2_MOD] = "%",
3232 [HLSL_OP2_MUL] = "*",
3233 [HLSL_OP2_NEQUAL] = "!=",
3234 [HLSL_OP2_RSHIFT] = ">>",
3235 [HLSL_OP2_SLT] = "slt",
3236
3237 [HLSL_OP3_CMP] = "cmp",
3238 [HLSL_OP3_DP2ADD] = "dp2add",
3239 [HLSL_OP3_TERNARY] = "ternary",
3240 [HLSL_OP3_MAD] = "mad",
3241 };
3242
3243 return op_names[op];
3244}
3245
3246static void dump_ir_expr(struct vkd3d_string_buffer *buffer, const struct hlsl_ir_expr *expr)
3247{
3248 unsigned int i;
3249
3251 for (i = 0; i < HLSL_MAX_OPERANDS && expr->operands[i].node; ++i)
3252 {
3253 dump_src(buffer, &expr->operands[i]);
3255 }
3257}
3258
3259static void dump_ir_if(struct hlsl_ctx *ctx, struct vkd3d_string_buffer *buffer, const struct hlsl_ir_if *if_node)
3260{
3262 dump_src(buffer, &if_node->condition);
3264 dump_block(ctx, buffer, &if_node->then_block);
3265 vkd3d_string_buffer_printf(buffer, " %10s } else {\n", "");
3266 dump_block(ctx, buffer, &if_node->else_block);
3267 vkd3d_string_buffer_printf(buffer, " %10s }", "");
3268}
3269
3270static void dump_ir_jump(struct vkd3d_string_buffer *buffer, const struct hlsl_ir_jump *jump)
3271{
3272 switch (jump->type)
3273 {
3274 case HLSL_IR_JUMP_BREAK:
3276 break;
3277
3280 break;
3281
3283 vkd3d_string_buffer_printf(buffer, "discard_neg");
3284 break;
3285
3287 vkd3d_string_buffer_printf(buffer, "discard_nz");
3288 break;
3289
3292 break;
3293
3295 vkd3d_string_buffer_printf(buffer, "unresolved_continue");
3296 break;
3297 }
3298}
3299
3300static void dump_ir_loop(struct hlsl_ctx *ctx, struct vkd3d_string_buffer *buffer, const struct hlsl_ir_loop *loop)
3301{
3302 vkd3d_string_buffer_printf(buffer, "for (;;) {\n");
3303 dump_block(ctx, buffer, &loop->body);
3304 vkd3d_string_buffer_printf(buffer, " %10s }", "");
3305}
3306
3308{
3309 static const char *const type_names[] =
3310 {
3311 [HLSL_RESOURCE_LOAD] = "load_resource",
3312 [HLSL_RESOURCE_SAMPLE] = "sample",
3313 [HLSL_RESOURCE_SAMPLE_CMP] = "sample_cmp",
3314 [HLSL_RESOURCE_SAMPLE_CMP_LZ] = "sample_cmp_lz",
3315 [HLSL_RESOURCE_SAMPLE_LOD] = "sample_lod",
3316 [HLSL_RESOURCE_SAMPLE_LOD_BIAS] = "sample_biased",
3317 [HLSL_RESOURCE_SAMPLE_GRAD] = "sample_grad",
3318 [HLSL_RESOURCE_GATHER_RED] = "gather_red",
3319 [HLSL_RESOURCE_GATHER_GREEN] = "gather_green",
3320 [HLSL_RESOURCE_GATHER_BLUE] = "gather_blue",
3321 [HLSL_RESOURCE_GATHER_ALPHA] = "gather_alpha",
3322 [HLSL_RESOURCE_SAMPLE_INFO] = "sample_info",
3323 [HLSL_RESOURCE_RESINFO] = "resinfo",
3324 };
3325
3326 VKD3D_ASSERT(load->load_type < ARRAY_SIZE(type_names));
3327 vkd3d_string_buffer_printf(buffer, "%s(resource = ", type_names[load->load_type]);
3328 dump_deref(buffer, &load->resource);
3329 vkd3d_string_buffer_printf(buffer, ", sampler = ");
3330 dump_deref(buffer, &load->sampler);
3331 if (load->coords.node)
3332 {
3333 vkd3d_string_buffer_printf(buffer, ", coords = ");
3334 dump_src(buffer, &load->coords);
3335 }
3336 if (load->sample_index.node)
3337 {
3338 vkd3d_string_buffer_printf(buffer, ", sample index = ");
3339 dump_src(buffer, &load->sample_index);
3340 }
3341 if (load->texel_offset.node)
3342 {
3343 vkd3d_string_buffer_printf(buffer, ", offset = ");
3344 dump_src(buffer, &load->texel_offset);
3345 }
3346 if (load->lod.node)
3347 {
3349 dump_src(buffer, &load->lod);
3350 }
3351 if (load->ddx.node)
3352 {
3354 dump_src(buffer, &load->ddx);
3355 }
3356 if (load->ddy.node)
3357 {
3359 dump_src(buffer, &load->ddy);
3360 }
3361 if (load->cmp.node)
3362 {
3364 dump_src(buffer, &load->cmp);
3365 }
3367}
3368
3370{
3371 vkd3d_string_buffer_printf(buffer, "store_resource(resource = ");
3372 dump_deref(buffer, &store->resource);
3373 vkd3d_string_buffer_printf(buffer, ", coords = ");
3374 dump_src(buffer, &store->coords);
3375 vkd3d_string_buffer_printf(buffer, ", value = ");
3376 dump_src(buffer, &store->value);
3378}
3379
3380static void dump_ir_string(struct vkd3d_string_buffer *buffer, const struct hlsl_ir_string_constant *string)
3381{
3383}
3384
3385static void dump_ir_store(struct vkd3d_string_buffer *buffer, const struct hlsl_ir_store *store)
3386{
3388 dump_deref(buffer, &store->lhs);
3389 if (store->writemask != VKD3DSP_WRITEMASK_ALL)
3392 dump_src(buffer, &store->rhs);
3394}
3395
3397{
3398 unsigned int i;
3399
3400 dump_src(buffer, &swizzle->val);
3401 if (swizzle->val.node->data_type->dimy > 1)
3402 {
3404 for (i = 0; i < swizzle->node.data_type->dimx; ++i)
3405 vkd3d_string_buffer_printf(buffer, "_m%u%u", (swizzle->swizzle >> i * 8) & 0xf, (swizzle->swizzle >> (i * 8 + 4)) & 0xf);
3406 }
3407 else
3408 {
3409 vkd3d_string_buffer_printf(buffer, "%s", debug_hlsl_swizzle(swizzle->swizzle, swizzle->node.data_type->dimx));
3410 }
3411}
3412
3414{
3415 dump_src(buffer, &index->val);
3417 dump_src(buffer, &index->idx);
3419}
3420
3422 const struct hlsl_ir_compile *compile)
3423{
3424 unsigned int i;
3425
3426 switch (compile->compile_type)
3427 {
3428 case HLSL_COMPILE_TYPE_COMPILE:
3429 vkd3d_string_buffer_printf(buffer, "compile %s {\n", compile->profile->name);
3430 break;
3431
3432 case HLSL_COMPILE_TYPE_CONSTRUCTGSWITHSO:
3433 vkd3d_string_buffer_printf(buffer, "ConstructGSWithSO {\n");
3434 break;
3435 }
3436
3437 dump_block(ctx, buffer, &compile->instrs);
3438
3439 vkd3d_string_buffer_printf(buffer, " %10s } (", "");
3440 for (i = 0; i < compile->args_count; ++i)
3441 {
3442 dump_src(buffer, &compile->args[i]);
3443 if (i + 1 < compile->args_count)
3445 }
3447}
3448
3450 const struct hlsl_ir_sampler_state *sampler_state)
3451{
3452 vkd3d_string_buffer_printf(buffer, "sampler_state {...}");
3453}
3454
3457{
3459}
3460
3461static void dump_ir_switch(struct hlsl_ctx *ctx, struct vkd3d_string_buffer *buffer, const struct hlsl_ir_switch *s)
3462{
3463 struct hlsl_ir_switch_case *c;
3464
3466 dump_src(buffer, &s->selector);
3468
3470 {
3471 if (c->is_default)
3472 {
3473 vkd3d_string_buffer_printf(buffer, " %10s default: {\n", "");
3474 }
3475 else
3476 {
3477 vkd3d_string_buffer_printf(buffer, " %10s case %u : {\n", "", c->value);
3478 }
3479
3480 dump_block(ctx, buffer, &c->body);
3481 vkd3d_string_buffer_printf(buffer, " %10s }\n", "");
3482 }
3483
3484 vkd3d_string_buffer_printf(buffer, " %10s }", "");
3485}
3486
3487static void dump_instr(struct hlsl_ctx *ctx, struct vkd3d_string_buffer *buffer, const struct hlsl_ir_node *instr)
3488{
3489 if (instr->index)
3490 vkd3d_string_buffer_printf(buffer, "%4u: ", instr->index);
3491 else
3492 vkd3d_string_buffer_printf(buffer, "%p: ", instr);
3493
3494 vkd3d_string_buffer_printf(buffer, "%10s | ", instr->data_type ? debug_hlsl_type(ctx, instr->data_type) : "");
3495
3496 switch (instr->type)
3497 {
3498 case HLSL_IR_CALL:
3500 break;
3501
3502 case HLSL_IR_CONSTANT:
3504 break;
3505
3506 case HLSL_IR_EXPR:
3508 break;
3509
3510 case HLSL_IR_IF:
3511 dump_ir_if(ctx, buffer, hlsl_ir_if(instr));
3512 break;
3513
3514 case HLSL_IR_INDEX:
3516 break;
3517
3518 case HLSL_IR_JUMP:
3520 break;
3521
3522 case HLSL_IR_LOAD:
3523 dump_deref(buffer, &hlsl_ir_load(instr)->src);
3524 break;
3525
3526 case HLSL_IR_LOOP:
3528 break;
3529
3532 break;
3533
3536 break;
3537
3540 break;
3541
3542 case HLSL_IR_STORE:
3544 break;
3545
3546 case HLSL_IR_SWITCH:
3548 break;
3549
3550 case HLSL_IR_SWIZZLE:
3552 break;
3553
3554 case HLSL_IR_COMPILE:
3556 break;
3557
3560 break;
3561
3564 break;
3565
3567 vkd3d_string_buffer_printf(buffer, "vsir_program instruction %u",
3568 hlsl_ir_vsir_instruction_ref(instr)->vsir_instr_idx);
3569 break;
3570 }
3571}
3572
3574{
3576 size_t i;
3577
3579 vkd3d_string_buffer_printf(&buffer, "Dumping function %s.\n", func->func->name);
3580 vkd3d_string_buffer_printf(&buffer, "Function parameters:\n");
3581 for (i = 0; i < func->parameters.count; ++i)
3582 {
3583 dump_ir_var(ctx, &buffer, func->parameters.vars[i]);
3585 }
3586 if (func->has_body)
3587 dump_block(ctx, &buffer, &func->body);
3588
3591}
3592
3594{
3595 unsigned int k, component_count = hlsl_type_component_count(var->data_type);
3597
3599 if (!var->default_values)
3600 {
3601 vkd3d_string_buffer_printf(&buffer, "var \"%s\" has no default values.\n", var->name);
3604 return;
3605 }
3606
3607 vkd3d_string_buffer_printf(&buffer, "var \"%s\" default values:", var->name);
3608 for (k = 0; k < component_count; ++k)
3609 {
3610 bool is_string = var->default_values[k].string;
3611
3612 if (k % 4 == 0 || is_string)
3614
3615 if (is_string)
3616 vkd3d_string_buffer_printf(&buffer, " %s", debugstr_a(var->default_values[k].string));
3617 else
3618 vkd3d_string_buffer_printf(&buffer, " 0x%08x", var->default_values[k].number.u);
3619 }
3621
3624}
3625
3626void hlsl_replace_node(struct hlsl_ir_node *old, struct hlsl_ir_node *new)
3627{
3628 struct hlsl_src *src, *next;
3629
3630 VKD3D_ASSERT(old->data_type == new->data_type || old->data_type->dimx == new->data_type->dimx);
3631 VKD3D_ASSERT(old->data_type == new->data_type || old->data_type->dimy == new->data_type->dimy);
3632
3634 {
3636 hlsl_src_from_node(src, new);
3637 }
3638 list_remove(&old->entry);
3639 hlsl_free_instr(old);
3640}
3641
3642
3644{
3645 struct hlsl_struct_field *field;
3646 size_t i;
3647
3648 vkd3d_free((void *)type->name);
3649 if (type->class == HLSL_CLASS_STRUCT)
3650 {
3651 for (i = 0; i < type->e.record.field_count; ++i)
3652 {
3653 field = &type->e.record.fields[i];
3654
3655 vkd3d_free((void *)field->name);
3656 hlsl_cleanup_semantic(&field->semantic);
3657 }
3658 vkd3d_free((void *)type->e.record.fields);
3659 }
3661}
3662
3664{
3665 struct hlsl_ir_node *node, *next_node;
3666
3667 if (!list)
3668 return;
3669 /* Iterate in reverse, to avoid use-after-free when unlinking sources from
3670 * the "uses" list. */
3673}
3674
3676{
3677 hlsl_free_instr_list(&block->instrs);
3678}
3679
3680static void free_ir_call(struct hlsl_ir_call *call)
3681{
3682 vkd3d_free(call);
3683}
3684
3686{
3688}
3689
3690static void free_ir_expr(struct hlsl_ir_expr *expr)
3691{
3692 unsigned int i;
3693
3694 for (i = 0; i < ARRAY_SIZE(expr->operands); ++i)
3695 hlsl_src_remove(&expr->operands[i]);
3697}
3698
3699static void free_ir_if(struct hlsl_ir_if *if_node)
3700{
3701 hlsl_block_cleanup(&if_node->then_block);
3702 hlsl_block_cleanup(&if_node->else_block);
3703 hlsl_src_remove(&if_node->condition);
3704 vkd3d_free(if_node);
3705}
3706
3707static void free_ir_jump(struct hlsl_ir_jump *jump)
3708{
3709 hlsl_src_remove(&jump->condition);
3710 vkd3d_free(jump);
3711}
3712
3713static void free_ir_load(struct hlsl_ir_load *load)
3714{
3715 hlsl_cleanup_deref(&load->src);
3717}
3718
3719static void free_ir_loop(struct hlsl_ir_loop *loop)
3720{
3721 hlsl_block_cleanup(&loop->body);
3722 vkd3d_free(loop);
3723}
3724
3726{
3727 hlsl_cleanup_deref(&load->sampler);
3728 hlsl_cleanup_deref(&load->resource);
3729 hlsl_src_remove(&load->coords);
3730 hlsl_src_remove(&load->lod);
3731 hlsl_src_remove(&load->ddx);
3732 hlsl_src_remove(&load->ddy);
3733 hlsl_src_remove(&load->cmp);
3734 hlsl_src_remove(&load->texel_offset);
3735 hlsl_src_remove(&load->sample_index);
3737}
3738
3740{
3741 vkd3d_free(string->string);
3742 vkd3d_free(string);
3743}
3744
3746{
3748 hlsl_src_remove(&store->coords);
3749 hlsl_src_remove(&store->value);
3750 vkd3d_free(store);
3751}
3752
3753static void free_ir_store(struct hlsl_ir_store *store)
3754{
3755 hlsl_src_remove(&store->rhs);
3756 hlsl_cleanup_deref(&store->lhs);
3757 vkd3d_free(store);
3758}
3759
3761{
3762 hlsl_src_remove(&swizzle->val);
3764}
3765
3766static void free_ir_switch(struct hlsl_ir_switch *s)
3767{
3768 hlsl_src_remove(&s->selector);
3770
3771 vkd3d_free(s);
3772}
3773
3775{
3776 hlsl_src_remove(&index->val);
3777 hlsl_src_remove(&index->idx);
3779}
3780
3781static void free_ir_compile(struct hlsl_ir_compile *compile)
3782{
3783 unsigned int i;
3784
3785 for (i = 0; i < compile->args_count; ++i)
3786 hlsl_src_remove(&compile->args[i]);
3787
3788 hlsl_block_cleanup(&compile->instrs);
3789 vkd3d_free(compile);
3790}
3791
3792static void free_ir_sampler_state(struct hlsl_ir_sampler_state *sampler_state)
3793{
3794 if (sampler_state->state_block)
3795 hlsl_free_state_block(sampler_state->state_block);
3796 vkd3d_free(sampler_state);
3797}
3798
3800{
3801 vkd3d_free(constant->name);
3803}
3804
3806{
3807 VKD3D_ASSERT(list_empty(&node->uses));
3808
3809 switch (node->type)
3810 {
3811 case HLSL_IR_CALL:
3813 break;
3814
3815 case HLSL_IR_CONSTANT:
3817 break;
3818
3819 case HLSL_IR_EXPR:
3821 break;
3822
3823 case HLSL_IR_IF:
3825 break;
3826
3827 case HLSL_IR_INDEX:
3829 break;
3830
3831 case HLSL_IR_JUMP:
3833 break;
3834
3835 case HLSL_IR_LOAD:
3837 break;
3838
3839 case HLSL_IR_LOOP:
3841 break;
3842
3845 break;
3846
3849 break;
3850
3853 break;
3854
3855 case HLSL_IR_STORE:
3857 break;
3858
3859 case HLSL_IR_SWIZZLE:
3861 break;
3862
3863 case HLSL_IR_SWITCH:
3865 break;
3866
3867 case HLSL_IR_COMPILE:
3869 break;
3870
3873 break;
3874
3877 break;
3878
3881 break;
3882 }
3883}
3884
3886{
3887 unsigned int i;
3888
3889 for (i = 0; i < attr->args_count; ++i)
3890 hlsl_src_remove(&attr->args[i]);
3891 hlsl_block_cleanup(&attr->instrs);
3892 vkd3d_free((void *)attr->name);
3894}
3895
3897{
3898 vkd3d_free((void *)semantic->name);
3899 vkd3d_free((void *)semantic->raw_name);
3900 memset(semantic, 0, sizeof(*semantic));
3901}
3902
3904{
3905 *dst = *src;
3906 dst->name = dst->raw_name = NULL;
3907 if (src->name && !(dst->name = hlsl_strdup(ctx, src->name)))
3908 return false;
3909 if (src->raw_name && !(dst->raw_name = hlsl_strdup(ctx, src->raw_name)))
3910 {
3912 return false;
3913 }
3914
3915 return true;
3916}
3917
3919{
3920 unsigned int i;
3921
3922 for (i = 0; i < decl->attr_count; ++i)
3923 hlsl_free_attribute((void *)decl->attrs[i]);
3924 vkd3d_free((void *)decl->attrs);
3925
3926 vkd3d_free(decl->parameters.vars);
3927 hlsl_block_cleanup(&decl->body);
3928 vkd3d_free(decl);
3929}
3930
3932{
3933 struct hlsl_ir_function_decl *decl, *next;
3934
3935 LIST_FOR_EACH_ENTRY_SAFE(decl, next, &func->overloads, struct hlsl_ir_function_decl, entry)
3936 free_function_decl(decl);
3937 vkd3d_free((void *)func->name);
3939}
3940
3941static void free_function_rb(struct rb_entry *entry, void *context)
3942{
3944}
3945
3946void hlsl_add_function(struct hlsl_ctx *ctx, char *name, struct hlsl_ir_function_decl *decl)
3947{
3948 struct hlsl_ir_function *func;
3949 struct rb_entry *func_entry;
3950
3951 if (ctx->internal_func_name)
3952 {
3953 char *internal_name;
3954
3955 if (!(internal_name = hlsl_strdup(ctx, ctx->internal_func_name)))
3956 return;
3958 name = internal_name;
3959 }
3960
3961 func_entry = rb_get(&ctx->functions, name);
3962 if (func_entry)
3963 {
3964 func = RB_ENTRY_VALUE(func_entry, struct hlsl_ir_function, entry);
3965 decl->func = func;
3966 list_add_tail(&func->overloads, &decl->entry);
3968 return;
3969 }
3970 func = hlsl_alloc(ctx, sizeof(*func));
3971 func->name = name;
3972 list_init(&func->overloads);
3973 decl->func = func;
3974 list_add_tail(&func->overloads, &decl->entry);
3975 rb_put(&ctx->functions, func->name, &func->entry);
3976}
3977
3979{
3980 uint32_t ret = 0;
3981 unsigned int i;
3982
3983 /* Leave replicate swizzles alone; some instructions need them. */
3984 if (swizzle == HLSL_SWIZZLE(X, X, X, X)
3985 || swizzle == HLSL_SWIZZLE(Y, Y, Y, Y)
3986 || swizzle == HLSL_SWIZZLE(Z, Z, Z, Z)
3987 || swizzle == HLSL_SWIZZLE(W, W, W, W))
3988 return swizzle;
3989
3990 for (i = 0; i < 4; ++i)
3991 {
3992 if (writemask & (1 << i))
3993 {
3994 ret |= (swizzle & 3) << (i * 2);
3995 swizzle >>= 2;
3996 }
3997 }
3998 return ret;
3999}
4000
4002{
4003 static const unsigned int swizzles[16] =
4004 {
4005 0,
4006 HLSL_SWIZZLE(X, X, X, X),
4007 HLSL_SWIZZLE(Y, Y, Y, Y),
4008 HLSL_SWIZZLE(X, Y, X, X),
4009 HLSL_SWIZZLE(Z, Z, Z, Z),
4010 HLSL_SWIZZLE(X, Z, X, X),
4011 HLSL_SWIZZLE(Y, Z, X, X),
4012 HLSL_SWIZZLE(X, Y, Z, X),
4013 HLSL_SWIZZLE(W, W, W, W),
4014 HLSL_SWIZZLE(X, W, X, X),
4015 HLSL_SWIZZLE(Y, W, X, X),
4016 HLSL_SWIZZLE(X, Y, W, X),
4017 HLSL_SWIZZLE(Z, W, X, X),
4018 HLSL_SWIZZLE(X, Z, W, X),
4019 HLSL_SWIZZLE(Y, Z, W, X),
4020 HLSL_SWIZZLE(X, Y, Z, W),
4021 };
4022
4023 return swizzles[writemask & 0xf];
4024}
4025
4026unsigned int hlsl_combine_writemasks(unsigned int first, unsigned int second)
4027{
4028 unsigned int ret = 0, i, j = 0;
4029
4030 for (i = 0; i < 4; ++i)
4031 {
4032 if (first & (1 << i))
4033 {
4034 if (second & (1 << j++))
4035 ret |= (1 << i);
4036 }
4037 }
4038
4039 return ret;
4040}
4041
4043{
4044 uint32_t ret = 0;
4045 unsigned int i;
4046 for (i = 0; i < dim; ++i)
4047 {
4048 unsigned int s = hlsl_swizzle_get_component(second, i);
4050 }
4051 return ret;
4052}
4053
4055{
4056 unsigned int i;
4057
4058 static const struct hlsl_profile_info profiles[] =
4059 {
4060 {"cs_4_0", VKD3D_SHADER_TYPE_COMPUTE, 4, 0, 0, 0, false},
4061 {"cs_4_1", VKD3D_SHADER_TYPE_COMPUTE, 4, 1, 0, 0, false},
4062 {"cs_5_0", VKD3D_SHADER_TYPE_COMPUTE, 5, 0, 0, 0, false},
4063 {"cs_5_1", VKD3D_SHADER_TYPE_COMPUTE, 5, 1, 0, 0, false},
4064 {"ds_5_0", VKD3D_SHADER_TYPE_DOMAIN, 5, 0, 0, 0, false},
4065 {"ds_5_1", VKD3D_SHADER_TYPE_DOMAIN, 5, 1, 0, 0, false},
4066 {"fx_2_0", VKD3D_SHADER_TYPE_EFFECT, 2, 0, 0, 0, false},
4067 {"fx_4_0", VKD3D_SHADER_TYPE_EFFECT, 4, 0, 0, 0, false},
4068 {"fx_4_1", VKD3D_SHADER_TYPE_EFFECT, 4, 1, 0, 0, false},
4069 {"fx_5_0", VKD3D_SHADER_TYPE_EFFECT, 5, 0, 0, 0, false},
4070 {"gs_4_0", VKD3D_SHADER_TYPE_GEOMETRY, 4, 0, 0, 0, false},
4071 {"gs_4_1", VKD3D_SHADER_TYPE_GEOMETRY, 4, 1, 0, 0, false},
4072 {"gs_5_0", VKD3D_SHADER_TYPE_GEOMETRY, 5, 0, 0, 0, false},
4073 {"gs_5_1", VKD3D_SHADER_TYPE_GEOMETRY, 5, 1, 0, 0, false},
4074 {"hs_5_0", VKD3D_SHADER_TYPE_HULL, 5, 0, 0, 0, false},
4075 {"hs_5_1", VKD3D_SHADER_TYPE_HULL, 5, 1, 0, 0, false},
4076 {"ps.1.0", VKD3D_SHADER_TYPE_PIXEL, 1, 0, 0, 0, false},
4077 {"ps.1.1", VKD3D_SHADER_TYPE_PIXEL, 1, 1, 0, 0, false},
4078 {"ps.1.2", VKD3D_SHADER_TYPE_PIXEL, 1, 2, 0, 0, false},
4079 {"ps.1.3", VKD3D_SHADER_TYPE_PIXEL, 1, 3, 0, 0, false},
4080 {"ps.1.4", VKD3D_SHADER_TYPE_PIXEL, 1, 4, 0, 0, false},
4081 {"ps.2.0", VKD3D_SHADER_TYPE_PIXEL, 2, 0, 0, 0, false},
4082 {"ps.2.a", VKD3D_SHADER_TYPE_PIXEL, 2, 1, 0, 0, false},
4083 {"ps.2.b", VKD3D_SHADER_TYPE_PIXEL, 2, 2, 0, 0, false},
4084 {"ps.2.sw", VKD3D_SHADER_TYPE_PIXEL, 2, 0, 0, 0, true},
4085 {"ps.3.0", VKD3D_SHADER_TYPE_PIXEL, 3, 0, 0, 0, false},
4086 {"ps_1_0", VKD3D_SHADER_TYPE_PIXEL, 1, 0, 0, 0, false},
4087 {"ps_1_1", VKD3D_SHADER_TYPE_PIXEL, 1, 1, 0, 0, false},
4088 {"ps_1_2", VKD3D_SHADER_TYPE_PIXEL, 1, 2, 0, 0, false},
4089 {"ps_1_3", VKD3D_SHADER_TYPE_PIXEL, 1, 3, 0, 0, false},
4090 {"ps_1_4", VKD3D_SHADER_TYPE_PIXEL, 1, 4, 0, 0, false},
4091 {"ps_2_0", VKD3D_SHADER_TYPE_PIXEL, 2, 0, 0, 0, false},
4092 {"ps_2_a", VKD3D_SHADER_TYPE_PIXEL, 2, 1, 0, 0, false},
4093 {"ps_2_b", VKD3D_SHADER_TYPE_PIXEL, 2, 2, 0, 0, false},
4094 {"ps_2_sw", VKD3D_SHADER_TYPE_PIXEL, 2, 0, 0, 0, true},
4095 {"ps_3_0", VKD3D_SHADER_TYPE_PIXEL, 3, 0, 0, 0, false},
4096 {"ps_3_sw", VKD3D_SHADER_TYPE_PIXEL, 3, 0, 0, 0, true},
4097 {"ps_4_0", VKD3D_SHADER_TYPE_PIXEL, 4, 0, 0, 0, false},
4098 {"ps_4_0_level_9_0", VKD3D_SHADER_TYPE_PIXEL, 4, 0, 9, 0, false},
4099 {"ps_4_0_level_9_1", VKD3D_SHADER_TYPE_PIXEL, 4, 0, 9, 1, false},
4100 {"ps_4_0_level_9_3", VKD3D_SHADER_TYPE_PIXEL, 4, 0, 9, 3, false},
4101 {"ps_4_1", VKD3D_SHADER_TYPE_PIXEL, 4, 1, 0, 0, false},
4102 {"ps_5_0", VKD3D_SHADER_TYPE_PIXEL, 5, 0, 0, 0, false},
4103 {"ps_5_1", VKD3D_SHADER_TYPE_PIXEL, 5, 1, 0, 0, false},
4104 {"tx_1_0", VKD3D_SHADER_TYPE_TEXTURE, 1, 0, 0, 0, false},
4105 {"vs.1.0", VKD3D_SHADER_TYPE_VERTEX, 1, 0, 0, 0, false},
4106 {"vs.1.1", VKD3D_SHADER_TYPE_VERTEX, 1, 1, 0, 0, false},
4107 {"vs.2.0", VKD3D_SHADER_TYPE_VERTEX, 2, 0, 0, 0, false},
4108 {"vs.2.a", VKD3D_SHADER_TYPE_VERTEX, 2, 1, 0, 0, false},
4109 {"vs.2.sw", VKD3D_SHADER_TYPE_VERTEX, 2, 0, 0, 0, true},
4110 {"vs.3.0", VKD3D_SHADER_TYPE_VERTEX, 3, 0, 0, 0, false},
4111 {"vs.3.sw", VKD3D_SHADER_TYPE_VERTEX, 3, 0, 0, 0, true},
4112 {"vs_1_0", VKD3D_SHADER_TYPE_VERTEX, 1, 0, 0, 0, false},
4113 {"vs_1_1", VKD3D_SHADER_TYPE_VERTEX, 1, 1, 0, 0, false},
4114 {"vs_2_0", VKD3D_SHADER_TYPE_VERTEX, 2, 0, 0, 0, false},
4115 {"vs_2_a", VKD3D_SHADER_TYPE_VERTEX, 2, 1, 0, 0, false},
4116 {"vs_2_sw", VKD3D_SHADER_TYPE_VERTEX, 2, 0, 0, 0, true},
4117 {"vs_3_0", VKD3D_SHADER_TYPE_VERTEX, 3, 0, 0, 0, false},
4118 {"vs_3_sw", VKD3D_SHADER_TYPE_VERTEX, 3, 0, 0, 0, true},
4119 {"vs_4_0", VKD3D_SHADER_TYPE_VERTEX, 4, 0, 0, 0, false},
4120 {"vs_4_0_level_9_0", VKD3D_SHADER_TYPE_VERTEX, 4, 0, 9, 0, false},
4121 {"vs_4_0_level_9_1", VKD3D_SHADER_TYPE_VERTEX, 4, 0, 9, 1, false},
4122 {"vs_4_0_level_9_3", VKD3D_SHADER_TYPE_VERTEX, 4, 0, 9, 3, false},
4123 {"vs_4_1", VKD3D_SHADER_TYPE_VERTEX, 4, 1, 0, 0, false},
4124 {"vs_5_0", VKD3D_SHADER_TYPE_VERTEX, 5, 0, 0, 0, false},
4125 {"vs_5_1", VKD3D_SHADER_TYPE_VERTEX, 5, 1, 0, 0, false},
4126 };
4127
4128 for (i = 0; i < ARRAY_SIZE(profiles); ++i)
4129 {
4130 if (!strcmp(target, profiles[i].name))
4131 return &profiles[i];
4132 }
4133
4134 return NULL;
4135}
4136
4137static int compare_function_rb(const void *key, const struct rb_entry *entry)
4138{
4139 const char *name = key;
4140 const struct hlsl_ir_function *func = RB_ENTRY_VALUE(entry, const struct hlsl_ir_function,entry);
4141
4142 return strcmp(name, func->name);
4143}
4144
4146{
4147 struct vkd3d_string_buffer *name;
4148 unsigned int x, y, bt, i, v;
4149 struct hlsl_type *type;
4150
4151 static const char * const names[] =
4152 {
4153 [HLSL_TYPE_FLOAT] = "float",
4154 [HLSL_TYPE_HALF] = "half",
4155 [HLSL_TYPE_DOUBLE] = "double",
4156 [HLSL_TYPE_INT] = "int",
4157 [HLSL_TYPE_UINT] = "uint",
4158 [HLSL_TYPE_BOOL] = "bool",
4159 };
4160
4161 static const char *const variants_float[] = {"min10float", "min16float"};
4162 static const char *const variants_int[] = {"min12int", "min16int"};
4163 static const char *const variants_uint[] = {"min16uint"};
4164
4165 static const char *const sampler_names[] =
4166 {
4167 [HLSL_SAMPLER_DIM_GENERIC] = "sampler",
4168 [HLSL_SAMPLER_DIM_COMPARISON] = "SamplerComparisonState",
4169 [HLSL_SAMPLER_DIM_1D] = "sampler1D",
4170 [HLSL_SAMPLER_DIM_2D] = "sampler2D",
4171 [HLSL_SAMPLER_DIM_3D] = "sampler3D",
4172 [HLSL_SAMPLER_DIM_CUBE] = "samplerCUBE",
4173 };
4174
4175 static const struct
4176 {
4177 char name[20];
4178 enum hlsl_type_class class;
4179 enum hlsl_base_type base_type;
4180 unsigned int dimx, dimy;
4181 }
4182 effect_types[] =
4183 {
4184 {"dword", HLSL_CLASS_SCALAR, HLSL_TYPE_UINT, 1, 1},
4185 {"vector", HLSL_CLASS_VECTOR, HLSL_TYPE_FLOAT, 4, 1},
4186 {"matrix", HLSL_CLASS_MATRIX, HLSL_TYPE_FLOAT, 4, 4},
4187 };
4188
4189 static const struct
4190 {
4191 const char *name;
4192 unsigned int version;
4193 }
4194 technique_types[] =
4195 {
4196 {"technique", 9},
4197 {"technique10", 10},
4198 {"technique11", 11},
4199 };
4200
4202 return;
4203
4204 for (bt = 0; bt <= HLSL_TYPE_LAST_SCALAR; ++bt)
4205 {
4206 for (y = 1; y <= 4; ++y)
4207 {
4208 for (x = 1; x <= 4; ++x)
4209 {
4211 vkd3d_string_buffer_printf(name, "%s%ux%u", names[bt], y, x);
4212 type = hlsl_new_type(ctx, name->buffer, HLSL_CLASS_MATRIX, bt, x, y);
4213 hlsl_scope_add_type(ctx->globals, type);
4214 ctx->builtin_types.matrix[bt][x - 1][y - 1] = type;
4215
4216 if (y == 1)
4217 {
4219 vkd3d_string_buffer_printf(name, "%s%u", names[bt], x);
4220 type = hlsl_new_type(ctx, name->buffer, HLSL_CLASS_VECTOR, bt, x, y);
4221 hlsl_scope_add_type(ctx->globals, type);
4222 ctx->builtin_types.vector[bt][x - 1] = type;
4223
4224 if (x == 1)
4225 {
4228 type = hlsl_new_type(ctx, name->buffer, HLSL_CLASS_SCALAR, bt, x, y);
4229 hlsl_scope_add_type(ctx->globals, type);
4230 ctx->builtin_types.scalar[bt] = type;
4231 }
4232 }
4233 }
4234 }
4235 }
4236
4237 for (bt = 0; bt <= HLSL_TYPE_LAST_SCALAR; ++bt)
4238 {
4239 const char *const *variants;
4240 unsigned int n_variants;
4241
4242 switch (bt)
4243 {
4244 case HLSL_TYPE_FLOAT:
4245 variants = variants_float;
4246 n_variants = ARRAY_SIZE(variants_float);
4247 break;
4248
4249 case HLSL_TYPE_INT:
4250 variants = variants_int;
4251 n_variants = ARRAY_SIZE(variants_int);
4252 break;
4253
4254 case HLSL_TYPE_UINT:
4255 variants = variants_uint;
4256 n_variants = ARRAY_SIZE(variants_uint);
4257 break;
4258
4259 default:
4260 n_variants = 0;
4261 variants = NULL;
4262 break;
4263 }
4264
4265 for (v = 0; v < n_variants; ++v)
4266 {
4267 for (y = 1; y <= 4; ++y)
4268 {
4269 for (x = 1; x <= 4; ++x)
4270 {
4272 vkd3d_string_buffer_printf(name, "%s%ux%u", variants[v], y, x);
4273 type = hlsl_new_type(ctx, name->buffer, HLSL_CLASS_MATRIX, bt, x, y);
4274 type->is_minimum_precision = 1;
4275 hlsl_scope_add_type(ctx->globals, type);
4276
4277 if (y == 1)
4278 {
4280 vkd3d_string_buffer_printf(name, "%s%u", variants[v], x);
4281 type = hlsl_new_type(ctx, name->buffer, HLSL_CLASS_VECTOR, bt, x, y);
4282 type->is_minimum_precision = 1;
4283 hlsl_scope_add_type(ctx->globals, type);
4284
4285 if (x == 1)
4286 {
4288 vkd3d_string_buffer_printf(name, "%s", variants[v]);
4289 type = hlsl_new_type(ctx, name->buffer, HLSL_CLASS_SCALAR, bt, x, y);
4290 type->is_minimum_precision = 1;
4291 hlsl_scope_add_type(ctx->globals, type);
4292 }
4293 }
4294 }
4295 }
4296 }
4297 }
4298
4299 for (bt = 0; bt <= HLSL_SAMPLER_DIM_LAST_SAMPLER; ++bt)
4300 {
4301 type = hlsl_new_simple_type(ctx, sampler_names[bt], HLSL_CLASS_SAMPLER);
4302 type->sampler_dim = bt;
4303 ctx->builtin_types.sampler[bt] = type;
4304 }
4305
4306 ctx->builtin_types.Void = hlsl_new_simple_type(ctx, "void", HLSL_CLASS_VOID);
4307 ctx->builtin_types.null = hlsl_new_type(ctx, "NULL", HLSL_CLASS_NULL, HLSL_TYPE_UINT, 1, 1);
4308 ctx->builtin_types.string = hlsl_new_simple_type(ctx, "string", HLSL_CLASS_STRING);
4309 ctx->builtin_types.error = hlsl_new_simple_type(ctx, "<error type>", HLSL_CLASS_ERROR);
4310 hlsl_scope_add_type(ctx->globals, ctx->builtin_types.string);
4325
4326 for (i = 0; i < ARRAY_SIZE(effect_types); ++i)
4327 {
4328 type = hlsl_new_type(ctx, effect_types[i].name, effect_types[i].class,
4329 effect_types[i].base_type, effect_types[i].dimx, effect_types[i].dimy);
4330 hlsl_scope_add_type(ctx->globals, type);
4331 }
4332
4333 for (i = 0; i < ARRAY_SIZE(technique_types); ++i)
4334 {
4336 type->e.version = technique_types[i].version;
4337 hlsl_scope_add_type(ctx->globals, type);
4338 }
4339
4341}
4342
4343static bool hlsl_ctx_init(struct hlsl_ctx *ctx, const struct vkd3d_shader_compile_info *compile_info,
4344 const struct hlsl_profile_info *profile, struct vkd3d_shader_message_context *message_context)
4345{
4346 unsigned int i;
4347
4348 memset(ctx, 0, sizeof(*ctx));
4349
4350 ctx->profile = profile;
4351
4352 ctx->message_context = message_context;
4353
4354 if (!(ctx->source_files = hlsl_alloc(ctx, sizeof(*ctx->source_files))))
4355 return false;
4356 if (!(ctx->source_files[0] = hlsl_strdup(ctx, compile_info->source_name ? compile_info->source_name : "<anonymous>")))
4357 {
4358 vkd3d_free(ctx->source_files);
4359 return false;
4360 }
4361 ctx->source_files_count = 1;
4362 ctx->location.source_name = ctx->source_files[0];
4363 ctx->location.line = ctx->location.column = 1;
4364 vkd3d_string_buffer_cache_init(&ctx->string_buffers);
4365
4366 list_init(&ctx->scopes);
4367
4368 if (!(ctx->dummy_scope = hlsl_new_scope(ctx, NULL)))
4369 {
4370 vkd3d_free((void *)ctx->source_files[0]);
4371 vkd3d_free(ctx->source_files);
4372 return false;
4373 }
4375 ctx->globals = ctx->cur_scope;
4376
4377 list_init(&ctx->types);
4379
4380 rb_init(&ctx->functions, compare_function_rb);
4381
4382 hlsl_block_init(&ctx->static_initializers);
4383 list_init(&ctx->extern_vars);
4384
4385 list_init(&ctx->buffers);
4386
4387 if (!(ctx->globals_buffer = hlsl_new_buffer(ctx, HLSL_BUFFER_CONSTANT,
4388 hlsl_strdup(ctx, "$Globals"), 0, NULL, NULL, &ctx->location)))
4389 return false;
4390 if (!(ctx->params_buffer = hlsl_new_buffer(ctx, HLSL_BUFFER_CONSTANT,
4391 hlsl_strdup(ctx, "$Params"), 0, NULL, NULL, &ctx->location)))
4392 return false;
4393 ctx->cur_buffer = ctx->globals_buffer;
4394
4395 ctx->warn_implicit_truncation = true;
4396
4397 for (i = 0; i < compile_info->option_count; ++i)
4398 {
4399 const struct vkd3d_shader_compile_option *option = &compile_info->options[i];
4400
4401 switch (option->name)
4402 {
4405 ctx->matrix_majority = HLSL_MODIFIER_ROW_MAJOR;
4407 ctx->matrix_majority = HLSL_MODIFIER_COLUMN_MAJOR;
4408 break;
4409
4411 ctx->semantic_compat_mapping = option->value & VKD3D_SHADER_COMPILE_OPTION_BACKCOMPAT_MAP_SEMANTIC_NAMES;
4412 ctx->double_as_float_alias = option->value & VKD3D_SHADER_COMPILE_OPTION_DOUBLE_AS_FLOAT_ALIAS;
4413 break;
4414
4416 ctx->child_effect = option->value;
4417 break;
4418
4420 ctx->warn_implicit_truncation = option->value;
4421 break;
4422
4424 ctx->include_empty_buffers = option->value;
4425 break;
4426
4427 default:
4428 break;
4429 }
4430 }
4431
4432 if (!(ctx->error_instr = hlsl_new_error_expr(ctx)))
4433 return false;
4434 hlsl_block_add_instr(&ctx->static_initializers, ctx->error_instr);
4435
4437 ctx->output_control_point_count = UINT_MAX;
4438 ctx->output_primitive = 0;
4439 ctx->partitioning = 0;
4440
4441 return true;
4442}
4443
4444static void hlsl_ctx_cleanup(struct hlsl_ctx *ctx)
4445{
4446 struct hlsl_buffer *buffer, *next_buffer;
4447 struct hlsl_scope *scope, *next_scope;
4448 struct hlsl_ir_var *var, *next_var;
4449 struct hlsl_type *type, *next_type;
4450 unsigned int i;
4451
4452 for (i = 0; i < ctx->source_files_count; ++i)
4453 vkd3d_free((void *)ctx->source_files[i]);
4454 vkd3d_free(ctx->source_files);
4455 vkd3d_string_buffer_cache_cleanup(&ctx->string_buffers);
4456
4457 rb_destroy(&ctx->functions, free_function_rb, NULL);
4458
4459 /* State blocks must be free before the variables, because they contain instructions that may
4460 * refer to them. */
4461 LIST_FOR_EACH_ENTRY_SAFE(scope, next_scope, &ctx->scopes, struct hlsl_scope, entry)
4462 {
4463 LIST_FOR_EACH_ENTRY_SAFE(var, next_var, &scope->vars, struct hlsl_ir_var, scope_entry)
4464 {
4465 for (i = 0; i < var->state_block_count; ++i)
4466 hlsl_free_state_block(var->state_blocks[i]);
4467 vkd3d_free(var->state_blocks);
4468 var->state_blocks = NULL;
4469 var->state_block_count = 0;
4470 var->state_block_capacity = 0;
4471 }
4472 }
4473
4474 hlsl_block_cleanup(&ctx->static_initializers);
4475
4476 LIST_FOR_EACH_ENTRY_SAFE(scope, next_scope, &ctx->scopes, struct hlsl_scope, entry)
4477 {
4478 LIST_FOR_EACH_ENTRY_SAFE(var, next_var, &scope->vars, struct hlsl_ir_var, scope_entry)
4480 rb_destroy(&scope->types, NULL, NULL);
4481 vkd3d_free(scope);
4482 }
4483
4484 LIST_FOR_EACH_ENTRY_SAFE(type, next_type, &ctx->types, struct hlsl_type, entry)
4486
4487 LIST_FOR_EACH_ENTRY_SAFE(buffer, next_buffer, &ctx->buffers, struct hlsl_buffer, entry)
4488 {
4489 vkd3d_free((void *)buffer->name);
4491 }
4492
4493 vkd3d_free(ctx->constant_defs.regs);
4494}
4495
4496int hlsl_compile_shader(const struct vkd3d_shader_code *hlsl, const struct vkd3d_shader_compile_info *compile_info,
4497 struct vkd3d_shader_code *out, struct vkd3d_shader_message_context *message_context)
4498{
4500 const struct vkd3d_shader_hlsl_source_info *hlsl_source_info;
4501 struct hlsl_ir_function_decl *decl, *entry_func = NULL;
4502 const struct hlsl_profile_info *profile;
4503 struct hlsl_ir_function *func;
4504 const char *entry_point;
4505 struct hlsl_ctx ctx;
4506 int ret;
4507
4508 if (!(hlsl_source_info = vkd3d_find_struct(compile_info->next, HLSL_SOURCE_INFO)))
4509 {
4510 ERR("No HLSL source info given.\n");
4512 }
4513 entry_point = hlsl_source_info->entry_point ? hlsl_source_info->entry_point : "main";
4514
4515 if (!(profile = hlsl_get_target_info(hlsl_source_info->profile)))
4516 {
4517 FIXME("Unknown compilation target %s.\n", debugstr_a(hlsl_source_info->profile));
4519 }
4520
4522 {
4524 "The '%s' target profile is only compatible with the 'fx' target type.", profile->name);
4526 }
4527 else if (target_type == VKD3D_SHADER_TARGET_D3D_BYTECODE && profile->major_version > 3)
4528 {
4530 "The '%s' target profile is incompatible with the 'd3dbc' target type.", profile->name);
4532 }
4533 else if (target_type == VKD3D_SHADER_TARGET_DXBC_TPF && profile->major_version < 4)
4534 {
4536 "The '%s' target profile is incompatible with the 'dxbc-tpf' target type.", profile->name);
4538 }
4540 {
4542 "The '%s' target profile is incompatible with the 'fx' target type.", profile->name);
4544 }
4545
4546 if (!hlsl_ctx_init(&ctx, compile_info, profile, message_context))
4548
4549 if ((ret = hlsl_lexer_compile(&ctx, hlsl)) == 2)
4550 {
4553 }
4554
4555 if (ctx.result)
4556 {
4558 return ctx.result;
4559 }
4560
4561 /* If parsing failed without an error condition being recorded, we
4562 * plausibly hit some unimplemented feature. */
4563 if (ret)
4564 {
4567 }
4568
4569 if (ctx.profile->type == VKD3D_SHADER_TYPE_EFFECT)
4570 {
4572
4574 return ret;
4575 }
4576
4577 if ((func = hlsl_get_function(&ctx, entry_point)))
4578 {
4579 LIST_FOR_EACH_ENTRY(decl, &func->overloads, struct hlsl_ir_function_decl, entry)
4580 {
4581 if (!decl->has_body)
4582 continue;
4583 if (entry_func)
4584 {
4585 /* Depending on d3dcompiler version, either the first or last is
4586 * selected. */
4587 hlsl_fixme(&ctx, &decl->loc, "Multiple valid entry point definitions.");
4588 }
4589 entry_func = decl;
4590 }
4591 }
4592
4593 if (!entry_func)
4594 {
4595 const struct vkd3d_shader_location loc = {.source_name = compile_info->source_name};
4596
4598 "Entry point \"%s\" is not defined.", entry_point);
4601 }
4602
4606 {
4608 struct vkd3d_shader_compile_info info = *compile_info;
4609 struct vsir_program program;
4610
4611 if (profile->major_version < 4)
4612 {
4613 if ((ret = hlsl_emit_bytecode(&ctx, entry_func, VKD3D_SHADER_TARGET_D3D_BYTECODE, &info.source)) < 0)
4614 goto done;
4616 ret = d3dbc_parse(&info, config_flags, message_context, &program);
4617 }
4618 else
4619 {
4620 if ((ret = hlsl_emit_bytecode(&ctx, entry_func, VKD3D_SHADER_TARGET_DXBC_TPF, &info.source)) < 0)
4621 goto done;
4622 info.source_type = VKD3D_SHADER_SOURCE_DXBC_TPF;
4623 ret = tpf_parse(&info, config_flags, message_context, &program);
4624 }
4625 if (ret >= 0)
4626 {
4627 ret = vsir_program_compile(&program, config_flags, &info, out, message_context);
4629 }
4631 }
4632 else
4633 {
4634 ret = hlsl_emit_bytecode(&ctx, entry_func, target_type, out);
4635 }
4636
4637done:
4639 return ret;
4640}
4641
4642struct hlsl_ir_function_decl *hlsl_compile_internal_function(struct hlsl_ctx *ctx, const char *name, const char *hlsl)
4643{
4644 const struct hlsl_ir_function_decl *saved_cur_function = ctx->cur_function;
4645 struct vkd3d_shader_code code = {.code = hlsl, .size = strlen(hlsl)};
4646 const char *saved_internal_func_name = ctx->internal_func_name;
4647 struct vkd3d_string_buffer *internal_name;
4649 void *saved_scanner = ctx->scanner;
4650 int ret;
4651
4652 TRACE("name %s, hlsl %s.\n", debugstr_a(name), debugstr_a(hlsl));
4653
4654 /* The actual name of the function is mangled with a unique prefix, both to
4655 * allow defining multiple variants of a function with the same name, and to
4656 * avoid polluting the user name space. */
4657
4658 if (!(internal_name = hlsl_get_string_buffer(ctx)))
4659 return NULL;
4660 vkd3d_string_buffer_printf(internal_name, "<%s-%u>", name, ctx->internal_name_counter++);
4661
4662 /* Save and restore everything that matters.
4663 * Note that saving the scope stack is hard, and shouldn't be necessary. */
4664
4666 ctx->scanner = NULL;
4667 ctx->internal_func_name = internal_name->buffer;
4668 ctx->cur_function = NULL;
4670 ctx->scanner = saved_scanner;
4671 ctx->internal_func_name = saved_internal_func_name;
4672 ctx->cur_function = saved_cur_function;
4674 if (ret)
4675 {
4676 ERR("Failed to compile intrinsic, error %u.\n", ret);
4677 hlsl_release_string_buffer(ctx, internal_name);
4678 return NULL;
4679 }
4680 func = hlsl_get_first_func_decl(ctx, internal_name->buffer);
4681 hlsl_release_string_buffer(ctx, internal_name);
4682 return func;
4683}
#define index(s, c)
Definition: various.h:29
#define ARRAY_SIZE(A)
Definition: main.h:20
static void list_remove(struct list_entry *entry)
Definition: list.h:90
static int list_empty(struct list_entry *head)
Definition: list.h:58
static void list_add_tail(struct list_entry *head, struct list_entry *entry)
Definition: list.h:83
static void list_init(struct list_entry *head)
Definition: list.h:51
#define FIXME(fmt,...)
Definition: precomp.h:53
#define ERR(fmt,...)
Definition: precomp.h:57
Definition: list.h:39
Definition: _map.h:48
_STLP_TEMPLATE_FOR_CONT_EXT size_type count(const _KT &__x) const
Definition: _map.h:214
unsigned int component_count
int d3dbc_parse(const struct vkd3d_shader_compile_info *compile_info, uint64_t config_flags, struct vkd3d_shader_message_context *message_context, struct vsir_program *program)
Definition: d3dbc.c:1349
size_t const element_size
Definition: debug_heap.cpp:510
#define NULL
Definition: types.h:112
INT32 int32_t
Definition: types.h:71
UINT32 uint32_t
Definition: types.h:75
UINT64 uint64_t
Definition: types.h:77
UINT op
Definition: effect.c:235
unsigned int idx
Definition: utils.c:40
#define Z(I)
#define Y(I)
static const WCHAR version[]
Definition: asmname.c:66
BOOL next_node(stream_t *stream, strbuf_t *buf)
Definition: stream.c:140
#define UINT_MAX
Definition: limits.h:27
#define va_end(v)
Definition: stdarg.h:28
#define va_start(v, l)
Definition: stdarg.h:26
_ACRTIMP size_t __cdecl strlen(const char *)
Definition: string.c:1597
_ACRTIMP int __cdecl strcmp(const char *, const char *)
Definition: string.c:3324
char * va_list
Definition: vadefs.h:50
return ret
Definition: mutex.c:147
switch(r->id)
Definition: btrfs.c:3046
int hlsl_emit_effect_binary(struct hlsl_ctx *ctx, struct vkd3d_shader_code *out)
Definition: fx.c:2865
GLint level
Definition: gl.h:1546
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
const GLdouble * v
Definition: gl.h:2040
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLdouble s
Definition: gl.h:2039
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLdouble GLdouble t
Definition: gl.h:2047
GLenum func
Definition: glext.h:6028
GLdouble n
Definition: glext.h:7729
GLenum src
Definition: glext.h:6340
GLuint GLenum swizzle
Definition: glext.h:9511
GLuint GLuint * names
Definition: glext.h:11545
GLuint buffer
Definition: glext.h:5915
GLsizeiptr size
Definition: glext.h:5919
GLenum GLenum GLuint components
Definition: glext.h:9620
GLintptr offset
Definition: glext.h:5920
GLenum condition
Definition: glext.h:9255
GLuint GLuint GLuint GLuint arg1
Definition: glext.h:9513
const GLubyte * c
Definition: glext.h:8905
GLuint coords
Definition: glext.h:7368
GLuint GLuint GLuint GLuint GLuint GLuint GLuint GLuint GLuint GLuint arg3
Definition: glext.h:9515
GLuint index
Definition: glext.h:6031
GLuint GLuint GLuint GLuint GLuint GLuint GLuint arg2
Definition: glext.h:9514
GLuint program
Definition: glext.h:6723
GLfloat f
Definition: glext.h:7540
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLenum const GLfloat * params
Definition: glext.h:5645
GLenum GLenum dst
Definition: glext.h:6340
const GLint * first
Definition: glext.h:5794
GLuint GLfloat * val
Definition: glext.h:7180
GLfloat GLfloat p
Definition: glext.h:8902
GLfloat param
Definition: glext.h:5796
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble * u
Definition: glfuncs.h:240
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
enum wined3d_data_type data_type
Definition: glsl_shader.c:71
unsigned int hlsl_type_get_array_element_reg_size(const struct hlsl_type *type, enum hlsl_regset regset)
Definition: hlsl.c:444
static const char * get_case_insensitive_typename(const char *name)
Definition: hlsl.c:970
static unsigned int traverse_path_from_component_index(struct hlsl_ctx *ctx, struct hlsl_type **type_ptr, unsigned int *index_ptr)
Definition: hlsl.c:540
static bool func_decl_matches(const struct hlsl_ir_function_decl *decl, const struct hlsl_func_parameters *parameters)
Definition: hlsl.c:2662
static struct hlsl_ir_node * clone_if(struct hlsl_ctx *ctx, struct clone_instr_map *map, struct hlsl_ir_if *src)
Definition: hlsl.c:2178
static void dump_deref(struct vkd3d_string_buffer *buffer, const struct hlsl_deref *deref)
Definition: hlsl.c:3030
static struct hlsl_ir_node * clone_resource_store(struct hlsl_ctx *ctx, struct clone_instr_map *map, struct hlsl_ir_resource_store *src)
Definition: hlsl.c:2269
struct hlsl_ir_var * hlsl_get_var(struct hlsl_scope *scope, const char *name)
Definition: hlsl.c:123
static struct hlsl_ir_node * clone_call(struct hlsl_ctx *ctx, struct hlsl_ir_call *src)
Definition: hlsl.c:2157
static void dump_ir_stateblock_constant(struct vkd3d_string_buffer *buffer, const struct hlsl_ir_stateblock_constant *constant)
Definition: hlsl.c:3455
static struct hlsl_ir_node * clone_string_constant(struct hlsl_ctx *ctx, struct hlsl_ir_string_constant *src)
Definition: hlsl.c:2287
bool hlsl_scope_add_type(struct hlsl_scope *scope, struct hlsl_type *type)
Definition: hlsl.c:1285
static void free_ir_loop(struct hlsl_ir_loop *loop)
Definition: hlsl.c:3719
static struct hlsl_ir_node * clone_swizzle(struct hlsl_ctx *ctx, struct clone_instr_map *map, struct hlsl_ir_swizzle *src)
Definition: hlsl.c:2310
static void free_function(struct hlsl_ir_function *func)
Definition: hlsl.c:3931
bool hlsl_clone_block(struct hlsl_ctx *ctx, struct hlsl_block *dst_block, const struct hlsl_block *src_block)
Definition: hlsl.c:2544
static void dump_ir_store(struct vkd3d_string_buffer *buffer, const struct hlsl_ir_store *store)
Definition: hlsl.c:3385
struct vkd3d_string_buffer * hlsl_type_to_string(struct hlsl_ctx *ctx, const struct hlsl_type *type)
Definition: hlsl.c:2696
void hlsl_dump_var_default_values(const struct hlsl_ir_var *var)
Definition: hlsl.c:3593
void hlsl_dump_function(struct hlsl_ctx *ctx, const struct hlsl_ir_function_decl *func)
Definition: hlsl.c:3573
bool hlsl_types_are_equal(const struct hlsl_type *t1, const struct hlsl_type *t2)
Definition: hlsl.c:1095
struct hlsl_ir_node * hlsl_new_float_constant(struct hlsl_ctx *ctx, float f, const struct vkd3d_shader_location *loc)
Definition: hlsl.c:1545
bool hlsl_copy_deref(struct hlsl_ctx *ctx, struct hlsl_deref *deref, const struct hlsl_deref *other)
Definition: hlsl.c:1388
unsigned int hlsl_type_get_sm4_offset(const struct hlsl_type *type, unsigned int offset)
Definition: hlsl.c:332
static struct hlsl_type * hlsl_new_simple_type(struct hlsl_ctx *ctx, const char *name, enum hlsl_type_class class)
Definition: hlsl.c:451
static void dump_ir_constant(struct vkd3d_string_buffer *buffer, const struct hlsl_ir_constant *constant)
Definition: hlsl.c:3134
struct hlsl_ir_node * hlsl_new_sampler_state(struct hlsl_ctx *ctx, const struct hlsl_state_block *state_block, struct vkd3d_shader_location *loc)
Definition: hlsl.c:1937
bool hlsl_add_var(struct hlsl_ctx *ctx, struct hlsl_ir_var *decl, bool local_var)
Definition: hlsl.c:96
struct hlsl_ir_function_decl * hlsl_get_first_func_decl(struct hlsl_ctx *ctx, const char *name)
Definition: hlsl.c:1028
bool hlsl_type_is_resource(const struct hlsl_type *type)
Definition: hlsl.c:240
struct hlsl_type * hlsl_new_uav_type(struct hlsl_ctx *ctx, enum hlsl_sampler_dim dim, struct hlsl_type *format, bool rasteriser_ordered)
Definition: hlsl.c:938
static void hlsl_type_calculate_reg_size(struct hlsl_ctx *ctx, struct hlsl_type *type)
Definition: hlsl.c:345
void hlsl_block_cleanup(struct hlsl_block *block)
Definition: hlsl.c:3675
bool hlsl_index_chain_has_resource_access(struct hlsl_ir_index *index)
Definition: hlsl.c:2013
const char * hlsl_jump_type_to_string(enum hlsl_ir_jump_type type)
Definition: hlsl.c:2979
struct hlsl_ir_var * hlsl_new_synthetic_var(struct hlsl_ctx *ctx, const char *template, struct hlsl_type *type, const struct vkd3d_shader_location *loc)
Definition: hlsl.c:1349
static void dump_ir_resource_load(struct vkd3d_string_buffer *buffer, const struct hlsl_ir_resource_load *load)
Definition: hlsl.c:3307
static bool init_deref_from_component_index(struct hlsl_ctx *ctx, struct hlsl_block *block, struct hlsl_deref *deref, const struct hlsl_deref *prefix, unsigned int index, const struct vkd3d_shader_location *loc)
Definition: hlsl.c:801
void hlsl_add_function(struct hlsl_ctx *ctx, char *name, struct hlsl_ir_function_decl *decl)
Definition: hlsl.c:3946
struct hlsl_ir_node * hlsl_new_stateblock_constant(struct hlsl_ctx *ctx, const char *name, struct vkd3d_shader_location *loc)
Definition: hlsl.c:1978
struct hlsl_ir_node * hlsl_new_loop(struct hlsl_ctx *ctx, struct hlsl_block *block, enum hlsl_ir_loop_unroll_type unroll_type, unsigned int unroll_limit, const struct vkd3d_shader_location *loc)
Definition: hlsl.c:2057
struct hlsl_ir_node * hlsl_new_constant(struct hlsl_ctx *ctx, struct hlsl_type *type, const struct hlsl_constant_value *value, const struct vkd3d_shader_location *loc)
Definition: hlsl.c:1521
static struct hlsl_ir_node * clone_stateblock_constant(struct hlsl_ctx *ctx, struct clone_instr_map *map, struct hlsl_ir_stateblock_constant *constant)
Definition: hlsl.c:2373
static void dump_src(struct vkd3d_string_buffer *buffer, const struct hlsl_src *src)
Definition: hlsl.c:3007
void hlsl_fixme(struct hlsl_ctx *ctx, const struct vkd3d_shader_location *loc, const char *fmt,...)
Definition: hlsl.c:58
void hlsl_pop_scope(struct hlsl_ctx *ctx)
Definition: hlsl.c:2653
void hlsl_free_var(struct hlsl_ir_var *decl)
Definition: hlsl.c:161
unsigned int hlsl_type_component_count(const struct hlsl_type *type)
Definition: hlsl.c:1042
struct hlsl_type * hlsl_get_type(struct hlsl_scope *scope, const char *name, bool recursive, bool case_insensitive)
Definition: hlsl.c:995
static void dump_ir_loop(struct hlsl_ctx *ctx, struct vkd3d_string_buffer *buffer, const struct hlsl_ir_loop *loop)
Definition: hlsl.c:3300
bool hlsl_type_is_row_major(const struct hlsl_type *type)
Definition: hlsl.c:186
static void free_ir_jump(struct hlsl_ir_jump *jump)
Definition: hlsl.c:3707
void hlsl_push_scope(struct hlsl_ctx *ctx)
Definition: hlsl.c:2642
static bool clone_block(struct hlsl_ctx *ctx, struct hlsl_block *dst_block, const struct hlsl_block *src_block, struct clone_instr_map *map)
Definition: hlsl.c:2087
struct hlsl_ir_var * hlsl_new_synthetic_var_named(struct hlsl_ctx *ctx, const char *name, struct hlsl_type *type, const struct vkd3d_shader_location *loc, bool dummy_scope)
Definition: hlsl.c:1363
static void free_ir_compile(struct hlsl_ir_compile *compile)
Definition: hlsl.c:3781
void hlsl_note(struct hlsl_ctx *ctx, const struct vkd3d_shader_location *loc, enum vkd3d_shader_log_level level, const char *fmt,...)
Definition: hlsl.c:25
void hlsl_free_ir_switch_case(struct hlsl_ir_switch_case *c)
Definition: hlsl.c:2429
void hlsl_free_state_block_entry(struct hlsl_state_block_entry *entry)
Definition: hlsl.c:137
struct hlsl_ir_node * hlsl_new_switch(struct hlsl_ctx *ctx, struct hlsl_ir_node *selector, struct list *cases, const struct vkd3d_shader_location *loc)
Definition: hlsl.c:1682
static bool type_is_single_reg(const struct hlsl_type *type)
Definition: hlsl.c:1383
void hlsl_init_simple_deref_from_var(struct hlsl_deref *deref, struct hlsl_ir_var *var)
Definition: hlsl.c:1424
bool hlsl_index_is_noncontiguous(struct hlsl_ir_index *index)
Definition: hlsl.c:1999
static void free_function_rb(struct rb_entry *entry, void *context)
Definition: hlsl.c:3941
struct hlsl_ir_node * hlsl_new_store_index(struct hlsl_ctx *ctx, const struct hlsl_deref *lhs, struct hlsl_ir_node *idx, struct hlsl_ir_node *rhs, unsigned int writemask, const struct vkd3d_shader_location *loc)
Definition: hlsl.c:1448
struct hlsl_ir_node * hlsl_new_int_constant(struct hlsl_ctx *ctx, int32_t n, const struct vkd3d_shader_location *loc)
Definition: hlsl.c:1554
bool hlsl_clone_semantic(struct hlsl_ctx *ctx, struct hlsl_semantic *dst, const struct hlsl_semantic *src)
Definition: hlsl.c:3903
static struct hlsl_ir_node * clone_store(struct hlsl_ctx *ctx, struct clone_instr_map *map, struct hlsl_ir_store *src)
Definition: hlsl.c:2292
struct hlsl_ir_node * hlsl_new_cast(struct hlsl_ctx *ctx, struct hlsl_ir_node *node, struct hlsl_type *type, const struct vkd3d_shader_location *loc)
Definition: hlsl.c:1294
bool hlsl_index_is_resource_access(struct hlsl_ir_index *index)
Definition: hlsl.c:2006
const char * debug_hlsl_type(struct hlsl_ctx *ctx, const struct hlsl_type *type)
Definition: hlsl.c:2889
struct hlsl_type * hlsl_new_cb_type(struct hlsl_ctx *ctx, struct hlsl_type *format)
Definition: hlsl.c:956
bool hlsl_new_store_component(struct hlsl_ctx *ctx, struct hlsl_block *block, const struct hlsl_deref *lhs, unsigned int comp, struct hlsl_ir_node *rhs)
Definition: hlsl.c:1480
void hlsl_free_instr_list(struct list *list)
Definition: hlsl.c:3663
struct hlsl_ir_function_decl * hlsl_get_func_decl(struct hlsl_ctx *ctx, const char *name, const struct hlsl_func_parameters *parameters)
Definition: hlsl.c:2678
static struct hlsl_ir_node * clone_jump(struct hlsl_ctx *ctx, struct clone_instr_map *map, struct hlsl_ir_jump *src)
Definition: hlsl.c:2201
static void free_ir_index(struct hlsl_ir_index *index)
Definition: hlsl.c:3774
static void free_ir_string_constant(struct hlsl_ir_string_constant *string)
Definition: hlsl.c:3739
static void free_ir_constant(struct hlsl_ir_constant *constant)
Definition: hlsl.c:3685
static void dump_instr(struct hlsl_ctx *ctx, struct vkd3d_string_buffer *buffer, const struct hlsl_ir_node *instr)
Definition: hlsl.c:3487
uint32_t hlsl_map_swizzle(uint32_t swizzle, unsigned int writemask)
Definition: hlsl.c:3978
static struct hlsl_ir_node * clone_instr(struct hlsl_ctx *ctx, struct clone_instr_map *map, const struct hlsl_ir_node *instr)
Definition: hlsl.c:2481
struct hlsl_ir_node * hlsl_new_swizzle(struct hlsl_ctx *ctx, uint32_t s, unsigned int components, struct hlsl_ir_node *val, const struct vkd3d_shader_location *loc)
Definition: hlsl.c:1847
const char * debug_hlsl_swizzle(uint32_t swizzle, unsigned int size)
Definition: hlsl.c:3093
static void free_ir_load(struct hlsl_ir_load *load)
Definition: hlsl.c:3713
static void free_ir_resource_store(struct hlsl_ir_resource_store *store)
Definition: hlsl.c:3745
static void dump_ir_if(struct hlsl_ctx *ctx, struct vkd3d_string_buffer *buffer, const struct hlsl_ir_if *if_node)
Definition: hlsl.c:3259
struct hlsl_ir_node * hlsl_new_unary_expr(struct hlsl_ctx *ctx, enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg, const struct vkd3d_shader_location *loc)
Definition: hlsl.c:1611
static void dump_ir_expr(struct vkd3d_string_buffer *buffer, const struct hlsl_ir_expr *expr)
Definition: hlsl.c:3246
void hlsl_cleanup_deref(struct hlsl_deref *deref)
Definition: hlsl.c:1408
static void free_ir_swizzle(struct hlsl_ir_swizzle *swizzle)
Definition: hlsl.c:3760
void hlsl_cleanup_semantic(struct hlsl_semantic *semantic)
Definition: hlsl.c:3896
struct hlsl_ir_load * hlsl_new_var_load(struct hlsl_ctx *ctx, struct hlsl_ir_var *var, const struct vkd3d_shader_location *loc)
Definition: hlsl.c:1757
struct hlsl_type * hlsl_new_struct_type(struct hlsl_ctx *ctx, const char *name, struct hlsl_struct_field *fields, size_t field_count)
Definition: hlsl.c:901
static void clone_src(struct clone_instr_map *map, struct hlsl_src *dst, const struct hlsl_src *src)
Definition: hlsl.c:2152
struct hlsl_buffer * hlsl_new_buffer(struct hlsl_ctx *ctx, enum hlsl_buffer_type type, const char *name, uint32_t modifiers, const struct hlsl_reg_reservation *reservation, struct hlsl_scope *annotations, const struct vkd3d_shader_location *loc)
Definition: hlsl.c:2594
void hlsl_error(struct hlsl_ctx *ctx, const struct vkd3d_shader_location *loc, enum vkd3d_shader_error error, const char *fmt,...)
Definition: hlsl.c:35
void hlsl_warning(struct hlsl_ctx *ctx, const struct vkd3d_shader_location *loc, enum vkd3d_shader_error error, const char *fmt,...)
Definition: hlsl.c:48
static struct hlsl_scope * hlsl_new_scope(struct hlsl_ctx *ctx, struct hlsl_scope *upper)
Definition: hlsl.c:2629
static struct hlsl_ir_node * clone_expr(struct hlsl_ctx *ctx, struct clone_instr_map *map, struct hlsl_ir_expr *src)
Definition: hlsl.c:2167
struct hlsl_ir_node * hlsl_new_load_component(struct hlsl_ctx *ctx, struct hlsl_block *block, const struct hlsl_deref *deref, unsigned int comp, const struct vkd3d_shader_location *loc)
Definition: hlsl.c:1766
struct hlsl_ir_node * hlsl_new_compile(struct hlsl_ctx *ctx, enum hlsl_compile_type compile_type, const char *profile_name, struct hlsl_ir_node **args, unsigned int args_count, struct hlsl_block *args_instrs, const struct vkd3d_shader_location *loc)
Definition: hlsl.c:1866
unsigned int hlsl_type_element_count(const struct hlsl_type *type)
Definition: hlsl.c:209
uint32_t hlsl_swizzle_from_writemask(unsigned int writemask)
Definition: hlsl.c:4001
static void dump_ir_call(struct hlsl_ctx *ctx, struct vkd3d_string_buffer *buffer, const struct hlsl_ir_call *call)
Definition: hlsl.c:3106
struct hlsl_ir_node * hlsl_new_null_constant(struct hlsl_ctx *ctx, const struct vkd3d_shader_location *loc)
Definition: hlsl.c:1589
struct hlsl_type * hlsl_type_clone(struct hlsl_ctx *ctx, struct hlsl_type *old, unsigned int default_majority, uint32_t modifiers)
Definition: hlsl.c:1183
static void dump_ir_jump(struct vkd3d_string_buffer *buffer, const struct hlsl_ir_jump *jump)
Definition: hlsl.c:3270
unsigned int hlsl_type_get_component_offset(struct hlsl_ctx *ctx, struct hlsl_type *type, unsigned int index, enum hlsl_regset *regset)
Definition: hlsl.c:620
int hlsl_compile_shader(const struct vkd3d_shader_code *hlsl, const struct vkd3d_shader_compile_info *compile_info, struct vkd3d_shader_code *out, struct vkd3d_shader_message_context *message_context)
Definition: hlsl.c:4496
struct hlsl_ir_node * hlsl_new_copy(struct hlsl_ctx *ctx, struct hlsl_ir_node *node)
Definition: hlsl.c:1305
static void dump_ir_resource_store(struct vkd3d_string_buffer *buffer, const struct hlsl_ir_resource_store *store)
Definition: hlsl.c:3369
static void free_ir_expr(struct hlsl_ir_expr *expr)
Definition: hlsl.c:3690
struct hlsl_type * hlsl_type_get_component_type(struct hlsl_ctx *ctx, struct hlsl_type *type, unsigned int index)
Definition: hlsl.c:611
static void init_node(struct hlsl_ir_node *node, enum hlsl_ir_node_type type, struct hlsl_type *data_type, const struct vkd3d_shader_location *loc)
Definition: hlsl.c:1430
static void hlsl_ctx_cleanup(struct hlsl_ctx *ctx)
Definition: hlsl.c:4444
struct hlsl_ir_node * hlsl_new_expr(struct hlsl_ctx *ctx, enum hlsl_ir_expr_op op, struct hlsl_ir_node *operands[HLSL_MAX_OPERANDS], struct hlsl_type *data_type, const struct vkd3d_shader_location *loc)
Definition: hlsl.c:1595
static struct hlsl_ir_node * clone_constant(struct hlsl_ctx *ctx, struct hlsl_ir_constant *src)
Definition: hlsl.c:2162
uint32_t hlsl_combine_swizzles(uint32_t first, uint32_t second, unsigned int dim)
Definition: hlsl.c:4042
static struct hlsl_ir_node * clone_index(struct hlsl_ctx *ctx, struct clone_instr_map *map, struct hlsl_ir_index *src)
Definition: hlsl.c:2317
static int compare_function_rb(const void *key, const struct rb_entry *entry)
Definition: hlsl.c:4137
const struct hlsl_type * hlsl_get_multiarray_element_type(const struct hlsl_type *type)
Definition: hlsl.c:226
static bool init_deref(struct hlsl_ctx *ctx, struct hlsl_deref *deref, struct hlsl_ir_var *var, unsigned int path_len)
Definition: hlsl.c:692
unsigned int hlsl_get_multiarray_size(const struct hlsl_type *type)
Definition: hlsl.c:233
bool hlsl_type_is_shader(const struct hlsl_type *type)
Definition: hlsl.c:257
struct hlsl_ir_node * hlsl_new_ternary_expr(struct hlsl_ctx *ctx, enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg1, struct hlsl_ir_node *arg2, struct hlsl_ir_node *arg3)
Definition: hlsl.c:1627
static void declare_predefined_types(struct hlsl_ctx *ctx)
Definition: hlsl.c:4145
static void free_ir_resource_load(struct hlsl_ir_resource_load *load)
Definition: hlsl.c:3725
struct hlsl_ir_node * hlsl_new_uint_constant(struct hlsl_ctx *ctx, unsigned int n, const struct vkd3d_shader_location *loc)
Definition: hlsl.c:1562
static struct hlsl_ir_node * clone_compile(struct hlsl_ctx *ctx, struct clone_instr_map *map, struct hlsl_ir_compile *compile)
Definition: hlsl.c:2328
static struct hlsl_ir_node * clone_sampler_state(struct hlsl_ctx *ctx, struct clone_instr_map *map, struct hlsl_ir_sampler_state *sampler_state)
Definition: hlsl.c:2366
static struct hlsl_ir_node * hlsl_new_error_expr(struct hlsl_ctx *ctx)
Definition: hlsl.c:1637
static void dump_ir_swizzle(struct vkd3d_string_buffer *buffer, const struct hlsl_ir_swizzle *swizzle)
Definition: hlsl.c:3396
struct vkd3d_string_buffer * hlsl_component_to_string(struct hlsl_ctx *ctx, const struct hlsl_ir_var *var, unsigned int index)
Definition: hlsl.c:2864
struct hlsl_type * hlsl_get_element_type_from_path_index(struct hlsl_ctx *ctx, const struct hlsl_type *type, struct hlsl_ir_node *idx)
Definition: hlsl.c:848
static struct hlsl_ir_node * clone_loop(struct hlsl_ctx *ctx, struct clone_instr_map *map, struct hlsl_ir_loop *src)
Definition: hlsl.c:2222
struct hlsl_ir_node * hlsl_new_index(struct hlsl_ctx *ctx, struct hlsl_ir_node *val, struct hlsl_ir_node *idx, const struct vkd3d_shader_location *loc)
Definition: hlsl.c:2022
struct hlsl_type * hlsl_deref_get_type(struct hlsl_ctx *ctx, const struct hlsl_deref *deref)
Definition: hlsl.c:783
static int compare_hlsl_types_rb(const void *key, const struct rb_entry *entry)
Definition: hlsl.c:2613
void hlsl_replace_node(struct hlsl_ir_node *old, struct hlsl_ir_node *new)
Definition: hlsl.c:3626
struct hlsl_ir_node * hlsl_new_resource_store(struct hlsl_ctx *ctx, const struct hlsl_deref *resource, struct hlsl_ir_node *coords, struct hlsl_ir_node *value, const struct vkd3d_shader_location *loc)
Definition: hlsl.c:1833
const char * debug_hlsl_writemask(unsigned int writemask)
Definition: hlsl.c:3074
static void free_ir_call(struct hlsl_ir_call *call)
Definition: hlsl.c:3680
static void free_function_decl(struct hlsl_ir_function_decl *decl)
Definition: hlsl.c:3918
unsigned int hlsl_type_major_size(const struct hlsl_type *type)
Definition: hlsl.c:201
struct hlsl_ir_node * hlsl_new_resource_load(struct hlsl_ctx *ctx, const struct hlsl_resource_load_params *params, const struct vkd3d_shader_location *loc)
Definition: hlsl.c:1794
const char * hlsl_node_type_to_string(enum hlsl_ir_node_type type)
Definition: hlsl.c:2949
static struct hlsl_ir_node * map_instr(const struct clone_instr_map *map, struct hlsl_ir_node *src)
Definition: hlsl.c:2120
static bool hlsl_ctx_init(struct hlsl_ctx *ctx, const struct vkd3d_shader_compile_info *compile_info, const struct hlsl_profile_info *profile, struct vkd3d_shader_message_context *message_context)
Definition: hlsl.c:4343
unsigned int hlsl_combine_writemasks(unsigned int first, unsigned int second)
Definition: hlsl.c:4026
struct hlsl_ir_function_decl * hlsl_new_func_decl(struct hlsl_ctx *ctx, struct hlsl_type *return_type, const struct hlsl_func_parameters *parameters, const struct hlsl_semantic *semantic, const struct vkd3d_shader_location *loc)
Definition: hlsl.c:2554
struct hlsl_type * hlsl_new_texture_type(struct hlsl_ctx *ctx, enum hlsl_sampler_dim dim, struct hlsl_type *format, unsigned int sample_count)
Definition: hlsl.c:920
static void dump_ir_var(struct hlsl_ctx *ctx, struct vkd3d_string_buffer *buffer, const struct hlsl_ir_var *var)
Definition: hlsl.c:3015
static void dump_ir_compile(struct hlsl_ctx *ctx, struct vkd3d_string_buffer *buffer, const struct hlsl_ir_compile *compile)
Definition: hlsl.c:3421
static void free_ir_switch(struct hlsl_ir_switch *s)
Definition: hlsl.c:3766
struct hlsl_type * hlsl_new_array_type(struct hlsl_ctx *ctx, struct hlsl_type *basic_type, unsigned int array_size)
Definition: hlsl.c:880
static bool type_is_single_component(const struct hlsl_type *type)
Definition: hlsl.c:493
const struct hlsl_profile_info * hlsl_get_target_info(const char *target)
Definition: hlsl.c:4054
struct hlsl_ir_node * hlsl_new_binary_expr(struct hlsl_ctx *ctx, enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg1, struct hlsl_ir_node *arg2)
Definition: hlsl.c:1619
static bool clone_deref(struct hlsl_ctx *ctx, struct clone_instr_map *map, struct hlsl_deref *dst, const struct hlsl_deref *src)
Definition: hlsl.c:2136
struct hlsl_ir_switch_case * hlsl_new_switch_case(struct hlsl_ctx *ctx, unsigned int value, bool is_default, struct hlsl_block *body, const struct vkd3d_shader_location *loc)
Definition: hlsl.c:1664
static struct hlsl_type * hlsl_new_type(struct hlsl_ctx *ctx, const char *name, enum hlsl_type_class type_class, enum hlsl_base_type base_type, unsigned dimx, unsigned dimy)
Definition: hlsl.c:470
void hlsl_free_state_block(struct hlsl_state_block *state_block)
Definition: hlsl.c:150
struct hlsl_ir_load * hlsl_new_load_index(struct hlsl_ctx *ctx, const struct hlsl_deref *deref, struct hlsl_ir_node *idx, const struct vkd3d_shader_location *loc)
Definition: hlsl.c:1714
static void free_ir_stateblock_constant(struct hlsl_ir_stateblock_constant *constant)
Definition: hlsl.c:3799
static void free_ir_if(struct hlsl_ir_if *if_node)
Definition: hlsl.c:3699
static struct hlsl_ir_node * clone_resource_load(struct hlsl_ctx *ctx, struct clone_instr_map *map, struct hlsl_ir_resource_load *src)
Definition: hlsl.c:2238
bool hlsl_state_block_add_entry(struct hlsl_state_block *state_block, struct hlsl_state_block_entry *entry)
Definition: hlsl.c:1925
char * hlsl_sprintf_alloc(struct hlsl_ctx *ctx, const char *fmt,...)
Definition: hlsl.c:75
struct hlsl_ir_node * hlsl_new_call(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *decl, const struct vkd3d_shader_location *loc)
Definition: hlsl.c:1508
static struct hlsl_ir_node * clone_switch(struct hlsl_ctx *ctx, struct clone_instr_map *map, struct hlsl_ir_switch *s)
Definition: hlsl.c:2446
static void dump_ir_switch(struct hlsl_ctx *ctx, struct vkd3d_string_buffer *buffer, const struct hlsl_ir_switch *s)
Definition: hlsl.c:3461
bool hlsl_init_deref_from_index_chain(struct hlsl_ctx *ctx, struct hlsl_deref *deref, struct hlsl_ir_node *chain)
Definition: hlsl.c:717
unsigned int hlsl_type_minor_size(const struct hlsl_type *type)
Definition: hlsl.c:193
struct hlsl_ir_var * hlsl_new_var(struct hlsl_ctx *ctx, const char *name, struct hlsl_type *type, const struct vkd3d_shader_location *loc, const struct hlsl_semantic *semantic, uint32_t modifiers, const struct hlsl_reg_reservation *reg_reservation)
Definition: hlsl.c:1311
void hlsl_free_type(struct hlsl_type *type)
Definition: hlsl.c:3643
const char * debug_hlsl_expr_op(enum hlsl_ir_expr_op op)
Definition: hlsl.c:3176
static void dump_ir_index(struct vkd3d_string_buffer *buffer, const struct hlsl_ir_index *index)
Definition: hlsl.c:3413
void hlsl_free_attribute(struct hlsl_attribute *attr)
Definition: hlsl.c:3885
static struct hlsl_ir_node * clone_load(struct hlsl_ctx *ctx, struct clone_instr_map *map, struct hlsl_ir_load *src)
Definition: hlsl.c:2206
struct hlsl_ir_node * hlsl_new_vsir_instruction_ref(struct hlsl_ctx *ctx, unsigned int vsir_instr_idx, struct hlsl_type *type, const struct hlsl_reg *reg, const struct vkd3d_shader_location *loc)
Definition: hlsl.c:1698
static void dump_block(struct hlsl_ctx *ctx, struct vkd3d_string_buffer *buffer, const struct hlsl_block *block)
Definition: hlsl.c:2996
static void free_ir_sampler_state(struct hlsl_ir_sampler_state *sampler_state)
Definition: hlsl.c:3792
static void dump_ir_string(struct vkd3d_string_buffer *buffer, const struct hlsl_ir_string_constant *string)
Definition: hlsl.c:3380
static enum hlsl_regset type_get_regset(const struct hlsl_type *type)
Definition: hlsl.c:299
enum hlsl_regset hlsl_deref_get_regset(struct hlsl_ctx *ctx, const struct hlsl_deref *deref)
Definition: hlsl.c:327
struct vkd3d_string_buffer * hlsl_modifiers_to_string(struct hlsl_ctx *ctx, uint32_t modifiers)
Definition: hlsl.c:2901
struct hlsl_ir_function * hlsl_get_function(struct hlsl_ctx *ctx, const char *name)
Definition: hlsl.c:1019
struct hlsl_ir_node * hlsl_new_jump(struct hlsl_ctx *ctx, enum hlsl_ir_jump_type type, struct hlsl_ir_node *condition, const struct vkd3d_shader_location *loc)
Definition: hlsl.c:2044
void hlsl_free_instr(struct hlsl_ir_node *node)
Definition: hlsl.c:3805
struct hlsl_ir_function_decl * hlsl_compile_internal_function(struct hlsl_ctx *ctx, const char *name, const char *hlsl)
Definition: hlsl.c:4642
struct hlsl_ir_node * hlsl_new_if(struct hlsl_ctx *ctx, struct hlsl_ir_node *condition, struct hlsl_block *then_block, struct hlsl_block *else_block, const struct vkd3d_shader_location *loc)
Definition: hlsl.c:1647
struct hlsl_ir_node * hlsl_new_string_constant(struct hlsl_ctx *ctx, const char *str, const struct vkd3d_shader_location *loc)
Definition: hlsl.c:1571
static void free_ir_store(struct hlsl_ir_store *store)
Definition: hlsl.c:3753
void hlsl_cleanup_ir_switch_cases(struct list *cases)
Definition: hlsl.c:2436
struct hlsl_state_block_entry * clone_stateblock_entry(struct hlsl_ctx *ctx, const struct hlsl_state_block_entry *src, const char *name, bool lhs_has_index, unsigned int lhs_index, bool single_arg, unsigned int arg_index)
Definition: hlsl.c:2379
static void dump_ir_sampler_state(struct vkd3d_string_buffer *buffer, const struct hlsl_ir_sampler_state *sampler_state)
Definition: hlsl.c:3449
struct hlsl_ir_node * hlsl_new_bool_constant(struct hlsl_ctx *ctx, bool b, const struct vkd3d_shader_location *loc)
Definition: hlsl.c:1537
struct hlsl_ir_node * hlsl_new_simple_store(struct hlsl_ctx *ctx, struct hlsl_ir_var *lhs, struct hlsl_ir_node *rhs)
Definition: hlsl.c:1440
struct hlsl_ir_load * hlsl_new_load_parent(struct hlsl_ctx *ctx, const struct hlsl_deref *deref, const struct vkd3d_shader_location *loc)
Definition: hlsl.c:1744
#define HLSL_STORAGE_CENTROID
Definition: hlsl.h:411
static void hlsl_src_from_node(struct hlsl_src *src, struct hlsl_ir_node *node)
Definition: hlsl.h:1286
static bool hlsl_array_reserve(struct hlsl_ctx *ctx, void **elements, size_t *capacity, size_t element_count, size_t element_size)
Definition: hlsl.h:1336
hlsl_type_class
Definition: hlsl.h:82
@ HLSL_CLASS_COMPUTE_SHADER
Definition: hlsl.h:102
@ HLSL_CLASS_RASTERIZER_STATE
Definition: hlsl.h:94
@ HLSL_CLASS_RENDER_TARGET_VIEW
Definition: hlsl.h:95
@ HLSL_CLASS_VERTEX_SHADER
Definition: hlsl.h:101
@ HLSL_CLASS_MATRIX
Definition: hlsl.h:85
@ HLSL_CLASS_GEOMETRY_SHADER
Definition: hlsl.h:105
@ HLSL_CLASS_TECHNIQUE
Definition: hlsl.h:98
@ HLSL_CLASS_SAMPLER
Definition: hlsl.h:96
@ HLSL_CLASS_UAV
Definition: hlsl.h:100
@ HLSL_CLASS_VECTOR
Definition: hlsl.h:84
@ HLSL_CLASS_TEXTURE
Definition: hlsl.h:99
@ HLSL_CLASS_DEPTH_STENCIL_VIEW
Definition: hlsl.h:90
@ HLSL_CLASS_STRUCT
Definition: hlsl.h:87
@ HLSL_CLASS_CONSTANT_BUFFER
Definition: hlsl.h:106
@ HLSL_CLASS_VOID
Definition: hlsl.h:108
@ HLSL_CLASS_SCALAR
Definition: hlsl.h:83
@ HLSL_CLASS_EFFECT_GROUP
Definition: hlsl.h:91
@ HLSL_CLASS_PIXEL_SHADER
Definition: hlsl.h:93
@ HLSL_CLASS_BLEND_STATE
Definition: hlsl.h:107
@ HLSL_CLASS_STRING
Definition: hlsl.h:97
@ HLSL_CLASS_HULL_SHADER
Definition: hlsl.h:104
@ HLSL_CLASS_DOMAIN_SHADER
Definition: hlsl.h:103
@ HLSL_CLASS_NULL
Definition: hlsl.h:109
@ HLSL_CLASS_ARRAY
Definition: hlsl.h:88
@ HLSL_CLASS_DEPTH_STENCIL_STATE
Definition: hlsl.h:89
@ HLSL_CLASS_PASS
Definition: hlsl.h:92
@ HLSL_CLASS_ERROR
Definition: hlsl.h:110
static char * hlsl_strdup(struct hlsl_ctx *ctx, const char *string)
Definition: hlsl.h:1327
hlsl_ir_loop_unroll_type
Definition: hlsl.h:648
static struct hlsl_type * hlsl_get_vector_type(const struct hlsl_ctx *ctx, enum hlsl_base_type base_type, unsigned int dimx)
Definition: hlsl.h:1365
#define HLSL_ARRAY_ELEMENTS_COUNT_IMPLICIT
Definition: hlsl.h:429
#define HLSL_STORAGE_UNIFORM
Definition: hlsl.h:403
static void * hlsl_calloc(struct hlsl_ctx *ctx, size_t count, size_t size)
Definition: hlsl.h:1309
hlsl_regset
Definition: hlsl.h:146
@ HLSL_REGSET_NUMERIC
Definition: hlsl.h:151
@ HLSL_REGSET_LAST
Definition: hlsl.h:152
@ HLSL_REGSET_UAVS
Definition: hlsl.h:149
@ HLSL_REGSET_TEXTURES
Definition: hlsl.h:148
@ HLSL_REGSET_SAMPLERS
Definition: hlsl.h:147
@ HLSL_REGSET_LAST_OBJECT
Definition: hlsl.h:150
static void hlsl_block_init(struct hlsl_block *block)
Definition: hlsl.h:1268
hlsl_buffer_type
Definition: hlsl.h:984
@ HLSL_BUFFER_CONSTANT
Definition: hlsl.h:985
hlsl_ir_node_type
Definition: hlsl.h:314
@ HLSL_IR_LOOP
Definition: hlsl.h:321
@ HLSL_IR_SWIZZLE
Definition: hlsl.h:327
@ HLSL_IR_IF
Definition: hlsl.h:318
@ HLSL_IR_STATEBLOCK_CONSTANT
Definition: hlsl.h:332
@ HLSL_IR_INDEX
Definition: hlsl.h:319
@ HLSL_IR_CALL
Definition: hlsl.h:315
@ HLSL_IR_LOAD
Definition: hlsl.h:320
@ HLSL_IR_CONSTANT
Definition: hlsl.h:316
@ HLSL_IR_VSIR_INSTRUCTION_REF
Definition: hlsl.h:334
@ HLSL_IR_COMPILE
Definition: hlsl.h:330
@ HLSL_IR_RESOURCE_LOAD
Definition: hlsl.h:323
@ HLSL_IR_SAMPLER_STATE
Definition: hlsl.h:331
@ HLSL_IR_SWITCH
Definition: hlsl.h:328
@ HLSL_IR_RESOURCE_STORE
Definition: hlsl.h:324
@ HLSL_IR_STORE
Definition: hlsl.h:326
@ HLSL_IR_EXPR
Definition: hlsl.h:317
@ HLSL_IR_JUMP
Definition: hlsl.h:322
@ HLSL_IR_STRING_CONSTANT
Definition: hlsl.h:325
hlsl_base_type
Definition: hlsl.h:114
@ HLSL_TYPE_HALF
Definition: hlsl.h:116
@ HLSL_TYPE_BOOL
Definition: hlsl.h:120
@ HLSL_TYPE_UINT
Definition: hlsl.h:119
@ HLSL_TYPE_LAST_SCALAR
Definition: hlsl.h:121
@ HLSL_TYPE_INT
Definition: hlsl.h:118
@ HLSL_TYPE_FLOAT
Definition: hlsl.h:115
@ HLSL_TYPE_DOUBLE
Definition: hlsl.h:117
#define HLSL_STORAGE_EXTERN
Definition: hlsl.h:397
#define HLSL_STORAGE_GROUPSHARED
Definition: hlsl.h:401
static struct vkd3d_string_buffer * hlsl_get_string_buffer(struct hlsl_ctx *ctx)
Definition: hlsl.h:1346
#define HLSL_SWIZZLE(x, y, z, w)
Definition: hlsl.h:59
#define HLSL_STORAGE_STATIC
Definition: hlsl.h:402
static struct hlsl_type * hlsl_get_scalar_type(const struct hlsl_ctx *ctx, enum hlsl_base_type base_type)
Definition: hlsl.h:1360
#define HLSL_STORAGE_OUT
Definition: hlsl.h:409
#define HLSL_SWIZZLE_SHIFT(idx)
Definition: hlsl.h:66
static void hlsl_block_add_instr(struct hlsl_block *block, struct hlsl_ir_node *instr)
Definition: hlsl.h:1274
#define HLSL_MODIFIER_PRECISE
Definition: hlsl.h:399
@ HLSL_RESOURCE_SAMPLE
Definition: hlsl.h:836
@ HLSL_RESOURCE_GATHER_BLUE
Definition: hlsl.h:845
@ HLSL_RESOURCE_SAMPLE_GRAD
Definition: hlsl.h:841
@ HLSL_RESOURCE_SAMPLE_CMP
Definition: hlsl.h:837
@ HLSL_RESOURCE_SAMPLE_CMP_LZ
Definition: hlsl.h:838
@ HLSL_RESOURCE_RESINFO
Definition: hlsl.h:848
@ HLSL_RESOURCE_SAMPLE_LOD_BIAS
Definition: hlsl.h:840
@ HLSL_RESOURCE_SAMPLE_INFO
Definition: hlsl.h:847
@ HLSL_RESOURCE_GATHER_GREEN
Definition: hlsl.h:844
@ HLSL_RESOURCE_GATHER_RED
Definition: hlsl.h:843
@ HLSL_RESOURCE_SAMPLE_LOD
Definition: hlsl.h:839
@ HLSL_RESOURCE_LOAD
Definition: hlsl.h:835
@ HLSL_RESOURCE_GATHER_ALPHA
Definition: hlsl.h:846
static void * hlsl_alloc(struct hlsl_ctx *ctx, size_t size)
Definition: hlsl.h:1300
static bool hlsl_is_numeric_type(const struct hlsl_type *type)
Definition: hlsl.h:1388
#define HLSL_MODIFIER_CONST
Definition: hlsl.h:405
static void hlsl_block_add_block(struct hlsl_block *block, struct hlsl_block *add)
Definition: hlsl.h:1280
#define HLSL_STORAGE_LINEAR
Definition: hlsl.h:413
hlsl_sampler_dim
Definition: hlsl.h:125
@ HLSL_SAMPLER_DIM_GENERIC
Definition: hlsl.h:126
@ HLSL_SAMPLER_DIM_1DARRAY
Definition: hlsl.h:133
@ HLSL_SAMPLER_DIM_CUBEARRAY
Definition: hlsl.h:137
@ HLSL_SAMPLER_DIM_2DMSARRAY
Definition: hlsl.h:136
@ HLSL_SAMPLER_DIM_BUFFER
Definition: hlsl.h:138
@ HLSL_SAMPLER_DIM_2DMS
Definition: hlsl.h:135
@ HLSL_SAMPLER_DIM_LAST_SAMPLER
Definition: hlsl.h:132
@ HLSL_SAMPLER_DIM_2DARRAY
Definition: hlsl.h:134
@ HLSL_SAMPLER_DIM_CUBE
Definition: hlsl.h:131
@ HLSL_SAMPLER_DIM_3D
Definition: hlsl.h:130
@ HLSL_SAMPLER_DIM_2D
Definition: hlsl.h:129
@ HLSL_SAMPLER_DIM_RAW_BUFFER
Definition: hlsl.h:140
@ HLSL_SAMPLER_DIM_COMPARISON
Definition: hlsl.h:127
@ HLSL_SAMPLER_DIM_STRUCTURED_BUFFER
Definition: hlsl.h:139
@ HLSL_SAMPLER_DIM_1D
Definition: hlsl.h:128
int hlsl_emit_bytecode(struct hlsl_ctx *ctx, struct hlsl_ir_function_decl *entry_func, enum vkd3d_shader_target_type target_type, struct vkd3d_shader_code *out)
int hlsl_lexer_compile(struct hlsl_ctx *ctx, const struct vkd3d_shader_code *hlsl)
static bool hlsl_deref_is_lowered(const struct hlsl_deref *deref)
Definition: hlsl.h:822
#define HLSL_MODIFIER_ROW_MAJOR
Definition: hlsl.h:406
static void hlsl_src_remove(struct hlsl_src *src)
Definition: hlsl.h:1293
#define HLSL_STORAGE_SHARED
Definition: hlsl.h:400
#define HLSL_MODIFIERS_MAJORITY_MASK
Definition: hlsl.h:427
#define HLSL_MAX_OPERANDS
Definition: hlsl.h:750
#define HLSL_MODIFIER_COLUMN_MAJOR
Definition: hlsl.h:407
#define HLSL_STORAGE_IN
Definition: hlsl.h:408
hlsl_ir_expr_op
Definition: hlsl.h:681
@ HLSL_OP2_LESS
Definition: hlsl.h:727
@ HLSL_OP1_DSY
Definition: hlsl.h:695
@ HLSL_OP2_LOGIC_AND
Definition: hlsl.h:728
@ HLSL_OP2_LOGIC_OR
Definition: hlsl.h:729
@ HLSL_OP1_NEG
Definition: hlsl.h:705
@ HLSL_OP1_F32TOF16
Definition: hlsl.h:700
@ HLSL_OP2_DIV
Definition: hlsl.h:723
@ HLSL_OP1_NRM
Definition: hlsl.h:706
@ HLSL_OP1_DSY_COARSE
Definition: hlsl.h:696
@ HLSL_OP1_DSY_FINE
Definition: hlsl.h:697
@ HLSL_OP2_LSHIFT
Definition: hlsl.h:730
@ HLSL_OP2_ADD
Definition: hlsl.h:718
@ HLSL_OP1_SAT
Definition: hlsl.h:711
@ HLSL_OP1_F16TOF32
Definition: hlsl.h:699
@ HLSL_OP2_NEQUAL
Definition: hlsl.h:735
@ HLSL_OP1_DSX_FINE
Definition: hlsl.h:694
@ HLSL_OP1_COS_REDUCED
Definition: hlsl.h:691
@ HLSL_OP2_MIN
Definition: hlsl.h:732
@ HLSL_OP1_BIT_NOT
Definition: hlsl.h:687
@ HLSL_OP1_ABS
Definition: hlsl.h:686
@ HLSL_OP1_CEIL
Definition: hlsl.h:689
@ HLSL_OP2_MAX
Definition: hlsl.h:731
@ HLSL_OP1_TRUNC
Definition: hlsl.h:716
@ HLSL_OP1_FRACT
Definition: hlsl.h:702
@ HLSL_OP2_BIT_XOR
Definition: hlsl.h:721
@ HLSL_OP0_RASTERIZER_SAMPLE_COUNT
Definition: hlsl.h:684
@ HLSL_OP2_BIT_AND
Definition: hlsl.h:719
@ HLSL_OP2_MOD
Definition: hlsl.h:733
@ HLSL_OP3_MAD
Definition: hlsl.h:747
@ HLSL_OP2_RSHIFT
Definition: hlsl.h:736
@ HLSL_OP1_FLOOR
Definition: hlsl.h:701
@ HLSL_OP0_ERROR
Definition: hlsl.h:682
@ HLSL_OP1_COS
Definition: hlsl.h:690
@ HLSL_OP2_MUL
Definition: hlsl.h:734
@ HLSL_OP2_GEQUAL
Definition: hlsl.h:726
@ HLSL_OP2_SLT
Definition: hlsl.h:738
@ HLSL_OP2_EQUAL
Definition: hlsl.h:725
@ HLSL_OP1_ROUND
Definition: hlsl.h:709
@ HLSL_OP1_RCP
Definition: hlsl.h:707
@ HLSL_OP1_DSX
Definition: hlsl.h:692
@ HLSL_OP3_TERNARY
Definition: hlsl.h:746
@ HLSL_OP1_LOG2
Definition: hlsl.h:703
@ HLSL_OP1_EXP2
Definition: hlsl.h:698
@ HLSL_OP0_VOID
Definition: hlsl.h:683
@ HLSL_OP3_DP2ADD
Definition: hlsl.h:742
@ HLSL_OP2_CRS
Definition: hlsl.h:722
@ HLSL_OP3_CMP
Definition: hlsl.h:745
@ HLSL_OP1_LOGIC_NOT
Definition: hlsl.h:704
@ HLSL_OP1_RSQ
Definition: hlsl.h:710
@ HLSL_OP1_DSX_COARSE
Definition: hlsl.h:693
@ HLSL_OP1_SQRT
Definition: hlsl.h:715
@ HLSL_OP2_DOT
Definition: hlsl.h:724
@ HLSL_OP1_SIN
Definition: hlsl.h:713
@ HLSL_OP1_SIGN
Definition: hlsl.h:712
@ HLSL_OP2_BIT_OR
Definition: hlsl.h:720
@ HLSL_OP1_CAST
Definition: hlsl.h:688
@ HLSL_OP1_SIN_REDUCED
Definition: hlsl.h:714
@ HLSL_OP1_REINTERPRET
Definition: hlsl.h:708
static unsigned int hlsl_swizzle_get_component(uint32_t swizzle, unsigned int idx)
Definition: hlsl.h:68
hlsl_ir_jump_type
Definition: hlsl.h:760
@ HLSL_IR_JUMP_DISCARD_NZ
Definition: hlsl.h:764
@ HLSL_IR_JUMP_UNRESOLVED_CONTINUE
Definition: hlsl.h:769
@ HLSL_IR_JUMP_RETURN
Definition: hlsl.h:765
@ HLSL_IR_JUMP_CONTINUE
Definition: hlsl.h:762
@ HLSL_IR_JUMP_DISCARD_NEG
Definition: hlsl.h:763
@ HLSL_IR_JUMP_BREAK
Definition: hlsl.h:761
static void hlsl_release_string_buffer(struct hlsl_ctx *ctx, struct vkd3d_string_buffer *buffer)
Definition: hlsl.h:1355
#define HLSL_MODIFIER_VOLATILE
Definition: hlsl.h:404
#define HLSL_STORAGE_NOINTERPOLATION
Definition: hlsl.h:398
#define HLSL_STORAGE_NOPERSPECTIVE
Definition: hlsl.h:412
static int reg
Definition: i386-dis.c:1290
void vsir_program_cleanup(struct vsir_program *program)
Definition: ir.c:105
uint32_t entry
Definition: isohybrid.c:63
#define d
Definition: ke_i.h:81
#define e
Definition: ke_i.h:82
#define f
Definition: ke_i.h:83
#define c
Definition: ke_i.h:80
#define debugstr_a
Definition: kernel32.h:31
#define profile
Definition: kernel32.h:12
#define error(str)
Definition: mkdosfs.c:1605
char string[160]
Definition: util.h:11
static PVOID ptr
Definition: dispmode.c:27
static DWORD path_len
Definition: batch.c:31
const char * var
Definition: shader.c:5879
D3DXREGISTER_SET regset
Definition: shader.c:5881
const char * fields[10]
Definition: parser.c:313
static const char * target_type(DWORD dwType)
Definition: mixer.c:95
static BYTE parameters[]
Definition: asn.c:558
int k
Definition: mpi.c:3369
int other
Definition: msacm.c:1376
int load
Definition: msacm.c:1365
static UINT array_size
Definition: msctf.cpp:39
static BOOL is_string(parse_buffer *buf)
Definition: parsing.c:581
for(i=0;i< sizeof(testsuite)/sizeof(testsuite[0]);++i) ok(call_test(testsuite[i].func)
static unsigned __int64 next
Definition: rand_nt.c:6
const WCHAR * str
strcpy
Definition: string.h:131
#define LIST_FOR_EACH_ENTRY(elem, list, type, field)
Definition: list.h:236
#define LIST_FOR_EACH_ENTRY_SAFE(cursor, cursor2, list, type, field)
Definition: list.h:242
__WINE_SERVER_LIST_INLINE void list_move_head(struct list *dst, struct list *src)
Definition: list.h:196
#define LIST_FOR_EACH_ENTRY_SAFE_REV(cursor, cursor2, list, type, field)
Definition: list.h:266
#define RB_ENTRY_VALUE(element, type, field)
Definition: rbtree.h:26
static void rb_destroy(struct rb_tree *tree, rb_traverse_func_t *callback, void *context)
Definition: rbtree.h:185
static int rb_put(struct rb_tree *tree, const void *key, struct rb_entry *entry)
Definition: rbtree.h:204
static struct rb_entry * rb_get(const struct rb_tree *tree, const void *key)
Definition: rbtree.h:192
static void rb_init(struct rb_tree *tree, rb_compare_func_t compare)
Definition: rbtree.h:173
static const void * body(MD5_CTX *ctx, const void *data, unsigned long size)
Definition: md5.c:100
#define memset(x, y, z)
Definition: compat.h:39
#define args
Definition: format.c:66
#define TRACE(s)
Definition: solgame.cpp:4
Definition: polytest.cpp:36
Definition: match.c:390
Definition: cookie.c:202
WCHAR * name
Definition: cookie.c:203
struct clone_instr_map::@5996 * instrs
const struct hlsl_ir_node * src
Definition: hlsl.c:2078
struct hlsl_ir_node * dst
Definition: hlsl.c:2079
size_t count
Definition: hlsl.c:2081
size_t capacity
Definition: hlsl.c:2081
Definition: inflate.c:139
union constant::@270 value[4]
Definition: http.c:7252
struct list entry
Definition: wpp.c:51
char * value
Definition: wpp.c:53
char * name
Definition: wpp.c:52
Definition: query.h:86
Definition: parser.c:44
Definition: dsound.c:943
struct list instrs
Definition: hlsl.h:369
struct hlsl_reg_reservation reservation
Definition: hlsl.h:1001
uint32_t modifiers
Definition: hlsl.h:997
struct vkd3d_shader_location loc
Definition: hlsl.h:994
const char * name
Definition: hlsl.h:996
struct hlsl_scope * annotations
Definition: hlsl.h:1003
struct vkd3d_shader_message_context * message_context
Definition: hlsl.h:1026
struct hlsl_type * data_type
Definition: hlsl.h:818
unsigned int path_len
Definition: hlsl.h:805
struct hlsl_src rel_offset
Definition: hlsl.h:816
struct hlsl_src * path
Definition: hlsl.h:806
unsigned int const_offset
Definition: hlsl.h:817
struct hlsl_ir_var * var
Definition: hlsl.h:796
struct hlsl_ir_node node
Definition: hlsl.h:635
struct hlsl_ir_function_decl * decl
Definition: hlsl.h:636
unsigned int args_count
Definition: hlsl.h:918
struct hlsl_src * args
Definition: hlsl.h:917
struct hlsl_block instrs
Definition: hlsl.h:913
const struct hlsl_profile_info * profile
Definition: hlsl.h:909
enum hlsl_ir_compile::hlsl_compile_type compile_type
struct hlsl_ir_node node
Definition: hlsl.h:898
struct hlsl_ir_constant::hlsl_constant_value value
struct hlsl_src operands[HLSL_MAX_OPERANDS]
Definition: hlsl.h:756
const struct hlsl_attribute *const * attrs
Definition: hlsl.h:617
struct list entry
Definition: hlsl.h:605
struct hlsl_func_parameters parameters
Definition: hlsl.h:610
struct hlsl_ir_function * func
Definition: hlsl.h:608
struct hlsl_ir_var * return_var
Definition: hlsl.h:601
unsigned int attr_count
Definition: hlsl.h:616
struct list extern_vars
Definition: hlsl.h:630
struct hlsl_ir_var * early_return_var
Definition: hlsl.h:624
struct vkd3d_shader_location loc
Definition: hlsl.h:603
struct hlsl_type * return_type
Definition: hlsl.h:599
struct hlsl_block body
Definition: hlsl.h:612
struct hlsl_block then_block
Definition: hlsl.h:643
struct hlsl_src condition
Definition: hlsl.h:642
struct hlsl_ir_node node
Definition: hlsl.h:641
struct hlsl_block else_block
Definition: hlsl.h:644
struct hlsl_ir_node node
Definition: hlsl.h:774
struct hlsl_src condition
Definition: hlsl.h:777
enum hlsl_ir_jump_type type
Definition: hlsl.h:775
enum hlsl_ir_loop_unroll_type unroll_type
Definition: hlsl.h:661
unsigned int unroll_limit
Definition: hlsl.h:660
struct hlsl_ir_node node
Definition: hlsl.h:656
struct hlsl_block body
Definition: hlsl.h:658
unsigned int index
Definition: hlsl.h:361
struct list entry
Definition: hlsl.h:341
enum hlsl_ir_node_type type
Definition: hlsl.h:345
struct list uses
Definition: hlsl.h:353
struct hlsl_type * data_type
Definition: hlsl.h:349
struct vkd3d_shader_location loc
Definition: hlsl.h:355
struct hlsl_ir_node node
Definition: hlsl.h:862
struct hlsl_src coords value
Definition: hlsl.h:864
struct hlsl_deref resource
Definition: hlsl.h:863
struct hlsl_ir_node node
Definition: hlsl.h:924
struct hlsl_state_block * state_block
Definition: hlsl.h:926
struct hlsl_src rhs
Definition: hlsl.h:871
struct hlsl_deref lhs
Definition: hlsl.h:870
struct hlsl_ir_node node
Definition: hlsl.h:869
unsigned char writemask
Definition: hlsl.h:872
struct vkd3d_shader_location loc
Definition: hlsl.h:670
unsigned int value
Definition: hlsl.h:666
struct hlsl_src selector
Definition: hlsl.h:676
struct list cases
Definition: hlsl.h:677
const char * name
Definition: hlsl.h:456
struct hlsl_ir_var::hlsl_default_value * default_values
struct hlsl_scope * scope
Definition: hlsl.h:470
struct hlsl_semantic semantic
Definition: hlsl.h:457
struct hlsl_reg_reservation reg_reservation
Definition: hlsl.h:463
struct hlsl_ir_var::@6002 * objects_usage[HLSL_REGSET_LAST_OBJECT+1]
struct hlsl_type * data_type
Definition: hlsl.h:454
struct vkd3d_shader_location loc
Definition: hlsl.h:455
unsigned int state_block_count
Definition: hlsl.h:490
struct list scope_entry
Definition: hlsl.h:466
struct hlsl_state_block ** state_blocks
Definition: hlsl.h:489
struct hlsl_ir_node node
Definition: hlsl.h:941
unsigned int vsir_instr_idx
Definition: hlsl.h:944
enum vkd3d_shader_type type
Definition: hlsl.h:970
Definition: hlsl.h:282
struct rb_tree types
Definition: hlsl.h:956
struct list entry
Definition: hlsl.h:950
struct list vars
Definition: hlsl.h:953
struct hlsl_scope * upper
Definition: hlsl.h:958
const char * name
Definition: hlsl.h:241
const char * raw_name
Definition: hlsl.h:245
Definition: hlsl.h:382
Definition: hlsl.h:549
bool lhs_has_index
Definition: hlsl.h:561
unsigned int lhs_index
Definition: hlsl.h:562
size_t count
Definition: hlsl.h:576
size_t capacity
Definition: hlsl.h:576
struct hlsl_state_block_entry ** entries
Definition: hlsl.h:575
const char * name
Definition: hlsl.h:262
struct hlsl_type * type
Definition: hlsl.h:261
struct hlsl_semantic semantic
Definition: hlsl.h:263
struct vkd3d_shader_location loc
Definition: hlsl.h:260
uint32_t is_minimum_precision
Definition: hlsl.h:234
unsigned int dimx
Definition: hlsl.h:187
struct rb_entry scope_entry
Definition: hlsl.h:161
bool rasteriser_ordered
Definition: hlsl.h:219
struct hlsl_type * format
Definition: hlsl.h:217
struct hlsl_type::@5997::@5998 numeric
size_t field_count
Definition: hlsl.h:203
unsigned int version
Definition: hlsl.h:222
enum hlsl_sampler_dim sampler_dim
Definition: hlsl.h:172
const char * name
Definition: hlsl.h:174
uint32_t modifiers
Definition: hlsl.h:178
struct hlsl_type::@5997::@6000 array
unsigned int sample_count
Definition: hlsl.h:190
union hlsl_type::@5997 e
struct hlsl_type::@5997::@6001 resource
struct hlsl_type::@5997::@5999 record
enum hlsl_type_class class
Definition: hlsl.h:163
unsigned int dimy
Definition: hlsl.h:188
Definition: copy.c:22
Definition: list.h:15
Definition: name.c:39
WCHAR * name
Definition: name.c:42
Definition: getopt.h:109
WCHAR * name
Definition: getopt.h:110
Definition: rbtree.h:30
Definition: tools.h:99
const struct vkd3d_shader_compile_option * options
enum vkd3d_shader_target_type target_type
#define LIST_ENTRY(type)
Definition: queue.h:175
struct sock * chain
Definition: tcpcore.h:1
Character const *const prefix
Definition: tempnam.cpp:195
int tpf_parse(const struct vkd3d_shader_compile_info *compile_info, uint64_t config_flags, struct vkd3d_shader_message_context *message_context, struct vsir_program *program)
Definition: tpf.c:2900
#define new(TYPE, numElems)
Definition: treelist.c:54
Definition: dlist.c:348
Definition: pdh_main.c:64
const char * vkd3d_dbg_sprintf(const char *fmt,...) VKD3D_PRINTF_FUNC(1
#define vkd3d_unreachable()
Definition: vkd3d_common.h:119
#define VKD3D_ASSERT(cond)
Definition: vkd3d_common.h:49
static int ascii_strcasecmp(const char *a, const char *b)
Definition: vkd3d_common.h:437
static void vkd3d_free(void *ptr)
Definition: vkd3d_memory.h:52
bool vkd3d_array_reserve(void **elements, size_t *capacity, size_t element_count, size_t element_size)
Definition: memory.c:22
@ VKD3D_SHADER_COMPILE_OPTION_WARN_IMPLICIT_TRUNCATION
Definition: vkd3d_shader.h:352
@ VKD3D_SHADER_COMPILE_OPTION_BACKWARD_COMPATIBILITY
Definition: vkd3d_shader.h:310
@ VKD3D_SHADER_COMPILE_OPTION_PACK_MATRIX_ORDER
Definition: vkd3d_shader.h:302
@ VKD3D_SHADER_COMPILE_OPTION_CHILD_EFFECT
Definition: vkd3d_shader.h:341
@ VKD3D_SHADER_COMPILE_OPTION_INCLUDE_EMPTY_BUFFERS_IN_EFFECTS
Definition: vkd3d_shader.h:360
VKD3D_SHADER_API void vkd3d_shader_free_shader_code(struct vkd3d_shader_code *code)
@ VKD3D_SHADER_COMPILE_OPTION_BACKCOMPAT_MAP_SEMANTIC_NAMES
Definition: vkd3d_shader.h:193
@ VKD3D_SHADER_COMPILE_OPTION_DOUBLE_AS_FLOAT_ALIAS
Definition: vkd3d_shader.h:204
@ VKD3D_SHADER_SOURCE_D3D_BYTECODE
@ VKD3D_SHADER_SOURCE_DXBC_TPF
vkd3d_shader_log_level
vkd3d_shader_target_type
@ VKD3D_SHADER_TARGET_SPIRV_BINARY
@ VKD3D_SHADER_TARGET_D3D_ASM
@ VKD3D_SHADER_TARGET_SPIRV_TEXT
@ VKD3D_SHADER_TARGET_DXBC_TPF
@ VKD3D_SHADER_TARGET_D3D_BYTECODE
@ VKD3D_SHADER_TARGET_FX
@ VKD3D_SHADER_COMPILE_OPTION_PACK_MATRIX_COLUMN_MAJOR
Definition: vkd3d_shader.h:174
@ VKD3D_SHADER_COMPILE_OPTION_PACK_MATRIX_ROW_MAJOR
Definition: vkd3d_shader.h:173
void vkd3d_string_buffer_init(struct vkd3d_string_buffer *buffer)
int vkd3d_string_buffer_vprintf(struct vkd3d_string_buffer *buffer, const char *format, va_list args)
void vkd3d_shader_verror(struct vkd3d_shader_message_context *context, const struct vkd3d_shader_location *location, enum vkd3d_shader_error error, const char *format, va_list args)
void vkd3d_string_buffer_cleanup(struct vkd3d_string_buffer *buffer)
void vkd3d_string_buffer_clear(struct vkd3d_string_buffer *buffer)
void vkd3d_string_buffer_cache_init(struct vkd3d_string_buffer_cache *cache)
void vkd3d_shader_vwarning(struct vkd3d_shader_message_context *context, const struct vkd3d_shader_location *location, enum vkd3d_shader_error error, const char *format, va_list args)
void vkd3d_string_buffer_cache_cleanup(struct vkd3d_string_buffer_cache *cache)
void vkd3d_shader_vnote(struct vkd3d_shader_message_context *context, const struct vkd3d_shader_location *location, enum vkd3d_shader_log_level level, const char *format, va_list args)
uint64_t vkd3d_shader_init_config_flags(void)
int vsir_program_compile(struct vsir_program *program, uint64_t config_flags, const struct vkd3d_shader_compile_info *compile_info, struct vkd3d_shader_code *out, struct vkd3d_shader_message_context *message_context)
int vkd3d_string_buffer_printf(struct vkd3d_string_buffer *buffer, const char *format,...)
#define vkd3d_find_struct(c, t)
@ VKD3D_SHADER_TYPE_VERTEX
@ VKD3D_SHADER_TYPE_HULL
@ VKD3D_SHADER_TYPE_GEOMETRY
@ VKD3D_SHADER_TYPE_COMPUTE
@ VKD3D_SHADER_TYPE_TEXTURE
@ VKD3D_SHADER_TYPE_PIXEL
@ VKD3D_SHADER_TYPE_EFFECT
@ VKD3D_SHADER_TYPE_DOMAIN
vkd3d_shader_error
@ VKD3D_SHADER_ERROR_HLSL_NOT_IMPLEMENTED
@ VKD3D_SHADER_ERROR_HLSL_INVALID_LVALUE
@ VKD3D_SHADER_ERROR_HLSL_NOT_DEFINED
@ VKD3D_SHADER_ERROR_HLSL_INVALID_PROFILE
@ VKD3D_SHADER_ERROR_HLSL_INCOMPATIBLE_PROFILE
#define VKD3DSP_WRITEMASK_ALL
#define vkd3d_string_buffer_trace(buffer)
@ VKD3D_TESSELLATOR_DOMAIN_INVALID
@ VKD3D_ERROR_INVALID_ARGUMENT
Definition: vkd3d_types.h:51
@ VKD3D_ERROR_NOT_IMPLEMENTED
Definition: vkd3d_types.h:55
@ VKD3D_ERROR_INVALID_SHADER
Definition: vkd3d_types.h:53
@ VKD3D_ERROR_OUT_OF_MEMORY
Definition: vkd3d_types.h:49
wchar_t tm const _CrtWcstime_Writes_and_advances_ptr_ count wchar_t ** out
Definition: wcsftime.cpp:383
static size_t align(size_t addr, size_t alignment)
static unsigned int block
Definition: xmlmemory.c:101