Skip to content

Commit 9ca3821

Browse files
jot down some optimization ideas
1 parent c0d4777 commit 9ca3821

File tree

7 files changed

+30
-16
lines changed

7 files changed

+30
-16
lines changed

examples_tests/22.RaytracedAO/Renderer.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ Renderer::InitializationData Renderer::initSceneObjects(const SAssetBundle& mesh
264264
allocParams.MDIDataBuffMinAllocCnt = 1u; //so structs from different meshbuffers are adjacent in memory
265265

266266

267+
// TODO: after position moves to RGB21, need to split up normal from UV
267268
constexpr auto combinedNormalUVAttributeIx = 1;
268269
constexpr auto newEnabledAttributeMask = (0x1u<<combinedNormalUVAttributeIx)|0b1;
269270

@@ -277,6 +278,9 @@ Renderer::InitializationData Renderer::initSceneObjects(const SAssetBundle& mesh
277278
{
278279
core::vector<const ICPUMeshBuffer*> meshBuffersToProcess;
279280
meshBuffersToProcess.reserve(contents.size());
281+
// TODO: Optimize! Check which triangles need normals, bin into two separate meshbuffers, dont have normals for meshbuffers where all(abs(transpose(normals)*cross(pos1-pos0,pos2-pos0))~=1.f)
282+
// TODO: Optimize! Check which materials use any textures, if meshbuffer doens't use any textures, its pipeline doesn't need UV coordinates
283+
// TODO: separate pipeline for stuff without UVs and separate out the barycentric derivative FBO attachment
280284
for (const auto& asset : contents)
281285
{
282286
auto cpumesh = static_cast<asset::ICPUMesh*>(asset.get());

examples_tests/22.RaytracedAO/fillVisBuffer.frag

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// Copyright (C) 2018-2020 - DevSH Graphics Programming Sp. z O.O.
22
// This file is part of the "Nabla Engine".
33
// For conditions of distribution and use, see copyright notice in nabla.h
4-
#version 430 core
4+
#version 460 core
55
#extension GL_EXT_shader_16bit_storage : require
6+
#include <nbl/builtin/glsl/barycentric/extensions.glsl>
67

78

89
#define _NBL_GLSL_EXT_MITSUBA_LOADER_INSTANCE_DATA_BINDING_ 0
910
#include "virtualGeometry.glsl"
1011

11-
#undef NBL_GL_NV_fragment_shader_barycentric
1212
#include <nbl/builtin/glsl/barycentric/frag.glsl>
1313
layout(location = 2) flat in uint BackfacingBit_BatchInstanceGUID;
1414
layout(location = 3) flat in uint drawCmdFirstIndex;

examples_tests/22.RaytracedAO/fillVisBuffer.vert

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
// Copyright (C) 2018-2020 - DevSH Graphics Programming Sp. z O.O.
22
// This file is part of the "Nabla Engine".
33
// For conditions of distribution and use, see copyright notice in nabla.h
4-
#version 430 core
4+
#version 460 core
55
#extension GL_EXT_shader_16bit_storage : require
6+
#include <nbl/builtin/glsl/barycentric/extensions.glsl>
67

78
#include "rasterizationCommon.h"
89

@@ -14,7 +15,6 @@ layout(set=2, binding=0, row_major) readonly restrict buffer PerInstancePerCamer
1415
DrawData_t data[];
1516
} instanceDataPerCamera;
1617

17-
#undef NBL_GL_NV_fragment_shader_barycentric
1818
#include <nbl/builtin/glsl/barycentric/vert.glsl>
1919
layout(location = 2) flat out uint BackfacingBit_BatchInstanceGUID;
2020
layout(location = 3) flat out uint drawCmdFirstIndex;

examples_tests/22.RaytracedAO/raygen.comp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ void main()
4141
const uint batchInstanceGUID = bitfieldExtract(visBuffer[0],0,31-triangleIDBitcount);
4242
const vec2 compactBary = unpackUnorm2x16(visBuffer[1]);
4343
#ifdef TEX_PREFETCH_STREAM
44+
// TODO: separate pipeline and separate out the barycentric derivative FBO attachment, only write if need to, only fetch if `needs_texture_prefetch`
4445
const mat2 dBarydScreen = mat2(unpackHalf2x16(visBuffer[2]),unpackHalf2x16(visBuffer[3]));
4546
#endif
4647

examples_tests/22.RaytracedAO/raytraceCommon.glsl

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,12 @@ mat2 nbl_glsl_perturbNormal_dUVdSomething()
156156
#define _NBL_USER_PROVIDED_MATERIAL_COMPILER_GLSL_BACKEND_FUNCTIONS_
157157
#include <nbl/builtin/glsl/material_compiler/common.glsl>
158158

159+
160+
bool needs_texture_prefetch(in nbl_glsl_ext_Mitsuba_Loader_instance_data_t batchInstanceData)
161+
{
162+
return true;
163+
}
164+
159165
nbl_glsl_xoroshiro64star_state_t load_aux_vertex_attrs(
160166
in nbl_glsl_ext_Mitsuba_Loader_instance_data_t batchInstanceData,
161167
in uvec3 indices, in vec2 compactBary, in vec3 geomDenormal,
@@ -168,18 +174,21 @@ nbl_glsl_xoroshiro64star_state_t load_aux_vertex_attrs(
168174
{
169175
// if we ever support spatially varying emissive, we'll need to hoist barycentric computation and UV fetching to the position fetching
170176
#ifdef TEX_PREFETCH_STREAM
171-
const mat3x2 uvs = mat3x2(
172-
nbl_glsl_fetchVtxUV(indices[0],batchInstanceData),
173-
nbl_glsl_fetchVtxUV(indices[1],batchInstanceData),
174-
nbl_glsl_fetchVtxUV(indices[2],batchInstanceData)
175-
);
177+
if (needs_texture_prefetch(batchInstanceData))
178+
{
179+
const mat3x2 uvs = mat3x2(
180+
nbl_glsl_fetchVtxUV(indices[0],batchInstanceData),
181+
nbl_glsl_fetchVtxUV(indices[1],batchInstanceData),
182+
nbl_glsl_fetchVtxUV(indices[2],batchInstanceData)
183+
);
176184

177-
const nbl_glsl_MC_instr_stream_t tps = nbl_glsl_MC_oriented_material_t_getTexPrefetchStream(material);
185+
const nbl_glsl_MC_instr_stream_t tps = nbl_glsl_MC_oriented_material_t_getTexPrefetchStream(material);
178186

179-
dUVdBary = mat2(uvs[0]-uvs[2],uvs[1]-uvs[2]);
180-
const vec2 UV = dUVdBary*compactBary+uvs[2];
181-
const mat2 dUVdScreen = nbl_glsl_applyChainRule2D(dUVdBary,dBarydScreen);
182-
nbl_glsl_MC_runTexPrefetchStream(tps,UV,dUVdScreen);
187+
dUVdBary = mat2(uvs[0]-uvs[2],uvs[1]-uvs[2]);
188+
const vec2 UV = dUVdBary*compactBary+uvs[2];
189+
const mat2 dUVdScreen = nbl_glsl_applyChainRule2D(dUVdBary,dBarydScreen);
190+
nbl_glsl_MC_runTexPrefetchStream(tps,UV,dUVdScreen);
191+
}
183192
#endif
184193
// the rest is always only needed for continuing
185194

examples_tests/41.VisibilityBuffer/fillVBuffer.frag

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#version 430 core
1+
#version 460 core
22
#include <nbl/builtin/glsl/barycentric/extensions.glsl>
33

44
#include "common.glsl"

include/nbl/builtin/glsl/barycentric/extensions.glsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#define _NBL_BUILTIN_GLSL_BARYCENTRIC_EXTENSIONS_INCLUDED_
77

88
#ifdef NBL_GL_NV_fragment_shader_barycentric
9-
#extension GL_NV_fragment_shader_barycentric : require
9+
#extension GL_NV_fragment_shader_barycentric : enable
1010
#elif defined(NBL_GL_AMD_shader_explicit_vertex_parameter)
1111
#extension GL_AMD_shader_explicit_vertex_parameter : enable
1212
#endif

0 commit comments

Comments
 (0)