mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 18:48:36 +02:00
server now sends jobs to client and client can send result image to server
This commit is contained in:
@ -6,7 +6,7 @@
|
|||||||
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/09/27 14:52:10 by TheRed #+# #+# */
|
/* Created: 2024/09/27 14:52:10 by TheRed #+# #+# */
|
||||||
/* Updated: 2025/02/23 23:39:46 by tomoron ### ########.fr */
|
/* Updated: 2025/02/25 01:44:28 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -56,6 +56,16 @@ struct Vertex {
|
|||||||
glm::vec2 texCoord;
|
glm::vec2 texCoord;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct GPUDenoise
|
||||||
|
{
|
||||||
|
int enabled;
|
||||||
|
int pass;
|
||||||
|
float c_phi;
|
||||||
|
float p_phi;
|
||||||
|
float n_phi;
|
||||||
|
}; // il est chiant lui
|
||||||
|
|
||||||
# include "Object.hpp"
|
# include "Object.hpp"
|
||||||
# include "objects/Sphere.hpp"
|
# include "objects/Sphere.hpp"
|
||||||
# include "objects/Plane.hpp"
|
# include "objects/Plane.hpp"
|
||||||
|
@ -6,15 +6,15 @@
|
|||||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/02/20 18:25:18 by tomoron #+# #+# */
|
/* Created: 2025/02/20 18:25:18 by tomoron #+# #+# */
|
||||||
/* Updated: 2025/02/23 22:41:25 by tomoron ### ########.fr */
|
/* Updated: 2025/02/25 01:49:07 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef CLUSTERIZER_HPP
|
#pragma once
|
||||||
# define CLUSTERIZER_HPP
|
|
||||||
|
|
||||||
# include "RT.hpp"
|
# include "RT.hpp"
|
||||||
|
|
||||||
|
|
||||||
typedef enum e_job_status
|
typedef enum e_job_status
|
||||||
{
|
{
|
||||||
WAITING,
|
WAITING,
|
||||||
@ -24,19 +24,19 @@ typedef enum e_job_status
|
|||||||
|
|
||||||
typedef struct s_job
|
typedef struct s_job
|
||||||
{
|
{
|
||||||
std::string scene;
|
|
||||||
glm::vec3 pos;
|
glm::vec3 pos;
|
||||||
glm::vec2 dir;
|
glm::vec2 dir;
|
||||||
size_t samples;
|
size_t samples;
|
||||||
|
GPUDenoise denoise;
|
||||||
|
|
||||||
size_t id;
|
size_t frameNb;
|
||||||
} t_job;
|
} t_job;
|
||||||
|
|
||||||
typedef struct s_client
|
typedef struct s_client
|
||||||
{
|
{
|
||||||
std::vector<uint8_t> buffer;
|
std::vector<uint8_t> buffer;
|
||||||
t_job *curJob;
|
t_job *curJob;
|
||||||
int progress;
|
uint8_t progress;
|
||||||
bool ready;
|
bool ready;
|
||||||
} t_client;
|
} t_client;
|
||||||
|
|
||||||
@ -44,33 +44,31 @@ typedef enum e_msg
|
|||||||
{
|
{
|
||||||
RDY,
|
RDY,
|
||||||
JOB,
|
JOB,
|
||||||
JOB_RES_RQ,
|
PROGRESS_UPDATE,
|
||||||
ACK,
|
IMG_SEND_RQ,
|
||||||
WAIT,
|
IMG
|
||||||
IMAGE,
|
|
||||||
ERR,
|
|
||||||
UNKNOWN
|
|
||||||
} t_msg;
|
} t_msg;
|
||||||
|
|
||||||
class Clusterizer
|
class Clusterizer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Clusterizer(Arguments &args);
|
Clusterizer(Arguments &args, Renderer *renderer);
|
||||||
~Clusterizer();
|
~Clusterizer();
|
||||||
|
|
||||||
void update(void);
|
void update(Scene &scene, Window &win, std::vector<GLuint> &textures, ShaderProgram &denoisingProgram);
|
||||||
bool getError(void);
|
bool getError(void);
|
||||||
void imguiRender(void);
|
void imguiRender(void);
|
||||||
bool isServer(void);
|
bool isServer(void);
|
||||||
bool hasJobs(void);
|
bool hasJobs(void);
|
||||||
|
|
||||||
void addJob(glm::vec3 pos, glm::vec2 dir, size_t samples);
|
void addJob(glm::vec3 pos, glm::vec2 dir, size_t samples, size_t frames, GPUDenoise &denoise);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool _isActive;
|
bool _isActive;
|
||||||
bool _isServer;
|
bool _isServer;
|
||||||
bool _error;
|
bool _error;
|
||||||
std::string _sceneName;
|
std::string _sceneName;
|
||||||
|
Renderer *_renderer;
|
||||||
|
|
||||||
std::vector<t_job *> _jobs[3];
|
std::vector<t_job *> _jobs[3];
|
||||||
|
|
||||||
@ -78,18 +76,23 @@ class Clusterizer
|
|||||||
void imguiClients(void);
|
void imguiClients(void);
|
||||||
|
|
||||||
private: //client
|
private: //client
|
||||||
void initClient(std::string &dest);
|
void initClient(std::string &dest);
|
||||||
void openClientConnection(const char *ip, int port);
|
void openClientConnection(const char *ip, int port);
|
||||||
void clientHandleBuffer(void);
|
void clientHandleBuffer(void);
|
||||||
void updateClient(void);
|
void updateClient(Scene &scene, Window &win, std::vector<GLuint> &textures, ShaderProgram &denoisingProgram);
|
||||||
void clientGetJob(void);
|
void clientGetJob(void);
|
||||||
void clientReceive(void);
|
void clientReceive(void);
|
||||||
|
void handleCurrentJob(Scene &scene, Window &win, std::vector<GLuint> &textures, ShaderProgram &denoisingProgram);
|
||||||
|
void sendProgress(uint8_t progress);
|
||||||
|
void sendImageToServer(std::vector<GLuint> &textures, ShaderProgram &denoisingProgram);
|
||||||
|
|
||||||
int _serverFd;
|
int _serverFd;
|
||||||
std::string _serverIp;
|
std::string _serverIp;
|
||||||
int _serverPort;
|
int _serverPort;
|
||||||
std::vector<uint8_t> _receiveBuffer;
|
std::vector<uint8_t> _receiveBuffer;
|
||||||
t_job _currentJob;
|
t_job *_currentJob;
|
||||||
|
uint8_t _progress;
|
||||||
|
bool _srvReady;
|
||||||
|
|
||||||
private: //server
|
private: //server
|
||||||
void initServer(std::string port);
|
void initServer(std::string port);
|
||||||
@ -104,13 +107,8 @@ class Clusterizer
|
|||||||
|
|
||||||
int dispatchJobs(void);
|
int dispatchJobs(void);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int _serverSocket;
|
int _serverSocket;
|
||||||
struct pollfd *_pollfds;
|
struct pollfd *_pollfds;
|
||||||
std::map<int, t_client> _clients;
|
std::map<int, t_client> _clients;
|
||||||
size_t _curId;
|
size_t _curId;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/01/22 16:29:26 by tomoron #+# #+# */
|
/* Created: 2025/01/22 16:29:26 by tomoron #+# #+# */
|
||||||
/* Updated: 2025/02/24 00:32:38 by tomoron ### ########.fr */
|
/* Updated: 2025/02/24 17:21:08 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ class Renderer
|
|||||||
t_pathPoint createNextPoint(t_pathPoint from, t_pathPoint to);
|
t_pathPoint createNextPoint(t_pathPoint from, t_pathPoint to);
|
||||||
void getInterpolationPoints(t_pathPoint &prev, t_pathPoint &from, t_pathPoint &to, t_pathPoint &next);
|
void getInterpolationPoints(t_pathPoint &prev, t_pathPoint &from, t_pathPoint &to, t_pathPoint &next);
|
||||||
|
|
||||||
void initRender();
|
void initRender(Clusterizer *clust);
|
||||||
void createClusterJobs(Clusterizer &clust);
|
void createClusterJobs(Clusterizer &clust);
|
||||||
void fillGoodCodecList(std::vector<AVCodecID> &lst);
|
void fillGoodCodecList(std::vector<AVCodecID> &lst);
|
||||||
void addImageToRender(std::vector<GLuint> &textures, ShaderProgram &denoisingProgram);
|
void addImageToRender(std::vector<GLuint> &textures, ShaderProgram &denoisingProgram);
|
||||||
|
@ -6,12 +6,11 @@
|
|||||||
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/12/23 18:30:18 by ycontre #+# #+# */
|
/* Created: 2024/12/23 18:30:18 by ycontre #+# #+# */
|
||||||
/* Updated: 2025/02/04 03:11:36 by tomoron ### ########.fr */
|
/* Updated: 2025/02/25 01:44:31 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef RT_SCENE__HPP
|
#pragma once
|
||||||
# define RT_SCENE__HPP
|
|
||||||
|
|
||||||
# include "RT.hpp"
|
# include "RT.hpp"
|
||||||
|
|
||||||
@ -78,15 +77,6 @@ struct GPUDebug
|
|||||||
int box_treshold;
|
int box_treshold;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct GPUDenoise
|
|
||||||
{
|
|
||||||
int enabled;
|
|
||||||
int pass;
|
|
||||||
float c_phi;
|
|
||||||
float p_phi;
|
|
||||||
float n_phi;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct GPUBvh
|
struct GPUBvh
|
||||||
{
|
{
|
||||||
alignas(16) glm::vec3 min;
|
alignas(16) glm::vec3 min;
|
||||||
@ -176,5 +166,3 @@ class Scene
|
|||||||
|
|
||||||
Camera *_camera;
|
Camera *_camera;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/10/13 16:15:41 by TheRed #+# #+# */
|
/* Created: 2024/10/13 16:15:41 by TheRed #+# #+# */
|
||||||
/* Updated: 2025/02/22 22:11:34 by tomoron ### ########.fr */
|
/* Updated: 2025/02/25 01:50:04 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ class Window
|
|||||||
static void mouseButtonCallback(GLFWwindow *window, int button, int action, int mods);
|
static void mouseButtonCallback(GLFWwindow *window, int button, int action, int mods);
|
||||||
|
|
||||||
void imGuiNewFrame();
|
void imGuiNewFrame();
|
||||||
void imGuiRender(ShaderProgram &raytracing_program, Clusterizer &clusterizer);
|
void imGuiRender(ShaderProgram &raytracing_program);
|
||||||
|
|
||||||
GLFWwindow *getWindow(void) const;
|
GLFWwindow *getWindow(void) const;
|
||||||
float getFps(void) const;
|
float getFps(void) const;
|
||||||
@ -51,10 +51,12 @@ class Window
|
|||||||
bool isRendering();
|
bool isRendering();
|
||||||
|
|
||||||
void rendererUpdate(std::vector<GLuint> &textures, ShaderProgram &denoisingProgram);
|
void rendererUpdate(std::vector<GLuint> &textures, ShaderProgram &denoisingProgram);
|
||||||
|
void clusterizerUpdate(std::vector<GLuint> &textures, ShaderProgram &denoisingProgram);
|
||||||
private:
|
private:
|
||||||
GLFWwindow *_window;
|
GLFWwindow *_window;
|
||||||
Scene *_scene;
|
Scene *_scene;
|
||||||
Renderer *_renderer;
|
Renderer *_renderer;
|
||||||
|
Clusterizer *_clusterizer;
|
||||||
|
|
||||||
float _fps;
|
float _fps;
|
||||||
float _delta;
|
float _delta;
|
||||||
|
10
srcs/RT.cpp
10
srcs/RT.cpp
@ -6,7 +6,7 @@
|
|||||||
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/09/27 14:51:49 by TheRed #+# #+# */
|
/* Created: 2024/09/27 14:51:49 by TheRed #+# #+# */
|
||||||
/* Updated: 2025/02/22 22:09:46 by tomoron ### ########.fr */
|
/* Updated: 2025/02/25 01:51:27 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -28,10 +28,6 @@ int main(int argc, char **argv)
|
|||||||
if (args.error())
|
if (args.error())
|
||||||
return (1);
|
return (1);
|
||||||
|
|
||||||
Clusterizer clusterizer(args);
|
|
||||||
if (clusterizer.getError())
|
|
||||||
return(1);
|
|
||||||
|
|
||||||
Scene scene(args.getSceneName());
|
Scene scene(args.getSceneName());
|
||||||
if (scene.fail())
|
if (scene.fail())
|
||||||
return (1);
|
return (1);
|
||||||
@ -71,7 +67,7 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
while (!window.shouldClose())
|
while (!window.shouldClose())
|
||||||
{
|
{
|
||||||
clusterizer.update();
|
window.clusterizerUpdate(textures, denoising_program);
|
||||||
window.updateDeltaTime();
|
window.updateDeltaTime();
|
||||||
|
|
||||||
updateDataOnGPU(scene, buffers);
|
updateDataOnGPU(scene, buffers);
|
||||||
@ -103,7 +99,7 @@ int main(int argc, char **argv)
|
|||||||
render_program.use();
|
render_program.use();
|
||||||
drawScreenTriangle(VAO, textures[0], render_program.getProgram());
|
drawScreenTriangle(VAO, textures[0], render_program.getProgram());
|
||||||
|
|
||||||
window.imGuiRender(raytracing_program, clusterizer);
|
window.imGuiRender(raytracing_program);
|
||||||
|
|
||||||
window.display();
|
window.display();
|
||||||
window.pollEvents();
|
window.pollEvents();
|
||||||
|
@ -6,19 +6,29 @@
|
|||||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/02/20 18:24:39 by tomoron #+# #+# */
|
/* Created: 2025/02/20 18:24:39 by tomoron #+# #+# */
|
||||||
/* Updated: 2025/02/23 22:41:07 by tomoron ### ########.fr */
|
/* Updated: 2025/02/25 01:49:23 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "RT.hpp"
|
#include "RT.hpp"
|
||||||
|
|
||||||
Clusterizer::Clusterizer(Arguments &args)
|
//TODO before push :
|
||||||
|
// - client work on image when gets job
|
||||||
|
// - handle client disconnect
|
||||||
|
// - show image number in imgui
|
||||||
|
// - client send progress update when percent change
|
||||||
|
// - server action to send map name
|
||||||
|
// - when image is done, send a image send request and wait for server response
|
||||||
|
// - when server accepts send request, send full image
|
||||||
|
|
||||||
|
Clusterizer::Clusterizer(Arguments &args, Renderer *renderer)
|
||||||
{
|
{
|
||||||
_isActive = 1;
|
_isActive = 1;
|
||||||
_isServer = 0;
|
_isServer = 0;
|
||||||
_error = 0;
|
_error = 0;
|
||||||
_serverSocket = 0;
|
_serverSocket = 0;
|
||||||
_sceneName = args.getSceneName();
|
_sceneName = args.getSceneName();
|
||||||
|
_renderer = renderer;
|
||||||
|
|
||||||
if(args.getBoolean("server"))
|
if(args.getBoolean("server"))
|
||||||
{
|
{
|
||||||
@ -40,14 +50,14 @@ Clusterizer::~Clusterizer(void)
|
|||||||
close(_serverSocket);
|
close(_serverSocket);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Clusterizer::update(void)
|
void Clusterizer::update(Scene &scene, Window &win, std::vector<GLuint> &textures, ShaderProgram &denoisingProgram)
|
||||||
{
|
{
|
||||||
if(!_isActive)
|
if(!_isActive)
|
||||||
return ;
|
return ;
|
||||||
if(_isServer)
|
if(_isServer)
|
||||||
updateServer();
|
updateServer();
|
||||||
else
|
else
|
||||||
updateClient();
|
updateClient(scene, win, textures, denoisingProgram);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Clusterizer::getError(void)
|
bool Clusterizer::getError(void)
|
||||||
|
@ -6,12 +6,14 @@
|
|||||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/02/20 21:08:38 by tomoron #+# #+# */
|
/* Created: 2025/02/20 21:08:38 by tomoron #+# #+# */
|
||||||
/* Updated: 2025/02/22 22:50:10 by tomoron ### ########.fr */
|
/* Updated: 2025/02/25 01:48:47 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "RT.hpp"
|
#include "RT.hpp"
|
||||||
|
|
||||||
|
void shaderDenoise(ShaderProgram &denoising_program, GPUDenoise &denoise, std::vector<GLuint> textures);
|
||||||
|
|
||||||
void Clusterizer::initClient(std::string &dest)
|
void Clusterizer::initClient(std::string &dest)
|
||||||
{
|
{
|
||||||
_serverFd = 0;
|
_serverFd = 0;
|
||||||
@ -62,19 +64,36 @@ void Clusterizer::openClientConnection(const char *ip, int port)
|
|||||||
|
|
||||||
void Clusterizer::clientGetJob(void)
|
void Clusterizer::clientGetJob(void)
|
||||||
{
|
{
|
||||||
|
uint8_t *data;
|
||||||
|
std::cout << "received job" << std::endl;
|
||||||
if(_receiveBuffer.size() < sizeof(t_job) + 1)
|
if(_receiveBuffer.size() < sizeof(t_job) + 1)
|
||||||
return ;
|
return ;
|
||||||
|
|
||||||
_currentJob = *(t_job *)(_receiveBuffer.data() + 1);
|
data = _receiveBuffer.data();
|
||||||
|
_currentJob = new t_job;
|
||||||
|
*_currentJob = *(t_job *)(data + 1);
|
||||||
|
std::cout << "delete length : " << std::distance(_receiveBuffer.begin(), _receiveBuffer.begin() + sizeof(t_job) + 1) << std::endl;
|
||||||
_receiveBuffer.erase(_receiveBuffer.begin(), _receiveBuffer.begin() + sizeof(t_job) + 1);
|
_receiveBuffer.erase(_receiveBuffer.begin(), _receiveBuffer.begin() + sizeof(t_job) + 1);
|
||||||
|
std::cout << "new size : " << _receiveBuffer.size() << std::endl;
|
||||||
|
_progress = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Clusterizer::clientHandleBuffer(void)
|
void Clusterizer::clientHandleBuffer(void)
|
||||||
{
|
{
|
||||||
std::vector<uint8_t> sendBuf;
|
std::vector<uint8_t> sendBuf;
|
||||||
|
|
||||||
|
if(!_receiveBuffer.size())
|
||||||
|
return ;
|
||||||
|
std::cout << (int)_receiveBuffer.size() << std::endl;
|
||||||
|
std::cout << sizeof(t_job) + 1 << std::endl;
|
||||||
|
std::cout << std::endl;
|
||||||
if(_receiveBuffer[0] == JOB)
|
if(_receiveBuffer[0] == JOB)
|
||||||
clientGetJob();
|
clientGetJob();
|
||||||
|
else if(_receiveBuffer[0] == RDY)
|
||||||
|
_srvReady = 1;
|
||||||
|
else
|
||||||
|
_receiveBuffer.erase(_receiveBuffer.begin());
|
||||||
|
|
||||||
|
|
||||||
if(sendBuf.size())
|
if(sendBuf.size())
|
||||||
(void)write(1, sendBuf.data(), sendBuf.size());
|
(void)write(1, sendBuf.data(), sendBuf.size());
|
||||||
@ -95,9 +114,69 @@ void Clusterizer::clientReceive(void)
|
|||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
_receiveBuffer.insert(_receiveBuffer.end(), buffer, buffer + ret);
|
_receiveBuffer.insert(_receiveBuffer.end(), buffer, buffer + ret);
|
||||||
|
clientHandleBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Clusterizer::updateClient(void)
|
void Clusterizer::sendProgress(uint8_t progress)
|
||||||
|
{
|
||||||
|
uint8_t buf[2];
|
||||||
|
_progress = progress;
|
||||||
|
|
||||||
|
buf[0] = PROGRESS_UPDATE;
|
||||||
|
buf[1] = progress;
|
||||||
|
(void)write(_serverFd, buf, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Clusterizer::sendImageToServer(std::vector<GLuint> &textures, ShaderProgram &denoisingProgram)
|
||||||
|
{
|
||||||
|
_srvReady = 0;
|
||||||
|
std::vector<uint8_t> buffer(WIDTH * HEIGHT * 4);
|
||||||
|
|
||||||
|
(void)write(_serverFd, (uint8_t []){IMG_SEND_RQ}, 1);
|
||||||
|
while(!_srvReady)
|
||||||
|
{
|
||||||
|
clientReceive();
|
||||||
|
usleep(10000);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(_currentJob->denoise.enabled)
|
||||||
|
shaderDenoise(denoisingProgram, _currentJob->denoise, textures);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, textures[0]);
|
||||||
|
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_FLOAT, buffer.data());
|
||||||
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
|
||||||
|
(void)write(_serverFd, (uint8_t []){IMG}, 1);
|
||||||
|
(void)write(_serverFd, buffer.data(), buffer.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
void Clusterizer::handleCurrentJob(Scene &scene, Window &win, std::vector<GLuint> &textures, ShaderProgram &denoisingProgram)
|
||||||
|
{
|
||||||
|
uint8_t progress;
|
||||||
|
if(!_currentJob)
|
||||||
|
return ;
|
||||||
|
|
||||||
|
if(scene.getCamera()->getPosition() != _currentJob->pos || scene.getCamera()->getDirection() != _currentJob->dir)
|
||||||
|
{
|
||||||
|
scene.getCamera()->setPosition(_currentJob->pos);
|
||||||
|
scene.getCamera()->setDirection(_currentJob->dir.x, _currentJob->dir.y);
|
||||||
|
win.setFrameCount(0);
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
|
if((size_t)win.getFrameCount() < _currentJob->samples)
|
||||||
|
{
|
||||||
|
progress = ((double)win.getFrameCount() / _currentJob->samples) * 100;
|
||||||
|
if(progress != _progress)
|
||||||
|
sendProgress(progress);
|
||||||
|
}
|
||||||
|
|
||||||
|
if((size_t)win.getFrameCount() == _currentJob->samples)
|
||||||
|
{
|
||||||
|
sendImageToServer(textures, denoisingProgram);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Clusterizer::updateClient(Scene &scene, Window &win, std::vector<GLuint> &textures, ShaderProgram &denoisingProgram)
|
||||||
{
|
{
|
||||||
if(!_serverFd)
|
if(!_serverFd)
|
||||||
{
|
{
|
||||||
@ -108,6 +187,5 @@ void Clusterizer::updateClient(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
clientReceive();
|
clientReceive();
|
||||||
if(_receiveBuffer.size())
|
handleCurrentJob(scene, win, textures, denoisingProgram);
|
||||||
clientHandleBuffer();
|
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/02/22 19:52:51 by tomoron #+# #+# */
|
/* Created: 2025/02/22 19:52:51 by tomoron #+# #+# */
|
||||||
/* Updated: 2025/02/22 23:39:46 by tomoron ### ########.fr */
|
/* Updated: 2025/02/24 20:52:33 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -28,12 +28,12 @@ void Clusterizer::imguiClients(void)
|
|||||||
ImGui::BeginChild("clientList", ImVec2(0, 0), true, 0);
|
ImGui::BeginChild("clientList", ImVec2(0, 0), true, 0);
|
||||||
for(auto it = _clients.begin();it != _clients.end(); it++)
|
for(auto it = _clients.begin();it != _clients.end(); it++)
|
||||||
{
|
{
|
||||||
if(!it->second.ready)
|
if(it->second.ready)
|
||||||
status = "not ready";
|
status = "idle";
|
||||||
else if(it->second.ready && it->second.curJob)
|
else if(!it->second.ready && it->second.curJob)
|
||||||
status = "working";
|
status = "working";
|
||||||
else if(it->second.ready)
|
else if(it->second.ready)
|
||||||
status = "idle";
|
status = "not ready";
|
||||||
|
|
||||||
ImGui::Text("status : %s", status.c_str());
|
ImGui::Text("status : %s", status.c_str());
|
||||||
if(it->second.curJob)
|
if(it->second.curJob)
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/02/20 21:08:38 by tomoron #+# #+# */
|
/* Created: 2025/02/20 21:08:38 by tomoron #+# #+# */
|
||||||
/* Updated: 2025/02/23 22:15:38 by tomoron ### ########.fr */
|
/* Updated: 2025/02/25 00:53:02 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -98,7 +98,6 @@ void Clusterizer::handleBuffer(int fd, std::vector<uint8_t> &buf)
|
|||||||
{
|
{
|
||||||
_clients[fd].ready = 1;
|
_clients[fd].ready = 1;
|
||||||
std::cout << "client " << fd << " is ready !" << std::endl;
|
std::cout << "client " << fd << " is ready !" << std::endl;
|
||||||
sendBuffer.push_back(ACK);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(sendBuffer.size())
|
if(sendBuffer.size())
|
||||||
@ -120,7 +119,8 @@ int Clusterizer::updateBuffer(int fd)
|
|||||||
|
|
||||||
int Clusterizer::dispatchJobs(void)
|
int Clusterizer::dispatchJobs(void)
|
||||||
{
|
{
|
||||||
t_job *tmp;
|
t_job *tmp;
|
||||||
|
uint8_t sendBuf;
|
||||||
int dispatched;
|
int dispatched;
|
||||||
|
|
||||||
dispatched = 0;
|
dispatched = 0;
|
||||||
@ -134,26 +134,30 @@ int Clusterizer::dispatchJobs(void)
|
|||||||
tmp = _jobs[WAITING].front();
|
tmp = _jobs[WAITING].front();
|
||||||
_jobs[WAITING].erase(_jobs[WAITING].begin());
|
_jobs[WAITING].erase(_jobs[WAITING].begin());
|
||||||
_jobs[IN_PROGRESS].push_back(tmp);
|
_jobs[IN_PROGRESS].push_back(tmp);
|
||||||
|
sendBuf = JOB;
|
||||||
|
(void)write(it->first, &sendBuf, 1);
|
||||||
(void)write(it->first, &tmp, sizeof(t_job));
|
(void)write(it->first, &tmp, sizeof(t_job));
|
||||||
it->second.ready = 0;
|
it->second.ready = 0;
|
||||||
it->second.progress = 0;
|
it->second.progress = 0;
|
||||||
it->second.curJob = tmp;
|
it->second.curJob = tmp;
|
||||||
dispatched = 1;
|
dispatched = 1;
|
||||||
}
|
}
|
||||||
|
if(!_jobs[WAITING].size())
|
||||||
|
return (1);
|
||||||
}
|
}
|
||||||
return (dispatched);
|
return (dispatched);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Clusterizer::addJob(glm::vec3 pos, glm::vec2 dir, size_t samples)
|
void Clusterizer::addJob(glm::vec3 pos, glm::vec2 dir, size_t samples, size_t frame, GPUDenoise &denoise)
|
||||||
{
|
{
|
||||||
t_job *tmp;
|
t_job *tmp;
|
||||||
|
|
||||||
tmp = new t_job;
|
tmp = new t_job;
|
||||||
tmp->scene = _sceneName;
|
|
||||||
tmp->pos = pos;
|
tmp->pos = pos;
|
||||||
tmp->dir = dir;
|
tmp->dir = dir;
|
||||||
tmp->samples = samples;
|
tmp->samples = samples;
|
||||||
tmp->id = _curId++;
|
tmp->frameNb = frame;
|
||||||
|
tmp->denoise = denoise;
|
||||||
_jobs[WAITING].push_back(tmp);
|
_jobs[WAITING].push_back(tmp);
|
||||||
|
|
||||||
std::cout << "new job added : " << std::endl;
|
std::cout << "new job added : " << std::endl;
|
||||||
@ -171,6 +175,8 @@ void Clusterizer::updateServer(void)
|
|||||||
while(didSomething)
|
while(didSomething)
|
||||||
{
|
{
|
||||||
didSomething = acceptClients();
|
didSomething = acceptClients();
|
||||||
|
if(dispatchJobs())
|
||||||
|
didSomething = 1;
|
||||||
recv = poll(_pollfds, _clients.size(), 1);
|
recv = poll(_pollfds, _clients.size(), 1);
|
||||||
if(!recv)
|
if(!recv)
|
||||||
return ;
|
return ;
|
||||||
@ -186,7 +192,5 @@ void Clusterizer::updateServer(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(dispatchJobs())
|
|
||||||
didSomething = 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/01/22 16:34:53 by tomoron #+# #+# */
|
/* Created: 2025/01/22 16:34:53 by tomoron #+# #+# */
|
||||||
/* Updated: 2025/02/24 00:49:53 by tomoron ### ########.fr */
|
/* Updated: 2025/02/25 00:52:27 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ Renderer::Renderer(Scene *scene, Window *win, Arguments &args)
|
|||||||
|
|
||||||
try{
|
try{
|
||||||
if(_headless)
|
if(_headless)
|
||||||
initRender();
|
initRender(0);
|
||||||
}
|
}
|
||||||
catch(std::exception &e)
|
catch(std::exception &e)
|
||||||
{
|
{
|
||||||
@ -136,7 +136,7 @@ void Renderer::addTeleport(glm::vec3 from_pos, glm::vec2 from_dir, glm::vec3 to
|
|||||||
|
|
||||||
void Renderer::createClusterJobs(Clusterizer &clust)
|
void Renderer::createClusterJobs(Clusterizer &clust)
|
||||||
{
|
{
|
||||||
float delta;
|
double delta;
|
||||||
size_t frames;
|
size_t frames;
|
||||||
glm::vec3 pos;
|
glm::vec3 pos;
|
||||||
glm::vec2 dir;
|
glm::vec2 dir;
|
||||||
@ -147,15 +147,15 @@ void Renderer::createClusterJobs(Clusterizer &clust)
|
|||||||
while(_destPathIndex)
|
while(_destPathIndex)
|
||||||
{
|
{
|
||||||
interpolateMovement(delta * frames, &pos, &dir);
|
interpolateMovement(delta * frames, &pos, &dir);
|
||||||
clust.addJob(pos, dir, _samples);
|
frames++;
|
||||||
|
clust.addJob(pos, dir, _samples, frames, _scene->getDenoise());
|
||||||
if(_curPathIndex == _destPathIndex)
|
if(_curPathIndex == _destPathIndex)
|
||||||
_destPathIndex = 0;
|
_destPathIndex = 0;
|
||||||
(void)clust;
|
(void)clust;
|
||||||
frames++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::initRender(void)
|
void Renderer::initRender(Clusterizer *clust)
|
||||||
{
|
{
|
||||||
if(_path.size() < 2)
|
if(_path.size() < 2)
|
||||||
throw std::runtime_error("render path doesn't have enough path points");
|
throw std::runtime_error("render path doesn't have enough path points");
|
||||||
@ -167,10 +167,9 @@ void Renderer::initRender(void)
|
|||||||
_curPathIndex = 0;
|
_curPathIndex = 0;
|
||||||
_destPathIndex = _path.size() - 1;
|
_destPathIndex = _path.size() - 1;
|
||||||
_renderStartTime = glfwGetTime();
|
_renderStartTime = glfwGetTime();
|
||||||
// if(clust && clust->isServer())
|
if(clust && clust->isServer())
|
||||||
// createClusterJobs(*clust);
|
createClusterJobs(*clust);
|
||||||
// else
|
else
|
||||||
if(1)
|
|
||||||
{
|
{
|
||||||
_frameCount = 0;
|
_frameCount = 0;
|
||||||
_curSamples = 0;
|
_curSamples = 0;
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/02/20 15:54:35 by tomoron #+# #+# */
|
/* Created: 2025/02/20 15:54:35 by tomoron #+# #+# */
|
||||||
/* Updated: 2025/02/24 00:34:48 by tomoron ### ########.fr */
|
/* Updated: 2025/02/24 17:42:35 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -171,7 +171,7 @@ void Renderer::imguiRenderSettings(Clusterizer &clust)
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
if(ImGui::Button("start render"))
|
if(ImGui::Button("start render"))
|
||||||
initRender();
|
initRender(&clust);
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
if(ImGui::Button("save path"))
|
if(ImGui::Button("save path"))
|
||||||
savePath();
|
savePath();
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/10/13 16:16:24 by TheRed #+# #+# */
|
/* Created: 2024/10/13 16:16:24 by TheRed #+# #+# */
|
||||||
/* Updated: 2025/02/23 19:05:24 by tomoron ### ########.fr */
|
/* Updated: 2025/02/25 01:51:46 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -24,6 +24,7 @@ Window::Window(Scene *scene, int width, int height, const char *title, int sleep
|
|||||||
_frameCount = 0;
|
_frameCount = 0;
|
||||||
_pixelisation = 0;
|
_pixelisation = 0;
|
||||||
_renderer = new Renderer(scene, this, args);
|
_renderer = new Renderer(scene, this, args);
|
||||||
|
_clusterizer = new Clusterizer(args, _renderer);
|
||||||
glfwSetErrorCallback(GLFWErrorCallback);
|
glfwSetErrorCallback(GLFWErrorCallback);
|
||||||
if (!glfwInit())
|
if (!glfwInit())
|
||||||
{
|
{
|
||||||
@ -184,6 +185,11 @@ void Window::rendererUpdate(std::vector<GLuint> &textures, ShaderProgram &denoi
|
|||||||
_renderer->update(textures, denoisingProgram);
|
_renderer->update(textures, denoisingProgram);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Window::clusterizerUpdate(std::vector<GLuint> &textures, ShaderProgram &denoisingProgram)
|
||||||
|
{
|
||||||
|
_clusterizer->update(*_scene, *this, textures, denoisingProgram);
|
||||||
|
}
|
||||||
|
|
||||||
void Window::imGuiNewFrame()
|
void Window::imGuiNewFrame()
|
||||||
{
|
{
|
||||||
ImGui_ImplOpenGL3_NewFrame();
|
ImGui_ImplOpenGL3_NewFrame();
|
||||||
@ -191,7 +197,7 @@ void Window::imGuiNewFrame()
|
|||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::imGuiRender(ShaderProgram &raytracing_program, Clusterizer &clusterizer)
|
void Window::imGuiRender(ShaderProgram &raytracing_program)
|
||||||
{
|
{
|
||||||
bool has_changed = false;
|
bool has_changed = false;
|
||||||
|
|
||||||
@ -317,8 +323,8 @@ void Window::imGuiRender(ShaderProgram &raytracing_program, Clusterizer &cluster
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
_renderer->renderImgui(clusterizer);
|
_renderer->renderImgui(*_clusterizer);
|
||||||
clusterizer.imguiRender();
|
_clusterizer->imguiRender();
|
||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user