diff options
author | Brecht Van Lommel <brecht@blender.org> | 2021-09-14 16:37:47 +0300 |
---|---|---|
committer | Brecht Van Lommel <brecht@blender.org> | 2021-09-30 21:48:08 +0300 |
commit | a754e35198d852ea34e2b82cd2b126538e6f5a3b (patch) | |
tree | 9118b3fa19ab70aa1b50440ce62e5d028d940cfd /intern/cycles/device/hip | |
parent | ac582056e2e70f3b0d91ff69d0307dd357e2e2ed (diff) |
Cycles: refactor API for GPU display
* Split GPUDisplay into two classes. PathTraceDisplay to implement the Cycles side,
and DisplayDriver to implement the host application side. The DisplayDriver is now
a fully abstract base class, embedded in the PathTraceDisplay.
* Move copy_pixels_to_texture implementation out of the host side into the Cycles side,
since it can be implemented in terms of the texture buffer mapping.
* Move definition of DeviceGraphicsInteropDestination into display driver header, so
that we do not need to expose private device headers in the public API.
* Add more detailed comments about how the DisplayDriver should be implemented.
The "driver" terminology might not be obvious, but is also used in other renderers.
Differential Revision: https://developer.blender.org/D12626
Diffstat (limited to 'intern/cycles/device/hip')
-rw-r--r-- | intern/cycles/device/hip/graphics_interop.cpp | 22 | ||||
-rw-r--r-- | intern/cycles/device/hip/graphics_interop.h | 5 |
2 files changed, 21 insertions, 6 deletions
diff --git a/intern/cycles/device/hip/graphics_interop.cpp b/intern/cycles/device/hip/graphics_interop.cpp index add6dbed5e1..0d5d71019b3 100644 --- a/intern/cycles/device/hip/graphics_interop.cpp +++ b/intern/cycles/device/hip/graphics_interop.cpp @@ -37,11 +37,15 @@ HIPDeviceGraphicsInterop::~HIPDeviceGraphicsInterop() } } -void HIPDeviceGraphicsInterop::set_destination(const DeviceGraphicsInteropDestination &destination) +void HIPDeviceGraphicsInterop::set_display_interop( + const DisplayDriver::GraphicsInterop &display_interop) { - const int64_t new_buffer_area = int64_t(destination.buffer_width) * destination.buffer_height; + const int64_t new_buffer_area = int64_t(display_interop.buffer_width) * + display_interop.buffer_height; - if (opengl_pbo_id_ == destination.opengl_pbo_id && buffer_area_ == new_buffer_area) { + need_clear_ = display_interop.need_clear; + + if (opengl_pbo_id_ == display_interop.opengl_pbo_id && buffer_area_ == new_buffer_area) { return; } @@ -52,12 +56,12 @@ void HIPDeviceGraphicsInterop::set_destination(const DeviceGraphicsInteropDestin } const hipError_t result = hipGraphicsGLRegisterBuffer( - &hip_graphics_resource_, destination.opengl_pbo_id, hipGraphicsRegisterFlagsNone); + &hip_graphics_resource_, display_interop.opengl_pbo_id, hipGraphicsRegisterFlagsNone); if (result != hipSuccess) { LOG(ERROR) << "Error registering OpenGL buffer: " << hipewErrorString(result); } - opengl_pbo_id_ = destination.opengl_pbo_id; + opengl_pbo_id_ = display_interop.opengl_pbo_id; buffer_area_ = new_buffer_area; } @@ -77,6 +81,14 @@ device_ptr HIPDeviceGraphicsInterop::map() hip_device_assert( device_, hipGraphicsResourceGetMappedPointer(&hip_buffer, &bytes, hip_graphics_resource_)); + if (need_clear_) { + hip_device_assert( + device_, + hipMemsetD8Async(static_cast<hipDeviceptr_t>(hip_buffer), 0, bytes, queue_->stream())); + + need_clear_ = false; + } + return static_cast<device_ptr>(hip_buffer); } diff --git a/intern/cycles/device/hip/graphics_interop.h b/intern/cycles/device/hip/graphics_interop.h index adcaa13a2d7..2b2d287ff6c 100644 --- a/intern/cycles/device/hip/graphics_interop.h +++ b/intern/cycles/device/hip/graphics_interop.h @@ -39,7 +39,7 @@ class HIPDeviceGraphicsInterop : public DeviceGraphicsInterop { HIPDeviceGraphicsInterop &operator=(const HIPDeviceGraphicsInterop &other) = delete; HIPDeviceGraphicsInterop &operator=(HIPDeviceGraphicsInterop &&other) = delete; - virtual void set_destination(const DeviceGraphicsInteropDestination &destination) override; + virtual void set_display_interop(const DisplayDriver::GraphicsInterop &display_interop) override; virtual device_ptr map() override; virtual void unmap() override; @@ -53,6 +53,9 @@ class HIPDeviceGraphicsInterop : public DeviceGraphicsInterop { /* Buffer area in pixels of the corresponding PBO. */ int64_t buffer_area_ = 0; + /* The destination was requested to be cleared. */ + bool need_clear_ = false; + hipGraphicsResource hip_graphics_resource_ = nullptr; }; |