Hongtae Kim 6 年 前
コミット
e06023b2c6

+ 2
- 0
Samples.props ファイルの表示

@@ -5,12 +5,14 @@
5 5
   <PropertyGroup>
6 6
     <OutDir>$(SolutionDir)Build\$(Platform)_$(Configuration)\</OutDir>
7 7
     <IntDir>$(SolutionDir)Build\Intermediates\$(ProjectName)_$(Platform)_$(Configuration)\</IntDir>
8
+    <_PropertySheetDisplayName>Triangle</_PropertySheetDisplayName>
8 9
   </PropertyGroup>
9 10
   <ItemDefinitionGroup>
10 11
     <ClCompile>
11 12
       <ObjectFileName>$(IntDir)%(RelativeDir)</ObjectFileName>
12 13
       <AdditionalIncludeDirectories>../../DK;../Common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
13 14
       <PreprocessorDefinitions>DKGL_STATIC=1;%(PreprocessorDefinitions)</PreprocessorDefinitions>
15
+      <LanguageStandard>stdcpp17</LanguageStandard>
14 16
     </ClCompile>
15 17
   </ItemDefinitionGroup>
16 18
   <ItemGroup />

+ 0
- 11
Samples/Common/app.cpp ファイルの表示

@@ -1,11 +0,0 @@
1
-#include "app.h"
2
-
3
-SampleApp::SampleApp()
4
-{
5
-
6
-}
7
-
8
-SampleApp::~SampleApp()
9
-{
10
-
11
-}

+ 44
- 2
Samples/Common/app.h ファイルの表示

@@ -7,6 +7,48 @@
7 7
 class SampleApp : public DKApplication
8 8
 {
9 9
 public:
10
-	SampleApp();
11
-	~SampleApp();
10
+    SampleApp()
11
+    {
12
+    }
13
+    ~SampleApp()
14
+    {
15
+    }
16
+
17
+    void OnInitialize(void) override
18
+    {
19
+        DKLogD("%s", DKGL_FUNCTION_NAME);
20
+
21
+        DKString resPath = DefaultPath(SystemPath::AppResource);
22
+        resPath = resPath.FilePathStringByAppendingPath("Data");
23
+        DKLog("resPath: %ls", (const wchar_t*)resPath);
24
+        resourcePool.AddLocatorForPath(resPath);
25
+    }
26
+    void OnTerminate(void) override
27
+    {
28
+        DKLogD("%s", DKGL_FUNCTION_NAME);
29
+
30
+        DKLogI("Memory Pool Statistics");
31
+        size_t numBuckets = DKMemoryPoolNumberOfBuckets();
32
+        DKMemoryPoolBucketStatus* buckets = new DKMemoryPoolBucketStatus[numBuckets];
33
+        DKMemoryPoolQueryAllocationStatus(buckets, numBuckets);
34
+        size_t usedBytes = 0;
35
+        for (int i = 0; i < numBuckets; ++i)
36
+        {
37
+            if (buckets[i].totalChunks > 0)
38
+            {
39
+                DKLogI("--> %5lu:  %5lu/%5lu, usage: %.1f%%, used: %.1fKB, total: %.1fKB",
40
+                    buckets[i].chunkSize,
41
+                    buckets[i].usedChunks, buckets[i].totalChunks,
42
+                    double(buckets[i].usedChunks) / double(buckets[i].totalChunks) * 100.0,
43
+                    double(buckets[i].chunkSize * buckets[i].usedChunks) / 1024.0,
44
+                    double(buckets[i].chunkSize * buckets[i].totalChunks) / 1024.0
45
+                );
46
+                usedBytes += buckets[i].chunkSize * buckets[i].usedChunks;
47
+            }
48
+        }
49
+        DKLogI("MemoryPool Usage: %.1fMB / %.1fMB", double(usedBytes) / (1024 * 1024), double(DKMemoryPoolSize()) / (1024 * 1024));
50
+        delete[] buckets;
51
+    }
52
+
53
+    DKResourcePool resourcePool;
12 54
 };

+ 272
- 0
Samples/Common/util.h ファイルの表示

