@@ -90,7 +90,70 @@ int main()
90
90
auto * smgr = device->getSceneManager ();
91
91
92
92
//
93
- core::smart_refctd_ptr<video::IGPUMeshBuffer> mb;
93
+ asset::SBufferBinding<asset::ICPUBuffer> inverseBindPoses,jointAABBs;
94
+ core::smart_refctd_ptr<asset::ICPUSkeleton> skeleton;
95
+ {
96
+ constexpr uint32_t kJointCount = 2u ;
97
+ asset::SBufferBinding<asset::ICPUBuffer> parentIDs,defaultTransforms,inverseBindPoses,jointAABBs;
98
+ {
99
+ parentIDs.buffer = core::make_smart_refctd_ptr<asset::ICPUBuffer>(sizeof (asset::ICPUSkeleton)*kJointCount );
100
+ {
101
+ asset::ICPUSkeleton::joint_id_t parentJointIDs[] = { asset::ICPUSkeleton::invalid_joint_id,0u };
102
+ memcpy (parentIDs.buffer ->getPointer (),parentJointIDs,sizeof (parentJointIDs));
103
+ }
104
+ defaultTransforms.buffer = core::make_smart_refctd_ptr<asset::ICPUBuffer>(sizeof (matrix3x4SIMD)*kJointCount );
105
+ inverseBindPoses.buffer = core::make_smart_refctd_ptr<asset::ICPUBuffer>(sizeof (matrix3x4SIMD)*kJointCount );
106
+ {
107
+ auto * dftTransforms = reinterpret_cast <matrix3x4SIMD*>(defaultTransforms.buffer ->getPointer ());
108
+ auto * invBindPoses = reinterpret_cast <matrix3x4SIMD*>(inverseBindPoses.buffer ->getPointer ());
109
+ for (auto i=0u ; i<kJointCount ; i++)
110
+ {
111
+ dftTransforms[i] = matrix3x4SIMD ();
112
+ dftTransforms[i].setTranslation (core::vectorSIMDf (0 .f ,float (i)*2 .f -1 .f ,0 .f ));
113
+ dftTransforms[i].getInverse (invBindPoses[i]);
114
+ }
115
+ }
116
+ jointAABBs.buffer = core::make_smart_refctd_ptr<asset::ICPUBuffer>(sizeof (aabbox3df)*kJointCount );
117
+ }
118
+ const char * jointNames[] = {" root" ," bendy" };
119
+ skeleton = core::make_smart_refctd_ptr<asset::ICPUSkeleton>(std::move (parentIDs),std::move (defaultTransforms),&jointNames[0 ],&jointNames[0 ]+kJointCount );
120
+ }
121
+ core::smart_refctd_ptr<video::IGPUAnimationLibrary> gpuanimations;
122
+ {
123
+ constexpr uint32_t kKeyframeCount = 16u ;
124
+ constexpr uint32_t kAnimationCount = 3u ;
125
+ core::smart_refctd_ptr<asset::ICPUAnimationLibrary> animations;
126
+ {
127
+ asset::SBufferBinding<asset::ICPUBuffer> keyframes = {0ull ,core::make_smart_refctd_ptr<asset::ICPUBuffer>(sizeof (asset::ICPUAnimationLibrary::Keyframe)*kKeyframeCount )};
128
+ asset::SBufferBinding<asset::ICPUBuffer> timestamps = {0ull ,core::make_smart_refctd_ptr<asset::ICPUBuffer>(sizeof (asset::ICPUAnimationLibrary::timestamp_t )*kKeyframeCount )};
129
+ asset::SBufferRange<asset::ICPUBuffer> namedAnims;
130
+ namedAnims.offset = 0ull ;
131
+ namedAnims.size = sizeof (asset::ICPUAnimationLibrary::Animation)*kAnimationCount ;
132
+ namedAnims.buffer = core::make_smart_refctd_ptr<asset::ICPUBuffer>(namedAnims.size );
133
+ animations = core::make_smart_refctd_ptr<asset::ICPUAnimationLibrary>(std::move (keyframes),std::move (timestamps),kKeyframeCount ,std::move (namedAnims));
134
+ }
135
+ {
136
+ const uint32_t animationOffsets[] = { 0u ,1u ,2u };
137
+ const asset::ICPUAnimationLibrary::Animation anims[] = {
138
+ {0u ,kKeyframeCount ,asset::ICPUAnimationLibrary::Animation::EIM_NEAREST},
139
+ {0u ,kKeyframeCount ,asset::ICPUAnimationLibrary::Animation::EIM_LINEAR},
140
+ {0u ,kKeyframeCount ,asset::ICPUAnimationLibrary::Animation::EIM_CUBIC},
141
+ };
142
+ for (auto i=0u ; i<kAnimationCount ; i++)
143
+ animations->getAnimation (animationOffsets[i]) = anims[i];
144
+ const char * animationNames[] = { " moveNearest" ," moveLinear" ," moveCubic" };
145
+ animations->addAnimationNames (animationNames,animationNames+kAnimationCount ,animationOffsets);
146
+
147
+ for (auto i=0u ; i<kAnimationCount ; i++)
148
+ {
149
+ assert (animations->getAnimationOffsetFromName (animationNames[i]) == animationOffsets[i]);
150
+ }
151
+ }
152
+ gpuanimations = driver->getGPUObjectsFromAssets <asset::ICPUAnimationLibrary>(&animations,&animations+1u )->begin ()[0 ];
153
+ }
154
+
155
+ //
156
+ core::smart_refctd_ptr<video::IGPUMeshBuffer> gpumb;
94
157
{
95
158
VertexStruct vertices[8 ];
96
159
vertices[0 ] = VertexStruct{{-1 .f ,-1 .f ,-1 .f },{ 0 , 0 }};
@@ -101,6 +164,8 @@ int main()
101
164
vertices[5 ] = VertexStruct{{ 1 .f ,-1 .f , 1 .f },{255 ,127 }};
102
165
vertices[6 ] = VertexStruct{{-1 .f , 1 .f , 1 .f },{ 0 ,255 }};
103
166
vertices[7 ] = VertexStruct{{ 1 .f , 1 .f , 1 .f },{127 ,255 }};
167
+ asset::SBufferBinding<asset::ICPUBuffer> bindings[asset::ICPUMeshBuffer::MAX_ATTR_BUF_BINDING_COUNT];
168
+ bindings[0u ] = {0u ,core::make_smart_refctd_ptr<asset::CCustomAllocatorCPUBuffer<core::null_allocator<uint8_t >>>(sizeof (vertices),vertices,core::adopt_memory)};
104
169
105
170
uint16_t indices_indexed16[] =
106
171
{
@@ -111,27 +176,28 @@ int main()
111
176
0 ,2 ,4 ,2 ,4 ,6 ,
112
177
1 ,3 ,5 ,3 ,5 ,7
113
178
};
179
+ asset::SBufferBinding<asset::ICPUBuffer> indexBinding{0u ,core::make_smart_refctd_ptr<asset::CCustomAllocatorCPUBuffer<core::null_allocator<uint8_t >>>(sizeof (indices_indexed16),indices_indexed16,core::adopt_memory)};
114
180
115
181
asset::SPushConstantRange range[1 ] = {asset::ISpecializedShader::ESS_VERTEX,0u ,sizeof (core::matrix4SIMD)};
116
182
117
- auto createGPUSpecializedShaderFromSource = [=](const char * source, asset::ISpecializedShader::E_SHADER_STAGE stage)
183
+ auto createSpecializedShaderFromSource = [=](const char * source, asset::ISpecializedShader::E_SHADER_STAGE stage)
118
184
{
119
185
auto spirv = device->getAssetManager ()->getGLSLCompiler ()->createSPIRVFromGLSL (source, stage, " main" , " runtimeID" );
120
- auto unspec = driver->createGPUShader (std::move (spirv));
121
- return driver->createGPUSpecializedShader (unspec.get (), { nullptr ,nullptr ," main" ,stage });
186
+ return core::make_smart_refctd_ptr<asset::ICPUSpecializedShader>(std::move (spirv),asset::ICPUSpecializedShader::SInfo{ nullptr ,nullptr ," main" ,stage });
122
187
};
123
188
// origFilepath is only relevant when you have filesystem #includes in your shader
124
- auto createGPUSpecializedShaderFromSourceWithIncludes = [&](const char * source, asset::ISpecializedShader::E_SHADER_STAGE stage, const char * origFilepath)
189
+ auto createSpecializedShaderFromSourceWithIncludes = [&](const char * source, asset::ISpecializedShader::E_SHADER_STAGE stage, const char * origFilepath)
125
190
{
126
191
auto resolved_includes = device->getAssetManager ()->getGLSLCompiler ()->resolveIncludeDirectives (source, stage, origFilepath);
127
- return createGPUSpecializedShaderFromSource (reinterpret_cast <const char *>(resolved_includes->getSPVorGLSL ()->getPointer ()), stage);
192
+ return createSpecializedShaderFromSource (reinterpret_cast <const char *>(resolved_includes->getSPVorGLSL ()->getPointer ()), stage);
128
193
};
129
- core::smart_refctd_ptr<video::IGPUSpecializedShader> shaders[2 ] =
194
+ constexpr uint32_t kShaderCount = 2u ;
195
+ core::smart_refctd_ptr<asset::ICPUSpecializedShader> shaders[kShaderCount ] =
130
196
{
131
- createGPUSpecializedShaderFromSourceWithIncludes (vertexSource,asset::ISpecializedShader::ESS_VERTEX, " shader.vert" ),
132
- createGPUSpecializedShaderFromSource (fragmentSource,asset::ISpecializedShader::ESS_FRAGMENT)
197
+ createSpecializedShaderFromSourceWithIncludes (vertexSource,asset::ISpecializedShader::ESS_VERTEX, " shader.vert" ),
198
+ createSpecializedShaderFromSource (fragmentSource,asset::ISpecializedShader::ESS_FRAGMENT)
133
199
};
134
- auto shadersPtr = reinterpret_cast <video::IGPUSpecializedShader **>(shaders);
200
+ auto shadersPtr = reinterpret_cast <asset::ICPUSpecializedShader **>(shaders);
135
201
136
202
asset::SVertexInputParams inputParams;
137
203
inputParams.enabledAttribFlags = 0b11u ;
@@ -152,17 +218,19 @@ int main()
152
218
asset::SStencilOpParams defaultStencil;
153
219
asset::SRasterizationParams rasterParams;
154
220
rasterParams.faceCullingMode = asset::EFCM_NONE;
155
- auto pipeline = driver-> createGPURenderpassIndependentPipeline ( nullptr ,driver-> createGPUPipelineLayout (range,range+ 1u , nullptr , nullptr , nullptr , nullptr ),
156
- shadersPtr,shadersPtr+ sizeof (shaders)/ sizeof ( core::smart_refctd_ptr<video::IGPUSpecializedShader> ),
157
- inputParams,blendParams,assemblyParams,rasterParams);
158
-
159
- asset::SBufferBinding<video::IGPUBuffer> bindings[video::IGPUMeshBuffer::MAX_ATTR_BUF_BINDING_COUNT] ;
160
- bindings[ 0u ] = { 0u ,driver-> createFilledDeviceLocalGPUBufferOnDedMem ( sizeof (vertices),vertices)};
161
- mb = core::make_smart_refctd_ptr<video::IGPUMeshBuffer >(std::move (pipeline),nullptr ,bindings,asset::SBufferBinding<video::IGPUBuffer>{ 0u ,driver-> createFilledDeviceLocalGPUBufferOnDedMem ( sizeof (indices_indexed16),indices_indexed16)} );
221
+ auto pipeline = core::make_smart_refctd_ptr<asset::ICPURenderpassIndependentPipeline>(
222
+ core::make_smart_refctd_ptr<asset::ICPUPipelineLayout>(range,range+ 1u , nullptr , nullptr , nullptr , nullptr ),
223
+ shadersPtr,shadersPtr+ kShaderCount ,
224
+ inputParams,blendParams,assemblyParams,rasterParams
225
+ ) ;
226
+
227
+ auto mb = core::make_smart_refctd_ptr<asset::ICPUMeshBuffer >(std::move (pipeline),nullptr ,bindings,std::move (indexBinding) );
162
228
{
229
+ mb->setSkin (std::move (inverseBindPoses),std::move (jointAABBs),std::move (skeleton),1u );
163
230
mb->setIndexType (asset::EIT_16BIT);
164
231
mb->setIndexCount (2 *3 *6 );
165
232
}
233
+ gpumb = driver->getGPUObjectsFromAssets <asset::ICPUMeshBuffer>(&mb,&mb+1u )->begin ()[0 ];
166
234
}
167
235
168
236
@@ -187,9 +255,9 @@ int main()
187
255
188
256
// ! Stress test for memleaks aside from demo how to create meshes that live on the GPU RAM
189
257
{
190
- driver->bindGraphicsPipeline (mb ->getPipeline ());
191
- driver->pushConstants (mb ->getPipeline ()->getLayout (), asset::ISpecializedShader::ESS_VERTEX, 0u , sizeof (core::matrix4SIMD), mvp.pointer ());
192
- driver->drawMeshBuffer (mb .get ());
258
+ driver->bindGraphicsPipeline (gpumb ->getPipeline ());
259
+ driver->pushConstants (gpumb ->getPipeline ()->getLayout (), asset::ISpecializedShader::ESS_VERTEX, 0u , sizeof (core::matrix4SIMD), mvp.pointer ());
260
+ driver->drawMeshBuffer (gpumb .get ());
193
261
}
194
262
driver->endScene ();
195
263
0 commit comments