Render fixes after refactoring #79

Merged
Bogdan Nagirniak merged 5 commits from hydra-refactor-fixes into hydra-render 2023-07-29 11:45:06 +02:00
4 changed files with 25 additions and 67 deletions
Showing only changes of commit 4d8d9ae681 - Show all commits

View File

@ -57,8 +57,6 @@ void FinalEngine::render(Depsgraph *depsgraph)
render_task_delegate_->add_aov(pxr::HdAovTokens->color);
render_task_delegate_->add_aov(pxr::HdAovTokens->depth);
render_task_delegate_->bind();
pxr::HdTaskSharedPtrVector tasks;
if (light_tasks_delegate_) {
if (scene->r.alphamode != R_ALPHAPREMUL) {
@ -67,6 +65,9 @@ void FinalEngine::render(Depsgraph *depsgraph)
tasks.push_back(light_tasks_delegate_->simple_task());
}
tasks.push_back(render_task_delegate_->task());
render_task_delegate_->bind();
engine_->Execute(render_index_.get(), &tasks);
char elapsed_time[32];

View File

@ -148,6 +148,16 @@ pxr::SdfPath RenderTaskDelegate::buffer_id(pxr::TfToken const &aov_key) const
return GetDelegateID().AppendElementString("aov_" + aov_key.GetString());
}
GPURenderTaskDelegate::~GPURenderTaskDelegate()
{
if (tex_color_) {
GPU_texture_free(tex_color_);
}
if (tex_depth_) {
GPU_texture_free(tex_depth_);
}
}
void GPURenderTaskDelegate::set_viewport(pxr::GfVec4d const &viewport)
{
if (task_params_.viewport == viewport) {
@ -241,23 +251,9 @@ void GPURenderTaskDelegate::read_aov(pxr::TfToken const &aov_key, GPUTexture *te
MEM_freeN(tex_data);
}
GPUTexture *GPURenderTaskDelegate::aov_texture(pxr::TfToken const &aov_key) const
{
GPUTexture *tex = nullptr;
if (aov_key == pxr::HdAovTokens->color) {
tex = tex_color_;
}
else if (aov_key == pxr::HdAovTokens->depth) {
tex = tex_depth_;
}
return tex;
}
void GPURenderTaskDelegate::bind()
{
if (!framebuffer_) {
framebuffer_ = GPU_framebuffer_create("fb_render_hydra");
}
framebuffer_ = GPU_framebuffer_create("fb_render_hydra");
GPU_framebuffer_ensure_config(
&framebuffer_, {GPU_ATTACHMENT_TEXTURE(tex_depth_), GPU_ATTACHMENT_TEXTURE(tex_color_)});
GPU_framebuffer_bind(framebuffer_);
@ -268,9 +264,7 @@ void GPURenderTaskDelegate::bind()
/* Workaround missing/buggy VAOs in hgiGL and hdSt. For OpenGL compatibility
* profile this is not a problem, but for core profile it is. */
if (GPU_backend_get_type() == GPU_BACKEND_OPENGL) {
if (VAO_ == 0) {
glGenVertexArrays(1, &VAO_);
}
glGenVertexArrays(1, &VAO_);
glBindVertexArray(VAO_);
}
}
@ -281,8 +275,6 @@ void GPURenderTaskDelegate::unbind()
glDeleteVertexArrays(1, &VAO_);
}
GPU_framebuffer_free(framebuffer_);
GPU_texture_free(tex_color_);
GPU_texture_free(tex_depth_);
}
} // namespace blender::render::hydra

View File

@ -52,12 +52,12 @@ class GPURenderTaskDelegate : public RenderTaskDelegate {
public:
using RenderTaskDelegate::RenderTaskDelegate;
~GPURenderTaskDelegate() override;
void set_viewport(pxr::GfVec4d const &viewport) override;
void add_aov(pxr::TfToken const &aov_key) override;
void read_aov(pxr::TfToken const &aov_key, void *data) override;
void read_aov(pxr::TfToken const &aov_key, GPUTexture *texture) override;
GPUTexture *aov_texture(pxr::TfToken const &aov_key) const;
void bind() override;
void unbind() override;
};

View File

@ -240,13 +240,6 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context)
render_task_delegate_->add_aov(pxr::HdAovTokens->color);
render_task_delegate_->add_aov(pxr::HdAovTokens->depth);
//if ((bl_engine_->type->flag & RE_USE_GPU_CONTEXT) == 0) {
//render_task_delegate_->bind();
//}
///* Workaround missing/buggy VAOs in hgiGL and hdSt. For OpenGL compatibility
// * profile this is not a problem, but for core profile it is. */
pxr::HdTaskSharedPtrVector tasks;
if (light_tasks_delegate_) {
if (scene->r.alphamode != R_ALPHAPREMUL) {
@ -256,52 +249,24 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context)
}
tasks.push_back(render_task_delegate_->task());
GPUFrameBuffer *prev_fb = GPU_framebuffer_active_get();
GPUFrameBuffer *framebuffer = nullptr;
GLuint VAO;
if (bl_engine_->type->flag & RE_USE_GPU_CONTEXT) {
GPURenderTaskDelegate *r = dynamic_cast<GPURenderTaskDelegate *>(render_task_delegate_.get());
framebuffer = GPU_framebuffer_create("fb_render_hydra");
GPU_framebuffer_ensure_config(
&framebuffer,
{GPU_ATTACHMENT_TEXTURE(r->aov_texture(pxr::HdAovTokens->depth)),
GPU_ATTACHMENT_TEXTURE(r->aov_texture(pxr::HdAovTokens->color))});
GPU_framebuffer_bind(framebuffer);
float clear_color[4] = {0.0f, 0.0f, 0.0f, 0.0f};
GPU_framebuffer_clear_color_depth(framebuffer, clear_color, 1.0f);
if (GPU_backend_get_type() == GPU_BACKEND_OPENGL) {
glGenVertexArrays(1, &VAO);
glBindVertexArray(VAO);
}
}
GPUFrameBuffer *view_framebuffer = GPU_framebuffer_active_get();
render_task_delegate_->bind();
engine_->Execute(render_index_.get(), &tasks);
if (bl_engine_->type->flag & RE_USE_GPU_CONTEXT) {
if (GPU_backend_get_type() == GPU_BACKEND_OPENGL) {
glDeleteVertexArrays(1, &VAO);
}
GPU_framebuffer_free(framebuffer);
}
render_task_delegate_->unbind();
//if ((bl_engine_->type->flag & RE_USE_GPU_CONTEXT) == 0) {
draw_texture_.write_data(view_settings.width(), view_settings.height(), nullptr);
render_task_delegate_->read_aov(pxr::HdAovTokens->color, draw_texture_.texture());
draw_texture_.write_data(view_settings.width(), view_settings.height(), nullptr);
render_task_delegate_->read_aov(pxr::HdAovTokens->color, draw_texture_.texture());
GPU_framebuffer_bind(prev_fb);
GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_IMAGE);
GPU_shader_bind(shader);
GPU_framebuffer_bind(view_framebuffer);
GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_IMAGE);
GPU_shader_bind(shader);
draw_texture_.draw(shader, viewport);
//}
draw_texture_.draw(shader, viewport);
GPU_shader_unbind();
//if (GPU_backend_get_type() == GPU_BACKEND_OPENGL) {
// glDeleteVertexArrays(1, &VAO);
//}
//render_task_delegate_->unbind();
if (renderer_percent_done() == 0.0f) {
time_begin_ = PIL_check_seconds_timer();
}