-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathShaderViewable.h
109 lines (92 loc) · 2.98 KB
/
ShaderViewable.h
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
103
104
105
106
107
108
#pragma once
#include <string>
#include <vector>
#include <cstdint>
#include <memory.h>
namespace VkInline
{
namespace Internal
{
class CommandBuffer;
}
typedef std::vector<char> ViewBuf;
// root class of all shader-viewable objects
class ShaderViewable
{
public:
ShaderViewable() {}
virtual ~ShaderViewable() {}
virtual ViewBuf view() const = 0;
const std::string& name_view_type() const { return m_name_view_type; }
virtual void apply_barriers(const Internal::CommandBuffer& cmdbuf, unsigned dstFlags) const {}
protected:
std::string m_name_view_type;
};
struct CapturedShaderViewable
{
const char* obj_name;
const ShaderViewable* obj;
};
class SomeShaderViewable : public ShaderViewable
{
public:
SomeShaderViewable(const char* name_view_type, const void* data_view = "", size_t size_view = 1)
{
m_name_view_type = name_view_type;
m_view_buf.resize(size_view);
memcpy(m_view_buf.data(), data_view, size_view);
}
virtual ViewBuf view() const
{
return m_view_buf;
}
private:
ViewBuf m_view_buf;
};
#define DECLAR_SV_BASIC(clsname, type_host, type_dev)\
class clsname : public SomeShaderViewable\
{\
public:\
clsname(type_host in) : SomeShaderViewable(#type_dev, &in, sizeof(type_host)) {}\
};
DECLAR_SV_BASIC(SVInt32, int32_t, int)
DECLAR_SV_BASIC(SVUInt32, uint32_t, uint)
DECLAR_SV_BASIC(SVFloat, float, float)
DECLAR_SV_BASIC(SVDouble, double, double)
#define DECLAR_SV_VEC(clsname, type_elem_host, type_dev, num_elem)\
class clsname : public SomeShaderViewable\
{\
public:\
clsname(const type_elem_host* in) : SomeShaderViewable(#type_dev, in, sizeof(type_elem_host)*num_elem){}\
};
DECLAR_SV_VEC(SVIVec2, int32_t, ivec2, 2)
DECLAR_SV_VEC(SVIVec3, int32_t, ivec3, 3)
DECLAR_SV_VEC(SVIVec4, int32_t, ivec4, 4)
DECLAR_SV_VEC(SVUVec2, uint32_t, uvec2, 2)
DECLAR_SV_VEC(SVUVec3, uint32_t, uvec3, 3)
DECLAR_SV_VEC(SVUVec4, uint32_t, uvec4, 4)
DECLAR_SV_VEC(SVVec2, float, vec2, 2)
DECLAR_SV_VEC(SVVec3, float, vec3, 3)
DECLAR_SV_VEC(SVVec4, float, vec4, 4)
DECLAR_SV_VEC(SVDVec2, double, dvec2, 2)
DECLAR_SV_VEC(SVDVec3, double, dvec3, 3)
DECLAR_SV_VEC(SVDVec4, double, dvec4, 4)
DECLAR_SV_VEC(SVMat2x2, float, mat2x2, 2 * 2)
DECLAR_SV_VEC(SVMat2x3, float, mat2x3, 2 * 3)
DECLAR_SV_VEC(SVMat2x4, float, mat2x4, 2 * 4)
DECLAR_SV_VEC(SVMat3x2, float, mat3x2, 3 * 2)
DECLAR_SV_VEC(SVMat3x3, float, mat3x3, 3 * 3)
DECLAR_SV_VEC(SVMat3x4, float, mat3x4, 3 * 4)
DECLAR_SV_VEC(SVMat4x2, float, mat4x2, 4 * 2)
DECLAR_SV_VEC(SVMat4x3, float, mat4x3, 4 * 3)
DECLAR_SV_VEC(SVMat4x4, float, mat4x4, 4 * 4)
DECLAR_SV_VEC(SVDMat2x2, double, dmat2x2, 2 * 2)
DECLAR_SV_VEC(SVDMat2x3, double, dmat2x3, 2 * 3)
DECLAR_SV_VEC(SVDMat2x4, double, dmat2x4, 2 * 4)
DECLAR_SV_VEC(SVDMat3x2, double, dmat3x2, 3 * 2)
DECLAR_SV_VEC(SVDMat3x3, double, dmat3x3, 3 * 3)
DECLAR_SV_VEC(SVDMat3x4, double, dmat3x4, 3 * 4)
DECLAR_SV_VEC(SVDMat4x2, double, dmat4x2, 4 * 2)
DECLAR_SV_VEC(SVDMat4x3, double, dmat4x3, 4 * 3)
DECLAR_SV_VEC(SVDMat4x4, double, dmat4x4, 4 * 4)
}