From 7b7cc17cb4c1fa969162a0bee95d9cf23ae9da19 Mon Sep 17 00:00:00 2001 From: bsavery Date: Thu, 20 Jul 2023 14:26:18 -0700 Subject: [PATCH] Changes to enable MacOS viewport. --- .../render/hydra/render_task_delegate.cc | 1 + .../blender/render/hydra/viewport_engine.cc | 23 +++++++++++-------- source/blender/render/hydra/viewport_engine.h | 1 + 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/source/blender/render/hydra/render_task_delegate.cc b/source/blender/render/hydra/render_task_delegate.cc index 5351be086ca2..deb04e377f0d 100644 --- a/source/blender/render/hydra/render_task_delegate.cc +++ b/source/blender/render/hydra/render_task_delegate.cc @@ -62,6 +62,7 @@ void RenderTaskDelegate::set_renderer_aov(pxr::TfToken const &aov) binding.aovName = aov; binding.renderBufferId = buffer_id; binding.aovSettings = aov_desc.aovSettings; + binding.clearValue = pxr::VtValue(pxr::GfVec4f(0)); task_params_.aovBindings.push_back(binding); GetRenderIndex().GetChangeTracker().MarkTaskDirty(get_task_id(), diff --git a/source/blender/render/hydra/viewport_engine.cc b/source/blender/render/hydra/viewport_engine.cc index 75306e459e6a..fea0534b15f1 100644 --- a/source/blender/render/hydra/viewport_engine.cc +++ b/source/blender/render/hydra/viewport_engine.cc @@ -136,7 +136,7 @@ pxr::GfCamera ViewSettings::gf_camera() (float)border[3] / screen_height)); } -DrawTexture::DrawTexture() : texture_(nullptr), width_(0), height_(0), channels_(4) +DrawTexture::DrawTexture() : texture_(nullptr), width_(0), height_(0), channels_(4), format_(GPU_DATA_HALF_FLOAT) { float coords[8] = {0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0}; @@ -173,7 +173,7 @@ void DrawTexture::set_buffer(pxr::HdRenderBuffer *buffer) } void *data = buffer->Map(); - GPU_texture_update(texture_, GPU_DATA_FLOAT, data); + GPU_texture_update(texture_, format_, data); buffer->Unmap(); } @@ -204,7 +204,14 @@ void DrawTexture::create(pxr::HdRenderBuffer *buffer) 1, GPU_RGBA16F, GPU_TEXTURE_USAGE_GENERAL, - (float *)data); + nullptr); + /* Hydra Storm defaults to HdFormatFloat16Vec4 for the color AOV. + * For now, assume anything else is Float32. */ + format_ = GPU_DATA_HALF_FLOAT; + if (buffer->GetFormat() != pxr::HdFormat::HdFormatFloat16Vec4) { + format_ = GPU_DATA_FLOAT; + } + GPU_texture_update(texture_, format_, data); buffer->Unmap(); GPU_texture_filter_mode(texture_, true); @@ -240,9 +247,7 @@ void ViewportEngine::render(Depsgraph * /* depsgraph */, bContext *context) simple_light_task_delegate_->set_camera_path(free_camera_delegate_->GetCameraId()); } - if ((bl_engine_->type->flag & RE_USE_GPU_CONTEXT) == 0) { - render_task_delegate_->set_renderer_aov(pxr::HdAovTokens->color); - } + render_task_delegate_->set_renderer_aov(pxr::HdAovTokens->color); GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_IMAGE); GPU_shader_bind(shader); @@ -255,10 +260,8 @@ void ViewportEngine::render(Depsgraph * /* depsgraph */, bContext *context) engine_->Execute(render_index_.get(), &tasks); - if ((bl_engine_->type->flag & RE_USE_GPU_CONTEXT) == 0) { - draw_texture_.set_buffer(render_task_delegate_->get_renderer_aov(pxr::HdAovTokens->color)); - draw_texture_.draw(shader, view_settings.border[0], view_settings.border[1]); - } + draw_texture_.set_buffer(render_task_delegate_->get_renderer_aov(pxr::HdAovTokens->color)); + draw_texture_.draw(shader, view_settings.border[0], view_settings.border[1]); GPU_shader_unbind(); diff --git a/source/blender/render/hydra/viewport_engine.h b/source/blender/render/hydra/viewport_engine.h index a21ccda581e8..215697e9394c 100644 --- a/source/blender/render/hydra/viewport_engine.h +++ b/source/blender/render/hydra/viewport_engine.h @@ -28,6 +28,7 @@ class DrawTexture { GPUTexture *texture_; GPUBatch *batch_; int width_, height_, channels_; + eGPUDataFormat format_; }; class ViewportEngine : public Engine { -- 2.30.2