profiles/mojoshader_profile_spirv.c
author Martin Krošlák <kroslakma@gmail.com>
Thu, 23 Jul 2020 18:16:22 -0400
changeset 1299 02d36217591b
parent 1278 be0f548f321f
child 1303 7a43f238f28a
permissions -rw-r--r--
Fix SM1 shaders on SPIR-V after TEX* opcodes changes: - Fix implicit input attribute on SPIR-V profile - Remove texcoord attribs from other TEX* opcodes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
     1
/**
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
     2
 * MojoShader; generate shader programs from bytecode of compiled
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
     3
 *  Direct3D shaders.
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
     4
 *
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
     5
 * Please see the file LICENSE.txt in the source's root directory.
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
     6
 *
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
     7
 *  This file written by Ryan C. Gordon.
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
     8
 */
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
     9
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    10
#define __MOJOSHADER_INTERNAL__ 1
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    11
#include "mojoshader_profile.h"
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    12
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    13
#pragma GCC visibility push(hidden)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    14
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    15
#if SUPPORT_PROFILE_SPIRV
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    16
#include "spirv/spirv.h"
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    17
#include "spirv/GLSL.std.450.h"
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    18
#include <float.h>
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    19
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    20
static const int SPV_NO_SWIZZLE = 0xE4; // 0xE4 == 11100100 ... 0 1 2 3. No swizzle.
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    21
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    22
#define EMIT_SPIRV_OPCODE_UNIMPLEMENTED_FUNC(op) \
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    23
    void emit_SPIRV_##op(Context *ctx) { \
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    24
        fail(ctx, #op " unimplemented in spirv profile"); \
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    25
    }
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    26
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    27
typedef struct SpirvTexm3x3SetupResult
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    28
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    29
    // vec4 load results
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    30
    uint32 id_dst_pad0;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    31
    uint32 id_dst_pad1;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    32
    uint32 id_dst;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    33
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    34
    // float dot results
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    35
    uint32 id_res_x;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    36
    uint32 id_res_y;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    37
    uint32 id_res_z;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    38
} SpirvTexm3x3SetupResult;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    39
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    40
static const char *spv_get_uniform_array_varname(Context *ctx,
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    41
                                                   const RegisterType regtype,
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    42
                                                   char *buf, const size_t len)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    43
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    44
    const char *shadertype = ctx->shader_type_str;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    45
    const char *type = "";
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    46
    switch (regtype)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    47
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    48
        case REG_TYPE_CONST: type = "vec4"; break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    49
        case REG_TYPE_CONSTINT: type = "ivec4"; break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    50
        case REG_TYPE_CONSTBOOL: type = "bool"; break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    51
        default: fail(ctx, "BUG: used a uniform we don't know how to define.");
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    52
    } // switch
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    53
    snprintf(buf, len, "%s_uniforms_%s", shadertype, type);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    54
    return buf;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    55
} // spv_get_uniform_array_varname
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    56
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    57
static uint32 spv_bumpid(Context *ctx)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    58
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    59
    return (ctx->spirv.idmax += 1);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    60
} // spv_bumpid
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    61
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    62
static RegisterList *spv_getreg(Context *ctx, const RegisterType regtype, const int regnum)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    63
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    64
    RegisterList *r = reglist_find(&ctx->used_registers, regtype, regnum);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    65
    if (!r)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    66
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    67
        failf(ctx, "register not found rt=%d, rn=%d", regtype, regnum);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    68
        return NULL;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    69
    } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    70
    return r;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    71
} // spv_getreg
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    72
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    73
static void spv_componentlist_free(Context *ctx, ComponentList *cl)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    74
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    75
    ComponentList *next;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    76
    while (cl)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    77
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    78
        next = cl->next;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    79
        Free(ctx, cl);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    80
        cl = next;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    81
    } // while
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    82
} // spv_componentlist_free
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    83
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    84
static ComponentList *spv_componentlist_alloc(Context *ctx)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    85
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    86
    ComponentList *ret = (ComponentList *) Malloc(ctx, sizeof(ComponentList));
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    87
    if (!ret) return NULL;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    88
    ret->id = 0;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    89
    ret->v.i = 0;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    90
    ret->next = NULL;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    91
    return ret;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    92
} // spv_componentlist_alloc
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    93
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    94
static const char *get_SPIRV_varname_in_buf(Context *ctx, const RegisterType rt,
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    95
                                           const int regnum, char *buf,
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    96
                                           const size_t buflen)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    97
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    98
    // turns out these are identical at the moment.
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    99
    return get_D3D_varname_in_buf(ctx, rt, regnum, buf, buflen);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   100
} // get_SPIRV_varname_in_buf
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   101
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   102
const char *get_SPIRV_varname(Context *ctx, const RegisterType rt,
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   103
                                    const int regnum)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   104
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   105
    // turns out these are identical at the moment.
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   106
    return get_D3D_varname(ctx, rt, regnum);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   107
} // get_SPIRV_varname
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   108
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   109
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   110
static inline const char *get_SPIRV_const_array_varname_in_buf(Context *ctx,
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   111
                                                const int base, const int size,
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   112
                                                char *buf, const size_t buflen)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   113
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   114
    snprintf(buf, buflen, "c_array_%d_%d", base, size);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   115
    return buf;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   116
} // get_SPIRV_const_array_varname_in_buf
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   117
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   118
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   119
const char *get_SPIRV_const_array_varname(Context *ctx, int base, int size)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   120
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   121
    char buf[64];
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   122
    get_SPIRV_const_array_varname_in_buf(ctx, base, size, buf, sizeof (buf));
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   123
    return StrDup(ctx, buf);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   124
} // get_SPIRV_const_array_varname
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   125
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   126
static uint32 spv_get_uniform_array_id(Context *ctx, const RegisterType regtype)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   127
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   128
    uint32 id;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   129
    switch (regtype)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   130
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   131
        case REG_TYPE_CONST:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   132
            id = ctx->spirv.uniform_arrays.idvec4;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   133
            if (id == 0)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   134
            {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   135
                id = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   136
                ctx->spirv.uniform_arrays.idvec4 = id;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   137
            } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   138
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   139
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   140
        case REG_TYPE_CONSTINT:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   141
            id = ctx->spirv.uniform_arrays.idivec4;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   142
            if (id == 0)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   143
            {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   144
                id = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   145
                ctx->spirv.uniform_arrays.idivec4 = id;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   146
            } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   147
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   148
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   149
        case REG_TYPE_CONSTBOOL:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   150
            id = ctx->spirv.uniform_arrays.idbool;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   151
            if (id == 0)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   152
            {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   153
                id = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   154
                ctx->spirv.uniform_arrays.idbool = id;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   155
            } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   156
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   157
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   158
        default:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   159
            fail(ctx, "Unexpected register type used to access uniform array.");
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   160
            id = 0;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   161
    } // switch
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   162
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   163
    return id;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   164
} // spv_get_uniform_array_id
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   165
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   166
static void spv_emit_part_va(Context* ctx, uint32 word_count, uint32 argc, SpvOp op, va_list args)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   167
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   168
    assert(ctx->output != NULL);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   169
    if (isfail(ctx))
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   170
        return;  // we failed previously, don't go on...
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   171
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   172
    uint32 word = op | (word_count << 16);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   173
    buffer_append(ctx->output, &word, sizeof(word));
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   174
    while (--argc)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   175
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   176
        word = va_arg(args, uint32);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   177
        buffer_append(ctx->output, &word, sizeof(word));
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   178
    } // while
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   179
} // spv_emit_part_va
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   180
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   181
static void spv_emit_part(Context* ctx, uint32 word_count, uint32 argc, SpvOp op, ...)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   182
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   183
    va_list args;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   184
    va_start(args, op);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   185
    spv_emit_part_va(ctx, word_count, argc, op, args);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   186
    va_end(args);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   187
} // spv_emit_part
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   188
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   189
static void spv_emit(Context *ctx, uint32 word_count, SpvOp op, ...)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   190
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   191
    va_list args;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   192
    va_start(args, op);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   193
    spv_emit_part_va(ctx, word_count, word_count, op, args);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   194
    va_end(args);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   195
} // spv_emit
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   196
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   197
static void spv_emit_word(Context *ctx, uint32 word)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   198
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   199
    assert(ctx->output != NULL);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   200
    if (isfail(ctx))
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   201
        return;  // we failed previously, don't go on...
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   202
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   203
    buffer_append(ctx->output, &word, sizeof(word));
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   204
} // spv_emit_word
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   205
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   206
static void spv_emit_str(Context *ctx, const char *str)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   207
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   208
    size_t len;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   209
    uint32 trail;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   210
    assert(ctx->output != NULL);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   211
    if (isfail(ctx))
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   212
        return;  // we failed previously, don't go on...
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   213
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   214
    if (str == NULL)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   215
        return spv_emit_word(ctx, 0);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   216
    len = strlen(str) + 1;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   217
    buffer_append(ctx->output, str, len);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   218
    len = len % 4;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   219
    if (len)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   220
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   221
        trail = 0;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   222
        buffer_append(ctx->output, &trail, 4 - len);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   223
    } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   224
} // spv_emit_str
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   225
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   226
// get the word count of a string
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   227
static uint32 spv_strlen(const char *str)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   228
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   229
    size_t len = strlen(str);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   230
    return (uint32) ((len / 4) + 1);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   231
} // spv_strlen
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   232
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   233
// emits an OpName straight into ctx->globals
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   234
static void spv_output_name(Context *ctx, uint32 id, const char *str)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   235
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   236
    if (isfail(ctx))
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   237
        return;  // we failed previously, don't go on...
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   238
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   239
    push_output(ctx, &ctx->globals);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   240
    spv_emit_part(ctx, 2 + spv_strlen(str), 2, SpvOpName, id);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   241
    spv_emit_str(ctx, str);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   242
    pop_output(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   243
} // spv_output_name
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   244
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   245
// emit an OpName instruction to identify a register
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   246
static void spv_output_regname(Context *ctx, uint32 id, RegisterType regtype, int regnum)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   247
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   248
    char varname[64];
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   249
    snprintf(varname, sizeof(varname), "%s_", ctx->shader_type_str);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   250
    size_t offset = strlen(varname);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   251
    get_SPIRV_varname_in_buf(ctx, regtype, regnum, varname + offset, sizeof(varname) - offset);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   252
    spv_output_name(ctx, id, varname);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   253
} // spv_output_regname
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   254
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   255
// emits an OpDecorate BuiltIn straight into ctx->helpers
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   256
static void spv_output_builtin(Context *ctx, uint32 id, SpvBuiltIn builtin)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   257
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   258
    if (isfail(ctx))
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   259
        return;  // we failed previously, don't go on...
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   260
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   261
    push_output(ctx, &ctx->helpers);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   262
    spv_emit(ctx, 4, SpvOpDecorate, id, SpvDecorationBuiltIn, builtin);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   263
    pop_output(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   264
} // spv_output_builtin
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   265
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   266
static uint32 spv_output_location(Context *ctx, uint32 id, uint32 loc)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   267
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   268
    push_output(ctx, &ctx->helpers);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   269
    spv_emit(ctx, 4, SpvOpDecorate, id, SpvDecorationLocation, loc);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   270
    pop_output(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   271
    return (buffer_size(ctx->helpers) >> 2) - 1;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   272
} // spv_output_location
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   273
1278
be0f548f321f spirv: Fix bogus detection of PSIZE0
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1277
diff changeset
   274
