utils/testparse.c
author Ethan Lee <flibitijibibo@flibitijibibo.com>
Tue, 07 Jul 2020 17:44:32 -0400
changeset 1278 be0f548f321f
parent 1246 cd51a61272e4
permissions -rw-r--r--
spirv: Fix bogus detection of PSIZE0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
244
30ceb789b9a1 More comment headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 192
diff changeset
     1
/**
30ceb789b9a1 More comment headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 192
diff changeset
     2
 * MojoShader; generate shader programs from bytecode of compiled
30ceb789b9a1 More comment headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 192
diff changeset
     3
 *  Direct3D shaders.
30ceb789b9a1 More comment headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 192
diff changeset
     4
 *
30ceb789b9a1 More comment headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 192
diff changeset
     5
 * Please see the file LICENSE.txt in the source's root directory.
30ceb789b9a1 More comment headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 192
diff changeset
     6
 *
30ceb789b9a1 More comment headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 192
diff changeset
     7
 *  This file written by Ryan C. Gordon.
30ceb789b9a1 More comment headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 192
diff changeset
     8
 */
30ceb789b9a1 More comment headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 192
diff changeset
     9
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
    10
#include <stdio.h>
9
aea1b254e6a5 [svn] Patched to compile.
icculus
parents: 7
diff changeset
    11
#include <stdlib.h>
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
    12
#include <string.h>
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
    13
#include <assert.h>
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
    14
#include "../mojoshader.h"
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
    15
#define __MOJOSHADER_INTERNAL__ 1
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
    16
#include "../mojoshader_internal.h"
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
    17
#ifdef MOJOSHADER_HAS_SPIRV_TOOLS
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
    18
#include "spirv-tools/libspirv.h"
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
    19
#endif
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
    20
254
13184ff204b9 More Windows patches.
Ryan C. Gordon <icculus@icculus.org>
parents: 244
diff changeset
    21
#ifdef _MSC_VER
13184ff204b9 More Windows patches.
Ryan C. Gordon <icculus@icculus.org>
parents: 244
diff changeset
    22
#define snprintf _snprintf
13184ff204b9 More Windows patches.
Ryan C. Gordon <icculus@icculus.org>
parents: 244
diff changeset
    23
#endif
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    24
50
427f32b5eeff [svn] Fixed test malloc.
icculus
parents: 48
diff changeset
    25
#if MOJOSHADER_DEBUG_MALLOC
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    26
static void *Malloc(int len)
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    27
{
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    28
    void *ptr = malloc(len + sizeof (int));
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    29
    int *store = (int *) ptr;
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    30
    printf("malloc() %d bytes (%p)\n", len, ptr);
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    31
    if (ptr == NULL) return NULL;
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    32
    *store = len;
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    33
    return (void *) (store + 1);
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    34
} // Malloc
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    35
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    36
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    37
static void Free(void *_ptr)
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    38
{
50
427f32b5eeff [svn] Fixed test malloc.
icculus
parents: 48
diff changeset
    39
    int *ptr = (((int *) _ptr) - 1);
427f32b5eeff [svn] Fixed test malloc.
icculus
parents: 48
diff changeset
    40
    int len = *ptr;
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    41
    printf("free() %d bytes (%p)\n", len, ptr);
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    42
    free(ptr);
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    43
} // Free
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    44
#else
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    45
#define Malloc NULL
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    46
#define Free NULL
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    47
#endif
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    48
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
    49
static inline void do_indent(const unsigned int indent)
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
    50
{
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
    51
    unsigned int i;
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
    52
    for (i = 0; i < indent; i++)
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
    53
        printf("    ");
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
    54
}
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
    55
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
    56
#define INDENT() do { if (indent) { do_indent(indent); } } while (0)
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
    57
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
    58
48
86dc2c772d26 [svn] Enabled -Wall, found some bugs.
icculus
parents: 47
diff changeset
    59
