Browse Source

PSO/Reflection 테스트용 VertexDescriptor (DKVertexDescriptor) 자동 생성.

Hongtae Kim 6 years ago
parent
commit
5451065d33
2 changed files with 88 additions and 16 deletions
  1. 84
    16
      TestApp1/TestApp1.cpp
  2. 4
    0
      TestApp1/TestApp1.vcxproj

+ 84
- 16
TestApp1/TestApp1.cpp View File

@@ -88,6 +88,86 @@ const char* ShaderDataTypeStr(DKShaderDataType t)
88 88
 	return "Error";
89 89
 }
90 90
 
91
+DKVertexDescriptor VertexDescriptorForVertexAttributes(const DKArray<DKVertexAttribute>& attrs)
92
+{
93
+    uint32_t vertexSize = 0;
94
+    DKVertexDescriptor descriptor = {};
95
+
96
+    for (uint32_t i = 0; i < attrs.Count(); ++i)
97
+    {         
98
+        if (const DKVertexAttribute& attr = attrs.Value(i); attr.active)
99
+        {
100
+            DKVertexAttributeDescriptor desc = {};
101
+
102
+            switch (attr.type)
103
+            {
104
+               case DKShaderDataType::Float:
105
+               case DKShaderDataType::Half:
106
+               case DKShaderDataType::Int:
107
+               case DKShaderDataType::UInt:
108
+               case DKShaderDataType::Short:
109
+               case DKShaderDataType::UShort:
110
+               case DKShaderDataType::Char:
111
+               case DKShaderDataType::UChar:
112
+               case DKShaderDataType::Bool:
113
+                   desc.format = DKVertexFormat::Float;
114
+                   desc.offset = vertexSize;
115
+                   vertexSize += 4;
116
+                   break;
117
+               case DKShaderDataType::Float2:
118
+               case DKShaderDataType::Half2:
119
+               case DKShaderDataType::Int2:
120
+               case DKShaderDataType::UInt2:
121
+               case DKShaderDataType::Short2:
122
+               case DKShaderDataType::UShort2:
123
+               case DKShaderDataType::Char2:
124
+               case DKShaderDataType::UChar2:
125
+               case DKShaderDataType::Bool2:
126
+                   desc.format = DKVertexFormat::Float2;
127
+                   desc.offset = vertexSize;
128
+                   vertexSize += 8;
129
+                   break;
130
+               case DKShaderDataType::Float3:
131
+               case DKShaderDataType::Half3:
132
+               case DKShaderDataType::Int3:
133
+               case DKShaderDataType::UInt3:
134
+               case DKShaderDataType::Short3:
135
+               case DKShaderDataType::UShort3:
136
+               case DKShaderDataType::Char3:
137
+               case DKShaderDataType::UChar3:
138
+               case DKShaderDataType::Bool3:
139
+                   desc.format = DKVertexFormat::Float3;
140
+                   desc.offset = vertexSize;
141
+                   vertexSize += 12;
142
+                   break;
143
+               case DKShaderDataType::Float4:
144
+               case DKShaderDataType::Half4:
145
+               case DKShaderDataType::Int4:
146
+               case DKShaderDataType::UInt4:
147
+               case DKShaderDataType::Short4:
148
+               case DKShaderDataType::UShort4:
149
+               case DKShaderDataType::Char4:
150
+               case DKShaderDataType::UChar4:
151
+               case DKShaderDataType::Bool4:
152
+                   desc.format = DKVertexFormat::Float4;
153
+                   desc.offset = vertexSize;
154
+                   vertexSize += 16;
155
+                   break;
156
+               default:
157
+                   DKASSERT_DESC(0, "Unsupported type!");
158
+                   break;
159
+            }
160
+            desc.location = attr.location;
161
+
162
+            descriptor.attributes.Add(desc);
163
+        }
164
+    }
165
+
166
+    descriptor.layouts = { { DKVertexStepRate::Vertex, vertexSize}, };
167
+
168
+    return descriptor;
169
+};
170
+
91 171
 void PrintShaderResource(const DKShaderResource& res)