static void spv_output_attrib_location(Context *ctx, uint32 id,
be0f548f321f spirv: Fix bogus detection of PSIZE0
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1277
diff changeset
   275
                                       MOJOSHADER_usage usage, uint32 index)
1277
da61410edbc9 Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1274
diff changeset
   276
{
da61410edbc9 Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1274
diff changeset
   277
    SpirvPatchTable* table = &ctx->spirv.patch_table;
da61410edbc9 Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1274
diff changeset
   278
    push_output(ctx, &ctx->helpers);
da61410edbc9 Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1274
diff changeset
   279
    spv_emit(ctx, 4, SpvOpDecorate, id, SpvDecorationLocation, 0xDEADBEEF);
da61410edbc9 Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1274
diff changeset
   280
    pop_output(ctx);
1278
be0f548f321f spirv: Fix bogus detection of PSIZE0
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1277
diff changeset
   281
    table->attrib_offsets[usage][index] = (buffer_size(ctx->helpers) >> 2) - 1;
1277
da61410edbc9 Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1274
diff changeset
   282
} // spv_output_attrib_location
da61410edbc9 Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1274
diff changeset
   283
1253
c84325b641cc Add descriptor set assignment
Martin Krošlák <kroslakma@gmail.com>
parents: 1249
diff changeset
   284
static void spv_output_sampler_binding(Context *ctx, uint32 id, uint32 binding)
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   285
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   286
    if (isfail(ctx))
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   287
        return;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   288
1253
c84325b641cc Add descriptor set assignment
Martin Krošlák <kroslakma@gmail.com>
parents: 1249
diff changeset
   289
    uint32 set = 0;
c84325b641cc Add descriptor set assignment
Martin Krošlák <kroslakma@gmail.com>
parents: 1249
diff changeset
   290
    if (ctx->spirv.mode == SPIRV_MODE_VK)
c84325b641cc Add descriptor set assignment
Martin Krošlák <kroslakma@gmail.com>
parents: 1249
diff changeset
   291
    {
c84325b641cc Add descriptor set assignment
Martin Krošlák <kroslakma@gmail.com>
parents: 1249
diff changeset
   292
        set = shader_is_vertex(ctx) ? MOJOSHADER_SPIRV_VS_SAMPLER_SET
c84325b641cc Add descriptor set assignment
Martin Krošlák <kroslakma@gmail.com>
parents: 1249
diff changeset
   293
                                    : MOJOSHADER_SPIRV_PS_SAMPLER_SET;
c84325b641cc Add descriptor set assignment
Martin Krošlák <kroslakma@gmail.com>
parents: 1249
diff changeset
   294
    } // if
