server now sends jobs to client and client can send result image to server

This commit is contained in:
2025-02-25 01:53:08 +01:00
parent fcc6f8266b
commit 29f00cf9b2
13 changed files with 182 additions and 91 deletions

View File

@ -6,15 +6,15 @@
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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
# define CLUSTERIZER_HPP
#pragma once
# include "RT.hpp"
typedef enum e_job_status
{
WAITING,
@ -24,19 +24,19 @@ typedef enum e_job_status
typedef struct s_job
{
std::string scene;
glm::vec3 pos;
glm::vec2 dir;
size_t samples;
GPUDenoise denoise;
size_t id;
size_t frameNb;
} t_job;
typedef struct s_client
{
std::vector<uint8_t> buffer;
t_job *curJob;
int progress;
uint8_t progress;
bool ready;
} t_client;
@ -44,33 +44,31 @@ typedef enum e_msg
{
RDY,
JOB,
JOB_RES_RQ,
ACK,
WAIT,
IMAGE,
ERR,
UNKNOWN
PROGRESS_UPDATE,
IMG_SEND_RQ,
IMG
} t_msg;
class Clusterizer
{
public:
Clusterizer(Arguments &args);
Clusterizer(Arguments &args, Renderer *renderer);
~Clusterizer();
void update(void);
void update(Scene &scene, Window &win, std::vector<GLuint> &textures, ShaderProgram &denoisingProgram);
bool getError(void);
void imguiRender(void);
bool isServer(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:
bool _isActive;
bool _isServer;
bool _error;
std::string _sceneName;
Renderer *_renderer;
std::vector<t_job *> _jobs[3];
@ -78,18 +76,23 @@ class Clusterizer
void imguiClients(void);
private: //client
void initClient(std::string &dest);
void openClientConnection(const char *ip, int port);
void clientHandleBuffer(void);
void updateClient(void);
void clientGetJob(void);
void clientReceive(void);
void initClient(std::string &dest);
void openClientConnection(const char *ip, int port);
void clientHandleBuffer(void);
void updateClient(Scene &scene, Window &win, std::vector<GLuint> &textures, ShaderProgram &denoisingProgram);
void clientGetJob(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;
std::string _serverIp;
int _serverPort;
std::vector<uint8_t> _receiveBuffer;
t_job _currentJob;
t_job *_currentJob;
uint8_t _progress;
bool _srvReady;
private: //server
void initServer(std::string port);
@ -104,13 +107,8 @@ class Clusterizer
int dispatchJobs(void);
int _serverSocket;
struct pollfd *_pollfds;
std::map<int, t_client> _clients;
size_t _curId;
};
#endif

View File

@ -6,7 +6,7 @@
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
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 fillGoodCodecList(std::vector<AVCodecID> &lst);
void addImageToRender(std::vector<GLuint> &textures, ShaderProgram &denoisingProgram);

View File

@ -6,12 +6,11 @@
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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
# define RT_SCENE__HPP
#pragma once
# include "RT.hpp"
@ -78,15 +77,6 @@ struct GPUDebug
int box_treshold;
};
struct GPUDenoise
{
int enabled;
int pass;
float c_phi;
float p_phi;
float n_phi;
};
struct GPUBvh
{
alignas(16) glm::vec3 min;
@ -176,5 +166,3 @@ class Scene
Camera *_camera;
};
#endif

View File

@ -6,7 +6,7 @@
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
void imGuiNewFrame();
void imGuiRender(ShaderProgram &raytracing_program, Clusterizer &clusterizer);
void imGuiRender(ShaderProgram &raytracing_program);
GLFWwindow *getWindow(void) const;
float getFps(void) const;
@ -51,10 +51,12 @@ class Window
bool isRendering();
void rendererUpdate(std::vector<GLuint> &textures, ShaderProgram &denoisingProgram);
void clusterizerUpdate(std::vector<GLuint> &textures, ShaderProgram &denoisingProgram);
private:
GLFWwindow *_window;
Scene *_scene;
Renderer *_renderer;
Clusterizer *_clusterizer;
float _fps;
float _delta;