Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpu/metal/mtl_framebuffer.mm
| Show All 21 Lines | |||||
| { | { | ||||
| context_ = ctx; | context_ = ctx; | ||||
| is_dirty_ = true; | is_dirty_ = true; | ||||
| is_loadstore_dirty_ = true; | is_loadstore_dirty_ = true; | ||||
| dirty_state_ctx_ = nullptr; | dirty_state_ctx_ = nullptr; | ||||
| has_pending_clear_ = false; | has_pending_clear_ = false; | ||||
| colour_attachment_count_ = 0; | colour_attachment_count_ = 0; | ||||
| srgb_enabled_ = false; | enabled_srgb_ = false; | ||||
| is_srgb_ = false; | srgb_ = false; | ||||
| for (int i = 0; i < GPU_FB_MAX_COLOR_ATTACHMENT; i++) { | for (int i = 0; i < GPU_FB_MAX_COLOR_ATTACHMENT; i++) { | ||||
| mtl_color_attachments_[i].used = false; | mtl_color_attachments_[i].used = false; | ||||
| } | } | ||||
| mtl_depth_attachment_.used = false; | mtl_depth_attachment_.used = false; | ||||
| mtl_stencil_attachment_.used = false; | mtl_stencil_attachment_.used = false; | ||||
| for (int i = 0; i < MTL_FB_CONFIG_MAX; i++) { | for (int i = 0; i < MTL_FB_CONFIG_MAX; i++) { | ||||
| ▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| /* Verify Context is valid. */ | /* Verify Context is valid. */ | ||||
| if (context_ != static_cast<MTLContext *>(unwrap(GPU_context_active_get()))) { | if (context_ != static_cast<MTLContext *>(unwrap(GPU_context_active_get()))) { | ||||
| BLI_assert_msg(false, "Trying to use the same frame-buffer in multiple context's."); | BLI_assert_msg(false, "Trying to use the same frame-buffer in multiple context's."); | ||||
| return; | return; | ||||
| } | } | ||||
| /* Ensure local MTLAttachment data is up to date. */ | |||||
| this->update_attachments(true); | |||||
| /* Ensure SRGB state is up-to-date and valid. */ | /* Ensure SRGB state is up-to-date and valid. */ | ||||
| bool srgb_state_changed = srgb_enabled_ != enabled_srgb; | bool srgb_state_changed = enabled_srgb_ != enabled_srgb; | ||||
| if (context_->active_fb != this || srgb_state_changed) { | if (context_->active_fb != this || srgb_state_changed) { | ||||
| if (srgb_state_changed) { | if (srgb_state_changed) { | ||||
| this->mark_dirty(); | this->mark_dirty(); | ||||
| } | } | ||||
| srgb_enabled_ = enabled_srgb; | enabled_srgb_ = enabled_srgb; | ||||
| GPU_shader_set_framebuffer_srgb_target(srgb_enabled_ && is_srgb_); | GPU_shader_set_framebuffer_srgb_target(enabled_srgb && srgb_); | ||||
| } | } | ||||
| /* Ensure local MTLAttachment data is up to date. */ | |||||
| this->update_attachments(true); | |||||
| /* Reset clear state on bind -- Clears and load/store ops are set after binding. */ | /* Reset clear state on bind -- Clears and load/store ops are set after binding. */ | ||||
| this->reset_clear_state(); | this->reset_clear_state(); | ||||
| /* Bind to active context. */ | /* Bind to active context. */ | ||||
| MTLContext *mtl_context = reinterpret_cast<MTLContext *>(GPU_context_active_get()); | MTLContext *mtl_context = reinterpret_cast<MTLContext *>(GPU_context_active_get()); | ||||
| if (mtl_context) { | if (mtl_context) { | ||||
| mtl_context->framebuffer_bind(this); | mtl_context->framebuffer_bind(this); | ||||
| dirty_state_ = true; | dirty_state_ = true; | ||||
| ▲ Show 20 Lines • Show All 612 Lines • ▼ Show 20 Lines | switch (type) { | ||||
| default: | default: | ||||
| /* Non-attachment parameters. */ | /* Non-attachment parameters. */ | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| /* Check whether the first attachment is SRGB. */ | /* Check whether the first attachment is SRGB. */ | ||||
| if (first_attachment != GPU_FB_MAX_ATTACHMENT) { | if (first_attachment != GPU_FB_MAX_ATTACHMENT) { | ||||
| is_srgb_ = (first_attachment_mtl.texture->format_get() == GPU_SRGB8_A8); | srgb_ = (first_attachment_mtl.texture->format_get() == GPU_SRGB8_A8); | ||||
| } | } | ||||
| /* Reset viewport and Scissor (If viewport is smaller or equal to the framebuffer size). */ | /* Reset viewport and Scissor (If viewport is smaller or equal to the framebuffer size). */ | ||||
| if (update_viewport && t_viewport[2] <= width_ && t_viewport[3] <= height_) { | if (update_viewport && t_viewport[2] <= width_ && t_viewport[3] <= height_) { | ||||
| this->viewport_set(t_viewport); | this->viewport_set(t_viewport); | ||||
| this->scissor_set(t_viewport); | this->scissor_set(t_viewport); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 860 Lines • ▼ Show 20 Lines | for (int attachment_ind = 0; attachment_ind < GPU_FB_MAX_COLOR_ATTACHMENT; attachment_ind++) { | ||||
| id<MTLTexture> texture = | id<MTLTexture> texture = | ||||
| mtl_color_attachments_[attachment_ind].texture->get_metal_handle_base(); | mtl_color_attachments_[attachment_ind].texture->get_metal_handle_base(); | ||||
| if (texture == nil) { | if (texture == nil) { | ||||
| MTL_LOG_ERROR("Attempting to assign invalid texture as attachment\n"); | MTL_LOG_ERROR("Attempting to assign invalid texture as attachment\n"); | ||||
| } | } | ||||
| /* IF SRGB is enabled, but we are rendering with SRGB disabled, sample texture view. */ | /* IF SRGB is enabled, but we are rendering with SRGB disabled, sample texture view. */ | ||||
| /* TODO(Metal): Consider caching SRGB texture view. */ | |||||
| id<MTLTexture> source_color_texture = texture; | id<MTLTexture> source_color_texture = texture; | ||||
| if (this->get_is_srgb() && !this->get_srgb_enabled()) { | if (this->get_is_srgb() && | ||||
| source_color_texture = [texture newTextureViewWithPixelFormat:MTLPixelFormatRGBA8Unorm]; | mtl_color_attachments_[attachment_ind].texture->is_format_srgb() && | ||||
| !this->get_srgb_enabled()) { | |||||
| source_color_texture = | |||||
| mtl_color_attachments_[attachment_ind].texture->get_non_srgb_handle(); | |||||
| BLI_assert(source_color_texture != nil); | |||||
| } | } | ||||
| /* Resolve appropriate load action -- IF force load, perform load. | /* Resolve appropriate load action -- IF force load, perform load. | ||||
| * If clear but framebuffer has no pending clear, also load. */ | * If clear but framebuffer has no pending clear, also load. */ | ||||
| eGPULoadOp load_action = mtl_color_attachments_[attachment_ind].load_action; | eGPULoadOp load_action = mtl_color_attachments_[attachment_ind].load_action; | ||||
| if (descriptor_config == MTL_FB_CONFIG_LOAD) { | if (descriptor_config == MTL_FB_CONFIG_LOAD) { | ||||
| /* MTL_FB_CONFIG_LOAD must always load. */ | /* MTL_FB_CONFIG_LOAD must always load. */ | ||||
| load_action = GPU_LOADACTION_LOAD; | load_action = GPU_LOADACTION_LOAD; | ||||
| ▲ Show 20 Lines • Show All 268 Lines • Show Last 20 Lines | |||||