30 if (b_engine.support_display_space_shader(b_scene)) {
31 return make_unique<BlenderDisplaySpaceShader>(b_engine, b_scene);
34 return make_unique<BlenderFallbackDisplayShader>();
111 LOG(ERROR) <<
"Failed to compile fallback shader";
117 LOG(ERROR) <<
"Shader doesn't contain the 'image_texture' uniform.";
124 LOG(ERROR) <<
"Shader doesn't contain the 'fullscreen' uniform.";
166 LOG(ERROR) <<
"Error retrieving shader program for display space shader.";
200 if (
this == &other) {
215 if (
width != texture_width ||
height != texture_height) {
223 width = texture_width;
236 LOG(ERROR) <<
"Error creating texture.";
303 if (
this == &other) {
318 buffer_recreated =
false;
320 const size_t required_size =
sizeof(
half4) * new_width * new_height;
327 buffer_recreated =
true;
339 buffer_recreated =
true;
343 LOG(ERROR) <<
"Error creating texture pixel buffer object.";
398 texture.gpu_resources_destroy();
403 return texture.gpu_texture !=
nullptr;
417 tile.gpu_resources_destroy();
438 void gl_resources_destroy_and_clear()
441 tile.gpu_resources_destroy();
451 const bool background)
472 if (!
tiles_->current_tile.tile.ready_to_draw()) {
474 <<
"Unexpectedly moving to the next tile without any data provided for current tile.";
482 DCHECK(!
tiles_->current_tile.need_update_texture_pixels);
484 tiles_->finished_tiles.tiles.emplace_back(std::move(
tiles_->current_tile.tile));
488 const int texture_width,
489 const int texture_height)
512 tiles_->finished_tiles.gl_resources_destroy_and_clear();
525 const int buffer_width =
params.size.x;
526 const int buffer_height =
params.size.y;
527 bool interop_recreated =
false;
530 buffer_width, buffer_height, interop_recreated) ||
534 tiles_->current_tile.gpu_resources_destroy();
539 if (interop_recreated) {
556 LOG(ERROR) <<
"Display driver tile pixel buffer unavailable.";
561 tile.buffer_object.gpu_pixel_buffer,
589 tiles_->current_tile.need_update_texture_pixels =
true;
617 GPUPixelBuffer *pix_buf =
tiles_->current_tile.buffer_object.gpu_pixel_buffer;
619 LOG(ERROR) <<
"Display driver tile pixel buffer unavailable.";
623 if (!mapped_rgba_pixels) {
624 LOG(ERROR) <<
"Error mapping BlenderDisplayDriver pixel buffer object.";
626 return mapped_rgba_pixels;
631 GPUPixelBuffer *pix_buf =
tiles_->current_tile.buffer_object.gpu_pixel_buffer;
633 LOG(ERROR) <<
"Display driver tile pixel buffer unavailable.";
664 interop_device.
uuid.resize(uuid.
size());
665 std::copy_n(uuid.
data(), uuid.
size(), interop_device.
uuid.data());
667 return interop_device;
690 tiles_->current_tile.buffer_object.gpu_pixel_buffer);
724 const int texcoord_attribute,
725 const int position_attribute)
727 const int x =
params.full_offset.x;
728 const int y =
params.full_offset.y;
730 const int width =
params.size.x;
731 const int height =
params.size.y;
735 immAttr2f(texcoord_attribute, 1.0f, 0.0f);
738 immAttr2f(texcoord_attribute, 1.0f, 1.0f);
741 immAttr2f(texcoord_attribute, 0.0f, 0.0f);
744 immAttr2f(texcoord_attribute, 0.0f, 1.0f);
751 const int texcoord_attribute,
752 const int position_attribute,
762 LOG(ERROR) <<
"Display driver tile GPU texture resource unavailable.";
773 const float zoomed_width =
draw_tile.params.size.x * zoom.
x;
774 const float zoomed_height =
draw_tile.params.size.y * zoom.
y;
779 else if (zoomed_width -
draw_tile.params.size.x > -0.5f ||
780 zoomed_height -
draw_tile.params.size.y > -0.5f)
841 ccl::BlenderDisplayShader::tex_coord_attribute_name,
847 ccl::BlenderDisplayShader::position_attribute_name,
858 if (
tiles_->current_tile.need_update_texture_pixels) {
860 tiles_->current_tile.need_update_texture_pixels =
false;
888 LOG(ERROR) <<
"Error creating GPU context.";
894 LOG(ERROR) <<
"Error creating GPU resources for Cycles Display Driver.";
928 LOG(ERROR) <<
"Error enabling GPU context.";
936 LOG(ERROR) <<
"Error creating GPU synchronization primitives.";
953 tiles_->current_tile.gpu_resources_destroy();
954 tiles_->finished_tiles.gl_resources_destroy_and_clear();
eGPUBackendType GPU_backend_get_type()
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)
void GPU_shader_bind(GPUShader *shader, const blender::gpu::shader::SpecializationConstants *constants_state=nullptr)
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_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)
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_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)
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()
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 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()
GPUShader * shader_program_
BL::RenderEngine b_engine_
GPUShader * get_shader_program() override
BlenderDisplaySpaceShader(BL::RenderEngine &b_engine, BL::Scene &b_scene)
GPUShader * bind(const int width, const int height) override
bool shader_compile_attempted_
~BlenderFallbackDisplayShader() override
GPUShader * shader_program_
GPUShader * bind(const int width, const int height) override
void create_shader_if_needed()
GPUShader * get_shader_program() override
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()
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
TEX_TEMPLATE DataVec texture(T, FltCoord, float=0.0f) RET
#define assert(assertion)
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)
#define VLOG_DEVICE_STATS
DrawTileAndPBO current_tile
struct BlenderDisplayDriver::Tiles::@320314337316024065247102135170126226027070301201 finished_tiles
static constexpr GPUSamplerState default_sampler()