@@ -0,0 +1,272 @@
1
+#ifdef _WIN32
2
+#include "Win32/stdafx.h"
3
+#endif
4
+#include <DK.h>
5
+
6
+DKString ShaderStageNames(uint32_t s)
7
+{
8
+    DKArray<const char*> stages;
9
+    if (s & (uint32_t)DKShaderStage::Vertex)
10
+        stages.Add("Vertex");
11
+    if (s & (uint32_t)DKShaderStage::TessellationControl)
12
+        stages.Add("TessCtrl");
13
+    if (s & (uint32_t)DKShaderStage::TessellationEvaluation)
14
+        stages.Add("TessEval");
15
+    if (s & (uint32_t)DKShaderStage::Geometry)
16
+        stages.Add("Geometry");
17
+    if (s & (uint32_t)DKShaderStage::Fragment)
18
+        stages.Add("Fragment");
19
+    if (s & (uint32_t)DKShaderStage::Compute)
20
+        stages.Add("Compute");
21
+
22
+    if (stages.IsEmpty())
23
+        return "";
24
+
25
+    DKString str = stages.Value(0);
26
+    for (int i = 1; i < stages.Count(); ++i)
27
+        str += DKString::Format(", %ls", stages.Value(i));
28
+    return str;
29
+}
30
+
31
+const char* ShaderDataTypeStr(DKShaderDataType t)
32
+{
33
+    switch (t) {
34
+    case DKShaderDataType::Unknown:				return "Unknown";
35
+    case DKShaderDataType::None:				return "None";
36
+
37
+    case DKShaderDataType::Struct:				return "Struct";
38
+    case DKShaderDataType::Texture:				return "Texture";
39
+    case DKShaderDataType::Sampler:				return "Sampler";
40
+
41
+    case DKShaderDataType::Float:				return "Float";
42
+    case DKShaderDataType::Float2:				return "Float2";
43
+    case DKShaderDataType::Float3:				return "Float3";
44
+    case DKShaderDataType::Float4:				return "Float4";
45
+
46
+    case DKShaderDataType::Float2x2:			return "Float2x2";
47
+    case DKShaderDataType::Float2x3:			return "Float2x3";
48
+    case DKShaderDataType::Float2x4:			return "Float2x4";
49
+
50
+    case DKShaderDataType::Float3x2:			return "Float3x2";
51
+    case DKShaderDataType::Float3x3:			return "Float3x3";
52
+    case DKShaderDataType::Float3x4:			return "Float3x4";
53
+
54
+    case DKShaderDataType::Float4x2:			return "Float4x2";
55
+    case DKShaderDataType::Float4x3:			return "Float4x3";
56
+    case DKShaderDataType::Float4x4:			return "Float4x4";
57
+
58
+    case DKShaderDataType::Half:				return "Half";
59
+    case DKShaderDataType::Half2:				return "Half2";
60
+    case DKShaderDataType::Half3:				return "Half3";
61
+    case DKShaderDataType::Half4:				return "Half4";
62
+
63
+    case DKShaderDataType::Half2x2:				return "Half2x2";
64
+    case DKShaderDataType::Half2x3:				return "Half2x3";
65
+    case DKShaderDataType::Half2x4:				return "Half2x4";
66
+
67
+    case DKShaderDataType::Half3x2:				return "Half3x2";
68
+    case DKShaderDataType::Half3x3:				return "Half3x3";
69
+    case DKShaderDataType::Half3x4:				return "Half3x4";
70
+
71
+    case DKShaderDataType::Half4x2:				return "Half4x2";
72
+    case DKShaderDataType::Half4x3:				return "Half4x3";
73
+    case DKShaderDataType::Half4x4:				return "Half4x4";
74
+
75
+    case DKShaderDataType::Int:					return "Int";
76
+    case DKShaderDataType::Int2:				return "Int2";
77
+    case DKShaderDataType::Int3:				return "Int3";
78
+    case DKShaderDataType::Int4:				return "Int4";
79
+
80
+    case DKShaderDataType::UInt:				return "UInt";
81
+    case DKShaderDataType::UInt2:				return "UInt2";
82
+    case DKShaderDataType::UInt3:				return "UInt3";
83
+    case DKShaderDataType::UInt4:				return "UInt4";
84
+
85
+    case DKShaderDataType::Short:				return "Short";
86
+    case DKShaderDataType::Short2:				return "Short2";
87
+    case DKShaderDataType::Short3:				return "Short3";
88
+    case DKShaderDataType::Short4:				return "Short4";
89
+
90
+    case DKShaderDataType::UShort:				return "UShort";
91
+    case DKShaderDataType::UShort2:				return "UShort2";
92
+    case DKShaderDataType::UShort3:				return "UShort3";
93
+    case DKShaderDataType::UShort4:				return "UShort4";
94
+
95
+    case DKShaderDataType::Char:				return "Char";
96
+    case DKShaderDataType::Char2:				return "Char2";
97
+    case DKShaderDataType::Char3:				return "Char3";
98
+    case DKShaderDataType::Char4:				return "Char4";
99
+
100
+    case DKShaderDataType::UChar:				return "UChar";
101
+    case DKShaderDataType::UChar2:				return "UChar2";
102
+    case DKShaderDataType::UChar3:				return "UChar3";
103
+    case DKShaderDataType::UChar4:				return "UChar4";
104
+
105
+    case DKShaderDataType::Bool:				return "Bool";
106
+    case DKShaderDataType::Bool2:				return "Bool2";
107
+    case DKShaderDataType::Bool3:				return "Bool3";
108
+    case DKShaderDataType::Bool4:				return "Bool4";
109
+    }
110
+    return "Error";
111
+}
112
+
113
+void PrintShaderResource(const DKShaderResource& res, DKLogCategory c = DKLogCategory::Info)
114
+{
115
+    struct MemberPrinter
116
+    {
117
+        const DKShaderResource& res;
118
+        int indent;
119
+        DKLogCategory c;
120
+        void operator()(const DKShaderResourceStruct& str) const
121
+        {
122
+            DKString indentStr = "";
123
+            for (int i = 0; i < indent; ++i)
124
+            {
125
+                indentStr += "    ";
126
+            }
127
+            for (const DKShaderResourceStructMember& mem : str.members)
128
+            {
129
+                if (mem.count > 1)
130
+                {
131
+                    DKLog(c, " %ls+ %ls[%d] (%s, Offset: %d, Stride: %d)",
132
+                        (const wchar_t*)indentStr,
133
+                        (const wchar_t*)mem.name,
134
+                        mem.count,
135
+                        ShaderDataTypeStr(mem.dataType),
136
+                        mem.offset, mem.stride);
137
+
138
+                }
139
+                else
140
+                {
141
+                    DKLog(c, " %ls+ %ls (%s, Offset: %d)",
142
+                        (const wchar_t*)indentStr,
143
+                        (const wchar_t*)mem.name,
144
+                        ShaderDataTypeStr(mem.dataType),
145
+                        mem.offset);
146
+                }
147
+
148
+                auto* p = res.structTypeMemberMap.Find(mem.typeInfoKey);
149
+                if (p)
150
+                {
151
+                    DKLog(c, " %ls  Struct \"%ls\"",
152
+                        (const wchar_t*)indentStr,
153
+                        (const wchar_t*)mem.typeInfoKey);
154
+                    MemberPrinter{ res, indent + 1, c }.operator()(p->value);
155
+                }
156
+            }
157
+        }
158
+    };
159
+
160
+
161
+    if (res.count > 1)
162
+        DKLog(c, "ShaderResource: %ls[%d] (set=%d, binding=%d, stages=%ls)",
163
+        (const wchar_t*)res.name, res.count, res.set, res.binding,
164
+            (const wchar_t*)ShaderStageNames(res.stages));
165
+    else
166
+        DKLog(c, "ShaderResource: %ls (set=%d, binding=%d, stages=%ls)",
167
+        (const wchar_t*)res.name, res.set, res.binding,
168
+            (const wchar_t*)ShaderStageNames(res.stages));
169
+
170
+    const char* type = "Unknown (ERROR)";
171
+    switch (res.type)
172
+    {
173
+    case DKShaderResource::TypeBuffer: type = "Buffer"; break;
174
+    case DKShaderResource::TypeTexture:	type = "Texture"; break;
175
+    case DKShaderResource::TypeSampler:	type = "Sampler"; break;
176
+    case DKShaderResource::TypeTextureSampler: type = "SampledTexture"; break;
177
+    }
178
+    const char* access = "Unknown (ERROR)";
179
+    switch (res.access)
180
+    {
181
+    case DKShaderResource::AccessReadOnly:	access = "ReadOnly"; break;
182
+    case DKShaderResource::AccessWriteOnly:	access = "WriteOnly"; break;
183
+    case DKShaderResource::AccessReadWrite:	access = "ReadWrite"; break;
184
+    }
185
+
186
+    if (res.type == DKShaderResource::TypeBuffer)
187
+    {
188
+        DKLog(c, " Type:%s, Access:%s, Enabled:%d, Size:%d",
189
+            type,
190
+            access,
191
+            int(res.enabled),
192
+            res.typeInfo.buffer.size);
193
+    }
194
+    else
195
+    {
196
+        DKLog(c, " Type:%s, Access:%s, Enabled:%d",
197
+            type,
198
+            access,
199
+            int(res.enabled));
200
+    }
201
+    if (res.typeInfoKey.Length() > 0)
202
+        DKLog(c, " Struct \"%ls\"", (const wchar_t*)res.typeInfoKey);
203
+    if (res.type == DKShaderResource::TypeBuffer)
204
+    {
205
+        auto p = res.structTypeMemberMap.Find(res.typeInfoKey);
206
+        if (p)
207
+            MemberPrinter{ res, 1 , c }.operator()(p->value);
208
+    }
209
+}
210
+
211
+void PrintShaderReflection(const DKShader* shader, DKLogCategory c = DKLogCategory::Warning)
212
+{
213
+    DKString stage = ShaderStageNames((uint32_t)shader->Stage());
214
+    if (stage.Length() == 0)
215
+        stage = "Unknown";
216
+
217
+    DKLog(c, "=========================================================");
218
+    DKLog(c, "Shader<%ls.SPIR-V>.InputAttributes: %d",
219
+        (const wchar_t*)stage, shader->InputAttributes().Count());
220
+    for (int i = 0; i < shader->InputAttributes().Count(); ++i)
221
+    {
222
+        const DKShaderAttribute& attr = shader->InputAttributes().Value(i);
223
+        DKLog(c, "  [in] ShaderAttribute[%d]: \"%ls\" (location:%u)",
224
+            i, (const wchar_t*)attr.name, attr.location);
225
+    }
226
+    DKLog(c, "---------------------------------------------------------");
227
+    DKLog(c, "Shader<%ls.SPIR-V>.OutputAttributes: %d",
228
+        (const wchar_t*)stage, shader->OutputAttributes().Count());
229
+    for (int i = 0; i < shader->OutputAttributes().Count(); ++i)
230
+    {
231
+        const DKShaderAttribute& attr = shader->OutputAttributes().Value(i);
232
+        DKLog(c, "  [out] ShaderAttribute[%d]: \"%ls\" (location:%u)",
233
+            i, (const wchar_t*)attr.name, attr.location);
234
+    }
235
+    DKLog(c, "---------------------------------------------------------");
236
+    DKLog(c, "Shader<%ls.SPIR-V>.Resources: %d",
237
+        (const wchar_t*)stage, shader->Resources().Count());
238
+    for (auto& arg : shader->Resources())
239
+        PrintShaderResource(arg, c);
240
+    for (int i = 0; i < shader->PushConstantBufferLayouts().Count(); ++i)
241
+    {
242
+        const DKShaderPushConstantLayout& layout = shader->PushConstantBufferLayouts().Value(i);
243
+        DKLog(c, " PushConstant:%d \"%ls\" (offset:%u, size:%u, stages:%ls)",
244
+            i, (const wchar_t*)layout.name, layout.offset, layout.size,
245
+            (const wchar_t*)ShaderStageNames(layout.stages));
246
+    }
247
+    DKLog(c, "=========================================================");
248
+}
249
+
250
+void PrintPipelineReflection(const DKPipelineReflection* reflection, DKLogCategory c = DKLogCategory::Error)
251
+{
252
+    DKLog(c, "=========================================================");
253
+    DKLog(c, "PipelineReflection.InputAttributes: %d", reflection->inputAttributes.Count());
254
+    for (int i = 0; i < reflection->inputAttributes.Count(); ++i)
255
+    {
256
+        const DKShaderAttribute& attr = reflection->inputAttributes.Value(i);
257
+        DKLog(c, "  [in] ShaderAttribute[%d]: \"%ls\" (location:%u)",
258
+            i, (const wchar_t*)attr.name, attr.location);
259
+    }
260
+    DKLog(c, "---------------------------------------------------------");
261
+    DKLog(c, "PipelineReflection.Resources: %d", reflection->resources.Count());
262
+    for (auto& arg : reflection->resources)
263
+        PrintShaderResource(arg, c);
264
+    for (int i = 0; i < reflection->pushConstantLayouts.Count(); ++i)
265
+    {
266
+        const DKShaderPushConstantLayout& layout = reflection->pushConstantLayouts.Value(i);
267
+        DKLog(c, " PushConstant:%d \"%ls\" (offset:%u, size:%u, stages:%ls)",
268
+            i, (const wchar_t*)layout.name, layout.offset, layout.size,
269
+            (const wchar_t*)ShaderStageNames(layout.stages));
270
+    }
271
+    DKLog(c, "=========================================================");
272
+}