92 172
 {
93 173
 	struct MemberPrinter
@@ -206,22 +286,6 @@ public:
206 286
 		DKObject<DKData> vertData = resourcePool.LoadResourceData("shaders/texturearray/instancing.vert.spv");
207 287
 		DKObject<DKData> fragData = resourcePool.LoadResourceData("shaders/texturearray/instancing.frag.spv");
208 288
 
209
-		struct Vertex
210
-		{
211
-			DKVector3 position;
212
-			DKVector2 uv;
213
-			DKVector3 normal;
214
-		};
215
-		DKVertexDescriptor vertexDescriptor;
216
-		vertexDescriptor.attributes = {
217
-			{ DKVertexFormat::Float3, 0, 0, 0 },
218
-			{ DKVertexFormat::Float2, sizeof(DKVector2), 0, 1 },
219
-			{ DKVertexFormat::Float3, sizeof(DKVector3), 0, 2 },
220
-		};
221
-		vertexDescriptor.layouts = {
222
-			{ DKVertexStepRate::Vertex, sizeof(Vertex), 0 },
223
-		};
224
-
225 289
 		DKShader vertShader(vertData, DKShader::Vertex);
226 290
 		DKShader fragShader(fragData, DKShader::Fragment);
227 291
 
@@ -241,6 +305,10 @@ public:
241 305
 			DKLog("  --> VertexAttribute[%d]: \"%ls\" (location:%u)", i, (const wchar_t*)attr.name, attr.location);
242 306
 		}
243 307
 
308
+        // setup dummy vertex-descriptor
309
+        DKVertexDescriptor vertexDescriptor = VertexDescriptorForVertexAttributes(vertShaderFunction->VertexAttributes());
310
+
311
+        // setup rendering pipeline state object (PSO)
244 312
 		DKRenderPipelineDescriptor pipelineDescriptor;
245 313
 		pipelineDescriptor.vertexFunction = vertShaderFunction;
246 314
 		pipelineDescriptor.fragmentFunction = fragShaderFunction;

+ 4
- 0
TestApp1/TestApp1.vcxproj View File

@@ -96,6 +96,7 @@
96 96
       <Optimization>Disabled</Optimization>
97 97
       <PreprocessorDefinitions>DKGL_STATIC=1;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
98 98
       <AdditionalIncludeDirectories>../DK</AdditionalIncludeDirectories>
99
+      <LanguageStandard>stdcpp17</LanguageStandard>
99 100
     </ClCompile>
100 101
     <Link>
101 102
       <SubSystem>Windows</SubSystem>
@@ -117,6 +118,7 @@ xcopy /Y /D /R /Q /E "$(SolutionDir)Data" "$(OutDir)Data\"
117 118
       <Optimization>Disabled</Optimization>
118 119
       <PreprocessorDefinitions>DKGL_STATIC=1;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
119 120
       <AdditionalIncludeDirectories>../DK</AdditionalIncludeDirectories>
121
+      <LanguageStandard>stdcpp17</LanguageStandard>
120 122
     </ClCompile>
121 123
     <Link>
122 124
       <SubSystem>Windows</SubSystem>
@@ -140,6 +142,7 @@ xcopy /Y /D /R /Q /E "$(SolutionDir)Data" "$(OutDir)Data\"
140 142
       <IntrinsicFunctions>true</IntrinsicFunctions>
141 143
       <PreprocessorDefinitions>DKGL_STATIC=1;WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
142 144
       <AdditionalIncludeDirectories>../DK</AdditionalIncludeDirectories>
145
+      <LanguageStandard>stdcpp17</LanguageStandard>
143 146
     </ClCompile>
144 147
     <Link>
145 148
       <SubSystem>Windows</SubSystem>
@@ -165,6 +168,7 @@ xcopy /Y /D /R /Q /E "$(SolutionDir)Data" "$(OutDir)Data\"
165 168
       <IntrinsicFunctions>true</IntrinsicFunctions>
166 169
       <PreprocessorDefinitions>DKGL_STATIC=1;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
167 170
       <AdditionalIncludeDirectories>../DK</AdditionalIncludeDirectories>
171
+      <LanguageStandard>stdcpp17</LanguageStandard>
168 172
     </ClCompile>
169 173
     <Link>
170 174
       <SubSystem>Windows</SubSystem>