profiles/mojoshader_profile_spirv.c
author Ethan Lee <flibitijibibo@flibitijibibo.com>
Sun, 30 Aug 2020 21:35:31 -0400
changeset 1303 7a43f238f28a
parent 1299 02d36217591b
child 1318 ff4eb6d9c9c2
permissions -rw-r--r--
spirv: Separate pixel shader outputs from inputs, fix linker accordingly
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
1303
7a43f238f28a spirv: Separate pixel shader outputs from inputs, fix linker accordingly
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1299
diff changeset
   274
static void spv_output_color_location(Context *ctx, uint32 id, uint32 index)
7a43f238f28a spirv: Separate pixel shader outputs from inputs, fix linker accordingly
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1299
diff changeset
   275
{
7a43f238f28a spirv: Separate pixel shader outputs from inputs, fix linker accordingly
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1299
diff changeset
   276
    SpirvPatchTable* table = &ctx->spirv.patch_table;
7a43f238f28a spirv: Separate pixel shader outputs from inputs, fix linker accordingly
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1299
diff changeset
   277
    push_output(ctx, &ctx->helpers);
7a43f238f28a spirv: Separate pixel shader outputs from inputs, fix linker accordingly
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1299
diff changeset
   278
    spv_emit(ctx, 4, SpvOpDecorate, id, SpvDecorationLocation, index);
7a43f238f28a spirv: Separate pixel shader outputs from inputs, fix linker accordingly
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1299
diff changeset
   279
    pop_output(ctx);
7a43f238f28a spirv: Separate pixel shader outputs from inputs, fix linker accordingly
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1299
diff changeset
   280
    table->output_offsets[index] = (buffer_size(ctx->helpers) >> 2) - 1;
7a43f238f28a spirv: Separate pixel shader outputs from inputs, fix linker accordingly
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1299
diff changeset
   281
} // spv_output_color_location
7a43f238f28a spirv: Separate pixel shader outputs from inputs, fix linker accordingly
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1299
diff changeset
   282
1278
be0f548f321f spirv: Fix bogus detection of PSIZE0
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1277
diff changeset
   283
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
   284
                                       MOJOSHADER_usage usage, uint32 index)
1277
da61410edbc9 Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1274
diff changeset
   285
{
da61410edbc9 Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1274
diff changeset
   286
    SpirvPatchTable* table = &ctx->spirv.patch_table;
da61410edbc9 Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1274
diff changeset
   287
    push_output(ctx, &ctx->helpers);
da61410edbc9 Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1274
diff changeset
   288
    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
   289
    pop_output(ctx);
1278
be0f548f321f spirv: Fix bogus detection of PSIZE0
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1277
diff changeset
   290
    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
   291
} // spv_output_attrib_location
da61410edbc9 Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1274
diff changeset
   292
1253
c84325b641cc Add descriptor set assignment
Martin Krošlák <kroslakma@gmail.com>
parents: 1249
diff changeset
   293
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
   294
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   295
    if (isfail(ctx))
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   296
        return;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   297
1253
c84325b641cc Add descriptor set assignment
Martin Krošlák <kroslakma@gmail.com>
parents: 1249
diff changeset
   298
    uint32 set = 0;
c84325b641cc Add descriptor set assignment
Martin Krošlák <kroslakma@gmail.com>
parents: 1249
diff changeset
   299
    if (ctx->spirv.mode == SPIRV_MODE_VK)
c84325b641cc Add descriptor set assignment
Martin Krošlák <kroslakma@gmail.com>
parents: 1249
diff changeset
   300
    {
c84325b641cc Add descriptor set assignment
Martin Krošlák <kroslakma@gmail.com>
parents: 1249
diff changeset
   301
        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
   302
                                    : MOJOSHADER_SPIRV_PS_SAMPLER_SET;
c84325b641cc Add descriptor set assignment
Martin Krošlák <kroslakma@gmail.com>
parents: 1249
diff changeset
   303
    } // if
c84325b641cc Add descriptor set assignment
Martin Krošlák <kroslakma@gmail.com>
parents: 1249
diff changeset
   304
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   305
    push_output(ctx, &ctx->helpers);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   306
    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
   307
    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
   308
    pop_output(ctx);
