mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 18:48:36 +02:00
+ | New topbvh stats
This commit is contained in:
@ -20,8 +20,8 @@ int main(int argc, char **argv)
|
|||||||
return (1);
|
return (1);
|
||||||
|
|
||||||
Window window(&scene, WIDTH, HEIGHT, "RT_GPU", 0);
|
Window window(&scene, WIDTH, HEIGHT, "RT_GPU", 0);
|
||||||
// Shader shader("shaders/vertex.vert", "shaders/frag.frag", "shaders/compute.glsl");
|
Shader shader("shaders/vertex.vert", "shaders/frag.frag", "shaders/compute.glsl");
|
||||||
Shader shader("shaders/vertex.vert", "shaders/frag.frag", "shaders/debug.glsl");
|
// Shader shader("shaders/vertex.vert", "shaders/frag.frag", "shaders/debug.glsl");
|
||||||
|
|
||||||
GLint max_gpu_size;
|
GLint max_gpu_size;
|
||||||
glGetIntegerv(GL_MAX_SHADER_STORAGE_BLOCK_SIZE, &max_gpu_size);
|
glGetIntegerv(GL_MAX_SHADER_STORAGE_BLOCK_SIZE, &max_gpu_size);
|
||||||
|
@ -61,6 +61,14 @@ bool Scene::parseScene(char *name)
|
|||||||
TopBVH *top_bvh = new TopBVH(_gpu_bvh_data, _gpu_bvh, 0, _gpu_bvh_data.size());
|
TopBVH *top_bvh = new TopBVH(_gpu_bvh_data, _gpu_bvh, 0, _gpu_bvh_data.size());
|
||||||
_gpu_top_bvh = top_bvh->getGPUTopBvhs();
|
_gpu_top_bvh = top_bvh->getGPUTopBvhs();
|
||||||
|
|
||||||
|
std::cout << "TopBVH done" << std::endl;
|
||||||
|
std::cout << "\tTopBVH size: " << top_bvh->getSize() << std::endl;
|
||||||
|
std::cout << "\tTopBVH leaves: " << top_bvh->getLeaves() << std::endl << std::endl;
|
||||||
|
|
||||||
|
TopBVHStats stats = top_bvh->analyzeBVHLeaves();
|
||||||
|
std::cout << "\tMin bvh per leaf: " << stats.min_bvh << std::endl;
|
||||||
|
std::cout << "\tMax bvh per leaf: " << stats.max_bvh << std::endl;
|
||||||
|
std::cout << "\tAverage bvh per leaf: " << stats.average_bvh << std::endl << std::endl;
|
||||||
|
|
||||||
std::cout << "Parsing done" << std::endl;
|
std::cout << "Parsing done" << std::endl;
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ Shader::Shader(std::string vertexPath, std::string fragmentPath, std::string com
|
|||||||
const char *fragmentCode = loadFileWithIncludes(fragmentPath);
|
const char *fragmentCode = loadFileWithIncludes(fragmentPath);
|
||||||
const char *computeCode = loadFileWithIncludes(computePath);
|
const char *computeCode = loadFileWithIncludes(computePath);
|
||||||
|
|
||||||
printWithLineNumbers(computeCode);
|
// printWithLineNumbers(computeCode);
|
||||||
|
|
||||||
_vertex = glCreateShader(GL_VERTEX_SHADER);
|
_vertex = glCreateShader(GL_VERTEX_SHADER);
|
||||||
|
|
||||||
|
@ -163,19 +163,6 @@ void TopBVH::subdivide(std::vector<GPUBvhData> &bvhs_data, std::vector<GPUBvh> &
|
|||||||
_bvh_count = 0;
|
_bvh_count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int TopBVH::getSize()
|
|
||||||
{
|
|
||||||
int count = 0;
|
|
||||||
|
|
||||||
if (_is_leaf)
|
|
||||||
return (0);
|
|
||||||
|
|
||||||
count += 1 + _left->getSize();
|
|
||||||
count += 1 + _right->getSize();
|
|
||||||
|
|
||||||
return (count);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TopBVH::flatten(std::vector<GPUTopBvh> &top_bvhs, int ¤tIndex)
|
void TopBVH::flatten(std::vector<GPUTopBvh> &top_bvhs, int ¤tIndex)
|
||||||
{
|
{
|
||||||
GPUTopBvh self_top_bvh;
|
GPUTopBvh self_top_bvh;
|
||||||
@ -212,3 +199,59 @@ std::vector<GPUTopBvh> TopBVH::getGPUTopBvhs()
|
|||||||
|
|
||||||
return (bvhs);
|
return (bvhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int TopBVH::getSize()
|
||||||
|
{
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
if (_is_leaf)
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
count += 1 + _left->getSize();
|
||||||
|
count += 1 + _right->getSize();
|
||||||
|
|
||||||
|
return (count);
|
||||||
|
}
|
||||||
|
|
||||||
|
int TopBVH::getLeaves()
|
||||||
|
{
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
if (_is_leaf)
|
||||||
|
return (1);
|
||||||
|
|
||||||
|
count += _left->getLeaves();
|
||||||
|
count += _right->getLeaves();
|
||||||
|
|
||||||
|
return (count);
|
||||||
|
}
|
||||||
|
|
||||||
|
TopBVHStats TopBVH::analyzeBVHLeaves()
|
||||||
|
{
|
||||||
|
if (_is_leaf)
|
||||||
|
return {
|
||||||
|
_bvh_count, // min
|
||||||
|
_bvh_count, // max
|
||||||
|
(float)_bvh_count // average
|
||||||
|
};
|
||||||
|
|
||||||
|
// Get stats from left and right subtrees
|
||||||
|
TopBVHStats left = _left->analyzeBVHLeaves();
|
||||||
|
TopBVHStats right = _left->analyzeBVHLeaves();
|
||||||
|
|
||||||
|
// Combine the results
|
||||||
|
int min_count = std::min(left.min_bvh, right.min_bvh);
|
||||||
|
int max_count = std::max(left.max_bvh, right.max_bvh);
|
||||||
|
|
||||||
|
// Calculate weighted average based on number of leaves in each subtree
|
||||||
|
float left_leaf_count = (left.average_bvh > 0) ? 1.0f : 0.0f;
|
||||||
|
float right_leaf_count = (right.average_bvh > 0) ? 1.0f : 0.0f;
|
||||||
|
float total_leaf_count = left_leaf_count + right_leaf_count;
|
||||||
|
|
||||||
|
float avg_count = 0.0f;
|
||||||
|
if (total_leaf_count > 0)
|
||||||
|
avg_count = (left.average_bvh * left_leaf_count +
|
||||||
|
right.average_bvh * right_leaf_count) / total_leaf_count;
|
||||||
|
|
||||||
|
return {min_count, max_count, avg_count};
|
||||||
|
}
|
Reference in New Issue
Block a user