c84325b641cc Add descriptor set assignment
Martin Krošlák <kroslakma@gmail.com>
parents: 1249
diff changeset
   295
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   296
    push_output(ctx, &ctx->helpers);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   297
    spv_emit(ctx, 4, SpvOpDecorate, id, SpvDecorationDescriptorSet, set);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   298
    spv_emit(ctx, 4, SpvOpDecorate, id, SpvDecorationBinding, binding);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   299
    pop_output(ctx);
1253
c84325b641cc Add descriptor set assignment
Martin Krošlák <kroslakma@gmail.com>
parents: 1249
diff changeset
   300
} // spv_output_sampler_binding
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   301
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   302
static SpirvTypeIdx spv_change_base_type_vec_dim(SpirvTypeIdx sti, uint32 dim)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   303
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   304
    uint32 dimSub1 = dim - 1;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   305
    assert(STI_CORE_START_ <= sti && sti < STI_CORE_END_);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   306
    assert(dimSub1 < 4);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   307
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   308
    SpirvTypeIdx sti_base = (SpirvTypeIdx)(sti & ~0x3);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   309
    SpirvTypeIdx sti_new = (SpirvTypeIdx)(sti_base | dimSub1);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   310
    return sti_new;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   311
} // spv_change_base_type_vec_dim
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   312
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   313
static uint32 spv_get_type(Context *ctx, SpirvTypeIdx tidx)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   314
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   315
    assert(((uint32)tidx) < ((uint32)STI_LENGTH_));
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   316
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   317
    uint32 tid = ctx->spirv.tid[tidx];
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   318
    if (tid)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   319
        return tid;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   320
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   321
    push_output(ctx, &ctx->mainline_intro);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   322
    if (STI_CORE_START_ <= tidx && tidx < STI_CORE_END_)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   323
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   324
        uint32 dim = tidx & 0x3;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   325
        SpirvType type = (SpirvType)((tidx >> 2) & 0x3);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   326
        if (dim)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   327
        {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   328
            uint32 tid_base = spv_get_type(ctx, (SpirvTypeIdx)(tidx - dim));
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   329
            tid = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   330
            spv_emit(ctx, 4, SpvOpTypeVector, tid, tid_base, dim + 1);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   331
        } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   332
        else
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   333
        {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   334
            tid = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   335
            switch (type)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   336
            {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   337
                case ST_FLOAT: spv_emit(ctx, 3, SpvOpTypeFloat, tid, 32); break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   338
                case ST_SINT: spv_emit(ctx, 4, SpvOpTypeInt, tid, 32, 1); break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   339
                case ST_UINT: spv_emit(ctx, 4, SpvOpTypeInt, tid, 32, 0); break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   340
                case ST_BOOL: spv_emit(ctx, 2, SpvOpTypeBool, tid); break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   341
                default: assert(!"Unexpected value of SpirvType."); break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   342
            } // switch
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   343
        } // else
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   344
    } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   345
    else if (STI_IMAGE2D <= tidx && tidx <= STI_IMAGECUBE)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   346
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   347
        static const SpvDim dim_table[] = {SpvDim2D, SpvDim3D, SpvDimCube};
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   348
        SpvDim dim = dim_table[tidx - STI_IMAGE2D];
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   349
        uint32 tid_float = spv_get_type(ctx, STI_FLOAT);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   350
        uint32 id_image = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   351
        tid = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   352
        spv_emit(ctx, 9, SpvOpTypeImage, id_image, tid_float, dim, 0, 0, 0, 1, SpvImageFormatUnknown);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   353
        spv_emit(ctx, 3, SpvOpTypeSampledImage, tid, id_image);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   354
    } // else if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   355
    else if (tidx == STI_VOID)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   356
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   357
        tid = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   358
        spv_emit(ctx, 2, SpvOpTypeVoid, tid);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   359
    } // else if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   360
    else if (tidx == STI_FUNC_VOID)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   361
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   362
        uint32 tid_void = spv_get_type(ctx, STI_VOID);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   363
        tid = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   364
        spv_emit(ctx, 3, SpvOpTypeFunction, tid, tid_void);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   365
    } // else if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   366
    else if (tidx == STI_FUNC_LIT)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   367
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   368
        uint32 tid_vec4 = spv_get_type(ctx, STI_VEC4);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   369
        tid = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   370
        spv_emit(ctx, 3 + 1, SpvOpTypeFunction, tid, tid_vec4, tid_vec4);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   371
    } // else if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   372
    else if (STI_PTR_START_ <= tidx && tidx < STI_PTR_END_)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   373
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   374
        uint32 dim = (tidx & (1 << 4)) ? 3 : 0;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   375
        SpirvType type = (SpirvType)((tidx >> 2) & 0x3);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   376
        uint32 tid_base = spv_get_type(ctx, (SpirvTypeIdx)((1 << 4) | (type << 2) | dim));
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   377
        static const SpvStorageClass sc_map[] = {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   378
            SpvStorageClassInput,
1248
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
   379
            SpvStorageClassInput,
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   380
            SpvStorageClassOutput,
1248
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
   381
            SpvStorageClassOutput,
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
   382
            SpvStorageClassPrivate,
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   383
            SpvStorageClassPrivate,
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   384
            SpvStorageClassUniformConstant,
1248
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
   385
            SpvStorageClassUniform,
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   386
        };
