Fixed rendering for MacOS #82

Merged
Bogdan Nagirniak merged 10 commits from BLEN-473 into hydra-render 2023-08-02 09:37:25 +02:00
3 changed files with 22 additions and 13 deletions
Showing only changes of commit e6a5bd7351 - Show all commits

View File

@ -62,6 +62,7 @@ set(INC_SYS
${BOOST_INCLUDE_DIR} ${BOOST_INCLUDE_DIR}
${TBB_INCLUDE_DIR} ${TBB_INCLUDE_DIR}
${GFLAGS_INCLUDE_DIRS} ${GFLAGS_INCLUDE_DIRS}
${EIGEN3_INCLUDE_DIRS}
) )
set(LIB set(LIB

View File

@ -13,8 +13,9 @@
#include "MEM_guardedalloc.h" #include "MEM_guardedalloc.h"
#include "Eigen/Core"
#include "engine.h" #include "engine.h"
#include "render_task_delegate.h"
namespace blender::render::hydra { namespace blender::render::hydra {
@ -127,19 +128,29 @@ void RenderTaskDelegate::add_aov(pxr::TfToken const &aov_key)
CLOG_INFO(LOG_RENDER_HYDRA, 1, "%s", aov_key.GetText()); CLOG_INFO(LOG_RENDER_HYDRA, 1, "%s", aov_key.GetText());
} }
void RenderTaskDelegate::read_aov(pxr::TfToken const &aov_key, void *data) void RenderTaskDelegate::read_aov(pxr::TfToken const &aov_key, float *data)
{ {
pxr::HdRenderBuffer *buffer = static_cast<pxr::HdRenderBuffer *>( pxr::HdRenderBuffer *buffer = static_cast<pxr::HdRenderBuffer *>(
GetRenderIndex().GetBprim(pxr::HdPrimTypeTokens->renderBuffer, buffer_id(aov_key))); GetRenderIndex().GetBprim(pxr::HdPrimTypeTokens->renderBuffer, buffer_id(aov_key)));
if (!buffer) { if (!buffer) {
return; return;
} }
void *buf_data = buffer->Map();
memcpy(data, pxr::HdFormat format = buffer->GetFormat();
buf_data, size_t len = buffer->GetWidth() * buffer->GetHeight() * pxr::HdGetComponentCount(format);
buffer->GetWidth() * buffer->GetHeight() * pxr::HdDataSizeOfFormat(buffer->GetFormat())); if (pxr::HdGetComponentFormat(format) == pxr::HdFormatFloat32) {
float *buf_data = (float *)buffer->Map();
memcpy(data, buf_data, len * sizeof(float));
buffer->Unmap(); buffer->Unmap();
} }
else if (pxr::HdGetComponentFormat(format) == pxr::HdFormatFloat16) {
Eigen::half *buf_data = (Eigen::half *)buffer->Map();
for (size_t i = 0; i < len; ++i) {
data[i] = buf_data[i];
}
buffer->Unmap();
}
}
void RenderTaskDelegate::read_aov(pxr::TfToken const &aov_key, GPUTexture *texture) void RenderTaskDelegate::read_aov(pxr::TfToken const &aov_key, GPUTexture *texture)
{ {
@ -228,7 +239,7 @@ void GPURenderTaskDelegate::add_aov(pxr::TfToken const &aov_key)
CLOG_INFO(LOG_RENDER_HYDRA, 1, "%s", aov_key.GetText()); CLOG_INFO(LOG_RENDER_HYDRA, 1, "%s", aov_key.GetText());
} }
void GPURenderTaskDelegate::read_aov(pxr::TfToken const &aov_key, void *data) void GPURenderTaskDelegate::read_aov(pxr::TfToken const &aov_key, float *data)
{ {
GPUTexture *tex = nullptr; GPUTexture *tex = nullptr;
int c; int c;
@ -253,14 +264,11 @@ void GPURenderTaskDelegate::read_aov(pxr::TfToken const &aov_key, void *data)
void GPURenderTaskDelegate::read_aov(pxr::TfToken const &aov_key, GPUTexture *texture) void GPURenderTaskDelegate::read_aov(pxr::TfToken const &aov_key, GPUTexture *texture)
{ {
GPUTexture *tex = nullptr; GPUTexture *tex = nullptr;
int c;
if (aov_key == pxr::HdAovTokens->color) { if (aov_key == pxr::HdAovTokens->color) {
tex = tex_color_; tex = tex_color_;
c = 4;
} }
else if (aov_key == pxr::HdAovTokens->depth) { else if (aov_key == pxr::HdAovTokens->depth) {
tex = tex_depth_; tex = tex_depth_;
c = 1;
} }
if (!tex) { if (!tex) {
return; return;

View File

@ -34,7 +34,7 @@ class RenderTaskDelegate : public pxr::HdSceneDelegate {
virtual bool is_converged(); virtual bool is_converged();
virtual void set_viewport(pxr::GfVec4d const &viewport); virtual void set_viewport(pxr::GfVec4d const &viewport);
virtual void add_aov(pxr::TfToken const &aov_key); virtual void add_aov(pxr::TfToken const &aov_key);
virtual void read_aov(pxr::TfToken const &aov_key, void *data); virtual void read_aov(pxr::TfToken const &aov_key, float *data);
virtual void read_aov(pxr::TfToken const &aov_key, GPUTexture *texture); virtual void read_aov(pxr::TfToken const &aov_key, GPUTexture *texture);
virtual void bind(); virtual void bind();
virtual void unbind(); virtual void unbind();
@ -56,7 +56,7 @@ class GPURenderTaskDelegate : public RenderTaskDelegate {
void set_viewport(pxr::GfVec4d const &viewport) override; void set_viewport(pxr::GfVec4d const &viewport) override;
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, float *data) override;
void read_aov(pxr::TfToken const &aov_key, GPUTexture *texture) override; void read_aov(pxr::TfToken const &aov_key, GPUTexture *texture) override;
void bind() override; void bind() override;
void unbind() override; void unbind() override;