+ 25
- 0
Samples/Data/texture.frag ファイルの表示

@@ -0,0 +1,25 @@
1
+#version 450
2
+
3
+layout (binding = 1) uniform sampler2D samplerColor;
4
+
5
+layout (location = 0) in vec2 inUV;
6
+layout (location = 1) in float inLodBias;
7
+layout (location = 2) in vec3 inNormal;
8
+layout (location = 3) in vec3 inViewVec;
9
+layout (location = 4) in vec3 inLightVec;
10
+
11
+layout (location = 0) out vec4 outFragColor;
12
+
13
+void main() 
14
+{
15
+	vec4 color = texture(samplerColor, inUV, inLodBias);
16
+
17
+	vec3 N = normalize(inNormal);
18
+	vec3 L = normalize(inLightVec);
19
+	vec3 V = normalize(inViewVec);
20
+	vec3 R = reflect(-L, N);
21
+	vec3 diffuse = max(dot(N, L), 0.0) * vec3(1.0);
22
+	float specular = pow(max(dot(R, V), 0.0), 16.0) * color.a;
23
+
24
+	outFragColor = vec4(diffuse * color.rgb + specular, 1.0);	
25
+}

バイナリ
Samples/Data/texture.frag.spv ファイルの表示


+ 41
- 0
Samples/Data/texture.vert ファイルの表示

