Skip to content

Commit 5d24f9c

Browse files
Merge pull request #22 from Crisspl/spirv-optimizer
spirv-opt integration, VK->GL extensions mapping NBL_ defines, material compiler bugfixes
2 parents e6b4b6d + 0dabfde commit 5d24f9c

File tree

70 files changed

+3626
-2264
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+3626
-2264
lines changed

3rdparty/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,6 @@ if (NBL_COMPILE_WITH_CUDA)
447447
endif()
448448

449449
set(NBL_3RDPARTY_TARGETS
450-
${RADEON_RAYS_DEPENDENTS}
451450
lzma
452451
lz4
453452
aesGladman
@@ -477,6 +476,9 @@ set(NBL_3RDPARTY_TARGETS
477476
if (NBL_BUILD_MITSUBA_LOADER)
478477
list(APPEND NBL_3RDPARTY_TARGETS expat)
479478
endif()
479+
if (NBL_BUILD_RADEON_RAYS)
480+
list(APPEND NBL_3RDPARTY_TARGETS ${RADEON_RAYS_DEPENDENTS})
481+
endif()
480482
if(ENABLE_HLSL)
481483
list(APPEND NBL_3RDPARTY_TARGETS HLSL)
482484
endif()

examples_tests/18.MitsubaLoader/main.cpp

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ vec2 SampleSphericalMap(in vec3 v)
5454
return uv;
5555
}
5656
57-
vec3 nbl_computeLighting(inout nbl_glsl_IsotropicViewSurfaceInteraction out_interaction, in mat2 dUV, in MC_precomputed_t precomp)
57+
vec3 nbl_computeLighting(inout nbl_glsl_IsotropicViewSurfaceInteraction out_interaction, in mat2 dUV, in nbl_glsl_MC_precomputed_t precomp)
5858
{
5959
nbl_glsl_xoroshiro64star_state_t scramble_start_state = textureLod(scramblebuf,gl_FragCoord.xy/VIEWPORT_SZ,0).rg;
6060
@@ -63,16 +63,16 @@ vec3 nbl_computeLighting(inout nbl_glsl_IsotropicViewSurfaceInteraction out_inte
6363
vec3 color = vec3(0.0);
6464
6565
#ifdef USE_ENVMAP
66-
instr_stream_t gcs = getGenChoiceStream(precomp);
67-
instr_stream_t rnps = getRemAndPdfStream(precomp);
66+
nbl_glsl_instr_stream_t gcs = getGenChoiceStream(precomp);
67+
nbl_glsl_instr_stream_t rnps = getRemAndPdfStream(precomp);
6868
for (int i = 0; i < SAMPLE_COUNT; ++i)
6969
{
7070
nbl_glsl_xoroshiro64star_state_t scramble_state = scramble_start_state;
7171
7272
vec3 rand = rand3d(i,scramble_state);
7373
float pdf;
7474
nbl_glsl_LightSample s;
75-
vec3 rem = runGenerateAndRemainderStream(precomp, gcs, rnps, rand, pdf, s);
75+
vec3 rem = nbl_glsl_runGenerateAndRemainderStream(precomp, gcs, rnps, rand, pdf, s);
7676
7777
vec2 uv = SampleSphericalMap(s.L);
7878
color += rem*textureLod(envMap, uv, 0.0).xyz;
@@ -260,6 +260,23 @@ int main()
260260
params.WindowSize.Width = film.width;
261261
params.WindowSize.Height = film.height;
262262
}
263+
else return 1; // no cameras
264+
265+
const auto& sensor = globalMeta->sensors.front(); //always choose frist one
266+
auto isOkSensorType = [](const ext::MitsubaLoader::CElementSensor& sensor) -> bool {
267+
return sensor.type == ext::MitsubaLoader::CElementSensor::Type::PERSPECTIVE || sensor.type == ext::MitsubaLoader::CElementSensor::Type::THINLENS;
268+
};
269+
270+
if (!isOkSensorType(sensor))
271+
return 1;
272+
273+
bool leftHandedCamera = false;
274+
{
275+
auto relativeTransform = sensor.transform.matrix.extractSub3x4();
276+
if (relativeTransform.getPseudoDeterminant().x < 0.f)
277+
leftHandedCamera = true;
278+
}
279+
263280
params.DriverType = video::EDT_OPENGL;
264281
auto device = createDeviceEx(params);
265282

@@ -313,6 +330,7 @@ int main()
313330
//gather all meshes into core::vector and modify their pipelines
314331
core::vector<core::smart_refctd_ptr<asset::ICPUMesh>> cpumeshes;
315332
cpumeshes.reserve(meshes.getSize());
333+
uint32_t cc = cpumeshes.capacity();
316334
for (auto it = meshes.getContents().begin(); it != meshes.getContents().end(); ++it)
317335
{
318336
cpumeshes.push_back(core::smart_refctd_ptr_static_cast<asset::ICPUMesh>(std::move(*it)));
@@ -394,7 +412,7 @@ int main()
394412
}
395413
}
396414

397-
constexpr uint32_t ENVMAP_SAMPLE_COUNT = 16u;
415+
constexpr uint32_t ENVMAP_SAMPLE_COUNT = 64u;
398416
constexpr float LIGHT_INTENSITY_SCALE = 0.01f;
399417

400418
core::unordered_set<const asset::ICPURenderpassIndependentPipeline*> modifiedPipelines;
@@ -418,6 +436,8 @@ int main()
418436
modifiedShaders.insert({ core::smart_refctd_ptr<asset::ICPUSpecializedShader>(fs),newfs });
419437
pipeline->setShaderAtStage(asset::ICPUSpecializedShader::ESS_FRAGMENT, newfs.get());
420438
}
439+
// invert what is recognized as frontface in case of RH camera
440+
pipeline->getRasterizationParams().frontFaceIsCCW = !leftHandedCamera;
421441
modifiedPipelines.insert(pipeline);
422442
}
423443
}
@@ -442,7 +462,6 @@ int main()
442462
}
443463
}
444464

