summaryrefslogtreecommitdiff
path: root/source/slang/slang-stdlib-textures.h
blob: a6166cc2d8fdf5db8bfe3d7d733887b647126c13 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#pragma once

#include "slang-ir.h"
#include "slang-type-system-shared.h"
#include "../core/slang-string.h"

namespace Slang
{

static const struct BaseTextureShapeInfo {
    char const*			    shapeName;
    SlangResourceShape      baseShape;
    int					    coordCount;
} kBaseTextureShapes[] = {
    { "1D",		SLANG_TEXTURE_1D,	1 },
    { "2D",		SLANG_TEXTURE_2D,	2 },
    { "3D",		SLANG_TEXTURE_3D,	3 },
    { "Cube",	SLANG_TEXTURE_CUBE, 3 },
};

static const struct BaseTextureAccessInfo {
    char const* name;
    SlangResourceAccess access;
} kBaseTextureAccessLevels[] = {
    { "",                   SLANG_RESOURCE_ACCESS_READ },
    { "RW",                 SLANG_RESOURCE_ACCESS_READ_WRITE },
    { "RasterizerOrdered",  SLANG_RESOURCE_ACCESS_RASTER_ORDERED },
    { "Feedback",           SLANG_RESOURCE_ACCESS_FEEDBACK },
};

struct TextureTypeInfo
{
    TextureTypeInfo(
        BaseTextureShapeInfo const& base,
        bool isArray,
        bool isMultisample,
        bool isShadow,
        StringBuilder& inSB,
        String const& inPath);

    BaseTextureShapeInfo const& base;
    bool isArray;
    bool isMultisample;
    bool isShadow;
    StringBuilder& sb;
    String path;

    void emitTypeDecl();

public:
    //
    // Functions for writing specific parts of a definition
    //
    void writeGetDimensionFunctions();

    //
    // More general utilities
    //
    enum class ReadNoneMode
    {
        Never,
        Always
    };

    void writeFuncBody(
        const char* funcName,
        const String& glsl,
        const String& cuda,
        const String& spirvDefault,
        const String& spirvRWDefault,
        const String& spirvCombined,
        const String& metal
        );
    void writeFuncWithSig(
        const char* funcName,
        const String& sig,
        const String& glsl = String{},
        const String& spirvDefault = String{},
        const String& spirvRWDefault = String{},
        const String& spirvCombined = String{},
        const String& cuda = String{},
        const String& metal = String{},
        const ReadNoneMode readNoneMode = ReadNoneMode::Never
    );
    void writeFunc(
        const char* returnType,
        const char* funcName,
        const String& params,
        const String& glsl = String{},
        const String& spirvDefault = String{},
        const String& spirvRWDefault = String{},
        const String& spirvCombined = String{},
        const String& cuda = String{},
        const String& metal = String{},
        const ReadNoneMode readNoneMode = ReadNoneMode::Never
    );

    // A pointer to a string representing the current level of indentation
    const char* i;
};

}