1253
c84325b641cc Add descriptor set assignment
Martin Krošlák <kroslakma@gmail.com>
parents: 1249
diff changeset
   309
} // spv_output_sampler_binding
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   310
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   311
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
   312
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   313
    uint32 dimSub1 = dim - 1;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   314
    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
   315
    assert(dimSub1 < 4);
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
    SpirvTypeIdx sti_base = (SpirvTypeIdx)(sti & ~0x3);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   318
    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
   319
    return sti_new;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   320
} // spv_change_base_type_vec_dim
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   321
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   322
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
   323
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   324
    assert(((uint32)tidx) < ((uint32)STI_LENGTH_));
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   325
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   326
    uint32 tid = ctx->spirv.tid[tidx];
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   327
    if (tid)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   328
        return tid;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   329
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   330
    push_output(ctx, &ctx->mainline_intro);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   331
    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
   332
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   333
        uint32 dim = tidx & 0x3;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   334
        SpirvType type = (SpirvType)((tidx >> 2) & 0x3);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   335
        if (dim)
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
            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
   338
            tid = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   339
            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
   340
        } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   341
        else
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   342
        {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   343
            tid = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   344
            switch (type)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   345
            {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   346
                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
   347
                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
   348
                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
   349
                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
   350
                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
   351
            } // switch
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   352
        } // else
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   353
    } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   354
    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
   355
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   356
        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
   357
        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
   358
        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
   359
        uint32 id_image = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   360
        tid = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   361
        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
   362
        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
   363
    } // else if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   364
    else if (tidx == STI_VOID)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   365
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   366
        tid = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   367
        spv_emit(ctx, 2, SpvOpTypeVoid, tid);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   368
    } // else if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   369
    else if (tidx == STI_FUNC_VOID)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   370
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   371
        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
   372
        tid = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   373
        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
   374
    } // else if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   375
    else if (tidx == STI_FUNC_LIT)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   376
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   377
        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
   378
        tid = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   379
        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
   380
    } // else if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   381
    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
   382
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   383
        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
   384
        SpirvType type = (SpirvType)((tidx >> 2) & 0x3);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   385
        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
   386
        static const SpvStorageClass sc_map[] = {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   387
            SpvStorageClassInput,
1248
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
   388
            SpvStorageClassInput,
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   389
            SpvStorageClassOutput,
1248
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
   390
            SpvStorageClassOutput,
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
   391
            SpvStorageClassPrivate,
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   392
            SpvStorageClassPrivate,
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   393
            SpvStorageClassUniformConstant,
1248
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
   394
            SpvStorageClassUniform,
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   395
        };
1248
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
   396
        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
   397
        tid = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   398
        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
   399
    } // else if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   400
    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
   401
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   402
        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
   403
        tid = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   404
        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
   405
    } // else if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   406
    else
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   407
        assert(!"Unexpected value of type index.");
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   408
    pop_output(ctx);
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
    ctx->spirv.tid[tidx] = tid;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   411
    return tid;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   412
} // spv_get_type
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   413
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   414
static uint32 spv_gettrue(Context *ctx)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   415
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   416
    if (ctx->spirv.idtrue)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   417
        return ctx->spirv.idtrue;
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
    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
   420
    uint32 id = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   421
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   422
    push_output(ctx, &ctx->mainline_intro);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   423
    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
   424
    pop_output(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   425
    return ctx->spirv.idtrue = id;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   426
} // spv_gettrue
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   427
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   428
static uint32 spv_getfalse(Context *ctx)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   429
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   430
    if (ctx->spirv.idfalse)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   431
        return ctx->spirv.idfalse;
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
    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
   434
    uint32 id = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   435
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   436
    push_output(ctx, &ctx->mainline_intro);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   437
    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
   438
    pop_output(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   439
    return ctx->spirv.idfalse = id;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   440
} // spv_getfalse
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   441
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   442
static uint32 spv_getext(Context *ctx)
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
    if (ctx->spirv.idext)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   445
        return ctx->spirv.idext;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   446
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   447
    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
   448
} // spv_getext
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   449
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   450
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
   451
                             MOJOSHADER_attributeType type)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   452
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   453
    uint32 idret, idtype;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   454
    if (type == MOJOSHADER_ATTRIBUTE_FLOAT)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   455
        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
   456
    else if (type == MOJOSHADER_ATTRIBUTE_INT)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   457
        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
   458
    else if (type == MOJOSHADER_ATTRIBUTE_UINT)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   459
        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
   460
    else
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   461
    {
1234
608cef8fa24d VS2010 buildfixes
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1228
diff changeset
   462
        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
   463
        return 0;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   464
    } // else
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   465
    idret = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   466
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   467
    push_output(ctx, &ctx->mainline_intro);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   468
    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
   469
    pop_output(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   470
    return idret;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   471
} // spv_output_scalar
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   472
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   473
// 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
   474