445-
//auto gpuVT = core::make_smart_refctd_ptr<video::IGPUVirtualTexture>(driver, globalMeta->VT.get());
446465
auto gpuds0 = driver->getGPUObjectsFromAssets(&cpuds0.get(), &cpuds0.get()+1)->front();
447466

448467
auto gpuds1layout = driver->getGPUObjectsFromAssets(&ds1layout, &ds1layout+1)->front();
@@ -572,28 +591,21 @@ int main()
572591
scene::ICameraSceneNode* camera = nullptr;
573592
core::recti viewport(core::position2di(0,0), core::position2di(params.WindowSize.Width,params.WindowSize.Height));
574593

575-
auto isOkSensorType = [](const ext::MitsubaLoader::CElementSensor& sensor) -> bool {
576-
return sensor.type==ext::MitsubaLoader::CElementSensor::Type::PERSPECTIVE || sensor.type==ext::MitsubaLoader::CElementSensor::Type::THINLENS;
577-
};
578594
//#define TESTING
579595
#ifdef TESTING
580596
if (0)
581597
#else
582598
if (globalMeta->sensors.size() && isOkSensorType(globalMeta->sensors.front()))
583599
#endif
584600
{
585-
const auto& sensor = globalMeta->sensors.front();
586601
const auto& film = sensor.film;
587602
viewport = core::recti(core::position2di(film.cropOffsetX,film.cropOffsetY), core::position2di(film.cropWidth,film.cropHeight));
588603

589604
auto extent = sceneBound.getExtent();
590605
camera = smgr->addCameraSceneNodeFPS(nullptr,100.f,core::min(extent.X,extent.Y,extent.Z)*0.0001f);
591606
// need to extract individual components
592-
bool leftHandedCamera = false;
593607
{
594608
auto relativeTransform = sensor.transform.matrix.extractSub3x4();
595-
if (relativeTransform.getPseudoDeterminant().x < 0.f)
596-
leftHandedCamera = true;
597609

598610
auto pos = relativeTransform.getTranslation();
599611
camera->setPosition(pos.getAsVector3df());
@@ -697,7 +709,7 @@ int main()
697709
uboData.NormalMat[11] = camera->getPosition().Z;
698710
driver->updateBufferRangeViaStagingBuffer(gpuubo.get(), 0u, sizeof(uboData), &uboData);
699711

700-
for (uint32_t j = 1u; j < gpumeshes->size(); ++j)
712+
for (uint32_t j = 0u; j < gpumeshes->size(); ++j)
701713
{
702714
auto& mesh = (*gpumeshes)[j];
703715

examples_tests/22.RaytracedAO/InstanceDataPerCamera.glsl

Lines changed: 0 additions & 12 deletions
This file was deleted.
-503 KB
Binary file not shown.

examples_tests/22.RaytracedAO/common.glsl

Lines changed: 14 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,49 +3,24 @@
33

44
#define MAX_ACCUMULATED_SAMPLES (1024*1024)
55

6+
#define WORKGROUP_SIZE 256
67

78
#ifdef __cplusplus
8-
#define mat4 nbl::core::matrix4SIMD
9-
#define mat4x3 nbl::core::matrix3x4SIMD
10-
#endif
11-
12-
13-
struct SLight
14-
{
15-
#ifdef __cplusplus
16-
SLight() : obb() {}
17-
SLight(const SLight& other) : obb(other.obb) {}
18-
SLight(const nbl::core::aabbox3df& bbox, const nbl::core::matrix3x4SIMD& tform) : SLight()
9+
#define uint uint32_t
10+
struct uvec2
1911
{
20-
auto extent = bbox.getExtent();
21-
obb.setScale(nbl::core::vectorSIMDf(extent.X,extent.Y,extent.Z));
22-
obb.setTranslation(nbl::core::vectorSIMDf(bbox.MinEdge.X,bbox.MinEdge.Y,bbox.MinEdge.Z));
23-
24-
obb = nbl::core::concatenateBFollowedByA(tform,obb);
25-
}
26-
27-
inline SLight& operator=(SLight&& other) noexcept
12+
uint32_t x,y;
13+
};
14+
struct vec2
2815
{
29-
std::swap(obb, other.obb);
30-
31-
return *this;
32-
}
33-
34-
// also known as an upper bound on lumens put into the scene
35-
inline float computeFluxBound(const nbl::core::vectorSIMDf& radiance) const
16+
float x,y;
17+
};
18+
struct vec3
3619
{
37-
const nbl::core::vectorSIMDf rec709LumaCoeffs(0.2126f, 0.7152f, 0.0722f, 0.f);
38-
const auto unitHemisphereArea = 2.f*nbl::core::PI<float>();
39-
40-
const auto unitBoxScale = obb.getScale();
41-
const float obbArea = 2.f*(unitBoxScale.x*unitBoxScale.y+unitBoxScale.x*unitBoxScale.z+unitBoxScale.y*unitBoxScale.z);
42-
43-
return nbl::core::dot(radiance,rec709LumaCoeffs).x*unitHemisphereArea*obbArea;
44-
}
45-
#endif
46-
47-
mat4x3 obb; // needs row_major qualifier
48-
};
49-
20+
float x,y,z;
21+
};
22+
#define mat4 nbl::core::matrix4SIMD
23+
#define mat4x3 nbl::core::matrix3x4SIMD
24+
#endif
5025