1248
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
   387
        SpvStorageClass sc = sc_map[((tidx & 0x3) << 1) | (ctx->spirv.mode == SPIRV_MODE_VK)];
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   388
        tid = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   389
        spv_emit(ctx, 4, SpvOpTypePointer, tid, sc, tid_base);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   390
    } // else if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   391
    else if (STI_PTR_IMAGE2D <= tidx && tidx <= STI_PTR_IMAGECUBE)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   392
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   393
        uint32 tid_image = spv_get_type(ctx, (SpirvTypeIdx)(tidx - (STI_PTR_IMAGE2D - STI_IMAGE2D)));
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   394
        tid = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   395
        spv_emit(ctx, 4, SpvOpTypePointer, tid, SpvStorageClassUniformConstant, tid_image);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   396
    } // else if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   397
    else
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   398
        assert(!"Unexpected value of type index.");
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   399
    pop_output(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   400
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   401
    ctx->spirv.tid[tidx] = tid;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   402
    return tid;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   403
} // spv_get_type
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   404
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   405
static uint32 spv_gettrue(Context *ctx)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   406
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   407
    if (ctx->spirv.idtrue)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   408
        return ctx->spirv.idtrue;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   409
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   410
    uint32 tid_bool = spv_get_type(ctx, STI_BOOL);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   411
    uint32 id = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   412
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   413
    push_output(ctx, &ctx->mainline_intro);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   414
    spv_emit(ctx, 3, SpvOpConstantTrue, tid_bool, id);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   415
    pop_output(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   416
    return ctx->spirv.idtrue = id;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   417
} // spv_gettrue
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   418
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   419
static uint32 spv_getfalse(Context *ctx)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   420
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   421
    if (ctx->spirv.idfalse)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   422
        return ctx->spirv.idfalse;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   423
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   424
    uint32 tid_bool = spv_get_type(ctx, STI_BOOL);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   425
    uint32 id = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   426
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   427
    push_output(ctx, &ctx->mainline_intro);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   428
    spv_emit(ctx, 3, SpvOpConstantFalse, tid_bool, id);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   429
    pop_output(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   430
    return ctx->spirv.idfalse = id;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   431
} // spv_getfalse
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   432
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   433
static uint32 spv_getext(Context *ctx)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   434
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   435
    if (ctx->spirv.idext)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   436
        return ctx->spirv.idext;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   437
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   438
    return ctx->spirv.idext = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   439
} // spv_getext
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   440
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   441
static uint32 spv_output_scalar(Context *ctx, ComponentList *cl,
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   442
                             MOJOSHADER_attributeType type)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   443
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   444
    uint32 idret, idtype;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   445
    if (type == MOJOSHADER_ATTRIBUTE_FLOAT)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   446
        idtype = spv_get_type(ctx, STI_FLOAT);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   447
    else if (type == MOJOSHADER_ATTRIBUTE_INT)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   448
        idtype = spv_get_type(ctx, STI_INT);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   449
    else if (type == MOJOSHADER_ATTRIBUTE_UINT)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   450
        idtype = spv_get_type(ctx, STI_UINT);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   451
    else
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   452
    {
1234
608cef8fa24d VS2010 buildfixes
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1228
diff changeset
   453
        failf(ctx, "spv_output_scalar: invalid attribute type %d", type);
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   454
        return 0;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   455
    } // else
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   456
    idret = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   457
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   458
    push_output(ctx, &ctx->mainline_intro);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   459
    spv_emit(ctx, 4, SpvOpConstant, idtype, idret, cl->v.u);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   460
    pop_output(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   461
    return idret;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   462
} // spv_output_scalar
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   463
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   464
// The spv_getscalar* functions retrieve the result id of an OpConstant
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   465
// instruction with the corresponding value v, or generate a new one.
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   466
static uint32 spv_getscalarf(Context *ctx, float v)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   467
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   468
    ComponentList *prev = &(ctx->spirv.cl.f), *cl = ctx->spirv.cl.f.next;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   469
    while (cl)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   470
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   471
        if (v == cl->v.f)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   472
            return cl->id;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   473
        else if (v < cl->v.f)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   474
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   475
        prev = cl;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   476
        cl = cl->next;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   477
    } // while
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   478
    cl = spv_componentlist_alloc(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   479
    cl->next = prev->next;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   480
    prev->next = cl;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   481
    cl->v.f = v;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   482
    cl->id = spv_output_scalar(ctx, cl, MOJOSHADER_ATTRIBUTE_FLOAT);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   483
    return cl->id;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   484
} // spv_getscalarf
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   485
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   486
static uint32 spv_getscalari(Context *ctx, int v)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   487
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   488
    ComponentList *prev = &(ctx->spirv.cl.i), *cl = ctx->spirv.cl.i.next;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   489
    while (cl)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   490
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   491
        if (v == cl->v.i)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   492
            return cl->id;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   493
        else if (v < cl->v.i)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   494
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   495
        prev = cl;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   496
        cl = cl->next;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   497
    } // while
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   498
    cl = spv_componentlist_alloc(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   499
    cl->next = prev->next;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   500
    prev->next = cl;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   501
    cl->v.i = v;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   502
    cl->id = spv_output_scalar(ctx, cl, MOJOSHADER_ATTRIBUTE_INT);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   503
    return cl->id;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   504
} // spv_getscalari
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   505
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   506
static uint32 spv_get_constant_composite(Context *ctx, uint32 tid, uint32* cache, float scalar)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   507
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   508
    uint32 i;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   509
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   510
    assert(tid != 0);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   511
    uint32 dim =
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   512
       (tid == ctx->spirv.tid[STI_VEC4]) ? 4 :
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   513
       (tid == ctx->spirv.tid[STI_VEC3]) ? 3 :
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   514
       (tid == ctx->spirv.tid[STI_VEC2]) ? 2 : 1;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   515
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   516
    uint32 id = cache[dim - 1];
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   517
    if (id)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   518
        return id;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   519
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   520
    uint32 sid = spv_getscalarf(ctx, scalar);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   521
    if (dim == 1)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   522
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   523
        cache[0] = sid;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   524
        return sid;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   525
    } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   526
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   527
    id = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   528
    push_output(ctx, &ctx->mainline_intro);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   529
    spv_emit_part(ctx, 3 + dim, 3, SpvOpConstantComposite, tid, id);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   530
    for (i = 0; i < dim; i++)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   531
        spv_emit_word(ctx, sid);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   532
    pop_output(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   533
    cache[dim - 1] = id;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   534
    return id;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   535
} // spv_get_constant_composite
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   536
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   537
static uint32 spv_get_zero(Context *ctx, uint32 tid)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   538
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   539
    return spv_get_constant_composite(ctx, tid, ctx->spirv.id_0_0, 0.0f);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   540
} // spv_get_zero
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   541
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   542
static uint32 spv_get_one(Context *ctx, uint32 tid)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   543
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   544
    return spv_get_constant_composite(ctx, tid, ctx->spirv.id_1_0, 1.0f);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   545
} // spv_get_one
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   546
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   547
static uint32 spv_get_flt_max(Context *ctx, uint32 tid)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   548
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   549
    return spv_get_constant_composite(ctx, tid, ctx->spirv.id_flt_max, FLT_MAX);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   550
} // spv_get_one
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   551
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   552
static uint32 spv_getvec4_zero(Context *ctx)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   553
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   554
    return spv_get_constant_composite(ctx, spv_get_type(ctx, STI_VEC4), ctx->spirv.id_0_0, 0.0f);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   555
} // spv_getvec4_zero
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   556
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   557
static uint32 spv_getvec4_one(Context *ctx)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   558
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   559
    return spv_get_constant_composite(ctx, spv_get_type(ctx, STI_VEC4), ctx->spirv.id_1_0, 1.0f);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   560
} // spv_getvec4_one
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   561
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   562
// Make a 4-channel vector with a value broadcast across all channels. Roughly equivalent to `vec4(value)` in GLSL
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   563
static uint32 spv_vectorbroadcast(Context *ctx, uint32 tid, uint32 value)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   564
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   565
    uint32 result = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   566
    push_output(ctx, &ctx->mainline);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   567
    spv_emit(ctx, 3 + 4, SpvOpCompositeConstruct, tid, result, value, value, value, value);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   568
    pop_output(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   569
    return result;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   570
} // spv_vectorbroadcast
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   571
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   572
static void spv_branch_push(Context *ctx, uint32 id_merge, uint32 patch_offset)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   573
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   574
    assert(((size_t)ctx->branch_labels_stack_index) < STATICARRAYLEN(ctx->branch_labels_stack));
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   575
    int pos = ctx->branch_labels_stack_index++;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   576
    ctx->branch_labels_stack[pos] = id_merge;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   577
    ctx->branch_labels_patch_stack[pos] = patch_offset;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   578
} // spv_branch_push
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   579
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   580
static void spv_branch_get(Context *ctx, uint32* out_id_merge, uint32* out_patch_offset)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   581
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   582
    assert(ctx->branch_labels_stack_index > 0);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   583
    int pos = ctx->branch_labels_stack_index - 1;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   584
    *out_id_merge = ctx->branch_labels_stack[pos];
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   585
    *out_patch_offset = ctx->branch_labels_patch_stack[pos];
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   586
} // spv_branch_get
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   587
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   588
static void spv_branch_pop(Context *ctx, uint32* out_id_merge, uint32* out_patch_offset)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   589
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   590
    spv_branch_get(ctx, out_id_merge, out_patch_offset);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   591
    ctx->branch_labels_stack_index--;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   592
} // spv_branch_pop
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   593
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   594
static void spv_loop_push(Context *ctx, const SpirvLoopInfo *loop)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   595
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   596
    assert(((size_t)ctx->spirv.loop_stack_idx) < STATICARRAYLEN(ctx->spirv.loop_stack));
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   597
    int pos = ctx->spirv.loop_stack_idx++;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   598
    ctx->spirv.loop_stack[pos] = *loop;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   599
} // spv_loop_push
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   600
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   601
static void spv_loop_get(Context *ctx, SpirvLoopInfo *loop)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   602
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   603
    assert(ctx->spirv.loop_stack_idx > 0);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   604
    int pos = ctx->spirv.loop_stack_idx - 1;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   605
    *loop = ctx->spirv.loop_stack[pos];
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   606
} // spv_loop_get
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   607
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   608
static void spv_loop_pop(Context *ctx, SpirvLoopInfo *loop)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   609
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   610
    spv_loop_get(ctx, loop);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   611
    ctx->spirv.loop_stack_idx--;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   612
} // spv_loop_pop
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   613
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   614
static uint32 spv_loop_get_aL(Context *ctx)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   615
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   616
    int i;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   617
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   618
    // Find the first enclosing loop..endloop. There may be rep..endrep nested inside, so it might
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   619
    // not be at the top of the stack.
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   620
    for (i = ctx->spirv.loop_stack_idx - 1; i >= 0; i--)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   621
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   622
        uint32 id_aL = ctx->spirv.loop_stack[i].id_aL;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   623
        if (id_aL)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   624
            return id_aL;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   625
    } // for
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   626
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   627
    assert(!"Referencing loop counter register aL in code not part of loop..endloop region.");
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   628
    return 0;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   629
} // spv_loop_get_aL
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   630
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   631
static SpvOp spv_get_comparison(Context *ctx)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   632
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   633
    static const SpvOp spv_cmp_ops[] = {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   634
        SpvOpUndef,
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   635
        SpvOpFOrdGreaterThan,
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   636
        SpvOpFOrdEqual,
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   637
        SpvOpFOrdGreaterThanEqual,
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   638
        SpvOpFOrdLessThan,
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   639
        SpvOpFOrdNotEqual,
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   640
        SpvOpFOrdLessThanEqual,
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   641
    };
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   642
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   643
    if (ctx->instruction_controls >= STATICARRAYLEN(spv_cmp_ops))
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   644
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   645
        fail(ctx, "unknown comparison control");
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   646
        return SpvOpUndef;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   647
    } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   648
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   649
    return spv_cmp_ops[ctx->instruction_controls];
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   650
} // spv_get_comparison
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   651
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   652
static void spv_check_read_reg_id(Context *ctx, RegisterList *r)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   653
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   654
    if (r->spirv.iddecl == 0)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   655
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   656
        assert(r->regtype != REG_TYPE_SAMPLER || (shader_is_pixel(ctx) && !shader_version_atleast(ctx, 1, 4)));
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   657
        assert(r->regtype != REG_TYPE_TEXTURE || (shader_is_pixel(ctx) && !shader_version_atleast(ctx, 1, 4)));
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   658
        switch (r->regtype)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   659
        {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   660
            case REG_TYPE_SAMPLER: // s# (only ps_1_1)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   661
            case REG_TYPE_TEXTURE: // t# (only ps_1_1)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   662
            case REG_TYPE_INPUT: // v#
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   663
            case REG_TYPE_TEMP: // r#
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   664
            case REG_TYPE_CONST: // c#
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   665
            case REG_TYPE_CONSTINT: // i#
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   666
            case REG_TYPE_CONSTBOOL: // b#
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   667
            case REG_TYPE_LABEL: // l#
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   668
            case REG_TYPE_PREDICATE: // p0
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   669
                r->spirv.iddecl = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   670
                break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   671
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   672
            case REG_TYPE_LOOP: // aL
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   673
                r->spirv.iddecl = spv_loop_get_aL(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   674
                break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   675
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   676
            default:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   677
            {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   678
                char varname[64];
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   679
                get_SPIRV_varname_in_buf(ctx, r->regtype, r->regnum, varname, sizeof(varname));
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   680
                failf(ctx, "register type %s is unimplemented\n", varname);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   681
                break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   682
            } // default
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   683
        } // switch
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   684
    } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   685
} // spv_check_read_reg_id
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   686
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   687
static void spv_check_write_reg_id(Context *ctx, RegisterList *r)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   688
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   689
    if (r->spirv.iddecl == 0)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   690
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   691
        switch (r->regtype)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   692
        {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   693
            // These registers require no declarations, so we can just create them as we see them
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   694
            case REG_TYPE_ADDRESS:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   695
            case REG_TYPE_TEMP:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   696
            case REG_TYPE_RASTOUT:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   697
            case REG_TYPE_COLOROUT:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   698
            case REG_TYPE_TEXCRDOUT:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   699
            case REG_TYPE_DEPTHOUT:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   700
            case REG_TYPE_ATTROUT:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   701
            case REG_TYPE_PREDICATE:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   702
                r->spirv.iddecl = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   703
                break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   704
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   705
            // Other register types should be explicitly declared, so it is an error for them to have iddecl == 0 by now
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   706
            default:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   707
            {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   708
                char varname[64];
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   709
                get_SPIRV_varname_in_buf(ctx, r->regtype, r->regnum, varname, sizeof(varname));
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   710
                failf(ctx, "tried to write to undeclared register %s\n", varname);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   711
                break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   712
            } // default
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   713
        } // switch
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   714
    } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   715
} // spv_check_write_reg_id
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   716
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   717
static uint32 spv_ptrimage_from_texturetype(Context *ctx, TextureType ttype)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   718
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   719
    switch (ttype)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   720
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   721
        case TEXTURE_TYPE_2D:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   722
            return spv_get_type(ctx, STI_PTR_IMAGE2D);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   723
        case TEXTURE_TYPE_CUBE:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   724
            return spv_get_type(ctx, STI_PTR_IMAGECUBE);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   725
        case TEXTURE_TYPE_VOLUME:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   726
            return spv_get_type(ctx, STI_PTR_IMAGE3D);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   727
        default:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   728
            fail(ctx, "BUG: used a sampler we don't know how to define.");
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   729
            return 0;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   730
    } // switch
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   731
} // spv_ptrimage_from_texturetype
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   732
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   733
static uint32 spv_image_from_texturetype(Context *ctx, TextureType ttype)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   734
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   735
    switch (ttype)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   736
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   737
        case TEXTURE_TYPE_2D:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   738
            return spv_get_type(ctx, STI_IMAGE2D);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   739
        case TEXTURE_TYPE_CUBE:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   740
            return spv_get_type(ctx, STI_IMAGECUBE);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   741
        case TEXTURE_TYPE_VOLUME:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   742
            return spv_get_type(ctx, STI_IMAGE3D);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   743
        default:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   744
            fail(ctx, "BUG: used a sampler we don't know how to define.");
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   745
            return 0;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   746
    } // switch
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   747
} // spv_ptrimage_from_texturetype
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   748
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   749
static uint32 spv_access_uniform(Context *ctx, SpirvTypeIdx sti_ptr, RegisterType regtype, uint32 id_offset)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   750
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   751
    uint32 tid_ptr = spv_get_type(ctx, sti_ptr);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   752
    uint32 id_arr = spv_get_uniform_array_id(ctx, regtype);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   753
    uint32 id_access = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   754
    push_output(ctx, &ctx->mainline);