@@ -0,0 +1,41 @@
1
+#version 450
2
+
3
+layout (location = 0) in vec3 inPos;
4
+layout (location = 1) in vec2 inUV;
5
+layout (location = 2) in vec3 inNormal;
6
+
7
+layout (binding = 0) uniform UBO 
8
+{
9
+	mat4 projection;
10
+	mat4 model;
11
+	vec4 viewPos;
12
+	float lodBias;
13
+} ubo;
14
+
15
+layout (location = 0) out vec2 outUV;
16
+layout (location = 1) out float outLodBias;
17
+layout (location = 2) out vec3 outNormal;
18
+layout (location = 3) out vec3 outViewVec;
19
+layout (location = 4) out vec3 outLightVec;
20
+
21
+out gl_PerVertex 
22
+{
23
+    vec4 gl_Position;   
24
+};
25
+
26
+void main() 
27
+{
28
+	outUV = inUV;
29
+	outLodBias = ubo.lodBias;
30
+
31
+	vec3 worldPos = vec3(ubo.model * vec4(inPos, 1.0));
32
+
33
+	gl_Position = ubo.projection * ubo.model * vec4(inPos.xyz, 1.0);
34
+
35
+    vec4 pos = ubo.model * vec4(inPos, 1.0);
36
+	outNormal = mat3(inverse(transpose(ubo.model))) * inNormal;
37
+	vec3 lightPos = vec3(0.0);
38
+	vec3 lPos = mat3(ubo.model) * lightPos.xyz;
39
+    outLightVec = lPos - pos.xyz;
40
+    outViewVec = ubo.viewPos.xyz - pos.xyz;		
41
+}

バイナリ
Samples/Data/texture.vert.spv ファイルの表示


+ 13
- 0
Samples/Data/triangle.frag ファイルの表示

@@ -0,0 +1,13 @@
1
+#version 450
2
+
3
+#extension GL_ARB_separate_shader_objects : enable
4
+#extension GL_ARB_shading_language_420pack : enable
5
+
6
+layout (location = 0) in vec3 inColor;
7
+
8
+layout (location = 0) out vec4 outFragColor;
9
+
10
+void main() 
11
+{
12
+  outFragColor = vec4(inColor, 1.0);
13
+}

バイナリ
Samples/Data/triangle.frag.spv ファイルの表示


