@@ -155,18 +155,25 @@ struct VTData
155
155
float Ni;
156
156
uint extra; //flags copied from MTL metadata
157
157
};
158
+ #define _NBL_FRAG_MATERIAL_PARAMETERS_STRUCT_DEFINED_
159
+ #define nbl_glsl_MaterialParametersStruct VTData
158
160
159
161
layout(set = 2, binding = 1, std430) readonly buffer VTDataBuffer
160
162
{
161
163
VTData vtData[];
162
164
} vtDataBuffer;
163
165
164
- #define _NBL_FRAG_PUSH_CONSTANTS_DEFINED_
165
-
166
166
layout (push_constant) uniform Block
167
167
{
168
168
uint dataBufferOffset;
169
169
} pc;
170
+ #define _NBL_FRAG_PUSH_CONSTANTS_DEFINED_
171
+
172
+ VTData nbl_glsl_getMaterialParameters()
173
+ {
174
+ return vtDataBuffer.vtData[drawID + pc.dataBufferOffset];
175
+ }
176
+ #define _NBL_FRAG_GET_MATERIAL_PARAMETERS_FUNCTION_DEFINED_
170
177
171
178
#ifndef _NO_UV
172
179
uint nbl_glsl_VT_layer2pid(in uint layer)
@@ -193,21 +200,45 @@ layout (push_constant) uniform Block
193
200
194
201
195
202
#ifndef _NO_UV
196
- vec4 nbl_sample_Ka(in vec2 uv, in mat2 dUV) { return nbl_glsl_vTextureGrad(vtDataBuffer.vtData[drawID + pc.dataBufferOffset] .map_Ka_data, uv, dUV); }
203
+ vec4 nbl_sample_Ka(in vec2 uv, in mat2 dUV) { return nbl_glsl_vTextureGrad(nbl_glsl_getMaterialParameters() .map_Ka_data, uv, dUV); }
197
204
198
- vec4 nbl_sample_Kd(in vec2 uv, in mat2 dUV) { return nbl_glsl_vTextureGrad(vtDataBuffer.vtData[drawID + pc.dataBufferOffset] .map_Kd_data, uv, dUV); }
205
+ vec4 nbl_sample_Kd(in vec2 uv, in mat2 dUV) { return nbl_glsl_vTextureGrad(nbl_glsl_getMaterialParameters() .map_Kd_data, uv, dUV); }
199
206
200
- vec4 nbl_sample_Ks(in vec2 uv, in mat2 dUV) { return nbl_glsl_vTextureGrad(vtDataBuffer.vtData[drawID + pc.dataBufferOffset] .map_Ks_data, uv, dUV); }
207
+ vec4 nbl_sample_Ks(in vec2 uv, in mat2 dUV) { return nbl_glsl_vTextureGrad(nbl_glsl_getMaterialParameters() .map_Ks_data, uv, dUV); }
201
208
202
- vec4 nbl_sample_Ns(in vec2 uv, in mat2 dUV) { return nbl_glsl_vTextureGrad(vtDataBuffer.vtData[drawID + pc.dataBufferOffset] .map_Ns_data, uv, dUV); }
209
+ vec4 nbl_sample_Ns(in vec2 uv, in mat2 dUV) { return nbl_glsl_vTextureGrad(nbl_glsl_getMaterialParameters() .map_Ns_data, uv, dUV); }
203
210
204
- vec4 nbl_sample_d(in vec2 uv, in mat2 dUV) { return nbl_glsl_vTextureGrad(vtDataBuffer.vtData[drawID + pc.dataBufferOffset] .map_d_data, uv, dUV); }
211
+ vec4 nbl_sample_d(in vec2 uv, in mat2 dUV) { return nbl_glsl_vTextureGrad(nbl_glsl_getMaterialParameters() .map_d_data, uv, dUV); }
205
212
206
- vec4 nbl_sample_bump(in vec2 uv, in mat2 dUV) { return nbl_glsl_vTextureGrad(vtDataBuffer.vtData[drawID + pc.dataBufferOffset] .map_bump_data, uv, dUV); }
213
+ vec4 nbl_sample_bump(in vec2 uv, in mat2 dUV) { return nbl_glsl_vTextureGrad(nbl_glsl_getMaterialParameters() .map_bump_data, uv, dUV); }
207
214
#endif
208
215
#define _NBL_TEXTURE_SAMPLE_FUNCTIONS_DEFINED_
209
216
)" ;
210
217
218
+ constexpr uint32_t TEX_OF_INTEREST_CNT = 6u ;
219
+ #include " nbl/nblpack.h"
220
+ struct SPushConstants // TODO: rename
221
+ {
222
+ // Ka
223
+ core::vector3df_SIMD ambient;
224
+ // Kd
225
+ core::vector3df_SIMD diffuse;
226
+ // Ks
227
+ core::vector3df_SIMD specular;
228
+ // Ke
229
+ core::vector3df_SIMD emissive;
230
+ uint64_t map_data[TEX_OF_INTEREST_CNT];
231
+ // Ns, specular exponent in phong model
232
+ float shininess = 32 .f;
233
+ // d
234
+ float opacity = 1 .f;
235
+ // Ni, index of refraction
236
+ float IoR = 1 .6f ;
237
+ uint32_t extra;
238
+ } PACK_STRUCT;
239
+ #include " nbl/nblunpack.h"
240
+ static_assert (sizeof (SPushConstants) <= asset::ICPUMeshBuffer::MAX_PUSH_CONSTANT_BYTESIZE, "doesnt fit in push constants");
241
+
211
242
core::smart_refctd_ptr<asset::ICPUSpecializedShader> createModifiedVertexShader (const asset::ICPUSpecializedShader* _fs)
212
243
{
213
244
const asset::ICPUShader* unspec = _fs->getUnspecialized ();
@@ -313,6 +344,7 @@ struct DrawData
313
344
core::vector<MbPipelineRange> ranges;
314
345
core::vector<core::smart_refctd_ptr<IGPURenderpassIndependentPipeline>> gpuPipelines;
315
346
core::vector<DrawIndexedIndirectInput> drawIndirectInput;
347
+ core::smart_refctd_ptr<IGPUBuffer> vtDataSSBO;
316
348
core::vector<uint32_t > pushConstantsData;
317
349
std::array<core::smart_refctd_ptr<IGPUDescriptorSet>, 3 > ds;
318
350
core::smart_refctd_ptr<IGPUVirtualTexture> vt;
@@ -338,9 +370,12 @@ void packMeshBuffers(video::IVideoDriver* driver, DrawData& drawData)
338
370
339
371
assert (!drawData.ranges .empty ());
340
372
341
- CCPUMeshPackerV2 mp (allocParams, 4096 /* std::numeric_limits<uint16_t>::max() / 3u*/ , 4096 /* std::numeric_limits<uint16_t>::max() / 3u*/ );
373
+ CCPUMeshPackerV2 mp (allocParams, std::numeric_limits<uint16_t >::max () / 3u , std::numeric_limits<uint16_t >::max () / 3u );
342
374
343
- const uint32_t mdiCntTotal = mp.calcMDIStructCount (drawData.ranges .begin ()->second .begin (), (drawData.ranges .end () - 1 )->second .end ());
375
+ auto wholeMbRangeBegin = drawData.ranges .begin ()->second .begin ();
376
+ auto wholeMbRangeEnd = (drawData.ranges .end () - 1 )->second .end ();
377
+
378
+ const uint32_t mdiCntTotal = mp.calcMDIStructCount (wholeMbRangeBegin, wholeMbRangeEnd);
344
379
auto allocData = core::make_refctd_dynamic_array<core::smart_refctd_dynamic_array<MeshPacker::ReservedAllocationMeshBuffers>>(mdiCntTotal);
345
380
346
381
const uint32_t offsetTableSz = mdiCntTotal * 3u ;
@@ -371,9 +406,9 @@ void packMeshBuffers(video::IVideoDriver* driver, DrawData& drawData)
371
406
372
407
for (uint32_t i = 0u ; i < drawData.ranges .size (); i++)
373
408
{
374
- auto mbRange = drawData.ranges [i];
375
- auto mbRangeBegin = mbRange.second . begin ();
376
- auto mbRangeEnd = mbRange.second . end ();
409
+ auto mbRange = drawData.ranges [i]. second ;
410
+ auto mbRangeBegin = mbRange.begin ();
411
+ auto mbRangeEnd = mbRange.end ();
377
412
378
413
const uint32_t mdiCnt = mp.calcMDIStructCount (mbRangeBegin, mbRangeEnd);
379
414
@@ -388,7 +423,7 @@ void packMeshBuffers(video::IVideoDriver* driver, DrawData& drawData)
388
423
_NBL_DEBUG_BREAK_IF (true );
389
424
}
390
425
391
- DrawIndexedIndirectInput mdiCallInput; // TODO: remove redundant objects
426
+ DrawIndexedIndirectInput mdiCallInput;
392
427
393
428
mdiCallInput.maxCount = mdiCnt;
394
429
@@ -418,6 +453,22 @@ void packMeshBuffers(video::IVideoDriver* driver, DrawData& drawData)
418
453
}*/
419
454
}
420
455
456
+ // prepare data for (set = 2, binding = 1) frag shader ssbo
457
+ {
458
+ // TODO: this is shit and `calcMDIStructCount` should be cashed so it would't be called so often, rewrite it
459
+ core::vector<SPushConstants> vtData;
460
+ vtData.reserve (mdiCntTotal);
461
+
462
+ for (auto it = wholeMbRangeBegin; it != wholeMbRangeEnd; it++)
463
+ {
464
+ const uint32_t mdiCntForThisMb = mp.calcMDIStructCount (it, it + 1 );
465
+ for (uint32_t i = 0u ; i < mdiCntForThisMb; i++)
466
+ vtData.push_back (*reinterpret_cast <SPushConstants*>((*it)->getPushConstantsDataPtr ()));
467
+ }
468
+
469
+ drawData.vtDataSSBO = driver->createFilledDeviceLocalGPUBufferOnDedMem (vtData.size () * sizeof (SPushConstants), vtData.data ());
470
+ }
471
+
421
472
drawData.vtxBindings [0 ] = { 0ull , driver->createFilledDeviceLocalGPUBufferOnDedMem (packerDataStore.vertexBuffer ->getSize (), packerDataStore.vertexBuffer ->getPointer ()) };
422
473
drawData.idxBuffer = driver->createFilledDeviceLocalGPUBufferOnDedMem (packerDataStore.indexBuffer ->getSize (), packerDataStore.indexBuffer ->getPointer ());
423
474
drawData.mdiBuffer = driver->createFilledDeviceLocalGPUBufferOnDedMem (packerDataStore.MDIDataBuffer ->getSize (), packerDataStore.MDIDataBuffer ->getPointer ());
@@ -448,30 +499,6 @@ struct commit_t
448
499
asset::ICPUSampler::E_TEXTURE_BORDER_COLOR border;
449
500
};
450
501
451
- constexpr uint32_t TEX_OF_INTEREST_CNT = 6u ;
452
- #include " nbl/nblpack.h"
453
- struct SPushConstants
454
- {
455
- // Ka
456
- core::vector3df_SIMD ambient;
457
- // Kd
458
- core::vector3df_SIMD diffuse;
459
- // Ks
460
- core::vector3df_SIMD specular;
461
- // Ke
462
- core::vector3df_SIMD emissive;
463
- uint64_t map_data[TEX_OF_INTEREST_CNT];
464
- // Ns, specular exponent in phong model
465
- float shininess = 32 .f;
466
- // d
467
- float opacity = 1 .f;
468
- // Ni, index of refraction
469
- float IoR = 1 .6f ;
470
- uint32_t extra;
471
- } PACK_STRUCT;
472
- #include " nbl/nblunpack.h"
473
- static_assert (sizeof (SPushConstants) <= asset::ICPUMeshBuffer::MAX_PUSH_CONSTANT_BYTESIZE, "doesnt fit in push constants");
474
-
475
502
constexpr uint32_t texturesOfInterest[TEX_OF_INTEREST_CNT]{
476
503
asset::CMTLMetadata::CRenderpassIndependentPipeline::EMP_AMBIENT,
477
504
asset::CMTLMetadata::CRenderpassIndependentPipeline::EMP_DIFFUSE,
@@ -571,8 +598,6 @@ void createVirtualTexture(video::IVideoDriver* driver, core::vector<ICPUMeshBuff
571
598
vt->commit (cm.addr , cm.texture .get (), cm.subresource , cm.uwrap , cm.vwrap , cm.border );
572
599
}
573
600
574
- // TODO: fill `VTDataBuffer` SSBO
575
-
576
601
outputGPUvt = core::make_smart_refctd_ptr<video::IGPUVirtualTexture>(driver, vt.get ());
577
602
}
578
603
@@ -591,8 +616,6 @@ void createPipeline(IVideoDriver* driver, ICPUSpecializedShader* vs, ICPUSpecial
591
616
auto bindings = core::make_refctd_dynamic_array<core::smart_refctd_dynamic_array<IGPUDescriptorSetLayout::SBinding>>(mpBindingsCnt + vtSizes.first );
592
617
auto vtSamplers = core::make_refctd_dynamic_array< core::smart_refctd_dynamic_array<core::smart_refctd_ptr<IGPUSampler>>>(vtSizes.second );
593
618
594
- // TODO: deal with vt bindings..
595
-
596
619
IGPUDescriptorSetLayout::SBinding* b = bindings->data ();
597
620
b[0 ].binding = 0u ; b[1 ].binding = 1u ; b[2 ].binding = 2u ; b[3 ].binding = 3u ;
598
621
b[0 ].type = b[1 ].type = b[2 ].type = EDT_UNIFORM_TEXEL_BUFFER;
@@ -659,7 +682,7 @@ void createPipeline(IVideoDriver* driver, ICPUSpecializedShader* vs, ICPUSpecial
659
682
w[0 ].binding = 0u ; w[1 ].binding = 0u ; w[2 ].binding = 1u ; w[3 ].binding = 2u ; w[4 ].binding = 3u ;
660
683
w[0 ].descriptorType = w[1 ].descriptorType = w[2 ].descriptorType = w[3 ].descriptorType = EDT_UNIFORM_TEXEL_BUFFER;
661
684
w[4 ].descriptorType = EDT_STORAGE_BUFFER;
662
- w[0 ].dstSet = w[1 ].dstSet = w[2 ].dstSet = w[3 ].dstSet = w[4 ].dstSet = w[ 5 ]. dstSet = drawData.ds [0 ].get ();
685
+ w[0 ].dstSet = w[1 ].dstSet = w[2 ].dstSet = w[3 ].dstSet = w[4 ].dstSet = drawData.ds [0 ].get ();
663
686
664
687
IGPUDescriptorSet::SDescriptorInfo info[5 ];
665
688
@@ -729,15 +752,16 @@ void createPipeline(IVideoDriver* driver, ICPUSpecializedShader* vs, ICPUSpecial
729
752
w2[1 ].descriptorType = EDT_STORAGE_BUFFER;
730
753
w2[1 ].dstSet = drawData.ds [2 ].get ();
731
754
732
- // TODO
755
+ core::smart_refctd_ptr<video::IGPUBuffer> buffer = driver->createFilledDeviceLocalGPUBufferOnDedMem (sizeof (video::IGPUVirtualTexture::SPrecomputedData), &drawData.vt ->getPrecomputedData ());
756
+
733
757
IGPUDescriptorSet::SDescriptorInfo info2[2 ];
734
758
info2[0 ].buffer .offset = 0u ;
735
- info2[0 ].buffer .size = 0u ;
736
- info2[0 ].desc = nullptr ;
759
+ info2[0 ].buffer .size = sizeof (video::IGPUVirtualTexture::SPrecomputedData) ;
760
+ info2[0 ].desc = buffer ;
737
761
738
762
info2[1 ].buffer .offset = 0u ;
739
- info2[1 ].buffer .size = 0u ;
740
- info2[1 ].desc = nullptr ;
763
+ info2[1 ].buffer .size = drawData. vtDataSSBO -> getSize () ;
764
+ info2[1 ].desc = drawData. vtDataSSBO ;
741
765
742
766
w2[0 ].info = &info2[0 ];
743
767
w2[1 ].info = &info2[1 ];
@@ -753,7 +777,7 @@ void createPipeline(IVideoDriver* driver, ICPUSpecializedShader* vs, ICPUSpecial
753
777
754
778
drawData.gpuPipelines .emplace_back (
755
779
driver->createGPURenderpassIndependentPipeline (
756
- nullptr , std::move (pipelineLayout),
780
+ nullptr , core::smart_refctd_ptr (pipelineLayout),
757
781
shaders, shaders + 2u ,
758
782
cpuPipeline->getVertexInputParams (),
759
783
cpuPipeline->getBlendParams (),
@@ -815,7 +839,7 @@ int main()
815
839
816
840
// TODO: change it to vector of smart pointers
817
841
core::vector<ICPUMeshBuffer*> meshBuffers;
818
- for (uint32_t i = 0u ; i < mesh_raw-> getMeshBufferVector (). size () ; i++)
842
+ for (uint32_t i = 0u ; i < 100 ; i++)
819
843
meshBuffers.push_back (mesh_raw->getMeshBufferVector ()[i].get ());
820
844
821
845
DrawData drawData;
0 commit comments