31 return make_unique<BlenderDisplaySpaceShader>(b_engine, b_scene);
84 LOG_ERROR <<
"Error retrieving shader program for display space shader.";
118 if (
this == &other) {
133 if (
width != texture_width ||
height != texture_height) {
141 width = texture_width;
149 blender::gpu::TextureFormat::SFLOAT_16_16_16_16,
221 if (
this == &other) {
236 buffer_recreated =
false;
238 const size_t required_size =
sizeof(
half4) * new_width * new_height;
245 buffer_recreated =
true;
257 buffer_recreated =
true;
261 LOG_ERROR <<
"Error creating texture pixel buffer object.";
356 void gl_resources_destroy_and_clear()
359 tile.gpu_resources_destroy();
370 const bool background)
398 if (!
tiles_->current_tile.tile.ready_to_draw()) {
400 <<
"Unexpectedly moving to the next tile without any data provided for current tile.";
408 DCHECK(!
tiles_->current_tile.need_update_texture_pixels);
410 tiles_->finished_tiles.tiles.emplace_back(std::move(
tiles_->current_tile.tile));
414 const int texture_width,
415 const int texture_height)
441 tiles_->finished_tiles.gl_resources_destroy_and_clear();
454 const int buffer_width = params.
size.
x;
455 const int buffer_height = params.
size.
y;
456 bool interop_recreated =
false;
459 buffer_width, buffer_height, interop_recreated) ||
463 tiles_->current_tile.gpu_resources_destroy();
468 if (interop_recreated) {
475 tiles_->current_tile.tile.params = params;
485 LOG_ERROR <<
"Display driver tile pixel buffer unavailable.";
490 tile.buffer_object.gpu_pixel_buffer,
520 tiles_->current_tile.need_update_texture_pixels =
true;
554 blender::GPUPixelBuffer *pix_buf =
tiles_->current_tile.buffer_object.gpu_pixel_buffer;
556 LOG_ERROR <<
"Display driver tile pixel buffer unavailable.";
560 if (!mapped_rgba_pixels) {
561 LOG_ERROR <<
"Error mapping BlenderDisplayDriver pixel buffer object.";
563 return mapped_rgba_pixels;
568 blender::GPUPixelBuffer *pix_buf =
tiles_->current_tile.buffer_object.gpu_pixel_buffer;
570 LOG_ERROR <<
"Display driver tile pixel buffer unavailable.";
601 interop_device.
uuid.resize(uuid.
size());
602 std::copy_n(uuid.
data(), uuid.
size(), interop_device.
uuid.data());
604 return interop_device;
627 tiles_->current_tile.buffer_object.gpu_pixel_buffer);
661 const int texcoord_attribute,
662 const int position_attribute)
667 const int width = params.
size.
x;
668 const int height = params.
size.
y;
688 const int texcoord_attribute,
689 const int position_attribute,
699 LOG_ERROR <<
"Display driver tile GPU texture resource unavailable.";
710 const float zoomed_width =
draw_tile.params.size.x * zoom.
x;
711 const float zoomed_height =
draw_tile.params.size.y * zoom.
y;
717 else if (zoomed_width -
draw_tile.params.size.x > -0.5f ||
718 zoomed_height -
draw_tile.params.size.y > -0.5f)
792 ccl::BlenderDisplayShader::tex_coord_attribute_name,
793 blender::gpu::VertAttrType::SFLOAT_32_32);
796 ccl::BlenderDisplayShader::position_attribute_name,
797 blender::gpu::VertAttrType::SFLOAT_32_32);
805 if (
tiles_->current_tile.need_update_texture_pixels) {
807 tiles_->current_tile.need_update_texture_pixels =
false;
834 if (!RE_engine_gpu_context_create(&
b_engine_)) {
835 LOG_ERROR <<
"Error creating GPU context.";
841 LOG_ERROR <<
"Error creating GPU resources for Display Driver.";
848 return RE_engine_gpu_context_enable(&
b_engine_);
853 RE_engine_gpu_context_disable(&
b_engine_);
858 RE_engine_gpu_context_destroy(&
b_engine_);
868 RE_engine_gpu_context_unlock(&
b_engine_);
875 LOG_ERROR <<
"Error enabling GPU context.";
883 LOG_ERROR <<
"Error creating GPU synchronization primitives.";
900 tiles_->current_tile.gpu_resources_destroy();
901 tiles_->finished_tiles.gl_resources_destroy_and_clear();
#define GPU_TEXTURE_FREE_SAFE(texture)
static void update_tile_texture_pixels(const DrawTileAndPBO &tile)
static void vertex_draw(const DisplayDriver::Params ¶ms, const int texcoord_attribute, const int position_attribute)
static void draw_tile(const float2 &zoom, const int texcoord_attribute, const int position_attribute, const DrawTile &draw_tile)
GraphicsInteropDevice graphics_interop_get_device() override
half4 * map_texture_buffer() override
void unmap_texture_buffer() override
void gpu_context_create()
blender::GPUFence * gpu_upload_sync_
bool gpu_context_enable()
thread_condition_variable has_update_cond_
void gpu_context_disable()
blender::RegionView3D * b_rv3d_
void graphics_interop_activate() override
void draw(const Params ¶ms) override
~BlenderDisplayDriver() override
thread_mutex has_update_mutex_
bool gpu_resources_create()
std::atomic< bool > need_zero_
void update_end() override
unique_ptr< Tiles > tiles_
unique_ptr< BlenderDisplayShader > display_shader_
void gpu_resources_destroy()
void graphics_interop_deactivate() override
void next_tile_begin() override
blender::GPUFence * gpu_render_sync_
void graphics_interop_update_buffer() override
void gpu_context_unlock()
blender::RenderEngine & b_engine_
bool update_begin(const Params ¶ms, const int texture_width, const int texture_height) override
void gpu_context_destroy()
void set_zoom(const float zoom_x, const float zoom_y)
BlenderDisplayDriver(blender::RenderEngine &b_engine, blender::Scene &b_scene, blender::RegionView3D *b_rv3d, const bool background)
virtual int get_position_attrib_location()
int tex_coord_attribute_location_
static constexpr const char * tex_coord_attribute_name
static constexpr const char * position_attribute_name
int position_attribute_location_
static unique_ptr< BlenderDisplayShader > create(blender::RenderEngine &b_engine, blender::Scene &b_scene)
virtual blender::gpu::Shader * get_shader_program()=0
virtual int get_tex_coord_attrib_location()
blender::gpu::Shader * shader_program_
blender::gpu::Shader * bind(const int width, const int height) override
blender::Scene & b_scene_
blender::gpu::Shader * get_shader_program() override
blender::RenderEngine & b_engine_
BlenderDisplaySpaceShader(blender::RenderEngine &b_engine, blender::Scene &b_scene)
GraphicsInteropBuffer graphics_interop_buffer_
bool gpu_resources_ensure(const uint new_width, const uint new_height, bool &buffer_recreated)
DisplayGPUPixelBuffer()=default
static std::atomic< int > num_used
DisplayGPUPixelBuffer(const DisplayGPUPixelBuffer &other)=delete
blender::GPUPixelBuffer * gpu_pixel_buffer
DisplayGPUPixelBuffer & operator=(DisplayGPUPixelBuffer &other)=delete
void gpu_resources_destroy()
DisplayGPUPixelBuffer(DisplayGPUPixelBuffer &&other) noexcept
DisplayGPUPixelBuffer & operator=(DisplayGPUPixelBuffer &&other)
bool gpu_resources_ensure(const uint texture_width, const uint texture_height)
DisplayGPUTexture & operator=(DisplayGPUTexture &other)=delete
DisplayGPUTexture(DisplayGPUTexture &&other) noexcept
DisplayGPUTexture & operator=(DisplayGPUTexture &&other)
static std::atomic< int > num_used
void gpu_resources_destroy()
blender::gpu::Texture * gpu_texture
DisplayGPUTexture()=default
DisplayGPUTexture(const DisplayGPUTexture &other)=delete
bool need_update_texture_pixels
void gpu_resources_destroy()
DisplayGPUPixelBuffer buffer_object
DrawTile(const DrawTile &other)=delete
void gpu_resources_destroy()
DrawTile(DrawTile &&other) noexcept=default
bool ready_to_draw() const
BlenderDisplayDriver::Params params
DrawTile & operator=(DrawTile &&other)=default
DrawTile & operator=(const DrawTile &other)=delete
DisplayGPUTexture texture
void assign(GraphicsInteropDevice::Type type, int64_t handle, size_t size)
constexpr const T * data() const
constexpr int64_t size() const
#define CCL_NAMESPACE_END
#define assert(assertion)
TEX_TEMPLATE DataVec texture(T, FltCoord, float=0.0f) RET
const ccl_global KernelWorkTile * tile
#define DCHECK(expression)
#define DCHECK_NOTNULL(expression)
void GPU_fence_free(GPUFence *fence)
bool GPU_type_matches_ex(GPUDeviceType device, GPUOSType os, GPUDriverType driver, GPUBackendType backend)
GPUVertFormat * immVertexFormat()
GPUBackendType GPU_backend_get_type()
void immBegin(GPUPrimType, uint vertex_len)
@ GPU_SAMPLER_EXTEND_MODE_EXTEND
void GPU_pixel_buffer_unmap(GPUPixelBuffer *pixel_buf)
void * GPU_pixel_buffer_map(GPUPixelBuffer *pixel_buf)
int GPU_shader_get_attribute(const gpu::Shader *shader, const char *name)
void GPU_fence_wait(GPUFence *fence)
void immAttr2f(uint attr_id, float x, float y)
@ GPU_BLEND_ALPHA_PREMULT
GPUFence * GPU_fence_create()
void immVertex2f(uint attr_id, float x, float y)
@ GPU_TEXTURE_USAGE_GENERAL
void GPU_texture_filter_mode(gpu::Texture *texture, bool use_filter)
void GPU_shader_bind(gpu::Shader *shader, const gpu::shader::SpecializationConstants *constants_state=nullptr)
void GPU_texture_bind_ex(gpu::Texture *texture, GPUSamplerState state, int unit)
uint GPU_vertformat_attr_add(GPUVertFormat *format, StringRef name, gpu::VertAttrType type)
void GPU_texture_extend_mode(gpu::Texture *texture, GPUSamplerExtendMode extend_mode)
gpu::Shader * GPU_shader_get_bound()
gpu::Shader * GPU_shader_get_builtin_shader(GPUBuiltinShader shader)
void GPU_pixel_buffer_free(GPUPixelBuffer *pixel_buf)
size_t GPU_pixel_buffer_size(GPUPixelBuffer *pixel_buf)
GPUPixelBuffer * GPU_pixel_buffer_create(size_t byte_size)
void immBindShader(gpu::Shader *shader)
Span< uint8_t > GPU_platform_uuid()
void GPU_blend(GPUBlend blend)
void GPU_fence_signal(GPUFence *fence)
void GPU_texture_update_sub_from_pixel_buffer(gpu::Texture *texture, eGPUDataFormat data_format, GPUPixelBuffer *pixel_buf, int offset_x, int offset_y, int offset_z, int width, int height, int depth)
gpu::Texture * GPU_texture_create_2d(const char *name, int width, int height, int mip_len, gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
GPUPixelBufferNativeHandle GPU_pixel_buffer_get_native_handle(GPUPixelBuffer *pixel_buf)
DrawTileAndPBO current_tile
struct BlenderDisplayDriver::Tiles::@017347327365203105213232372177334306235256047361 finished_tiles
static constexpr GPUSamplerState default_sampler()
std::unique_lock< std::mutex > thread_scoped_lock