static const char *shader_type(const MOJOSHADER_shaderType s)
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    60
{
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    61
    switch (s)
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    62
    {
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    63
        case MOJOSHADER_TYPE_UNKNOWN: return "unknown";
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    64
        case MOJOSHADER_TYPE_PIXEL: return "pixel";
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    65
        case MOJOSHADER_TYPE_VERTEX: return "vertex";
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    66
        case MOJOSHADER_TYPE_GEOMETRY: return "geometry";
48
86dc2c772d26 [svn] Enabled -Wall, found some bugs.
icculus
parents: 47
diff changeset
    67
        default: return "(bogus value?)";
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    68
    } // switch
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    69
48
86dc2c772d26 [svn] Enabled -Wall, found some bugs.
icculus
parents: 47
diff changeset
    70
    return NULL;  // shouldn't hit this.
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    71
} // shader_type
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    72
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    73
1028
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    74
static void print_typeinfo(const MOJOSHADER_symbolTypeInfo *info,
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    75
                           unsigned int indent)
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    76
{
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    77
    static const char *symclasses[] = {
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    78
        "scalar", "vector", "row-major matrix",
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    79
        "column-major matrix", "object", "struct"
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    80
    };
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    81
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    82
    static const char *symtypes[] = {
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    83
        "void", "bool", "int", "float", "string", "texture",
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    84
        "texture1d", "texture2d", "texture3d", "texturecube",
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    85
        "sampler", "sampler1d", "sampler2d", "sampler3d",
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    86
        "samplercube", "pixelshader", "vertexshader", "unsupported"
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    87
    };
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    88
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    89
    INDENT();
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    90
    printf("      symbol class %s\n", symclasses[info->parameter_class]);
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    91
    INDENT();
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    92
    printf("      symbol type %s\n", symtypes[info->parameter_type]);
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    93
    INDENT();
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    94
    printf("      rows %u\n", info->rows);
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    95
    INDENT();
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    96
    printf("      columns %u\n", info->columns);
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    97
    INDENT();
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    98
    printf("      elements %u\n", info->elements);
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    99
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   100
    if (info->member_count > 0)
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   101
    {
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   102
        int i;
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   103
        INDENT(); printf("      MEMBERS:\n");
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   104
        for (i = 0; i < info->member_count; i++)
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   105
        {
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   106
            const MOJOSHADER_symbolStructMember *member = &info->members[i];
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   107
            INDENT(); printf("      MEMBERS:\n");
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   108
            indent++;
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   109
            INDENT(); printf("      * %d: \"%s\"\n", i, member->name);
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   110
            print_typeinfo(&member->info, indent);
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   111
            indent--;
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   112
        } // for
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   113
    } // if
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   114
} // print_typeinfo
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   115
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   116
1044
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   117
static void print_symbols(const MOJOSHADER_symbol *sym,
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   118
                          const unsigned int symbol_count,
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   119
                          const unsigned int indent)
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   120
{
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   121
    INDENT(); printf("SYMBOLS:");
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   122
    if (symbol_count == 0)
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   123
        printf(" (none.)\n");
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   124
    else
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   125
    {
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   126
        int i;
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   127
        printf("\n");
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   128
        for (i = 0; i < symbol_count; i++, sym++)
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   129
        {
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   130
            static const char *regsets[] = {
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   131
                "bool", "int4", "float4", "sampler"
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   132
            };
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   133
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   134
            INDENT(); printf("    * %d: \"%s\"\n", i, sym->name);
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   135
            INDENT(); printf("      register set %s\n", regsets[sym->register_set]);
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   136
            INDENT(); printf("      register index %u\n", sym->register_index);
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   137
            INDENT(); printf("      register count %u\n", sym->register_count);
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   138
            print_typeinfo(&sym->info, indent);
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   139
        } // for
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   140
        printf("\n");
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   141
    } // else
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   142
} // print_symbols
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   143
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   144
1046
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   145
static void print_preshader_operand(const MOJOSHADER_preshader *preshader,
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   146
                                    const int instidx, const int opidx)
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   147
{
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   148
    static char mask[] = { 'x', 'y', 'z', 'w' };
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   149
    const MOJOSHADER_preshaderInstruction *inst = &preshader->instructions[instidx];
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   150
    const MOJOSHADER_preshaderOperand *operand = &inst->operands[opidx];
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   151
    const int elems = inst->element_count;
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   152
    const int isscalarop = (inst->opcode >= MOJOSHADER_PRESHADEROP_SCALAR_OPS);
1051
96a838f4e680 Fixed off-by-one error in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1046
diff changeset
   153
    const int isscalar = ((isscalarop) && (opidx == 0)); // probably wrong.
1046
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   154
    int i;
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   155
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   156
    switch (operand->type)
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   157
    {
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   158
        case MOJOSHADER_PRESHADEROPERAND_LITERAL:
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   159
        {
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   160
            const double *lit = &preshader->literals[operand->index];
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   161
            printf("(");
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   162
            if (isscalar)
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   163
            {
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   164
                const double val = *lit;
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   165
                for (i = 0; i < elems-1; i++)
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   166
                    printf("%g, ", val);
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   167
                printf("%g)", val);
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   168
            } // if
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   169
            else
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   170
            {
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   171
                for (i = 0; i < elems-1; i++, lit++)
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   172
                    printf("%g, ", *lit);
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   173
                printf("%g)", *lit);
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   174
            } // else
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   175
            break;
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   176
        } // case
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   177
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   178
        case MOJOSHADER_PRESHADEROPERAND_INPUT:
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   179
        case MOJOSHADER_PRESHADEROPERAND_OUTPUT:
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   180
        case MOJOSHADER_PRESHADEROPERAND_TEMP:
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   181
        {
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   182
            int idx = operand->index % 4;
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   183
            char regch = 'c';
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   184
            if (operand->type == MOJOSHADER_PRESHADEROPERAND_TEMP)
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   185
                regch = 'r';
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   186
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   187
            if (operand->array_register_count > 0)
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   188
            {
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   189
                for (i = operand->array_register_count - 1; i >= 0; i--)
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   190
                    printf("c%d[", operand->array_registers[i]);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   191
                printf("%c%d.%c", regch, operand->index / 4, mask[idx]);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   192
                for (i = 0; i < operand->array_register_count; i++)
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   193
                    printf("]");
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   194
                break;
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   195
            } // if
1046
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   196
            printf("%c%d", regch, operand->index / 4);
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   197
            if (isscalar)
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   198
                printf(".%c", mask[idx]);
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   199
            else if (elems != 4)
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   200
            {
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   201
                printf(".");
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   202
                for (i = 0; i < elems; i++)
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   203
                    printf("%c", mask[idx++]);
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   204
            } // else if
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   205
            break;
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   206
        } // case
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   207
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   208
        default:
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   209
            printf("[???{%d, %u}???]", (int) operand->type, operand->index);
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   210
            break;
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   211
    } // switch
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   212
} // print_preshader_operand
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   213
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   214
1030
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   215
static void print_preshader(const MOJOSHADER_preshader *preshader,
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   216
                            const int indent)
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   217
{
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   218
    MOJOSHADER_preshaderInstruction *inst = preshader->instructions;
1046
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   219
    int i, j;
1030
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   220
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   221
    static const char *opcodestr[] = {
1032
464f38a2fb70 Added some more preshader opcodes, cleaned up opcode handling elsewhere.
Ryan C. Gordon <icculus@icculus.org>
parents: 1030
diff changeset
   222
        "nop", "mov", "neg", "rcp", "frc", "exp", "log", "rsq", "sin", "cos",
1034
549f160533fa Found, I think, the final preshader opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1033
diff changeset
   223
        "asin", "acos", "atan", "min", "max", "lt", "ge", "add", "mul",
549f160533fa Found, I think, the final preshader opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1033
diff changeset
   224
        "atan2", "div", "cmp", "movc", "dot", "noise", "min", "max", "lt",
549f160533fa Found, I think, the final preshader opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1033
diff changeset
   225
        "ge", "add", "mul", "atan2", "div", "dot", "noise"
1030
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   226
    };
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   227
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   228
    INDENT(); printf("PRESHADER:\n");
1044
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   229
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   230
    print_symbols(preshader->symbols, preshader->symbol_count, indent + 1);
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   231
1030
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   232
    for (i = 0; i < preshader->instruction_count; i++, inst++)
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   233
    {
1046
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   234
        INDENT(); printf("    %s ", opcodestr[inst->opcode]);
1032
464f38a2fb70 Added some more preshader opcodes, cleaned up opcode handling elsewhere.
Ryan C. Gordon <icculus@icculus.org>
parents: 1030
diff changeset
   235
1046
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   236
        // print dest register first...
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   237
        print_preshader_operand(preshader, i, inst->operand_count - 1);
1030
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   238
1046
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   239
        // ...then the source registers.
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   240
        for (j = 0; j < inst->operand_count - 1; j++)
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   241
        {
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   242
            printf(", ");
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   243
            print_preshader_operand(preshader, i, j);
1030
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   244
        } // for
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   245
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   246
        printf("\n");
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   247
    } // for
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   248
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   249
    printf("\n");
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   250
} // print_preshader
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   251
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   252
1055
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   253
static void print_attrs(const char *category, const int count,
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   254
                        const MOJOSHADER_attribute *attributes,
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   255
                        const int indent)
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   256
{
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   257
    INDENT(); printf("%s:", category);
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   258
    if (count == 0)
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   259
        printf(" (none.)\n");
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   260
    else
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   261
    {
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   262
        int i;
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   263
        printf("\n");
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   264
        for (i = 0; i < count; i++)
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   265
        {
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   266
            static const char *usagenames[] = {
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   267
                "<unknown>",
1055
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   268
                "position", "blendweight", "blendindices", "normal",
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   269
                "psize", "texcoord", "tangent", "binormal", "tessfactor",
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   270
                "positiont", "color", "fog", "depth", "sample"
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   271
            };
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   272
            const MOJOSHADER_attribute *a = &attributes[i];
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   273
            char numstr[16] = { 0 };
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   274
            if (a->index != 0)
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   275
                snprintf(numstr, sizeof (numstr), "%d", a->index);
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   276
            INDENT();
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   277
            printf("    * %s%s", usagenames[1 + (int) a->usage], numstr);
1055
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   278
            if (a->name != NULL)
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   279
                printf(" (\"%s\")", a->name);
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   280
            printf("\n");
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   281
        } // for
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   282
    } // else
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   283
} // print_attrs
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   284
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   285
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   286
static void print_shader(const char *fname, const MOJOSHADER_parseData *pd,
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   287
                         unsigned int indent)
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
   288
{
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   289
    INDENT(); printf("PROFILE: %s\n", pd->profile);
536
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   290
    if (pd->error_count > 0)
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   291
    {
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   292
        int i;
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   293
        for (i = 0; i < pd->error_count; i++)
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   294
        {
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   295
            const MOJOSHADER_error *err = &pd->errors[i];
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   296
            INDENT();
577
bec531dd448e Report filenames in error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 536
diff changeset
   297
            printf("%s:%d: ERROR: %s\n",
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   298
                   err->filename ? err->filename : fname,
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   299
                   err->error_position, err->error);
536
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   300
        } // for
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   301
    } // if
53
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   302
    else
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   303
    {
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   304
        INDENT(); printf("SHADER TYPE: %s\n", shader_type(pd->shader_type));
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   305
        INDENT(); printf("VERSION: %d.%d\n", pd->major_ver, pd->minor_ver);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   306
        INDENT(); printf("INSTRUCTION COUNT: %d\n", (int) pd->instruction_count);
1171
9f27482a2f58 Report the main function name in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1156
diff changeset
   307
        INDENT(); printf("MAIN FUNCTION: %s\n", pd->mainfn);
1055
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   308
        print_attrs("INPUTS", pd->attribute_count, pd->attributes, indent);
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   309
        print_attrs("OUTPUTS", pd->output_count, pd->outputs, indent);
100
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   310
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   311
        INDENT(); printf("CONSTANTS:");
278
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   312
        if (pd->constant_count == 0)
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   313
            printf(" (none.)\n");
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   314
        else
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   315
        {
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   316
            int i;
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   317
            printf("\n");
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   318
            for (i = 0; i < pd->constant_count; i++)
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   319
            {
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   320
                static const char *typenames[] = { "float", "int", "bool" };
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   321
                const MOJOSHADER_constant *c = &pd->constants[i];
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   322
                INDENT();
278
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   323
                printf("    * %d: %s (", c->index, typenames[(int) c->type]);
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   324
                if (c->type == MOJOSHADER_UNIFORM_FLOAT)
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   325
                {
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   326
                    printf("%f %f %f %f", c->value.f[0], c->value.f[1],
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   327
                                          c->value.f[2], c->value.f[3]);
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   328
                } // if
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   329
                else if (c->type == MOJOSHADER_UNIFORM_INT)
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   330
                {
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   331
                    printf("%d %d %d %d", c->value.i[0], c->value.i[1],
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   332
                                          c->value.i[2], c->value.i[3]);
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   333
                } // else if
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   334
                else if (c->type == MOJOSHADER_UNIFORM_BOOL)
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   335
                {
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   336
                    printf("%s", c->value.b ? "true" : "false");
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   337
                } // else if
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   338
                else
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   339
                {
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   340
                    printf("???");
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   341
                } // else
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   342
                printf(")\n");
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   343
            } // for
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   344
        } // else
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   345
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   346
        INDENT(); printf("UNIFORMS:");
92
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   347
        if (pd->uniform_count == 0)
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   348
            printf(" (none.)\n");
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   349
        else
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   350
        {
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   351
            int i;
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   352
            printf("\n");
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   353
            for (i = 0; i < pd->uniform_count; i++)
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   354
            {
94
57adfb4769a0 Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents: 92
diff changeset
   355
                static const char *typenames[] = { "float", "int", "bool" };
92
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   356
                const MOJOSHADER_uniform *u = &pd->uniforms[i];
280
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   357
                const char *arrayof = "";
438
73492129c1af Expose true constant arrays in parseData, load them at link time for GLSL.
Ryan C. Gordon <icculus@icculus.org>
parents: 280
diff changeset
   358
                const char *constant = u->constant ? "const " : "";
280
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   359
                char arrayrange[64] = { '\0' };
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   360
                if (u->array_count > 0)
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   361
                {
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   362
                    arrayof = "array[";
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   363
                    snprintf(arrayrange, sizeof (arrayrange), "%d] ",
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   364
                             u->array_count);
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   365
                } // if
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   366
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   367
                INDENT();
438
73492129c1af Expose true constant arrays in parseData, load them at link time for GLSL.
Ryan C. Gordon <icculus@icculus.org>
parents: 280
diff changeset
   368
                printf("    * %d: %s%s%s%s", u->index, constant, arrayof,
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   369
                       arrayrange, typenames[(int) u->type]);
192
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   370
                if (u->name != NULL)
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   371
                    printf(" (\"%s\")", u->name);
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   372
                printf("\n");
92
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   373
            } // for
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   374
        } // else
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   375
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   376
        INDENT(); printf("SAMPLERS:");
148
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   377
        if (pd->sampler_count == 0)
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   378
            printf(" (none.)\n");
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   379
        else
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   380
        {
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   381
            int i;
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   382
            printf("\n");
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   383
            for (i = 0; i < pd->sampler_count; i++)
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   384
            {
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   385
                static const char *typenames[] = { "2d", "cube", "volume" };
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   386
                const MOJOSHADER_sampler *s = &pd->samplers[i];
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   387
                INDENT();
192
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   388
                printf("    * %d: %s", s->index, typenames[(int) s->type]);
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   389
                if (s->name != NULL)
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   390
                    printf(" (\"%s\")", s->name);
1090
636ffcd3f14a First shot at GLSL/ARB1 support for TEXBEM and TEXBEML opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1055
diff changeset
   391
                if (s->texbem)
636ffcd3f14a First shot at GLSL/ARB1 support for TEXBEM and TEXBEML opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1055
diff changeset
   392
                    printf(" [TEXBEM]");
192
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   393
                printf("\n");
148
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   394
            } // for
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   395
        } // else
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   396
1044
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   397
        print_symbols(pd->symbols, pd->symbol_count, indent);
1028
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   398
1030
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   399
        if (pd->preshader != NULL)
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   400
            print_preshader(pd->preshader, indent);
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   401
53
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   402
        if (pd->output != NULL)
113
8ebf445c5305 Print output in testparse.c byte-by-byte instead of as an ASCIZ string.
Ryan C. Gordon <icculus@icculus.org>
parents: 100
diff changeset
   403
        {
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   404
            const char *output;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   405
            int output_len;
113
8ebf445c5305 Print output in testparse.c byte-by-byte instead of as an ASCIZ string.
Ryan C. Gordon <icculus@icculus.org>
parents: 100
diff changeset
   406
            int i;
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   407
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   408
            if (strcmp(pd->profile, "spirv") == 0)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   409
            {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   410
#if SUPPORT_PROFILE_SPIRV && defined(MOJOSHADER_HAS_SPIRV_TOOLS)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   411
                int binary_len = pd->output_len - sizeof(SpirvPatchTable);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   412
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   413
                uint32_t *words = (uint32_t *) pd->output;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   414
                size_t word_count = binary_len / 4;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   415
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   416
                spv_text text;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   417
                spv_diagnostic diagnostic;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   418
                spv_context ctx = spvContextCreate(SPV_ENV_UNIVERSAL_1_0);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   419
                int options = /*SPV_BINARY_TO_TEXT_OPTION_COLOR |*/ SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   420
                spv_result_t disResult = spvBinaryToText(ctx, words, word_count, options, &text, &diagnostic);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   421
                if (disResult == SPV_SUCCESS)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   422
                {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   423
                    output = text->str;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   424
                    output_len = text->length;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   425
                } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   426
                else
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   427
                {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   428
                    fprintf(stderr, "\nERROR DIAGNOSTIC: %s\n\n", diagnostic->error);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   429
                } // else
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   430
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   431
                spv_result_t validateResult = spvValidateBinary(ctx, words, word_count, &diagnostic);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   432
                if (validateResult != SPV_SUCCESS)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   433
                {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   434
                    fprintf(stderr, "\nVALIDATION FAILURE: %s\n\n", diagnostic->error);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   435
                } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   436
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   437
                if (disResult != SPV_SUCCESS || validateResult != SPV_SUCCESS)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   438
                {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   439
                    exit(EXIT_FAILURE);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   440
                } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   441
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   442
                // FIXME: we're currently just leaking this disassembly...
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   443
#else
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   444
                output = pd->output;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   445
                output_len = pd->output_len;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   446
#endif
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   447
            } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   448
            else
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   449
            {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   450
                output = pd->output;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   451
                output_len = pd->output_len;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   452
            } // else
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   453
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   454
            INDENT();
113
8ebf445c5305 Print output in testparse.c byte-by-byte instead of as an ASCIZ string.
Ryan C. Gordon <icculus@icculus.org>
parents: 100
diff changeset
   455
            printf("OUTPUT:\n");
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   456
            indent++;
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   457
            INDENT();
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   458
            for (i = 0; i < output_len; i++)
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   459
            {
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   460
                putchar((int) output[i]);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   461
                if (output[i] == '\n')
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   462
                    INDENT();
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   463
            } // for
113
8ebf445c5305 Print output in testparse.c byte-by-byte instead of as an ASCIZ string.
Ryan C. Gordon <icculus@icculus.org>
parents: 100
diff changeset
   464
            printf("\n");
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   465
            indent--;
113
8ebf445c5305 Print output in testparse.c byte-by-byte instead of as an ASCIZ string.
Ryan C. Gordon <icculus@icculus.org>
parents: 100
diff changeset
   466
        } // if
53
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   467
    } // else
1030
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   468
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
   469
    printf("\n\n");
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   470
} // print_shader
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   471
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   472
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   473
#ifdef MOJOSHADER_EFFECT_SUPPORT
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   474
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   475
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   476
static void print_value(const MOJOSHADER_effectValue *value,
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   477
                        const unsigned int indent)
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   478
{
1173
4b2f745c643b GLSL: Use varyings when usage_str is NULL for vertex/pixel shaders
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1171
diff changeset
   479
    int i, r, c;
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   480
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   481
    INDENT();
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   482
    printf("VALUE: %s -> %s\n", value->name, value->semantic);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   483
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   484
    static const char *classes[] =
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   485
    {
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   486
        "SCALAR",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   487
        "VECTOR",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   488
        "ROW-MAJOR MATRIX",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   489
        "COLUMN-MAJOR MATRIX",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   490
        "OBJECT",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   491
        "STRUCT"
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   492
    };
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   493
    static const char *types[] =
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   494
    {
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   495
        "VOID",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   496
        "BOOL",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   497
        "INT",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   498
        "FLOAT",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   499
        "STRING",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   500
        "TEXTURE",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   501
        "TEXTURE1D",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   502
        "TEXTURE2D",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   503
        "TEXTURE3D",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   504
        "TEXTURECUBE",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   505
        "SAMPLER",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   506
        "SAMPLER1D",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   507
        "SAMPLER2D",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   508
        "SAMPLER3D",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   509
        "SAMPLERCUBE",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   510
        "PIXELSHADER",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   511
        "VERTEXSHADER",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   512
        "UNSUPPORTED"
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   513
    };
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   514
    do_indent(indent + 1);
1152
8f7653f0dc37 Effect struct parameter support
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1150
diff changeset
   515
    printf("CLASS: %s\n", classes[value->type.parameter_class]);
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   516
    do_indent(indent + 1);
1152
8f7653f0dc37 Effect struct parameter support
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1150
diff changeset
   517
    printf("TYPE: %s\n", types[value->type.parameter_type]);
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   518
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   519
    do_indent(indent + 1);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   520
    printf("ROWS/COLUMNS/ELEMENTS: %d, %d, %d\n",
1152
8f7653f0dc37 Effect struct parameter support
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1150
diff changeset
   521
           value->type.rows, value->type.columns, value->type.elements);
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   522
    do_indent(indent + 1);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   523
    printf("TOTAL VALUES: %d\n", value->value_count);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   524
1152
8f7653f0dc37 Effect struct parameter support
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1150
diff changeset
   525
    if (value->type.parameter_type == MOJOSHADER_SYMTYPE_SAMPLER
8f7653f0dc37 Effect struct parameter support
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1150
diff changeset
   526
     || value->type.parameter_type == MOJOSHADER_SYMTYPE_SAMPLER1D
8f7653f0dc37 Effect struct parameter support
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1150
diff changeset
   527
     || value->type.parameter_type == MOJOSHADER_SYMTYPE_SAMPLER2D
8f7653f0dc37 Effect struct parameter support
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1150
diff changeset
   528
     || value->type.parameter_type == MOJOSHADER_SYMTYPE_SAMPLER3D
8f7653f0dc37 Effect struct parameter support
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1150
diff changeset
   529
     || value->type.parameter_type == MOJOSHADER_SYMTYPE_SAMPLERCUBE)
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   530
    {
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   531
        do_indent(indent + 1);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   532
        printf("SAMPLER VALUES:\n");
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   533
        for (i = 0; i < value->value_count; i++)
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   534
        {
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   535
            MOJOSHADER_effectSamplerState *state = &value->valuesSS[i];
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   536
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   537
            static const char *samplerstatetypes[] =
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   538
            {
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   539
                "UNKNOWN0",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   540
                "UNKNOWN1",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   541
                "UNKNOWN2",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   542
                "UNKNOWN3",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   543
                "TEXTURE",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   544
                "ADDRESSU",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   545
                "ADDRESSV",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   546
                "ADDRESSW",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   547
                "BORDERCOLOR",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   548
                "MAGFILTER",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   549
                "MINFILTER",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   550
                "MIPFILTER",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   551
                "MIPMAPLODBIAS",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   552
                "MAXMIPLEVEL",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   553
                "MAXANISOTROPY",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   554
                "SRGBTEXTURE",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   555
                "ELEMENTINDEX",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   556
                "DMAPOFFSET",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   557
            };
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   558
            do_indent(indent + 2);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   559
            printf("TYPE: %s -> ", samplerstatetypes[state->type]);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   560
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   561
            /* Assuming only one value per state! */
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   562
            if (state->type == MOJOSHADER_SAMP_MIPMAPLODBIAS)
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   563
            {
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   564
                /* float types */
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   565
                printf("%.2f\n", *state->value.valuesF);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   566
            } // if
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   567
            else
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   568
            {
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   569
                /* int/enum types */
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   570
                printf("%d\n", *state->value.valuesI);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   571
            } // else
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   572
        } // for
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   573
    } // if
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   574
    else
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   575
    {
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   576
        do_indent(indent + 1);
1152
8f7653f0dc37 Effect struct parameter support
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1150
diff changeset
   577
        printf("%s VALUES:\n", types[value->type.parameter_type]);
1173
4b2f745c643b GLSL: Use varyings when usage_str is NULL for vertex/pixel shaders
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1171
diff changeset
   578
        i = 0;
4b2f745c643b GLSL: Use varyings when usage_str is NULL for vertex/pixel shaders
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1171
diff changeset
   579
        do
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   580
        {
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   581
            static const char *prints[] =
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   582
            {
1173
4b2f745c643b GLSL: Use varyings when usage_str is NULL for vertex/pixel shaders
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1171
diff changeset
   583
                "%X ",
4b2f745c643b GLSL: Use varyings when usage_str is NULL for vertex/pixel shaders
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1171
diff changeset
   584
                "%d ",
4b2f745c643b GLSL: Use varyings when usage_str is NULL for vertex/pixel shaders
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1171
diff changeset
   585
                "%d ",
4b2f745c643b GLSL: Use varyings when usage_str is NULL for vertex/pixel shaders
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1171
diff changeset
   586
                "%.2f ",
4b2f745c643b GLSL: Use varyings when usage_str is NULL for vertex/pixel shaders
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1171
diff changeset
   587
                "%d ",
4b2f745c643b GLSL: Use varyings when usage_str is NULL for vertex/pixel shaders
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1171
diff changeset
   588
                "%d ",
4b2f745c643b GLSL: Use varyings when usage_str is NULL for vertex/pixel shaders
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1171
diff changeset
   589
                "%d ",
4b2f745c643b GLSL: Use varyings when usage_str is NULL for vertex/pixel shaders
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1171
diff changeset
   590
                "%d ",
4b2f745c643b GLSL: Use varyings when usage_str is NULL for vertex/pixel shaders
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1171
diff changeset
   591
                "%d ",
4b2f745c643b GLSL: Use varyings when usage_str is NULL for vertex/pixel shaders
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1171
diff changeset
   592
                "%d ",
4b2f745c643b GLSL: Use varyings when usage_str is NULL for vertex/pixel shaders
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1171
diff changeset
   593
                "SAMPLER?! ",
4b2f745c643b GLSL: Use varyings when usage_str is NULL for vertex/pixel shaders
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1171
diff changeset
   594
                "SAMPLER?! ",
4b2f745c643b GLSL: Use varyings when usage_str is NULL for vertex/pixel shaders
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1171
diff changeset
   595
                "SAMPLER?! ",
4b2f745c643b GLSL: Use varyings when usage_str is NULL for vertex/pixel shaders
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1171
diff changeset
   596
                "SAMPLER?! ",
4b2f745c643b GLSL: Use varyings when usage_str is NULL for vertex/pixel shaders
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1171
diff changeset
   597
                "SAMPLER?! ",
4b2f745c643b GLSL: Use varyings when usage_str is NULL for vertex/pixel shaders
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1171
diff changeset
   598
                "%d ",
4b2f745c643b GLSL: Use varyings when usage_str is NULL for vertex/pixel shaders
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1171
diff changeset
   599
                "%d ",
4b2f745c643b GLSL: Use varyings when usage_str is NULL for vertex/pixel shaders
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1171
diff changeset
   600
                "%X "
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   601
            };
1173
4b2f745c643b GLSL: Use varyings when usage_str is NULL for vertex/pixel shaders
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1171
diff changeset
   602
            for (r = 0; r < value->type.rows; r++)
4b2f745c643b GLSL: Use varyings when usage_str is NULL for vertex/pixel shaders
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1171
diff changeset
   603
            {
4b2f745c643b GLSL: Use varyings when usage_str is NULL for vertex/pixel shaders
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1171
diff changeset
   604
                do_indent(indent + 2);
4b2f745c643b GLSL: Use varyings when usage_str is NULL for vertex/pixel shaders
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1171
diff changeset
   605
                for (c = 0; c < value->type.columns; c++)
4b2f745c643b GLSL: Use varyings when usage_str is NULL for vertex/pixel shaders
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1171
diff changeset
   606
                {
4b2f745c643b GLSL: Use varyings when usage_str is NULL for vertex/pixel shaders
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1171
diff changeset
   607
                    const int offset = (i * value->type.rows * 4) + (r * 4) + c;
4b2f745c643b GLSL: Use varyings when usage_str is NULL for vertex/pixel shaders
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1171
diff changeset
   608
                    if (value->type.parameter_type == MOJOSHADER_SYMTYPE_FLOAT)
4b2f745c643b GLSL: Use varyings when usage_str is NULL for vertex/pixel shaders
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1171
diff changeset
   609
                        printf(prints[value->type.parameter_type], value->valuesF[offset]);
4b2f745c643b GLSL: Use varyings when usage_str is NULL for vertex/pixel shaders
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1171
diff changeset
   610
                    else
4b2f745c643b GLSL: Use varyings when usage_str is NULL for vertex/pixel shaders
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1171
diff changeset
   611
                        printf(prints[value->type.parameter_type], value->valuesI[offset]);
4b2f745c643b GLSL: Use varyings when usage_str is NULL for vertex/pixel shaders
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1171
diff changeset
   612
                } // for
4b2f745c643b GLSL: Use varyings when usage_str is NULL for vertex/pixel shaders
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1171
diff changeset
   613
                printf("\n");
4b2f745c643b GLSL: Use varyings when usage_str is NULL for vertex/pixel shaders
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1171
diff changeset
   614
            } // for
4b2f745c643b GLSL: Use varyings when usage_str is NULL for vertex/pixel shaders
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1171
diff changeset
   615
        } while (++i < value->type.elements);
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   616
    } // else
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   617
} // print_value
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   618
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   619
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   620
static void print_effect(const char *fname, const MOJOSHADER_effect *effect,
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   621
                         const unsigned int indent)
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   622
{
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   623
    INDENT();
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   624
    printf("\n");
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   625
    if (effect->error_count > 0)
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   626
    {
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   627
        int i;
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   628
        for (i = 0; i < effect->error_count; i++)
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   629
        {
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   630
            const MOJOSHADER_error *err = &effect->errors[i];
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   631
            INDENT();
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   632
            printf("%s:%d: ERROR: %s\n",
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   633
                    err->filename ? err->filename : fname,
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   634
                    err->error_position, err->error);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   635
        } // for
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   636
    } // if
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   637
    else
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   638
    {
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   639
        int i, j, k;
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   640
        const MOJOSHADER_effectTechnique *technique = effect->techniques;
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   641
        const MOJOSHADER_effectObject *object = effect->objects;
1037
b102a563d9cb Filled in and fixed some stuff in the Effect parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 1034
diff changeset
   642
        const MOJOSHADER_effectParam *param = effect->params;
b102a563d9cb Filled in and fixed some stuff in the Effect parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 1034
diff changeset
   643
b102a563d9cb Filled in and fixed some stuff in the Effect parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 1034
diff changeset
   644
        for (i = 0; i < effect->param_count; i++, param++)
b102a563d9cb Filled in and fixed some stuff in the Effect parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 1034
diff changeset
   645
        {
b102a563d9cb Filled in and fixed some stuff in the Effect parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 1034
diff changeset
   646
            INDENT();
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   647
            printf("PARAM #%d\n", i);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   648
            print_value(&param->value, indent + 1);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   649
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   650
            if (param->annotation_count > 0)
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   651
            {
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   652
                do_indent(indent + 1);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   653
                printf("ANNOTATIONS:\n");
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   654
            } // if
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   655
            for (j = 0; j < param->annotation_count; j++)
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   656
            {
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   657
                print_value(&param->annotations[j], indent + 2);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   658
            } // for
1037
b102a563d9cb Filled in and fixed some stuff in the Effect parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 1034
diff changeset
   659
        } // for
b102a563d9cb Filled in and fixed some stuff in the Effect parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 1034
diff changeset
   660
        printf("\n");
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   661
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   662
        for (i = 0; i < effect->technique_count; i++, technique++)
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   663
        {
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   664
            const MOJOSHADER_effectPass *pass = technique->passes;
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   665
            INDENT();
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   666
            printf("TECHNIQUE #%d ('%s'):\n", i, technique->name);
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   667
            for (j = 0; j < technique->pass_count; j++, pass++)
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   668
            {
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   669
                const MOJOSHADER_effectState *state = pass->states;
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   670
                do_indent(indent + 1);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   671
                printf("PASS #%d ('%s'):\n", j, pass->name);
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   672
                for (k = 0; k < pass->state_count; k++, state++)
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   673
                {
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   674
                    do_indent(indent + 2);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   675
                    printf("STATE %d:\n", state->type);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   676
                    print_value(&state->value, indent + 3);
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   677
                } // for
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   678
            } // for
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   679
        } // for
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   680
        printf("\n");
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   681
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   682
        /* Start at index 1, 0 is always empty (thanks Microsoft!) */
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   683
        object++;
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   684
        for (i = 1; i < effect->object_count; i++, object++)
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   685
        {
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   686
            INDENT();
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   687
            if (object->type == MOJOSHADER_SYMTYPE_PIXELSHADER
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   688
             || object->type == MOJOSHADER_SYMTYPE_VERTEXSHADER)
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   689
            {
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   690
                if (object->shader.is_preshader)
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   691
                {
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   692
                    printf("OBJECT #%d: PRESHADER, technique %u, pass %u, param %s\n", i,
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   693
                           object->shader.technique, object->shader.pass,
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   694
                           effect->params[object->shader.params[0]].value.name);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   695
                    print_preshader(object->shader.preshader, indent + 1);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   696
                } // if
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   697
                else
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   698
                {
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   699
                    printf("OBJECT #%d: SHADER, technique %u, pass %u\n", i,
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   700
                           object->shader.technique, object->shader.pass);
1246
cd51a61272e4 Forgot to commit the new testparse...
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   701
                    print_shader(fname,
cd51a61272e4 Forgot to commit the new testparse...
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   702
                                 (MOJOSHADER_parseData*) object->shader.shader,
cd51a61272e4 Forgot to commit the new testparse...
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   703
                                 indent + 1);
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   704
                } // else
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   705
            } // if
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   706
            else if (object->type == MOJOSHADER_SYMTYPE_STRING)
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   707
                printf("OBJECT #%d: STRING, '%s'\n", i,
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   708
                       object->string.string);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   709
            else if (object->type == MOJOSHADER_SYMTYPE_SAMPLER
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   710
                  || object->type == MOJOSHADER_SYMTYPE_SAMPLER1D
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   711
                  || object->type == MOJOSHADER_SYMTYPE_SAMPLER2D
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   712
                  || object->type == MOJOSHADER_SYMTYPE_SAMPLER3D
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   713
                  || object->type == MOJOSHADER_SYMTYPE_SAMPLERCUBE)
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   714
                printf("OBJECT #%d: MAPPING, '%s'\n", i,
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   715
                       object->mapping.name);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   716
            else if (object->type == MOJOSHADER_SYMTYPE_TEXTURE
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   717
                  || object->type == MOJOSHADER_SYMTYPE_TEXTURE1D
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   718
                  || object->type == MOJOSHADER_SYMTYPE_TEXTURE2D
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   719
                  || object->type == MOJOSHADER_SYMTYPE_TEXTURE3D
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   720
                  || object->type == MOJOSHADER_SYMTYPE_TEXTURECUBE)
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   721
                printf("OBJECT #%d: TEXTURE\n", i);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   722
            else
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   723
                printf("UNKNOWN OBJECT: #%d\n", i);
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   724
        } // for
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   725
    } // else
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   726
} // print_effect
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   727
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   728
1246
cd51a61272e4 Forgot to commit the new testparse...
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   729
static const char *effect_profile = NULL;
cd51a61272e4 Forgot to commit the new testparse...
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   730
cd51a61272e4 Forgot to commit the new testparse...
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   731
cd51a61272e4 Forgot to commit the new testparse...
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   732
static void* MOJOSHADERCALL effect_compile_shader(
cd51a61272e4 Forgot to commit the new testparse...
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   733
    const char *mainfn,
cd51a61272e4 Forgot to commit the new testparse...
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   734
    const unsigned char *tokenbuf,
cd51a61272e4 Forgot to commit the new testparse...
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   735
    const unsigned int bufsize,
cd51a61272e4 Forgot to commit the new testparse...
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   736
    const MOJOSHADER_swizzle *swiz,
cd51a61272e4 Forgot to commit the new testparse...
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   737
    const unsigned int swizcount,
cd51a61272e4 Forgot to commit the new testparse...
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   738
    const MOJOSHADER_samplerMap *smap,
cd51a61272e4 Forgot to commit the new testparse...
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   739
    const unsigned int smapcount
cd51a61272e4 Forgot to commit the new testparse...
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   740
) {
cd51a61272e4 Forgot to commit the new testparse...
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   741
    return (MOJOSHADER_parseData*) MOJOSHADER_parse(effect_profile, mainfn,
cd51a61272e4 Forgot to commit the new testparse...
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   742
                                                    tokenbuf, bufsize,
cd51a61272e4 Forgot to commit the new testparse...
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   743
                                                    swiz, swizcount,
cd51a61272e4 Forgot to commit the new testparse...
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   744
                                                    smap, smapcount,
cd51a61272e4 Forgot to commit the new testparse...
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   745
                                                    Malloc, Free, NULL);
cd51a61272e4 Forgot to commit the new testparse...
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   746
} // effect_compile_shader
cd51a61272e4 Forgot to commit the new testparse...
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   747
cd51a61272e4 Forgot to commit the new testparse...
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   748
cd51a61272e4 Forgot to commit the new testparse...
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   749
static void MOJOSHADERCALL effect_delete_shader(void *shader)
cd51a61272e4 Forgot to commit the new testparse...
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   750
{
cd51a61272e4 Forgot to commit the new testparse...
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   751
    MOJOSHADER_freeParseData((MOJOSHADER_parseData*) shader);
cd51a61272e4 Forgot to commit the new testparse...
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   752
} // effect_delete_shader
cd51a61272e4 Forgot to commit the new testparse...
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   753
cd51a61272e4 Forgot to commit the new testparse...
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   754
cd51a61272e4 Forgot to commit the new testparse...
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   755
static MOJOSHADER_parseData* MOJOSHADERCALL effect_get_parse_data(void *shader)
cd51a61272e4 Forgot to commit the new testparse...
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   756
{
cd51a61272e4 Forgot to commit the new testparse...
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   757
    return (MOJOSHADER_parseData*) shader;
cd51a61272e4 Forgot to commit the new testparse...
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   758
} // effect_get_parse_data
cd51a61272e4 Forgot to commit the new testparse...
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   759
cd51a61272e4 Forgot to commit the new testparse...
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   760
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   761
#endif // MOJOSHADER_EFFECT_SUPPORT
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   762
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   763
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   764
static int do_parse(const char *fname, const unsigned char *buf,
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   765
                    const int len, const char *prof)
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   766
{
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   767
    int i;
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   768
    int retval = 0;
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   769
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   770
    // magic for an effects file (!!! FIXME: I _think_).
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   771
    if ( ((buf[0] == 0x01) && (buf[1] == 0x09) &&
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   772
          (buf[2] == 0xFF) && (buf[3] == 0xFE)) ||
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   773
         ((buf[0] == 0xCF) && (buf[1] == 0x0B) &&
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   774
          (buf[2] == 0xF0) && (buf[3] == 0xBC)) )
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   775
    {
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   776
#ifdef MOJOSHADER_EFFECT_SUPPORT
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   777
        const MOJOSHADER_effect *effect;
1246
cd51a61272e4 Forgot to commit the new testparse...
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   778
        const MOJOSHADER_effectShaderContext ctx =
cd51a61272e4 Forgot to commit the new testparse...
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   779
        {
cd51a61272e4 Forgot to commit the new testparse...
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   780
            effect_compile_shader,
cd51a61272e4 Forgot to commit the new testparse...
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   781
            NULL, /* Meh! */
cd51a61272e4 Forgot to commit the new testparse...
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   782
            effect_delete_shader,
cd51a61272e4 Forgot to commit the new testparse...
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   783
            effect_get_parse_data,
cd51a61272e4 Forgot to commit the new testparse...
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   784
            /* Meh! */
cd51a61272e4 Forgot to commit the new testparse...
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   785
            NULL,
cd51a61272e4 Forgot to commit the new testparse...
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   786
            NULL,
cd51a61272e4 Forgot to commit the new testparse...
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   787
            NULL,
cd51a61272e4 Forgot to commit the new testparse...
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   788
            NULL
cd51a61272e4 Forgot to commit the new testparse...
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   789
        };
cd51a61272e4 Forgot to commit the new testparse...
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   790
        effect_profile = prof;
cd51a61272e4 Forgot to commit the new testparse...
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   791
        effect = MOJOSHADER_compileEffect(buf, len, NULL, 0, NULL, 0, &ctx);
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   792
        int error_count = effect->error_count;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   793
        for (i = 0; i < effect->object_count; i++)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   794
        {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   795
            MOJOSHADER_effectObject *object = &effect->objects[i];
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   796
            switch (object->type)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   797
            {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   798
                case MOJOSHADER_SYMTYPE_VERTEXSHADER:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   799
                case MOJOSHADER_SYMTYPE_PIXELSHADER:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   800
                    if (!object->shader.is_preshader)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   801
                    {
1246
cd51a61272e4 Forgot to commit the new testparse...
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   802
                        const MOJOSHADER_parseData *shader =
cd51a61272e4 Forgot to commit the new testparse...
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   803
                            ctx.getParseData(object->shader.shader);
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   804
                        if (shader)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   805
                            error_count += shader->error_count;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   806
                    } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   807
                    break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   808
                default:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   809
                    break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   810
            }
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   811
        }
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1173
diff changeset
   812
        retval = (error_count == 0);
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   813
        printf("EFFECT: %s\n", fname);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   814
        print_effect(fname, effect, 1);
1246
cd51a61272e4 Forgot to commit the new testparse...
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   815
        MOJOSHADER_deleteEffect(effect);
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   816
#else
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   817
        printf("Is an effect, but effect support is disabled!\n");
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   818
#endif
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   819
    } // if
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   820
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   821
    else  // do it as a regular compiled shader.
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   822
    {
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   823
        const MOJOSHADER_parseData *pd;
1156
6e760a19f456 Added support for producing shader language source code for Apple's Metal API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1152
diff changeset
   824
        pd = MOJOSHADER_parse(prof, NULL, buf, len, NULL, 0,
1104
9147482e1ec7 Allow sampler type remapping.
Ryan C. Gordon <icculus@icculus.org>
parents: 1090
diff changeset
   825
                              NULL, 0, Malloc, Free, NULL);
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   826
        retval = (pd->error_count == 0);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   827
        printf("SHADER: %s\n", fname);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   828
        print_shader(fname, pd, 1);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   829
        MOJOSHADER_freeParseData(pd);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   830
    } // else
142
e064b4cefb4e Return a more-meaningful pass/fail error code from testparse main().
Ryan C. Gordon <icculus@icculus.org>
parents: 113
diff changeset
   831
e064b4cefb4e Return a more-meaningful pass/fail error code from testparse main().
Ryan C. Gordon <icculus@icculus.org>
parents: 113
diff changeset
   832
    return retval;
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
   833
} // do_parse
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
   834
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
   835
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   836
int main(int argc, char **argv)
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   837
{
142
e064b4cefb4e Return a more-meaningful pass/fail error code from testparse main().
Ryan C. Gordon <icculus@icculus.org>
parents: 113
diff changeset
   838
    int retval = 0;
e064b4cefb4e Return a more-meaningful pass/fail error code from testparse main().
Ryan C. Gordon <icculus@icculus.org>
parents: 113
diff changeset
   839
47
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   840
    printf("MojoShader testparse\n");
901
a9f799b93150 Report changeset, not version.
Ryan C. Gordon <icculus@icculus.org>
parents: 588
diff changeset
   841
    printf("Compiled against changeset %s\n", MOJOSHADER_CHANGESET);
a9f799b93150 Report changeset, not version.
Ryan C. Gordon <icculus@icculus.org>
parents: 588
diff changeset
   842
    printf("Linked against changeset %s\n", MOJOSHADER_changeset());
47
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   843
    printf("\n");
37
63b5ba0bcda0 [svn] Update testparse for renames.
icculus
parents: 18
diff changeset
   844
53
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   845
    if (argc <= 2)
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   846
        printf("\n\nUSAGE: %s <profile> [file1] ... [fileN]\n\n", argv[0]);
47
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   847
    else
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   848
    {
53
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   849
        const char *profile = argv[1];
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   850
        int i;
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   851
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   852
        for (i = 2; i < argc; i++)
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   853
        {
47
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   854
            FILE *io = fopen(argv[i], "rb");
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   855
            if (io == NULL)
53
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   856
                printf(" ... fopen('%s') failed.\n", argv[i]);
47
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   857
            else
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   858
            {
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   859
                unsigned char *buf = (unsigned char *) malloc(1000000);
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   860
                int rc = fread(buf, 1, 1000000, io);
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   861
                fclose(io);
902
cff5841d29e7 Report actual filename in errors.
Ryan C. Gordon <icculus@icculus.org>
parents: 901
diff changeset
   862
                if (!do_parse(argv[i], buf, rc, profile))
142
e064b4cefb4e Return a more-meaningful pass/fail error code from testparse main().
Ryan C. Gordon <icculus@icculus.org>
parents: 113
diff changeset
   863
                    retval = 1;
47
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   864
                free(buf);
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   865
            } // else
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   866
        } // for
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   867
    } // else
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   868
142
e064b4cefb4e Return a more-meaningful pass/fail error code from testparse main().
Ryan C. Gordon <icculus@icculus.org>
parents: 113
diff changeset
   869
    return retval;
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   870
} // main
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   871
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   872
// end of testparse.c ...
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   873