Matteo Bruni : d3dcompiler: Declare predefined data types.

Alexandre Julliard julliard at winehq.org
Tue Sep 18 14:04:31 CDT 2012


Module: wine
Branch: master
Commit: e7a9218ef1d7cdc12f3de26b021f0425ed04ca2a
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=e7a9218ef1d7cdc12f3de26b021f0425ed04ca2a

Author: Matteo Bruni <mbruni at codeweavers.com>
Date:   Tue Sep 18 18:18:05 2012 +0200

d3dcompiler: Declare predefined data types.

---

 dlls/d3dcompiler_43/hlsl.y  |   71 +++++++++++++++++++++++++++++++++++++++++++
 dlls/d3dcompiler_43/utils.c |   10 +++++-
 2 files changed, 80 insertions(+), 1 deletions(-)

diff --git a/dlls/d3dcompiler_43/hlsl.y b/dlls/d3dcompiler_43/hlsl.y
index 7ed50b4..35c9a4c 100644
--- a/dlls/d3dcompiler_43/hlsl.y
+++ b/dlls/d3dcompiler_43/hlsl.y
@@ -175,6 +175,76 @@ static BOOL declare_variable(struct hlsl_ir_var *decl, BOOL local)
 
 static DWORD add_modifier(DWORD modifiers, DWORD mod, const struct YYLTYPE *loc);
 
+BOOL add_type_to_scope(struct hlsl_scope *scope, struct hlsl_type *def)
+{
+    if (get_type(scope, def->name, FALSE))
+        return FALSE;
+
+    list_add_tail(&scope->types, &def->scope_entry);
+    return TRUE;
+}
+
+static void declare_predefined_types(struct hlsl_scope *scope)
+{
+    struct hlsl_type *type;
+    unsigned int x, y, bt;
+    static const char *names[] =
+    {
+        "float",
+        "half",
+        "double",
+        "int",
+        "uint",
+        "bool",
+    };
+    char name[10];
+
+    for (bt = 0; bt <= HLSL_TYPE_LAST_SCALAR; ++bt)
+    {
+        for (y = 1; y <= 4; ++y)
+        {
+            for (x = 1; x <= 4; ++x)
+            {
+                sprintf(name, "%s%ux%u", names[bt], x, y);
+                type = new_hlsl_type(d3dcompiler_strdup(name), HLSL_CLASS_MATRIX, bt, x, y);
+                add_type_to_scope(scope, type);
+
+                if (y == 1)
+                {
+                    sprintf(name, "%s%u", names[bt], x);
+                    type = new_hlsl_type(d3dcompiler_strdup(name), HLSL_CLASS_VECTOR, bt, x, y);
+                    add_type_to_scope(scope, type);
+
+                    if (x == 1)
+                    {
+                        sprintf(name, "%s", names[bt]);
+                        type = new_hlsl_type(d3dcompiler_strdup(name), HLSL_CLASS_SCALAR, bt, x, y);
+                        add_type_to_scope(scope, type);
+                    }
+                }
+            }
+        }
+    }
+
+    /* DX8 effects predefined types */
+    type = new_hlsl_type(d3dcompiler_strdup("DWORD"), HLSL_CLASS_SCALAR, HLSL_TYPE_INT, 1, 1);
+    add_type_to_scope(scope, type);
+    type = new_hlsl_type(d3dcompiler_strdup("FLOAT"), HLSL_CLASS_SCALAR, HLSL_TYPE_FLOAT, 1, 1);
+    add_type_to_scope(scope, type);
+    type = new_hlsl_type(d3dcompiler_strdup("VECTOR"), HLSL_CLASS_VECTOR, HLSL_TYPE_FLOAT, 4, 1);
+    add_type_to_scope(scope, type);
+    type = new_hlsl_type(d3dcompiler_strdup("MATRIX"), HLSL_CLASS_MATRIX, HLSL_TYPE_FLOAT, 4, 4);
+    add_type_to_scope(scope, type);
+    type = new_hlsl_type(d3dcompiler_strdup("STRING"), HLSL_CLASS_OBJECT, HLSL_TYPE_STRING, 1, 1);
+    add_type_to_scope(scope, type);
+    type = new_hlsl_type(d3dcompiler_strdup("TEXTURE"), HLSL_CLASS_OBJECT, HLSL_TYPE_TEXTURE, 1, 1);
+    add_type_to_scope(scope, type);
+    type = new_hlsl_type(d3dcompiler_strdup("PIXELSHADER"), HLSL_CLASS_OBJECT, HLSL_TYPE_PIXELSHADER, 1, 1);
+    add_type_to_scope(scope, type);
+    type = new_hlsl_type(d3dcompiler_strdup("VERTEXSHADER"), HLSL_CLASS_OBJECT, HLSL_TYPE_VERTEXSHADER, 1, 1);
+    add_type_to_scope(scope, type);
+}
+
 static unsigned int components_count_expr_list(struct list *list)
 {
     struct hlsl_ir_node *node;
@@ -1486,6 +1556,7 @@ struct bwriter_shader *parse_hlsl(enum shader_type type, DWORD major, DWORD mino
 
     push_scope(&hlsl_ctx);
     hlsl_ctx.globals = hlsl_ctx.cur_scope;
+    declare_predefined_types(hlsl_ctx.globals);
 
     hlsl_parse();
 
diff --git a/dlls/d3dcompiler_43/utils.c b/dlls/d3dcompiler_43/utils.c
index ad7887a..f288efc 100644
--- a/dlls/d3dcompiler_43/utils.c
+++ b/dlls/d3dcompiler_43/utils.c
@@ -860,7 +860,15 @@ struct hlsl_type *new_array_type(struct hlsl_type *basic_type, unsigned int arra
 
 struct hlsl_type *get_type(struct hlsl_scope *scope, const char *name, BOOL recursive)
 {
-    FIXME("stub.\n");
+    struct hlsl_type *type;
+
+    LIST_FOR_EACH_ENTRY(type, &scope->types, struct hlsl_type, scope_entry)
+    {
+        if (strcmp(type->name, name) == 0)
+            return type;
+    }
+    if (recursive && scope->upper)
+        return get_type(scope->upper, name, recursive);
     return NULL;
 }
 




More information about the wine-cvs mailing list