28 if (b_engine.support_display_space_shader(b_scene)) {
29 return make_unique<BlenderDisplaySpaceShader>(b_engine, b_scene);
32 return make_unique<BlenderFallbackDisplayShader>();
104 LOG(ERROR) <<
"Failed to compile fallback shader";
110 LOG(ERROR) <<
"Shader doesn't contain the 'image_texture' uniform.";
117 LOG(ERROR) <<
"Shader doesn't contain the 'fullscreen' uniform.";
137 : b_engine_(b_engine), b_scene_(b_scene)
159 LOG(ERROR) <<
"Error retrieving shader program for display space shader.";
193 if (
this == &other) {
208 if (
width != texture_width ||
height != texture_height) {
216 width = texture_width;
229 LOG(ERROR) <<
"Error creating texture.";
296 if (
this == &other) {
311 const size_t required_size =
sizeof(
half4) * new_width * new_height * 4;
332 LOG(ERROR) <<
"Error creating texture pixel buffer object.";
387 texture.gpu_resources_destroy();
392 return texture.gpu_texture != 0;
427 void gl_resources_destroy_and_clear()
430 tile.gpu_resources_destroy();
440 const bool background)
441 : b_engine_(b_engine),
442 background_(background),
444 tiles_(make_unique<
Tiles>())
461 if (!
tiles_->current_tile.tile.ready_to_draw()) {
463 <<
"Unexpectedly moving to the next tile without any data provided for current tile.";
471 DCHECK(!
tiles_->current_tile.need_update_texture_pixels);
473 tiles_->finished_tiles.tiles.emplace_back(std::move(
tiles_->current_tile.tile));
501 tiles_->finished_tiles.gl_resources_destroy_and_clear();
514 const int buffer_width =
params.size.x;
515 const int buffer_height =
params.size.y;
520 tiles_->current_tile.gpu_resources_destroy();
538 LOG(ERROR) <<
"Display driver tile pixel buffer unavailable.";
543 tile.buffer_object.gpu_pixel_buffer,
571 tiles_->current_tile.need_update_texture_pixels =
true;
591 GPUPixelBuffer *pix_buf =
tiles_->current_tile.buffer_object.gpu_pixel_buffer;
593 LOG(ERROR) <<
"Display driver tile pixel buffer unavailable.";
597 if (!mapped_rgba_pixels) {
598 LOG(ERROR) <<
"Error mapping BlenderDisplayDriver pixel buffer object.";
600 return mapped_rgba_pixels;
605 GPUPixelBuffer *pix_buf =
tiles_->current_tile.buffer_object.gpu_pixel_buffer;
607 LOG(ERROR) <<
"Display driver tile pixel buffer unavailable.";
624 tiles_->current_tile.buffer_object.gpu_pixel_buffer);
658 int texcoord_attribute,
659 int position_attribute)
661 const int x =
params.full_offset.x;
662 const int y =
params.full_offset.y;
664 const int width =
params.size.x;
665 const int height =
params.size.y;
669 immAttr2f(texcoord_attribute, 1.0f, 0.0f);
672 immAttr2f(texcoord_attribute, 1.0f, 1.0f);
673 immVertex2f(position_attribute, x + width, y + height);
675 immAttr2f(texcoord_attribute, 0.0f, 0.0f);
678 immAttr2f(texcoord_attribute, 0.0f, 1.0f);
685 const int texcoord_attribute,
686 const int position_attribute,
696 LOG(ERROR) <<
"Display driver tile GPU texture resource unavailable.";
707 const float zoomed_width =
draw_tile.params.size.x * zoom.
x;
708 const float zoomed_height =
draw_tile.params.size.y * zoom.
y;
709 if (texture.width !=
draw_tile.params.size.x || texture.height !=
draw_tile.params.size.y) {
713 else if (zoomed_width -
draw_tile.params.size.x > -0.5f ||
714 zoomed_height -
draw_tile.params.size.y > -0.5f)
784 if (
tiles_->current_tile.need_update_texture_pixels) {
786 tiles_->current_tile.need_update_texture_pixels =
false;
814 LOG(ERROR) <<
"Error creating GPU context.";
820 LOG(ERROR) <<
"Error creating GPU resources for Cycles Display Driver.";
854 LOG(ERROR) <<
"Error enabling GPU context.";
862 LOG(ERROR) <<
"Error creating GPU synchronization primitives.";
875 tiles_->current_tile.gpu_resources_destroy();
876 tiles_->finished_tiles.gl_resources_destroy_and_clear();
int GPU_shader_get_uniform(GPUShader *shader, const char *name)
void GPU_shader_uniform_int_ex(GPUShader *shader, int location, int length, int array_size, const int *value)
GPUShader * GPU_shader_create_from_info_name(const char *info_name)
int GPU_shader_get_attribute(const GPUShader *shader, const char *name)
void GPU_shader_uniform_float_ex(GPUShader *shader, int location, int length, int array_size, const float *value)
void GPU_shader_bind(GPUShader *shader)
void GPU_shader_free(GPUShader *shader)
GPUShader * GPU_shader_get_bound()
@ GPU_BLEND_ALPHA_PREMULT
void GPU_blend(eGPUBlend blend)
GPUFence * GPU_fence_create()
void GPU_fence_wait(GPUFence *fence)
void GPU_fence_signal(GPUFence *fence)
void GPU_fence_free(GPUFence *fence)
GPUTexture * GPU_texture_create_2d(const char *name, int width, int height, int mip_len, eGPUTextureFormat format, eGPUTextureUsage usage, const float *data)
void GPU_pixel_buffer_unmap(GPUPixelBuffer *pixel_buf)
void GPU_texture_bind_ex(GPUTexture *texture, GPUSamplerState state, int unit)
size_t GPU_pixel_buffer_size(GPUPixelBuffer *pixel_buf)
void * GPU_pixel_buffer_map(GPUPixelBuffer *pixel_buf)
void GPU_pixel_buffer_free(GPUPixelBuffer *pixel_buf)
void GPU_texture_update_sub_from_pixel_buffer(GPUTexture *texture, eGPUDataFormat data_format, GPUPixelBuffer *pixel_buf, int offset_x, int offset_y, int offset_z, int width, int height, int depth)
int64_t GPU_pixel_buffer_get_native_handle(GPUPixelBuffer *pixel_buf)
void GPU_texture_extend_mode(GPUTexture *texture, GPUSamplerExtendMode extend_mode)
@ GPU_TEXTURE_USAGE_GENERAL
@ GPU_SAMPLER_EXTEND_MODE_EXTEND
void GPU_texture_filter_mode(GPUTexture *texture, bool use_filter)
#define GPU_TEXTURE_FREE_SAFE(texture)
GPUPixelBuffer * GPU_pixel_buffer_create(size_t byte_size)
static void update_tile_texture_pixels(const DrawTileAndPBO &tile)
static GPUShader * compile_fallback_shader(void)
static void vertex_draw(const DisplayDriver::Params ¶ms, int texcoord_attribute, int position_attribute)
static void draw_tile(const float2 &zoom, const int texcoord_attribute, const int position_attribute, const DrawTile &draw_tile)
struct GPUShader GPUShader
virtual half4 * map_texture_buffer() override
virtual void unmap_texture_buffer() override
void gpu_context_create()
virtual void clear() override
GPUFence * gpu_upload_sync_
virtual bool update_begin(const Params ¶ms, int texture_width, int texture_height) override
bool gpu_context_enable()
std::atomic< bool > need_clear_
void gpu_context_disable()
GPUFence * gpu_render_sync_
virtual void graphics_interop_activate() override
virtual GraphicsInterop graphics_interop_get() override
virtual void draw(const Params ¶ms) override
bool gpu_resources_create()
void set_zoom(float zoom_x, float zoom_y)
virtual void flush() override
virtual void update_end() override
unique_ptr< Tiles > tiles_
unique_ptr< BlenderDisplayShader > display_shader_
void gpu_resources_destroy()
virtual void graphics_interop_deactivate() override
BL::RenderEngine b_engine_
virtual void next_tile_begin() override
BlenderDisplayDriver(BL::RenderEngine &b_engine, BL::Scene &b_scene, const bool background)
void gpu_context_unlock()
void gpu_context_destroy()
virtual GPUShader * get_shader_program()=0
virtual int get_position_attrib_location()
static unique_ptr< BlenderDisplayShader > create(BL::RenderEngine &b_engine, BL::Scene &b_scene)
int tex_coord_attribute_location_
static constexpr const char * tex_coord_attribute_name
static constexpr const char * position_attribute_name
int position_attribute_location_
virtual int get_tex_coord_attrib_location()
virtual void unbind() override
GPUShader * shader_program_
BL::RenderEngine b_engine_
virtual GPUShader * get_shader_program() override
BlenderDisplaySpaceShader(BL::RenderEngine &b_engine, BL::Scene &b_scene)
virtual GPUShader * bind(int width, int height) override
virtual void unbind() override
bool shader_compile_attempted_
GPUShader * shader_program_
virtual GPUShader * bind(int width, int height) override
void create_shader_if_needed()
virtual GPUShader * get_shader_program() override
int image_texture_location_
DisplayGPUPixelBuffer()=default
static std::atomic< int > num_used
DisplayGPUPixelBuffer(const DisplayGPUPixelBuffer &other)=delete
GPUPixelBuffer * gpu_pixel_buffer
DisplayGPUPixelBuffer & operator=(DisplayGPUPixelBuffer &other)=delete
void gpu_resources_destroy()
bool gpu_resources_ensure(const uint new_width, const uint new_height)
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()
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
#define CCL_NAMESPACE_END
void RE_engine_gpu_context_lock(RenderEngine *engine)
void RE_engine_gpu_context_unlock(RenderEngine *engine)
void RE_engine_gpu_context_destroy(RenderEngine *engine)
bool RE_engine_gpu_context_enable(RenderEngine *engine)
bool RE_engine_gpu_context_create(RenderEngine *engine)
void RE_engine_gpu_context_disable(RenderEngine *engine)
ccl_global const KernelWorkTile * tile
#define DCHECK(expression)
#define DCHECK_NOTNULL(expression)
#define VLOG_DEVICE_STATS
DrawTileAndPBO current_tile
struct BlenderDisplayDriver::Tiles::@1413 finished_tiles
static constexpr GPUSamplerState default_sampler()