+ 28
- 0
Samples/Data/triangle.vert ファイルの表示

@@ -0,0 +1,28 @@
1
+#version 450
2
+
3
+#extension GL_ARB_separate_shader_objects : enable
4
+#extension GL_ARB_shading_language_420pack : enable
5
+
6
+layout (location = 0) in vec3 inPos;
7
+layout (location = 1) in vec3 inColor;
8
+
9
+layout (binding = 0) uniform UBOX 
10
+{
11
+	mat4 projectionMatrix;
12
+	mat4 modelMatrix;
13
+	mat4 viewMatrix;
14
+} ubo;
15
+
16
+layout (location = 0) out vec3 outColor;
17
+
18
+out gl_PerVertex 
19
+{
20
+    vec4 gl_Position;   
21
+};
22
+
23
+
24
+void main() 
25
+{
26
+	outColor = inColor;
27
+	gl_Position = ubo.projectionMatrix * ubo.viewMatrix * ubo.modelMatrix * vec4(inPos.xyz, 1.0);
28
+}

バイナリ
Samples/Data/triangle.vert.spv ファイルの表示


+ 19
- 271
Samples/Triangle/Triangle.cpp ファイルの表示

@@ -1,243 +1,14 @@
1 1
 
2 2
 #include "app.h"
3
+#include "util.h"
3 4
 