5126
#endif
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#version 430 core
2+
3+
4+
#include "drawCommon.glsl"
5+
layout(local_size_x = WORKGROUP_SIZE) in;
6+
7+
8+
#include <nbl/builtin/glsl/utils/indirect_commands.glsl>
9+
layout(set=1, binding=0, std430, row_major) restrict readonly buffer PerInstanceStatic
10+
{
11+
ObjectStaticData_t staticData[];
12+
};
13+
layout(set=1, binding=1, row_major) writeonly restrict buffer PerInstancePerCamera
14+
{
15+
DrawData_t data[];
16+
} instanceDataPerCamera;
17+
layout(set=1, binding=2, std430, row_major) restrict readonly buffer PerInstanceCull
18+
{
19+
CullData_t cullData[];
20+
};
21+
layout(set=1, binding=3, std430) restrict coherent buffer IndirectDraws
22+
{
23+
nbl_glsl_DrawElementsIndirectCommand_t draws[];
24+
} commandBuff[2];
25+
26+
27+
28+
layout(push_constant, row_major) uniform PushConstants
29+
{
30+
CullShaderData_t data;
31+
} pc;
32+
33+
34+
35+
#include <nbl/builtin/glsl/utils/culling.glsl>
36+
#include <nbl/builtin/glsl/utils/transform.glsl>
37+
38+
39+
// base instance remains unchanged
40+
// we just do atomic add on the instance count
41+
void main()
42+
{
43+
uint globalObjectID = gl_GlobalInvocationID.x;
44+
if (globalObjectID>=pc.data.maxObjectCount)
45+
return;
46+
47+
const mat4x3 worldMatrix = cullData[globalObjectID].worldMatrix;
48+
const uint drawID = cullData[globalObjectID].drawID;
49+
50+
// clear drawcount for next buffer
51+
commandBuff[pc.data.currentCommandBufferIx^0x1u].draws[drawID].instanceCount = 0u;
52+
53+
// cull
54+
const mat4 MVP = nbl_glsl_pseudoMul4x4with4x3(pc.data.viewProjMatrix,worldMatrix);
55+
bool notCulled = true;
56+
if (false)
57+
{
58+
mat2x3 bbox;
59+
bbox[0] = cullData[globalObjectID].aabbMinEdge;
60+
bbox[1] = cullData[globalObjectID].aabbMaxEdge;
61+
notCulled = nbl_glsl_couldBeVisible(MVP,bbox);
62+
}
63+
64+
if (notCulled)
65+
{
66+
const uint instanceID = atomicAdd(commandBuff[pc.data.currentCommandBufferIx].draws[drawID].instanceCount,1u)+cullData[globalObjectID].baseInstance;
67+
68+
instanceDataPerCamera.data[instanceID].MVP = MVP;
69+
instanceDataPerCamera.data[instanceID].detMVP = pc.data.viewProjDeterminant*staticData[globalObjectID].detWorldMatrix;
70+
instanceDataPerCamera.data[instanceID].objectID = globalObjectID;
71+
}
72+
}

0 commit comments

Comments
 (0)