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
3 changed files with 60 additions and 18 deletions
Showing only changes of commit f23e3099ef - Show all commits

View File

@ -105,6 +105,7 @@ void RenderTaskDelegate::add_aov(pxr::TfToken const &aov_key)
binding.aovName = aov_key; binding.aovName = aov_key;
binding.renderBufferId = buf_id; binding.renderBufferId = buf_id;
binding.aovSettings = aov_desc.aovSettings; binding.aovSettings = aov_desc.aovSettings;
binding.clearValue = pxr::VtValue(pxr::GfVec4f(0));
task_params_.aovBindings.push_back(binding); task_params_.aovBindings.push_back(binding);
render_index.GetChangeTracker().MarkTaskDirty(task_id_, pxr::HdChangeTracker::DirtyParams); render_index.GetChangeTracker().MarkTaskDirty(task_id_, pxr::HdChangeTracker::DirtyParams);
} }
@ -237,6 +238,18 @@ void GPURenderTaskDelegate::read_aov(pxr::TfToken const &aov_key, GPUTexture *te
MEM_freeN(tex_data); 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() void GPURenderTaskDelegate::bind()
{ {
if (!framebuffer_) { if (!framebuffer_) {

View File

@ -57,6 +57,7 @@ class GPURenderTaskDelegate : public RenderTaskDelegate {
void add_aov(pxr::TfToken const &aov_key) 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, void *data) override;
void read_aov(pxr::TfToken const &aov_key, GPUTexture *texture) 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 bind() override;
void unbind() override; void unbind() override;
}; };

View File

@ -183,7 +183,7 @@ void DrawTexture::write_data(int width, int height, const void *data)
width, width,
height, height,
1, 1,
GPU_RGBA16F, GPU_RGBA32F,
GPU_TEXTURE_USAGE_GENERAL, GPU_TEXTURE_USAGE_GENERAL,
(float *)data); (float *)data);
} }
@ -237,20 +237,15 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context)
light_tasks_delegate_->set_viewport(viewport); light_tasks_delegate_->set_viewport(viewport);
} }
if ((bl_engine_->type->flag & RE_USE_GPU_CONTEXT) == 0) {
render_task_delegate_->add_aov(pxr::HdAovTokens->color); render_task_delegate_->add_aov(pxr::HdAovTokens->color);
} render_task_delegate_->add_aov(pxr::HdAovTokens->depth);
/* Workaround missing/buggy VAOs in hgiGL and hdSt. For OpenGL compatibility //if ((bl_engine_->type->flag & RE_USE_GPU_CONTEXT) == 0) {
* profile this is not a problem, but for core profile it is. */ //render_task_delegate_->bind();
GLuint VAO; //}
if (GPU_backend_get_type() == GPU_BACKEND_OPENGL) {
glGenVertexArrays(1, &VAO);
glBindVertexArray(VAO);
}
GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_IMAGE); ///* Workaround missing/buggy VAOs in hgiGL and hdSt. For OpenGL compatibility
GPU_shader_bind(shader); // * profile this is not a problem, but for core profile it is. */
pxr::HdTaskSharedPtrVector tasks; pxr::HdTaskSharedPtrVector tasks;
if (light_tasks_delegate_) { if (light_tasks_delegate_) {
@ -260,19 +255,52 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context)
tasks.push_back(light_tasks_delegate_->simple_task()); tasks.push_back(light_tasks_delegate_->simple_task());
} }
tasks.push_back(render_task_delegate_->task()); tasks.push_back(render_task_delegate_->task());
engine_->Execute(render_index_.get(), &tasks);
if ((bl_engine_->type->flag & RE_USE_GPU_CONTEXT) == 0) { GPUFrameBuffer *prev_fb = GPU_framebuffer_active_get();
draw_texture_.write_data(view_settings.width(), view_settings.height(), nullptr); GPUFrameBuffer *framebuffer = nullptr;
render_task_delegate_->read_aov(pxr::HdAovTokens->color, draw_texture_.texture()); GLuint VAO;
draw_texture_.draw(shader, viewport); 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);
}
} }
GPU_shader_unbind(); engine_->Execute(render_index_.get(), &tasks);
if (bl_engine_->type->flag & RE_USE_GPU_CONTEXT) {
if (GPU_backend_get_type() == GPU_BACKEND_OPENGL) { if (GPU_backend_get_type() == GPU_BACKEND_OPENGL) {
glDeleteVertexArrays(1, &VAO); glDeleteVertexArrays(1, &VAO);
} }
GPU_framebuffer_free(framebuffer);
}
//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());
GPU_framebuffer_bind(prev_fb);
GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_IMAGE);
GPU_shader_bind(shader);
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) { if (renderer_percent_done() == 0.0f) {
time_begin_ = PIL_check_seconds_timer(); time_begin_ = PIL_check_seconds_timer();