4
-DKString ShaderStageNames(uint32_t s)
5
-{
6
-    DKArray<const char*> stages;
7
-    if (s & (uint32_t)DKShaderStage::Vertex)
8
-        stages.Add("Vertex");
9
-    if (s & (uint32_t)DKShaderStage::TessellationControl)
10
-        stages.Add("TessCtrl");
11
-    if (s & (uint32_t)DKShaderStage::TessellationEvaluation)
12
-        stages.Add("TessEval");
13
-    if (s & (uint32_t)DKShaderStage::Geometry)
14
-        stages.Add("Geometry");
15
-    if (s & (uint32_t)DKShaderStage::Fragment)
16
-        stages.Add("Fragment");
17
-    if (s & (uint32_t)DKShaderStage::Compute)
18
-        stages.Add("Compute");
19
-
20
-    if (stages.IsEmpty())
21
-        return "";
22
-
23
-    DKString str = stages.Value(0);
24
-    for (int i = 1; i < stages.Count(); ++i)
25
-        str += DKString::Format(", %ls", stages.Value(i));
26
-    return str;
27
-}
28
-
29
-const char* ShaderDataTypeStr(DKShaderDataType t)
30
-{
31
-    switch (t) {
32
-    case DKShaderDataType::Unknown:				return "Unknown";
33
-    case DKShaderDataType::None:				return "None";
34
-
35
-    case DKShaderDataType::Struct:				return "Struct";
36
-    case DKShaderDataType::Texture:				return "Texture";
37
-    case DKShaderDataType::Sampler:				return "Sampler";
38
-
39
-    case DKShaderDataType::Float:				return "Float";
40
-    case DKShaderDataType::Float2:				return "Float2";
41
-    case DKShaderDataType::Float3:				return "Float3";
42
-    case DKShaderDataType::Float4:				return "Float4";
43
-
44
-    case DKShaderDataType::Float2x2:			return "Float2x2";
45
-    case DKShaderDataType::Float2x3:			return "Float2x3";
46
-    case DKShaderDataType::Float2x4:			return "Float2x4";
47
-
48
-    case DKShaderDataType::Float3x2:			return "Float3x2";
49
-    case DKShaderDataType::Float3x3:			return "Float3x3";
50
-    case DKShaderDataType::Float3x4:			return "Float3x4";
51
-
52
-    case DKShaderDataType::Float4x2:			return "Float4x2";
53
-    case DKShaderDataType::Float4x3:			return "Float4x3";
54
-    case DKShaderDataType::Float4x4:			return "Float4x4";
55
-
56
-    case DKShaderDataType::Half:				return "Half";
57
-    case DKShaderDataType::Half2:				return "Half2";
58
-    case DKShaderDataType::Half3:				return "Half3";
59
-    case DKShaderDataType::Half4:				return "Half4";
60
-
61
-    case DKShaderDataType::Half2x2:				return "Half2x2";
62
-    case DKShaderDataType::Half2x3:				return "Half2x3";
63
-    case DKShaderDataType::Half2x4:				return "Half2x4";
64
-
65
-    case DKShaderDataType::Half3x2:				return "Half3x2";
66
-    case DKShaderDataType::Half3x3:				return "Half3x3";
67
-    case DKShaderDataType::Half3x4:				return "Half3x4";
68
-
69
-    case DKShaderDataType::Half4x2:				return "Half4x2";
70
-    case DKShaderDataType::Half4x3:				return "Half4x3";
71
-    case DKShaderDataType::Half4x4:				return "Half4x4";
72 5
 
73
-    case DKShaderDataType::Int:					return "Int";
74
-    case DKShaderDataType::Int2:				return "Int2";
75
-    case DKShaderDataType::Int3:				return "Int3";
76
-    case DKShaderDataType::Int4:				return "Int4";
77
-
78
-    case DKShaderDataType::UInt:				return "UInt";
79
-    case DKShaderDataType::UInt2:				return "UInt2";
80
-    case DKShaderDataType::UInt3:				return "UInt3";
81
-    case DKShaderDataType::UInt4:				return "UInt4";
82
-
83
-    case DKShaderDataType::Short:				return "Short";
84
-    case DKShaderDataType::Short2:				return "Short2";
85
-    case DKShaderDataType::Short3:				return "Short3";
86
-    case DKShaderDataType::Short4:				return "Short4";
87
-
88
-    case DKShaderDataType::UShort:				return "UShort";
89
-    case DKShaderDataType::UShort2:				return "UShort2";
90
-    case DKShaderDataType::UShort3:				return "UShort3";
91
-    case DKShaderDataType::UShort4:				return "UShort4";
92
-
93
-    case DKShaderDataType::Char:				return "Char";
94
-    case DKShaderDataType::Char2:				return "Char2";
95
-    case DKShaderDataType::Char3:				return "Char3";
96
-    case DKShaderDataType::Char4:				return "Char4";
97
-
98
-    case DKShaderDataType::UChar:				return "UChar";
99
-    case DKShaderDataType::UChar2:				return "UChar2";
100
-    case DKShaderDataType::UChar3:				return "UChar3";
101
-    case DKShaderDataType::UChar4:				return "UChar4";
102
-
103
-    case DKShaderDataType::Bool:				return "Bool";
104
-    case DKShaderDataType::Bool2:				return "Bool2";
105
-    case DKShaderDataType::Bool3:				return "Bool3";
106
-    case DKShaderDataType::Bool4:				return "Bool4";
107
-    }
108
-    return "Error";
109
-}
110
-
111
-void PrintShaderResource(const DKShaderResource& res, DKLogCategory c = DKLogCategory::Info)
6
+class TriangleDemo : public SampleApp
112 7
 {
113
-    struct MemberPrinter
114
-    {
115
-        const DKShaderResource& res;
116
-        int indent;
117
-        DKLogCategory c;
118
-        void operator()(const DKShaderResourceStruct& str) const
119
-        {
120
-            DKString indentStr = "";
121
-            for (int i = 0; i < indent; ++i)
122
-            {
123
-                indentStr += "    ";
124
-            }
125
-            for (const DKShaderResourceStructMember& mem : str.members)
126
-            {
127
-                if (mem.count > 1)
128
-                {
129
-                    DKLog(c, " %ls+ %ls[%d] (%s, Offset: %d, Stride: %d)",
130
-                        (const wchar_t*)indentStr,
131
-                          (const wchar_t*)mem.name,
132
-                          mem.count,
133
-                          ShaderDataTypeStr(mem.dataType),
134
-                          mem.offset, mem.stride);
135
-
136
-                }
137
-                else
138
-                {
139
-                    DKLog(c, " %ls+ %ls (%s, Offset: %d)",
140
-                        (const wchar_t*)indentStr,
141
-                          (const wchar_t*)mem.name,
142
-                          ShaderDataTypeStr(mem.dataType),
143
-                          mem.offset);
144
-                }
145
-
146
-                auto* p = res.structTypeMemberMap.Find(mem.typeInfoKey);
147
-                if (p)
148
-                {
149
-                    DKLog(c, " %ls  Struct \"%ls\"",
150
-                        (const wchar_t*)indentStr,
151
-                          (const wchar_t*)mem.typeInfoKey);
152
-                    MemberPrinter{ res, indent + 1, c}.operator()(p->value);
153
-                }
154
-            }
155
-        }
156
-    };
157
-
158
-
159
-    if (res.count > 1)
160
-        DKLog(c, "ShaderResource: %ls[%d] (set=%d, binding=%d, stages=%ls)",
161
-        (const wchar_t*)res.name, res.count, res.set, res.binding,
162
-              (const wchar_t*)ShaderStageNames(res.stages));
163
-    else
164
-        DKLog(c, "ShaderResource: %ls (set=%d, binding=%d, stages=%ls)",
165
-        (const wchar_t*)res.name, res.set, res.binding,
166
-              (const wchar_t*)ShaderStageNames(res.stages));
167
-
168
-    const char* type = "Unknown (ERROR)";
169
-    switch (res.type)
170
-    {
171
-    case DKShaderResource::TypeBuffer: type = "Buffer"; break;
172
-    case DKShaderResource::TypeTexture:	type = "Texture"; break;
173
-    case DKShaderResource::TypeSampler:	type = "Sampler"; break;
174
-    case DKShaderResource::TypeTextureSampler: type = "SampledTexture"; break;
175
-    }
176
-    const char* access = "Unknown (ERROR)";
177
-    switch (res.access)
178
-    {
179
-    case DKShaderResource::AccessReadOnly:	access = "ReadOnly"; break;
180
-    case DKShaderResource::AccessWriteOnly:	access = "WriteOnly"; break;
181
-    case DKShaderResource::AccessReadWrite:	access = "ReadWrite"; break;
182
-    }
183
-
184
-    if (res.type == DKShaderResource::TypeBuffer)
185
-    {
186
-        DKLog(c, " Type:%s, Access:%s, Enabled:%d, Size:%d",
187
-              type,
188
-              access,
189
-              int(res.enabled),
190
-              res.typeInfo.buffer.size);
191
-    }
192
-    else
193
-    {
194
-        DKLog(c, " Type:%s, Access:%s, Enabled:%d",
195
-              type,
196
-              access,
197
-              int(res.enabled));
198
-    }
199
-    if (res.typeInfoKey.Length() > 0)
200
-        DKLog(c, " Struct \"%ls\"", (const wchar_t*)res.typeInfoKey);
201
-    if (res.type == DKShaderResource::TypeBuffer)
202
-    {
203
-        auto p = res.structTypeMemberMap.Find(res.typeInfoKey);
204
-        if (p)
205
-            MemberPrinter{ res, 1 , c}.operator()(p->value);
206
-    }
207
-}
208
-
209
-void PrintPipelineReflection(const DKPipelineReflection* reflection, DKLogCategory c = DKLogCategory::Error)
210
-{
211
-    DKLog(c, "=========================================================");
212
-    DKLog(c, "PipelineReflection.InputAttributes: %d", reflection->inputAttributes.Count());
213
-    for (int i = 0; i < reflection->inputAttributes.Count(); ++i)
214
-    {
215
-        const DKShaderAttribute& attr = reflection->inputAttributes.Value(i);
216
-        DKLog(c, "  [in] ShaderAttribute[%d]: \"%ls\" (location:%u)",
217
-              i, (const wchar_t*)attr.name, attr.location);
218
-    }
219
-    DKLog(c, "---------------------------------------------------------");
220
-    DKLog(c, "PipelineReflection.Resources: %d", reflection->resources.Count());
221
-    for (auto& arg : reflection->resources)
222
-        PrintShaderResource(arg, c);
223
-    for (int i = 0; i < reflection->pushConstantLayouts.Count(); ++i)
224
-    {
225
-        const DKShaderPushConstantLayout& layout = reflection->pushConstantLayouts.Value(i);
226
-        DKLog(c, " PushConstant:%d \"%ls\" (offset:%u, size:%u, stages:%ls)",
227
-              i, (const wchar_t*)layout.name, layout.offset, layout.size,
228
-              (const wchar_t*)ShaderStageNames(layout.stages));
229
-    }
230
-    DKLog(c, "=========================================================");
231
-}
232
-
233
-
234
-class TestApp1 : public DKApplication
235
-{
236
-	DKObject<DKWindow> window;
8
+    DKObject<DKWindow> window;
237 9
 	DKObject<DKThread> renderThread;
238
-	DKResourcePool resourcePool;
239
-
240 10
 	DKAtomicNumber32 runningRenderThread;
11
+
241 12
 public:
242 13
 	void RenderThread(void)
243 14
 	{
@@ -391,26 +162,23 @@ public:
391 162
 
392 163
 	void OnInitialize(void) override
393 164
 	{
165
+        SampleApp::OnInitialize();
394 166
 		DKLogD("%s", DKGL_FUNCTION_NAME);
395 167
 
396
-		DKString resPath = DefaultPath(SystemPath::AppResource);
397
-		resPath = resPath.FilePathStringByAppendingPath("Data");
398
-		DKLog("resPath: %ls", (const wchar_t*)resPath);
399
-		resourcePool.AddLocatorForPath(resPath);
168
+        // create window
169
+        window = DKWindow::Create("DefaultWindow");
170
+        window->SetOrigin({ 0, 0 });
171
+        window->Resize({ 320, 240 });
172
+        window->Activate();
400 173
 
401
-		window = DKWindow::Create("DefaultWindow");
402
-		window->SetOrigin({ 0, 0 });
403
-		window->Resize({ 320, 240 });
404
-		window->Activate();
405
-
406
-		window->AddEventHandler(this, DKFunction([this](const DKWindow::WindowEvent& e)
407
-		{
408
-			if (e.type == DKWindow::WindowEvent::WindowClosed)
409
-				DKApplication::Instance()->Terminate(0);
410
-		}), NULL, NULL);
174
+        window->AddEventHandler(this, DKFunction([this](const DKWindow::WindowEvent& e)
175
+        {
176
+            if (e.type == DKWindow::WindowEvent::WindowClosed)
177
+                DKApplication::Instance()->Terminate(0);
178
+        }), NULL, NULL);
411 179
 
412 180
 		runningRenderThread = 1;
413
-		renderThread = DKThread::Create(DKFunction(this, &TestApp1::RenderThread)->Invocation());
181
+		renderThread = DKThread::Create(DKFunction(this, &TriangleDemo::RenderThread)->Invocation());
414 182
 	}
415 183
 	void OnTerminate(void) override
416 184
 	{
@@ -419,29 +187,9 @@ public:
419 187
 		runningRenderThread = 0;
420 188
 		renderThread->WaitTerminate();
421 189
 		renderThread = NULL;
422
-		window = NULL;
190
+        window = NULL;
423 191
 
424
-		DKLogI("Memory Pool Statistics");
425
-		size_t numBuckets = DKMemoryPoolNumberOfBuckets();
426
-		DKMemoryPoolBucketStatus* buckets = new DKMemoryPoolBucketStatus[numBuckets];
427
-		DKMemoryPoolQueryAllocationStatus(buckets, numBuckets);
428
-		size_t usedBytes = 0;
429
-		for (int i = 0; i < numBuckets; ++i)
430
-		{
431
-			if (buckets[i].totalChunks > 0)
432
-			{
433
-				DKLogI("--> %5lu:  %5lu/%5lu, usage: %.1f%%, used: %.1fKB, total: %.1fKB",
434
-					   buckets[i].chunkSize,
435
-					   buckets[i].usedChunks, buckets[i].totalChunks,
436
-					   double(buckets[i].usedChunks) / double(buckets[i].totalChunks) * 100.0,
437
-					   double(buckets[i].chunkSize * buckets[i].usedChunks) / 1024.0,
438
-					   double(buckets[i].chunkSize * buckets[i].totalChunks) / 1024.0
439
-				);
440
-				usedBytes += buckets[i].chunkSize * buckets[i].usedChunks;
441
-			}
442
-		}
443
-		DKLogI("MemoryPool Usage: %.1fMB / %.1fMB", double(usedBytes) / (1024 * 1024), double(DKMemoryPoolSize()) / (1024 * 1024));
444
-		delete[] buckets;
192
+        SampleApp::OnTerminate();
445 193
 	}
446 194
 };
447 195
 
@@ -455,7 +203,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
455 203
 int main(int argc, const char * argv[])
456 204
 #endif
457 205
 {
458
-	TestApp1 app;
206
+    TriangleDemo app;
459 207
 	DKPropertySet::SystemConfig().SetValue("AppDelegate", "AppDelegate");
460 208
 	DKPropertySet::SystemConfig().SetValue("GraphicsAPI", "Vulkan");
461 209
 	return app.Run();

+ 21
- 1
Samples/Triangle/Triangle.vcxproj ファイルの表示

@@ -20,6 +20,7 @@
20 20
   </ItemGroup>
21 21
   <ItemGroup>
22 22
     <ClInclude Include="..\Common\app.h" />
23
+    <ClInclude Include="..\Common\util.h" />
23 24
     <ClInclude Include="..\Common\Win32\Resource.h" />
24 25
     <ClInclude Include="..\Common\Win32\stdafx.h" />
25 26
     <ClInclude Include="..\Common\Win32\targetver.h" />
@@ -32,7 +33,6 @@
32 33
     <ResourceCompile Include="..\Common\Win32\SampleApp.rc" />
33 34
   </ItemGroup>
34 35
   <ItemGroup>
35
-    <ClCompile Include="..\Common\app.cpp" />
36 36
     <ClCompile Include="..\Common\dkgl_new.cpp" />
37 37
     <ClCompile Include="Triangle.cpp" />
38 38
   </ItemGroup>
@@ -121,6 +121,11 @@
121 121
       <SubSystem>Windows</SubSystem>
122 122
       <GenerateDebugInformation>true</GenerateDebugInformation>
123 123
     </Link>
124
+    <PostBuildEvent>
125
+      <Command>echo Copying Resource Files...
126
+xcopy /Y /D /R /Q /E "$(SolutionDir)Samples\Data" "$(OutDir)Data\"
127
+</Command>
128
+    </PostBuildEvent>
124 129
   </ItemDefinitionGroup>
125 130
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
126 131
     <ClCompile>
@@ -134,6 +139,11 @@
134 139
       <SubSystem>Windows</SubSystem>
135 140
       <GenerateDebugInformation>true</GenerateDebugInformation>
136 141
     </Link>
142
+    <PostBuildEvent>
143
+      <Command>echo Copying Resource Files...
144
+xcopy /Y /D /R /Q /E "$(SolutionDir)Samples\Data" "$(OutDir)Data\"
145
+</Command>
146
+    </PostBuildEvent>
137 147
   </ItemDefinitionGroup>
138 148
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
139 149
     <ClCompile>
@@ -151,6 +161,11 @@
151 161
       <OptimizeReferences>true</OptimizeReferences>
152 162
       <GenerateDebugInformation>true</GenerateDebugInformation>
153 163
     </Link>
164
+    <PostBuildEvent>
165
+      <Command>echo Copying Resource Files...
166
+xcopy /Y /D /R /Q /E "$(SolutionDir)Samples\Data" "$(OutDir)Data\"
167
+</Command>
168
+    </PostBuildEvent>
154 169
   </ItemDefinitionGroup>
155 170
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
156 171
     <ClCompile>
@@ -168,6 +183,11 @@
168 183
       <OptimizeReferences>true</OptimizeReferences>
169 184
       <GenerateDebugInformation>true</GenerateDebugInformation>
170 185
     </Link>
186
+    <PostBuildEvent>
187
+      <Command>echo Copying Resource Files...
188
+xcopy /Y /D /R /Q /E "$(SolutionDir)Samples\Data" "$(OutDir)Data\"
189
+</Command>
190
+    </PostBuildEvent>
171 191
   </ItemDefinitionGroup>
172 192
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
173 193
   <ImportGroup Label="ExtensionTargets">

+ 3
- 3
Samples/Triangle/Triangle.vcxproj.filters ファイルの表示

@@ -24,6 +24,9 @@
24 24
     <ClInclude Include="..\Common\app.h">
25 25
       <Filter>Common</Filter>
26 26
     </ClInclude>
27
+    <ClInclude Include="..\Common\util.h">
28
+      <Filter>Common</Filter>
29
+    </ClInclude>
27 30
   </ItemGroup>
28 31
   <ItemGroup>
29 32
     <Image Include="..\Common\Win32\SampleApp.ico">
@@ -45,8 +48,5 @@
45 48
     <ClCompile Include="..\Common\dkgl_new.cpp">
46 49
       <Filter>Common</Filter>
47 50
     </ClCompile>
48
-    <ClCompile Include="..\Common\app.cpp">
49
-      <Filter>Common</Filter>
50
-    </ClCompile>
51 51
   </ItemGroup>
52 52
 </Project>