// 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
   475
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
   476
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   477
    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
   478
    while (cl)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   479
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   480
        if (v == cl->v.f)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   481
            return cl->id;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   482
        else if (v < cl->v.f)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   483
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   484
        prev = cl;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   485
        cl = cl->next;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   486
    } // while
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   487
    cl = spv_componentlist_alloc(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   488
    cl->next = prev->next;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   489
    prev->next = cl;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   490
    cl->v.f = v;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   491
    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
   492
    return cl->id;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   493
} // spv_getscalarf
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   494
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   495
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
   496
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   497
    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
   498
    while (cl)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   499
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   500
        if (v == cl->v.i)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   501
            return cl->id;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   502
        else if (v < cl->v.i)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   503
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   504
        prev = cl;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   505
        cl = cl->next;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   506
    } // while
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   507
    cl = spv_componentlist_alloc(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   508
    cl->next = prev->next;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   509
    prev->next = cl;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   510
    cl->v.i = v;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   511
    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
   512
    return cl->id;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   513
} // spv_getscalari
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   514
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   515
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
   516
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   517
    uint32 i;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   518
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   519
    assert(tid != 0);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   520
    uint32 dim =
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   521
       (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
   522
       (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
   523
       (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
   524
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   525
    uint32 id = cache[dim - 1];
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   526
    if (id)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   527
        return id;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   528
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   529
    uint32 sid = spv_getscalarf(ctx, scalar);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   530
    if (dim == 1)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   531
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   532
        cache[0] = sid;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   533
        return sid;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   534
    } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   535
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   536
    id = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   537
    push_output(ctx, &ctx->mainline_intro);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   538
    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
   539
    for (i = 0; i < dim; i++)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   540
        spv_emit_word(ctx, sid);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   541
    pop_output(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   542
    cache[dim - 1] = id;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   543
    return id;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   544
} // spv_get_constant_composite
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   545
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   546
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
   547
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   548
    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
   549
} // spv_get_zero
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   550
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   551
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
   552
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   553
    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
   554
} // spv_get_one
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   555
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   556
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
   557
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   558
    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
   559
} // spv_get_one
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   560
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   561
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
   562
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   563
    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
   564
} // spv_getvec4_zero
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   565
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   566
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
   567
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   568
    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
   569
} // spv_getvec4_one
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   570
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   571
// 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
   572
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
   573
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   574
    uint32 result = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   575
    push_output(ctx, &ctx->mainline);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   576
    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
   577
    pop_output(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   578
    return result;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   579
} // spv_vectorbroadcast
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   580
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   581
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
   582
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   583
    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
   584
    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
   585
    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
   586
    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
   587
} // spv_branch_push
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   588
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   589
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
   590
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   591
    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
   592
    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
   593
    *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
   594
    *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
   595
} // spv_branch_get
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   596
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   597
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
   598
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   599
    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
   600
    ctx->branch_labels_stack_index--;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   601
} // spv_branch_pop
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
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
   604
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   605
    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
   606
    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
   607
    ctx->spirv.loop_stack[pos] = *loop;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   608
} // spv_loop_push
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
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
   611
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   612
    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
   613
    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
   614
    *loop = ctx->spirv.loop_stack[pos];
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   615
} // spv_loop_get
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   616
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   617
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
   618
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   619
    spv_loop_get(ctx, loop);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   620
    ctx->spirv.loop_stack_idx--;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   621
} // spv_loop_pop
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   622
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   623
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
   624
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   625
    int i;
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
    // 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
   628
    // 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
   629
    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
   630
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   631
        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
   632
        if (id_aL)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   633
            return id_aL;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   634
    } // for
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   635
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   636
    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
   637
    return 0;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   638
} // spv_loop_get_aL
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   639
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   640
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
   641
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   642
    static const SpvOp spv_cmp_ops[] = {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   643
        SpvOpUndef,
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   644
        SpvOpFOrdGreaterThan,
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   645
        SpvOpFOrdEqual,
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   646
        SpvOpFOrdGreaterThanEqual,
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   647
        SpvOpFOrdLessThan,
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   648
        SpvOpFOrdNotEqual,
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   649
        SpvOpFOrdLessThanEqual,
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   650
    };
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
    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
   653
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   654
        fail(ctx, "unknown comparison control");
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   655
        return SpvOpUndef;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   656
    } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   657
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   658
    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
   659
} // spv_get_comparison
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   660
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   661
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
   662
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   663
    if (r->spirv.iddecl == 0)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   664
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   665
        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
   666
        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
   667
        switch (r->regtype)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   668
        {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   669
            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
   670
            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
   671
            case REG_TYPE_INPUT: // v#
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   672
            case REG_TYPE_TEMP: // r#
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   673
            case REG_TYPE_CONST: // c#
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   674
            case REG_TYPE_CONSTINT: // i#
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   675
            case REG_TYPE_CONSTBOOL: // b#
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   676
            case REG_TYPE_LABEL: // l#
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   677
            case REG_TYPE_PREDICATE: // p0
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   678
                r->spirv.iddecl = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   679
                break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   680
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   681
            case REG_TYPE_LOOP: // aL
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   682
                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
   683
                break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   684
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   685
            default:
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
                char varname[64];
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   688
                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
   689
                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
   690
                break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   691
            } // default
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   692
        } // switch
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   693
    } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   694
} // spv_check_read_reg_id
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   695
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   696
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
   697
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   698
    if (r->spirv.iddecl == 0)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   699
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   700
        switch (r->regtype)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   701
        {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   702
            // 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
   703
            case REG_TYPE_ADDRESS:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   704
            case REG_TYPE_TEMP:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   705
            case REG_TYPE_RASTOUT:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   706
            case REG_TYPE_COLOROUT:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   707
            case REG_TYPE_TEXCRDOUT:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   708
            case REG_TYPE_DEPTHOUT:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   709
            case REG_TYPE_ATTROUT:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   710
            case REG_TYPE_PREDICATE:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   711
                r->spirv.iddecl = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   712
                break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   713
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   714
            // 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
   715
            default:
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
                char varname[64];
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   718
                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
   719
                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
   720
                break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   721
            } // default
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   722
        } // switch
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   723
    } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   724
} // spv_check_write_reg_id
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   725
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   726
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
   727
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   728
    switch (ttype)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   729
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   730
        case TEXTURE_TYPE_2D:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   731
            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
   732
        case TEXTURE_TYPE_CUBE:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   733
            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
   734
        case TEXTURE_TYPE_VOLUME:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   735
            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
   736
        default:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   737
            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
   738
            return 0;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   739
    } // switch
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   740
} // spv_ptrimage_from_texturetype
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   741
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   742
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
   743
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   744
    switch (ttype)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   745
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   746
        case TEXTURE_TYPE_2D:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   747
            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
   748
        case TEXTURE_TYPE_CUBE:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   749
            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
   750
        case TEXTURE_TYPE_VOLUME:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   751
            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
   752
        default:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   753
            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
   754
            return 0;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   755
    } // switch
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   756
} // spv_ptrimage_from_texturetype
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   757
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   758
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
   759
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   760
    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
   761
    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
   762
    uint32 id_access = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   763
    push_output(ctx, &ctx->mainline);