1248
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
   755
    if (ctx->spirv.mode == SPIRV_MODE_VK)
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
   756
    {
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
   757
        uint32 id_uniform_block = ctx->spirv.id_uniform_block;
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
   758
        if (id_uniform_block == 0)
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
   759
        {
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
   760
            id_uniform_block = spv_bumpid(ctx);
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
   761
            ctx->spirv.id_uniform_block = id_uniform_block;
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
   762
        } // if
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
   763
        spv_emit(ctx, 4+2, SpvOpAccessChain, tid_ptr, id_access, id_uniform_block, id_arr, id_offset);
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
   764
    } // if
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
   765
    else
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
   766
    {
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
   767
        spv_emit(ctx, 4+1, SpvOpAccessChain, tid_ptr, id_access, id_arr, id_offset);
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
   768
    } // else
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   769
    pop_output(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   770
    return id_access;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   771
} // spv_access_uniform
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   772
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   773
static SpirvResult spv_loadreg(Context *ctx, RegisterList *r)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   774
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   775
    const RegisterType regtype = r->regtype;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   776
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   777
    spv_check_read_reg_id(ctx, r);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   778
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   779
    uint32 id_src = r->spirv.iddecl;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   780
    SpirvResult result;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   781
    if (regtype == REG_TYPE_SAMPLER)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   782
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   783
        RegisterList *sreg = reglist_find(&ctx->samplers, REG_TYPE_SAMPLER, r->regnum);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   784
        result.tid = spv_image_from_texturetype(ctx, (TextureType)sreg->index);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   785
    } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   786
    else if (regtype == REG_TYPE_CONSTBOOL)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   787
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   788
        if (!r->spirv.is_ssa)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   789
            id_src = spv_access_uniform(ctx, STI_PTR_INT_U, regtype, r->spirv.iddecl);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   790
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   791
        result.tid = spv_get_type(ctx, STI_INT);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   792
    } // else if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   793
    else if (regtype == REG_TYPE_CONSTINT)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   794
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   795
        if (!r->spirv.is_ssa)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   796
            id_src = spv_access_uniform(ctx, STI_PTR_IVEC4_U, regtype, r->spirv.iddecl);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   797
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   798
        result.tid = spv_get_type(ctx, STI_IVEC4);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   799
    } // else if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   800
    else if (regtype == REG_TYPE_CONST)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   801
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   802
        if (!r->spirv.is_ssa)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   803
            id_src = spv_access_uniform(ctx, STI_PTR_VEC4_U, regtype, r->spirv.iddecl);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   804
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   805
        result.tid = spv_get_type(ctx, STI_VEC4);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   806
    } // else if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   807
    else if (regtype == REG_TYPE_LOOP)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   808
        result.tid = spv_get_type(ctx, STI_INT);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   809
    else if (regtype == REG_TYPE_PREDICATE)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   810
        result.tid = spv_get_type(ctx, STI_BVEC4);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   811
    else
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   812
        result.tid = spv_get_type(ctx, STI_VEC4);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   813
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   814
    // Constants can be used directly, no need to load them.
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   815
    assert(r->spirv.is_ssa == 0 || r->spirv.is_ssa == 1);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   816
    if (r->spirv.is_ssa)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   817
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   818
        result.id = r->spirv.iddecl;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   819
        return result;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   820
    } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   821
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   822
    assert(id_src);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   823
    result.id = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   824
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   825
    push_output(ctx, &ctx->mainline);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   826
    spv_emit(ctx, 4, SpvOpLoad, result.tid, result.id, id_src);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   827
    pop_output(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   828
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   829
    return result;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   830
} // spv_loadreg
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   831
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   832
static uint32 spv_emit_swizzle(Context *ctx, uint32 arg, uint32 rtid, const int swizzle, const int writemask)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   833
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   834
    uint32 result = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   835
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   836
    const int writemask0 = (writemask >> 0) & 0x1;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   837
    const int writemask1 = (writemask >> 1) & 0x1;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   838
    const int writemask2 = (writemask >> 2) & 0x1;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   839
    const int writemask3 = (writemask >> 3) & 0x1;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   840
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   841
    const uint32 swizzle_x = (swizzle >> 0) & 0x3;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   842
    const uint32 swizzle_y = (swizzle >> 2) & 0x3;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   843
    const uint32 swizzle_z = (swizzle >> 4) & 0x3;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   844
    const uint32 swizzle_w = (swizzle >> 6) & 0x3;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   845
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   846
    push_output(ctx, &ctx->mainline);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   847
    // OpVectorShuffle takes two vectors to shuffle, but to do a swizzle
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   848
    // operation we can just ignore the second argument (meaning it can be
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   849
    // anything, and I am just making it `arg` for convenience)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   850
    uint32 word_count = 5 + writemask0 + writemask1 + writemask2 + writemask3;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   851
    spv_emit_part(ctx, word_count, 5, SpvOpVectorShuffle, rtid, result, arg, arg);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   852
    if (writemask0) spv_emit_word(ctx, swizzle_x);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   853
    if (writemask1) spv_emit_word(ctx, swizzle_y);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   854
    if (writemask2) spv_emit_word(ctx, swizzle_z);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   855
    if (writemask3) spv_emit_word(ctx, swizzle_w);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   856
    pop_output(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   857
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   858
    return result;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   859
} // spv_emit_swizzle
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   860
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   861
SpirvResult spv_swizzle(Context *ctx, SpirvResult arg, const int swizzle, const int writemask)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   862
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   863
    int i;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   864
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   865
    // Nothing to do, so return the same SSA value
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   866
    if (no_swizzle(swizzle) && writemask_xyzw(writemask))
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   867
        return arg;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   868
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   869
    assert(arg.tid != 0);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   870
    assert(writemask == 1
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   871
        || writemask == 3
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   872
        || writemask == 7
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   873
        || writemask == 15
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   874
    );
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   875
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   876
    SpirvTypeIdx sti_arg = STI_VOID;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   877
    for (i = STI_CORE_START_; i < STI_CORE_END_; i++)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   878
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   879
        if (ctx->spirv.tid[i] == arg.tid)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   880
        {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   881
            sti_arg = (SpirvTypeIdx)i;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   882
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   883
        } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   884
    } // for
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   885
    assert(sti_arg != STI_VOID);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   886
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   887
    // We should not leave any value undefined, as it may end up used (eg. dot
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   888
    // product), which will make everything relying on it's result undefined.
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   889
    // Therefore, we specifically determine true dimensionality of the result.
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   890
    int resdim = 0;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   891
    switch (writemask)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   892
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   893
        case 1:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   894
            resdim = 1;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   895
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   896
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   897
        case 3:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   898
            resdim = 2;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   899
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   900
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   901
        case 7:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   902
            resdim = 3;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   903
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   904
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   905
        case 15:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   906
            resdim = 4;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   907
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   908
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   909
        default:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   910
            failf(ctx, "Unexpected write mask in swizzle: 0x%X");
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   911
            assert(0);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   912
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   913
    } // switch
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   914
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   915
    SpirvTypeIdx sti_result = spv_change_base_type_vec_dim(sti_arg, resdim);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   916
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   917
    SpirvResult result = {0};
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   918
    result.id = (resdim != 1 || sti_arg != sti_result) ? spv_bumpid(ctx) : arg.id;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   919
    result.tid = spv_get_type(ctx, sti_result);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   920
    assert(result.tid != 0);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   921
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   922
    push_output(ctx, &ctx->mainline);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   923
    if (resdim != 1)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   924
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   925
        // OpVectorShuffle takes two vectors to shuffle, but to do a swizzle
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   926
        // operation we can just ignore the second argument (meaning it can be
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   927
        // anything, and I am just making it `arg` for convenience)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   928
        spv_emit_part(ctx, 5 + resdim, 5, SpvOpVectorShuffle, result.tid, result.id, arg.id, arg.id);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   929
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   930
        for (i = 0; i < resdim; i++)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   931
            spv_emit_word(ctx, (swizzle >> (2*i)) & 0x3);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   932
    } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   933
    else if (sti_arg != sti_result)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   934
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   935
        // OpVectorShuffle may not produce a scalar. Instead we use OpCompositeExtract.
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   936
        spv_emit(ctx, 5, SpvOpCompositeExtract, result.tid, result.id, arg.id, swizzle & 0x3);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   937
    } // else if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   938
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   939
    pop_output(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   940
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   941
    return result;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   942
} // make_GLSL_swizzle_string
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   943
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   944
static SpirvResult spv_load_srcarg(Context *ctx, const size_t idx, const int writemask)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   945
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   946
    SpirvResult result = {0};
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   947
    if (idx >= STATICARRAYLEN(ctx->source_args))
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   948
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   949
        fail(ctx, "Too many source args");
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   950
        return result;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   951
    } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   952
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   953
    const SourceArgInfo *arg = &ctx->source_args[idx];
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   954
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   955
    RegisterList *reg = spv_getreg(ctx, arg->regtype, arg->regnum);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   956
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   957
    if (arg->relative)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   958
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   959
        if (arg->regtype == REG_TYPE_INPUT)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   960
            fail(ctx, "relative input array access is unimplemented");
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   961
        else
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   962
        {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   963
            assert(arg->regtype == REG_TYPE_CONST);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   964
            const int arrayidx = arg->relative_array->index;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   965
            const int offset = arg->regnum - arrayidx;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   966
            assert(offset >= 0);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   967
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   968
            int is_constant = (arg->relative_array->constant != NULL);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   969
            uint32 id_array = 0;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   970
            if (is_constant)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   971
            {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   972
                id_array = ctx->spirv.constant_arrays.idvec4;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   973
                if (id_array == 0)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   974
                {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   975
                    id_array = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   976
                    ctx->spirv.constant_arrays.idvec4 = id_array;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   977
                } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   978
            } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   979
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   980
            RegisterList *reg_rel = spv_getreg(ctx, arg->relative_regtype, arg->relative_regnum);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   981
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   982
            spv_check_read_reg_id(ctx, reg_rel);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   983
            spv_check_read_reg_id(ctx, reg);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   984
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   985
            uint32 id_int = spv_get_type(ctx, STI_INT);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   986
            uint32 id_offset;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   987
            if (reg_rel->regtype == REG_TYPE_LOOP)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   988
                id_offset = reg_rel->spirv.iddecl;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   989
            else
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   990
            {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   991
                uint32 id_pint = spv_get_type(ctx, STI_PTR_INT_P);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   992
                uint32 id_compidx = spv_getscalari(ctx, arg->relative_component);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   993
                uint32 id_pcomp = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   994
                spv_emit(ctx, 5, SpvOpAccessChain, id_pint, id_pcomp, reg_rel->spirv.iddecl, id_compidx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   995
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   996
                id_offset = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   997
                spv_emit(ctx, 4, SpvOpLoad, id_int, id_offset, id_pcomp);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   998
            } // else
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   999
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1000
            if (!is_constant)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1001
            {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1002
                uint32 id_arraybase = reg->spirv.iddecl;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1003
                uint32 id_a = id_offset;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1004
                uint32 id_b = id_arraybase;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1005
                id_offset = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1006
                spv_emit(ctx, 5, SpvOpIAdd, id_int, id_offset, id_a, id_b);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1007
            } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1008
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1009
            if (offset)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1010
            {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1011
                uint32 id_a = id_offset;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1012
                uint32 id_b = spv_getscalari(ctx, offset);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1013
                id_offset = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1014
                spv_emit(ctx, 5, SpvOpIAdd, id_int, id_offset, id_a, id_b);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1015
            } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1016
1248
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
  1017
            uint32 id_pvalue;
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
  1018
            if (is_constant)
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
  1019
            {
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
  1020
                uint32 id_pvec4 = spv_get_type(ctx, STI_PTR_VEC4_P);
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
  1021
                id_pvalue = spv_bumpid(ctx);
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
  1022
                spv_emit(ctx, 4+1, SpvOpAccessChain, id_pvec4, id_pvalue, id_array, id_offset);
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
  1023
            } // if
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
  1024
            else
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
  1025
            {
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
  1026
                id_pvalue = spv_access_uniform(ctx, STI_PTR_VEC4_U, arg->regtype, id_offset);
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
  1027
            } // else
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1028
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1029
            result.tid = spv_get_type(ctx, STI_VEC4);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1030
            result.id = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1031
            spv_emit(ctx, 4, SpvOpLoad, result.tid, result.id, id_pvalue);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1032
        } // else
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1033
    } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1034
    else
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1035
        result = spv_loadreg(ctx, reg);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1036
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1037
    result = spv_swizzle(ctx, result, arg->swizzle, writemask);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1038
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1039
    switch (arg->src_mod)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1040
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1041
        case SRCMOD_NEGATE:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1042
        {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1043
            uint32 id_neg = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1044
            spv_emit(ctx, 4, SpvOpFNegate, result.tid, id_neg, result.id);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1045
            result.id = id_neg;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1046
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1047
        } // case
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1048
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1049
        case SRCMOD_BIASNEGATE:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1050
        {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1051
            uint32 id_half = spv_get_constant_composite(ctx, result.tid, ctx->spirv.id_0_5, 0.5f);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1052
            uint32 id_tmp  = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1053
            uint32 id_new  = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1054
            spv_emit(ctx, 5, SpvOpFSub, result.tid, id_tmp, result.id, id_half);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1055
            spv_emit(ctx, 4, SpvOpFNegate, result.tid, id_new, id_tmp);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1056
            result.id = id_new;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1057
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1058
        } // case
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1059
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1060
        case SRCMOD_BIAS:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1061
        {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1062
            uint32 id_half = spv_get_constant_composite(ctx, result.tid, ctx->spirv.id_0_5, 0.5f);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1063
            uint32 id_new  = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1064
            spv_emit(ctx, 5, SpvOpFSub, result.tid, id_new, result.id, id_half);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1065
            result.id = id_new;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1066
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1067
        } // case
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1068
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1069
        case SRCMOD_SIGNNEGATE:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1070
        {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1071
            uint32 id_half = spv_get_constant_composite(ctx, result.tid, ctx->spirv.id_0_5, 0.5f);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1072
            uint32 id_two  = spv_get_constant_composite(ctx, result.tid, ctx->spirv.id_2_0, 2.0f);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1073
            uint32 id_tmp0 = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1074
            uint32 id_tmp1 = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1075
            uint32 id_new  = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1076
            spv_emit(ctx, 5, SpvOpFSub, result.tid, id_tmp0, result.id, id_half);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1077
            spv_emit(ctx, 5, SpvOpFMul, result.tid, id_tmp1, id_tmp0, id_two);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1078
            spv_emit(ctx, 4, SpvOpFNegate, result.tid, id_new, id_tmp1);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1079
            result.id = id_new;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1080
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1081
        } // case
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1082
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1083
        case SRCMOD_SIGN:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1084
        {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1085
            uint32 id_half = spv_get_constant_composite(ctx, result.tid, ctx->spirv.id_0_5, 0.5f);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1086
            uint32 id_two  = spv_get_constant_composite(ctx, result.tid, ctx->spirv.id_2_0, 2.0f);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1087
            uint32 id_tmp  = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1088
            uint32 id_new  = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1089
            spv_emit(ctx, 5, SpvOpFSub, result.tid, id_tmp, result.id, id_half);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1090
            spv_emit(ctx, 5, SpvOpFMul, result.tid, id_new, id_tmp, id_two);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1091
            result.id = id_new;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1092
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1093
        } // case
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1094
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1095
        case SRCMOD_COMPLEMENT:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1096
        {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1097
            uint32 id_one = spv_get_constant_composite(ctx, result.tid, ctx->spirv.id_1_0, 1.0f);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1098
            uint32 id_new = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1099
            spv_emit(ctx, 5, SpvOpFSub, result.tid, id_new, id_one, result.id);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1100
            result.id = id_new;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1101
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1102
        } // case
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1103
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1104
        case SRCMOD_X2NEGATE:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1105
        {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1106
            uint32 id_two = spv_get_constant_composite(ctx, result.tid, ctx->spirv.id_2_0, 2.0f);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1107
            uint32 id_tmp = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1108
            uint32 id_new = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1109
            spv_emit(ctx, 5, SpvOpFMul, result.tid, id_tmp, result.id, id_two);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1110
            spv_emit(ctx, 4, SpvOpFNegate, result.tid, id_new, id_tmp);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1111
            result.id = id_new;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1112
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1113
        } // case
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1114
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1115
        case SRCMOD_X2:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1116
        {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1117
            uint32 id_two = spv_get_constant_composite(ctx, result.tid, ctx->spirv.id_2_0, 2.0f);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1118
            uint32 id_new = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1119
            spv_emit(ctx, 5, SpvOpFMul, result.tid, id_new, result.id, id_two);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1120
            result.id = id_new;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1121
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1122
        } // case
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1123
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1124
        // case SRCMOD_DZ:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1125
        //     fail(ctx, "SRCMOD_DZ unsupported"); return buf; // !!! FIXME
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1126
        //     postmod_str = "_dz";
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1127
        //     break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1128
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1129
        // case SRCMOD_DW:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1130
        //     fail(ctx, "SRCMOD_DW unsupported"); return buf; // !!! FIXME
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1131
        //     postmod_str = "_dw";
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1132
        //     break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1133
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1134
        case SRCMOD_ABSNEGATE:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1135
        {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1136
            uint32 id_abs = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1137
            uint32 id_neg = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1138
            spv_emit(ctx, 5 + 1, SpvOpExtInst, result.tid, id_abs, spv_getext(ctx), GLSLstd450FAbs, result.id);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1139
            spv_emit(ctx, 4, SpvOpFNegate, result.tid, id_neg, id_abs);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1140
            result.id = id_neg;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1141
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1142
        } // case
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1143
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1144
        case SRCMOD_ABS:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1145
        {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1146
            uint32 id_abs = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1147
            spv_emit(ctx, 5 + 1, SpvOpExtInst, result.tid, id_abs, spv_getext(ctx), GLSLstd450FAbs, result.id);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1148
            result.id = id_abs;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1149
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1150
        } // case
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1151
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1152
        case SRCMOD_NOT:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1153
        {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1154
            uint32 id_not = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1155
            spv_emit(ctx, 4, SpvOpLogicalNot, result.tid, id_not, result.id);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1156
            result.id = id_not;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1157
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1158
        } // case
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1159
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1160
        case SRCMOD_NONE:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1161
        case SRCMOD_TOTAL:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1162
            break;  // stop compiler whining.
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1163
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1164
        default:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1165
            failf(ctx, "unsupported source modifier %d", arg->src_mod);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1166
            return result;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1167
    } // switch
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1168
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1169
    return result;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1170
} // spv_load_srcarg
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1171