30 if (b_engine.support_display_space_shader(b_scene)) {
31 return make_unique<BlenderDisplaySpaceShader>(b_engine, b_scene);
34 return make_unique<BlenderFallbackDisplayShader>();
64 "gpu_shader_cycles_display_fallback");
112 LOG_ERROR <<
"Failed to compile fallback shader";
118 LOG_ERROR <<
"Shader doesn't contain the 'image_texture' uniform.";
125 LOG_ERROR <<
"Shader doesn't contain the 'fullscreen' uniform.";
167 LOG_ERROR <<
"Error retrieving shader program for display space shader.";
201 if (
this == &other) {
216 if (
width != texture_width ||
height != texture_height) {
224 width = texture_width;
232 blender::gpu::TextureFormat::SFLOAT_16_16_16_16,
304 if (
this == &other) {
319 buffer_recreated =
false;
321 const size_t required_size =
sizeof(
half4) * new_width * new_height;
328 buffer_recreated =
true;
340 buffer_recreated =
true;
344 LOG_ERROR <<
"Error creating texture pixel buffer object.";
399 texture.gpu_resources_destroy();
404 return texture.gpu_texture !=
nullptr;
418 tile.gpu_resources_destroy();
439 void gl_resources_destroy_and_clear()
442 tile.gpu_resources_destroy();
452 const bool background)
473 if (!
tiles_->current_tile.tile.ready_to_draw()) {
475 <<
"Unexpectedly moving to the next tile without any data provided for current tile.";
483 DCHECK(!
tiles_->current_tile.need_update_texture_pixels);
485 tiles_->finished_tiles.tiles.emplace_back(std::move(
tiles_->current_tile.tile));
489 const int texture_width,
490 const int texture_height)
513 tiles_->finished_tiles.gl_resources_destroy_and_clear();
526 const int buffer_width =
params.size.x;
527 const int buffer_height =
params.size.y;
528 bool interop_recreated =
false;
531 buffer_width, buffer_height, interop_recreated) ||
535 tiles_->current_tile.gpu_resources_destroy();
540 if (interop_recreated) {
557 LOG_ERROR <<
"Display driver tile pixel buffer unavailable.";
562 tile.buffer_object.gpu_pixel_buffer,
590 tiles_->current_tile.need_update_texture_pixels =
true;
618 GPUPixelBuffer *pix_buf =
tiles_->current_tile.buffer_object.gpu_pixel_buffer;
620 LOG_ERROR <<
"Display driver tile pixel buffer unavailable.";
624 if (!mapped_rgba_pixels) {
625 LOG_ERROR <<
"Error mapping BlenderDisplayDriver pixel buffer object.";
627 return mapped_rgba_pixels;
632 GPUPixelBuffer *pix_buf =
tiles_->current_tile.buffer_object.gpu_pixel_buffer;
634 LOG_ERROR <<
"Display driver tile pixel buffer unavailable.";
665 interop_device.
uuid.resize(uuid.
size());
666 std::copy_n(uuid.
data(), uuid.
size(), interop_device.
uuid.data());
668 return interop_device;
691 tiles_->current_tile.buffer_object.gpu_pixel_buffer);
725 const int texcoord_attribute,
726 const int position_attribute)
728 const int x =
params.full_offset.x;
729 const int y =
params.full_offset.y;
731 const int width =
params.size.x;
732 const int height =
params.size.y;
736 immAttr2f(texcoord_attribute, 1.0f, 0.0f);
739 immAttr2f(texcoord_attribute, 1.0f, 1.0f);
742 immAttr2f(texcoord_attribute, 0.0f, 0.0f);
745 immAttr2f(texcoord_attribute, 0.0f, 1.0f);
752 const int texcoord_attribute,
753 const int position_attribute,
763 LOG_ERROR <<
"Display driver tile GPU texture resource unavailable.";
774 const float zoomed_width =
draw_tile.params.size.x * zoom.
x;
775 const float zoomed_height =
draw_tile.params.size.y * zoom.
y;
780 else if (zoomed_width -
draw_tile.params.size.x > -0.5f ||
781 zoomed_height -
draw_tile.params.size.y > -0.5f)
843 ccl::BlenderDisplayShader::tex_coord_attribute_name,
844 blender::gpu::VertAttrType::SFLOAT_32_32);
847 ccl::BlenderDisplayShader::position_attribute_name,
848 blender::gpu::VertAttrType::SFLOAT_32_32);
856 if (
tiles_->current_tile.need_update_texture_pixels) {
858 tiles_->current_tile.need_update_texture_pixels =
false;
886 LOG_ERROR <<
"Error creating GPU context.";
892 LOG_ERROR <<
"Error creating GPU resources for Display Driver.";
926 LOG_ERROR <<
"Error enabling GPU context.";
934 LOG_ERROR <<
"Error creating GPU synchronization primitives.";
951 tiles_->current_tile.gpu_resources_destroy();
952 tiles_->finished_tiles.gl_resources_destroy_and_clear();
GPUBackendType GPU_backend_get_type()
void GPU_shader_free(blender::gpu::Shader *shader)
void GPU_shader_bind(blender::gpu::Shader *shader, const blender::gpu::shader::SpecializationConstants *constants_state=nullptr)
blender::gpu::Shader * GPU_shader_get_bound()
void GPU_shader_uniform_int_ex(blender::gpu::Shader *shader, int location, int length, int array_size, const int *value)
int GPU_shader_get_attribute(const blender::gpu::Shader *shader, const char *name)
blender::gpu::Shader * GPU_shader_create_from_info_name(const char *info_name)
int GPU_shader_get_uniform(blender::gpu::Shader *shader, const char *name)
void GPU_shader_uniform_float_ex(blender::gpu::Shader *shader, int location, int length, int array_size, const float *value)
@ GPU_BLEND_ALPHA_PREMULT
void GPU_blend(GPUBlend blend)
GPUFence * GPU_fence_create()
void GPU_fence_wait(GPUFence *fence)
void GPU_fence_signal(GPUFence *fence)
void GPU_fence_free(GPUFence *fence)
void GPU_pixel_buffer_unmap(GPUPixelBuffer *pixel_buf)
void GPU_texture_update_sub_from_pixel_buffer(blender::gpu::Texture *texture, eGPUDataFormat data_format, GPUPixelBuffer *pixel_buf, int offset_x, int offset_y, int offset_z, int width, int height, int depth)
GPUPixelBufferNativeHandle GPU_pixel_buffer_get_native_handle(GPUPixelBuffer *pixel_buf)
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_bind_ex(blender::gpu::Texture *texture, GPUSamplerState state, int unit)
void GPU_texture_extend_mode(blender::gpu::Texture *texture, GPUSamplerExtendMode extend_mode)
@ GPU_TEXTURE_USAGE_GENERAL
@ GPU_SAMPLER_EXTEND_MODE_EXTEND
#define GPU_TEXTURE_FREE_SAFE(texture)
blender::gpu::Texture * GPU_texture_create_2d(const char *name, int width, int height, int mip_len, blender::gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
void GPU_texture_filter_mode(blender::gpu::Texture *texture, bool use_filter)
GPUPixelBuffer * GPU_pixel_buffer_create(size_t byte_size)
static void update_tile_texture_pixels(const DrawTileAndPBO &tile)
static blender::gpu::Shader * compile_fallback_shader()
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)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
GraphicsInteropDevice graphics_interop_get_device() override
half4 * map_texture_buffer() override
void unmap_texture_buffer() override
void gpu_context_create()
GPUFence * gpu_upload_sync_
bool gpu_context_enable()
void gpu_context_disable()
GPUFence * gpu_render_sync_
void graphics_interop_activate() override
void draw(const Params ¶ms) override
~BlenderDisplayDriver() override
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
BL::RenderEngine b_engine_
void next_tile_begin() override
void graphics_interop_update_buffer() override
BlenderDisplayDriver(BL::RenderEngine &b_engine, BL::Scene &b_scene, const bool background)
void gpu_context_unlock()
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)
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 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
BL::RenderEngine b_engine_
blender::gpu::Shader * get_shader_program() override
BlenderDisplaySpaceShader(BL::RenderEngine &b_engine, BL::Scene &b_scene)
blender::gpu::Shader * get_shader_program() override
blender::gpu::Shader * bind(const int width, const int height) override
blender::gpu::Shader * shader_program_
bool shader_compile_attempted_
~BlenderFallbackDisplayShader() override
void create_shader_if_needed()
int image_texture_location_
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
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
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
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)
const ccl_global KernelWorkTile * tile
#define DCHECK(expression)
#define DCHECK_NOTNULL(expression)
DrawTileAndPBO current_tile
struct BlenderDisplayDriver::Tiles::@220260256064215041160000166140037002343373066044 finished_tiles
static constexpr GPUSamplerState default_sampler()