1248
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
   764
    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
   765
    {
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
   766
        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
   767
        if (id_uniform_block == 0)
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
   768
        {
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
   769
            id_uniform_block = spv_bumpid(ctx);
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
   770
            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
   771
        } // if
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
   772
        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
   773
    } // if
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
   774
    else
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
   775
    {
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
   776
        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
   777
    } // else
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   778
    pop_output(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   779
    return id_access;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   780
} // spv_access_uniform
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   781
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   782
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
   783
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   784
    const RegisterType regtype = r->regtype;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   785
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   786
    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
   787
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   788
    uint32 id_src = r->spirv.iddecl;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   789
    SpirvResult result;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   790
    if (regtype == REG_TYPE_SAMPLER)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   791
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   792
        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
   793
        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
   794
    } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   795
    else if (regtype == REG_TYPE_CONSTBOOL)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   796
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   797
        if (!r->spirv.is_ssa)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   798
            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
   799
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   800
        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
   801
    } // else if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   802
    else if (regtype == REG_TYPE_CONSTINT)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   803
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   804
        if (!r->spirv.is_ssa)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   805
            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
   806
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   807
        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
   808
    } // else if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   809
    else if (regtype == REG_TYPE_CONST)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   810
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   811
        if (!r->spirv.is_ssa)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   812
            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
   813
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   814
        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
   815
    } // else if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   816
    else if (regtype == REG_TYPE_LOOP)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   817
        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
   818
    else if (regtype == REG_TYPE_PREDICATE)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   819
        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
   820
    else
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   821
        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
   822
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   823
    // 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
   824
    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
   825
    if (r->spirv.is_ssa)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   826
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   827
        result.id = r->spirv.iddecl;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   828
        return result;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   829
    } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   830
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   831
    assert(id_src);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   832
    result.id = spv_bumpid(ctx);
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
    push_output(ctx, &ctx->mainline);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   835
    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
   836
    pop_output(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   837
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   838
    return result;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   839
} // spv_loadreg
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
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
   842
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   843
    uint32 result = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   844
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   845
    const int writemask0 = (writemask >> 0) & 0x1;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   846
    const int writemask1 = (writemask >> 1) & 0x1;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   847
    const int writemask2 = (writemask >> 2) & 0x1;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   848
    const int writemask3 = (writemask >> 3) & 0x1;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   849
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   850
    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
   851
    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
   852
    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
   853
    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
   854
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   855
    push_output(ctx, &ctx->mainline);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   856
    // 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
   857
    // 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
   858
    // 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
   859
    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
   860
    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
   861
    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
   862
    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
   863
    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
   864
    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
   865
    pop_output(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   866
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   867
    return result;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   868
} // spv_emit_swizzle
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   869
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   870
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
   871
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   872
    int i;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   873
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   874
    // 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
   875
    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
   876
        return arg;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   877
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   878
    assert(arg.tid != 0);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   879
    assert(writemask == 1
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   880
        || writemask == 3
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   881
        || writemask == 7
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   882
        || writemask == 15
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   883
    );
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   884
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   885
    SpirvTypeIdx sti_arg = STI_VOID;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   886
    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
   887
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   888
        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
   889
        {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   890
            sti_arg = (SpirvTypeIdx)i;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   891
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   892
        } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   893
    } // for
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   894
    assert(sti_arg != STI_VOID);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   895
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   896
    // 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
   897
    // 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
   898
    // 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
   899
    int resdim = 0;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   900
    switch (writemask)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   901
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   902
        case 1:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   903
            resdim = 1;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   904
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   905
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   906
        case 3:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   907
            resdim = 2;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   908
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   909
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   910
        case 7:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   911
            resdim = 3;
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
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   914
        case 15:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   915
            resdim = 4;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   916
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   917
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   918
        default:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   919
            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
   920
            assert(0);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   921
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   922
    } // switch
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   923
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   924
    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
   925
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   926
    SpirvResult result = {0};
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   927
    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
   928
    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
   929
    assert(result.tid != 0);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   930
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   931
    push_output(ctx, &ctx->mainline);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   932
    if (resdim != 1)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   933
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   934
        // 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
   935
        // 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
   936
        // 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
   937
        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
   938
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   939
        for (i = 0; i < resdim; i++)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   940
            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
   941
    } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   942
    else if (sti_arg != sti_result)
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
        // 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
   945
        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
   946
    } // else if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   947
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   948
    pop_output(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   949
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
} // make_GLSL_swizzle_string
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
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
   954
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   955
    SpirvResult result = {0};
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   956
    if (idx >= STATICARRAYLEN(ctx->source_args))
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   957
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   958
        fail(ctx, "Too many source args");
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   959
        return result;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   960
    } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   961
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   962
    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
   963
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   964
    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
   965
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   966
    if (arg->relative)
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
        if (arg->regtype == REG_TYPE_INPUT)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   969
            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
   970
        else
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
            assert(arg->regtype == REG_TYPE_CONST);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   973
            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
   974
            const int offset = arg->regnum - arrayidx;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   975
            assert(offset >= 0);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   976
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   977
            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
   978
            uint32 id_array = 0;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   979
            if (is_constant)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   980
            {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   981
                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
   982
                if (id_array == 0)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   983
                {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   984
                    id_array = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   985
                    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
   986
                } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   987
            } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   988
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   989
            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
   990
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   991
            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
   992
            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
   993
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   994
            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
   995
            uint32 id_offset;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   996
            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
   997
                id_offset = reg_rel->spirv.iddecl;
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
                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
  1001
                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
  1002
                uint32 id_pcomp = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1003
                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
  1004
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, 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
  1007
            } // else
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 (!is_constant)
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_arraybase = reg->spirv.iddecl;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1012
                uint32 id_a = id_offset;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1013
                uint32 id_b = id_arraybase;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1014
                id_offset = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1015
                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
  1016
            } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1017
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1018
            if (offset)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1019
            {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1020
                uint32 id_a = id_offset;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1021
                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
  1022
                id_offset = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1023
                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
  1024
            } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1025
