Fix 105449: Resolve selection in Metal backend #105529

Merged
Jeroen Bakker merged 1 commits from Jason-Fielder/blender:Fix_105449 into blender-v3.5-release 2023-03-07 16:00:34 +01:00
2 changed files with 30 additions and 25 deletions

View File

@ -62,11 +62,24 @@ template<> uint denormalize<uint>(float val)
return uint(float(DEPTH_SCALE_FACTOR) * val);
}
/* Float to other type case. */
template<typename T> T convert_type(float type)
{
return T(type);
}
/* Uint to other types. */
template<typename T> T convert_type(uint type)
{
return T(type);
}
/* Int to other types. */
template<typename T> T convert_type(int type)
{
return T(type);
}
template<> uchar convert_type<uchar>(float val)
{
return uchar(val * float(0xFF));
@ -141,8 +154,8 @@ kernel void compute_texture_read(constant TextureReadParams &params [[buffer(0)]
uint xx = position[0];
uint yy = position[1];
uint zz = position[2];
int index = (zz * (params.extent[0] * params.extent[1]) + yy * params.extnt[0] + xx) *
COMPONENT_COUNT_INPUT;
int index = (zz * (params.extent[0] * params.extent[1]) + yy * params.extent[0] + xx) *
COMPONENT_COUNT_OUTPUT;
read_colour = read_tex.read(uint3(params.offset[0], params.offset[1], params.offset[2]) +
uint3(xx, yy, zz));
@ -163,7 +176,7 @@ kernel void compute_texture_read(constant TextureReadParams &params [[buffer(0)]
uint yy = position[1];
uint layer = position[2];
int index = (layer * (params.extent[0] * params.extent[1]) + yy * params.extent[0] + xx) *
COMPONENT_COUNT_INPUT;
COMPONENT_COUNT_OUTPUT;
/* Read data */
# if IS_DEPTH_FORMAT == 1

View File

@ -606,17 +606,6 @@ void MTLFrameBuffer::update_attachments(bool update_viewport)
if (!dirty_attachments_) {
return;
}
/* Cache viewport and scissor (If we have existing attachments). */
int t_viewport[4], t_scissor[4];
update_viewport = update_viewport &&
(this->get_attachment_count() > 0 && this->has_depth_attachment() &&
this->has_stencil_attachment());
if (update_viewport) {
this->viewport_get(t_viewport);
this->scissor_get(t_scissor);
}
/* Clear current attachments state. */
this->remove_all_attachments();
@ -738,22 +727,25 @@ void MTLFrameBuffer::update_attachments(bool update_viewport)
}
}
/* Check whether the first attachment is SRGB. */
/* Extract attachment size and determine if framebuffer is SRGB. */
if (first_attachment != GPU_FB_MAX_ATTACHMENT) {
srgb_ = (first_attachment_mtl.texture->format_get() == GPU_SRGB8_A8);
}
/* 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_) {
this->viewport_set(t_viewport);
this->scissor_set(t_viewport);
/* Ensure size is correctly assigned. */
GPUAttachment &attach = attachments_[first_attachment];
int size[3];
GPU_texture_get_mipmap_size(attach.tex, attach.mip, size);
this->size_set(size[0], size[1]);
srgb_ = (GPU_texture_format(attach.tex) == GPU_SRGB8_A8);
}
else {
this->viewport_reset();
this->scissor_reset();
/* Empty frame-buffer. */
width_ = 0;
height_ = 0;
}
/* Reset viewport and Scissor. */
this->viewport_reset();
this->scissor_reset();
/* We have now updated our internal structures. */
dirty_attachments_ = false;
}