1248
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
  1026
            uint32 id_pvalue;
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
  1027
            if (is_constant)
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
  1028
            {
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
  1029
                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
  1030
                id_pvalue = spv_bumpid(ctx);
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
  1031
                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
  1032
            } // if
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
  1033
            else
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
  1034
            {
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
  1035
                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
  1036
            } // else
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1037
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1038
            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
  1039
            result.id = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1040
            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
  1041
        } // else
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1042
    } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1043
    else
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1044
        result = spv_loadreg(ctx, reg);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1045
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1046
    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
  1047
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1048
    switch (arg->src_mod)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1049
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1050
        case SRCMOD_NEGATE:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1051
        {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1052
            uint32 id_neg = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1053
            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
  1054
            result.id = id_neg;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1055
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1056
        } // case
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1057
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1058
        case SRCMOD_BIASNEGATE:
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
            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
  1061
            uint32 id_tmp  = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1062
            uint32 id_new  = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1063
            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
  1064
            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
  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_BIAS:
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_new  = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1073
            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
  1074
            result.id = id_new;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1075
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1076
        } // case
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1077
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1078
        case SRCMOD_SIGNNEGATE:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1079
        {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1080
            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
  1081
            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
  1082
            uint32 id_tmp0 = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1083
            uint32 id_tmp1 = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1084
            uint32 id_new  = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1085
            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
  1086
            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
  1087
            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
  1088
            result.id = id_new;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1089
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1090
        } // case
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1091
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1092
        case SRCMOD_SIGN:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1093
        {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1094
            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
  1095
            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
  1096
            uint32 id_tmp  = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1097
            uint32 id_new  = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1098
            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
  1099
            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
  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_COMPLEMENT:
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_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
  1107
            uint32 id_new = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1108
            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
  1109
            result.id = id_new;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1110
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1111
        } // case
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1112
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1113
        case SRCMOD_X2NEGATE:
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
            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
  1116
            uint32 id_tmp = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1117
            uint32 id_new = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1118
            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
  1119
            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
  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_X2:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1125
        {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1126
            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
  1127
            uint32 id_new = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1128
            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
  1129
            result.id = id_new;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1130
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1131
        } // case
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1132
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1133
        // case SRCMOD_DZ:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1134
        //     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
  1135
        //     postmod_str = "_dz";
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1136
        //     break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1137
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1138
        // case SRCMOD_DW:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1139
        //     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
  1140
        //     postmod_str = "_dw";
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
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1143
        case SRCMOD_ABSNEGATE:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1144
        {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1145
            uint32 id_abs = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1146
            uint32 id_neg = 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
            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
  1149
            result.id = id_neg;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1150
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1151
        } // case
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1152
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1153
        case SRCMOD_ABS:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1154
        {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1155
            uint32 id_abs = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1156
            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
  1157
            result.id = id_abs;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1158
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1159
        } // case
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1160
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1161
        case SRCMOD_NOT:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1162
        {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1163
            uint32 id_not = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1164
            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
  1165
            result.id = id_not;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1166
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1167
        } // case
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
        case SRCMOD_NONE: