Metal: Add AMD support for subpass transition #119784

Merged
Jeroen Bakker merged 5 commits from Jason-Fielder/blender:MetalAMDSubpassTransitionSupport into main 2024-04-11 15:24:05 +02:00
11 changed files with 160 additions and 56 deletions
Showing only changes of commit 5211c56297 - Show all commits

View File

@ -51,7 +51,6 @@ void update_autoflags_fcurve_direct(FCurve *fcu, PropertyRNA *prop);
int insert_keyframe(Main *bmain,
ReportList *reports,
ID *id,
bAction *act,
const char group[],
const char rna_path[],
int array_index,

View File

@ -546,7 +546,6 @@ static void generate_keyframe_reports_from_result(ReportList *reports,
int insert_keyframe(Main *bmain,
ReportList *reports,
ID *id,
bAction *act,
const char group[],
const char rna_path[],
int array_index,
@ -577,18 +576,15 @@ int insert_keyframe(Main *bmain,
return 0;
}
/* If no action is provided, keyframe to the default one attached to this ID-block. */
bAction *act = id_action_ensure(bmain, id);
if (act == nullptr) {
act = id_action_ensure(bmain, id);
if (act == nullptr) {
BKE_reportf(reports,
RPT_ERROR,
"Could not insert keyframe, as this type does not support animation data (ID = "
"%s, path = %s)",
id->name,
rna_path);
return 0;
}
BKE_reportf(reports,
RPT_ERROR,
"Could not insert keyframe, as this type does not support animation data (ID = "
"%s, path = %s)",
id->name,
rna_path);
return 0;
}
/* Apply NLA-mapping to frame to use (if applicable). */

View File

@ -138,7 +138,6 @@ void autokeyframe_object(bContext *C, Scene *scene, Object *ob, Span<std::string
insert_keyframe(bmain,
reports,
id,
adt->action,
(fcu->grp ? fcu->grp->name : nullptr),
fcu->rna_path,
fcu->array_index,
@ -267,7 +266,6 @@ void autokeyframe_pose_channel(bContext *C,
blender::animrig::insert_keyframe(bmain,
reports,
id,
act,
((fcu->grp) ? (fcu->grp->name) : (nullptr)),
fcu->rna_path,
fcu->array_index,
@ -361,7 +359,6 @@ bool autokeyframe_property(bContext *C,
changed = insert_keyframe(bmain,
reports,
id,
action,
(fcu && fcu->grp) ? fcu->grp->name : nullptr,
fcu ? fcu->rna_path : (path ? path->c_str() : nullptr),
rnaindex,

View File

@ -662,16 +662,24 @@ void smooth_fcurve_segment(FCurve *fcu,
}
/* ---------------- */
void ease_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float factor)
static float ease_sigmoid_function(const float x, const float width, const float shift)
{
const float x_shift = (x - shift) * width;
const float y = x_shift / sqrt(1 + pow2f(x_shift));
/* Normalize result to 0-1. */
return (y + 1) * 0.5f;
}
void ease_fcurve_segment(FCurve *fcu,
FCurveSegment *segment,
const float factor,
const float width)
{
const BezTriple *left_key = fcurve_segment_start_get(fcu, segment->start_index);
const float left_x = left_key->vec[1][0];
const float left_y = left_key->vec[1][1];
const BezTriple *right_key = fcurve_segment_end_get(fcu, segment->start_index + segment->length);
const float key_x_range = right_key->vec[1][0] - left_x;
const float key_y_range = right_key->vec[1][1] - left_y;
const float key_x_range = right_key->vec[1][0] - left_key->vec[1][0];
const float key_y_range = right_key->vec[1][1] - left_key->vec[1][1];
/* Happens if there is only 1 key on the FCurve. Needs to be skipped because it
* would be a divide by 0. */
@ -679,24 +687,20 @@ void ease_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float factor
return;
}
/* In order to have a curve that favors the right key, the curve needs to be mirrored in x and y.
* Having an exponent that is a fraction of 1 would produce a similar but inferior result. */
const bool inverted = factor > 0;
const float exponent = 1 + fabs(factor) * 4;
/* Using the factor on the xshift we are basicaly moving the curve horizontaly. */
const float shift = -factor;
const float y_min = ease_sigmoid_function(-1, width, shift);
const float y_max = ease_sigmoid_function(1, width, shift);
for (int i = segment->start_index; i < segment->start_index + segment->length; i++) {
/* For easy calculation of the curve, the values are normalized. */
const float normalized_x = (fcu->bezt[i].vec[1][0] - left_x) / key_x_range;
/* Mapping the x-location of the key within the segment to a -1/1 range. */
const float x = ((fcu->bezt[i].vec[1][0] - left_key->vec[1][0]) / key_x_range) * 2 - 1;
const float y = ease_sigmoid_function(x, width, shift);
/* Normalizing the y value to the min and max to ensure that the keys at the end are not
* detached from the rest of the animation. */
const float blend = (y - y_min) * (1 / (y_max - y_min));
float normalized_y = 0;
if (inverted) {
normalized_y = 1 - pow(1 - normalized_x, exponent);
}
else {
normalized_y = pow(normalized_x, exponent);
}
const float key_y_value = left_y + normalized_y * key_y_range;
const float key_y_value = left_key->vec[1][1] + key_y_range * blend;
BKE_fcurve_keyframe_move_value_with_handles(&fcu->bezt[i], key_y_value);
}
}

View File

@ -1010,7 +1010,6 @@ static int insert_key_button_exec(bContext *C, wmOperator *op)
changed = (blender::animrig::insert_keyframe(bmain,
op->reports,
ptr.owner_id,
nullptr,
group,
path->c_str(),
index,

View File

@ -1079,7 +1079,6 @@ static int insert_key_to_keying_set_path(bContext *C,
keyed_channels += blender::animrig::insert_keyframe(bmain,
reports,
keyingset_path->id,
nullptr,
groupname,
keyingset_path->rna_path,
array_index,

View File

@ -470,7 +470,10 @@ void smooth_fcurve_segment(FCurve *fcu,
float factor,
int kernel_size,
double *kernel);
void ease_fcurve_segment(FCurve *fcu, FCurveSegment *segment, float factor);
/** Snap the keys on the given FCurve segment to an S-Curve. By modifying the `factor` the part of
* the S-Curve that the keys are snapped to is moved on the x-axis.*/
void ease_fcurve_segment(FCurve *fcu, FCurveSegment *segment, float factor, float width);
enum tShearDirection {
SHEAR_FROM_LEFT = 1,
SHEAR_FROM_RIGHT,

View File

@ -840,7 +840,6 @@ static void insert_fcurve_key(bAnimContext *ac,
insert_keyframe(ac->bmain,
reports,
ale->id,
nullptr,
((fcu->grp) ? (fcu->grp->name) : (nullptr)),
fcu->rna_path,
fcu->array_index,

View File

@ -210,7 +210,6 @@ static void insert_graph_keys(bAnimContext *ac, eGraphKeys_InsertKey_Types mode)
insert_keyframe(ac->bmain,
reports,
ale->id,
nullptr,
((fcu->grp) ? (fcu->grp->name) : (nullptr)),
fcu->rna_path,
fcu->array_index,

View File

@ -918,22 +918,120 @@ void GRAPH_OT_blend_to_default(wmOperatorType *ot)
/** \name Ease Operator
* \{ */
static void ease_graph_keys(bAnimContext *ac, const float factor)
static void ease_graph_keys(bAnimContext *ac, const float factor, const float width)
{
apply_fcu_segment_function(ac, factor, ease_fcurve_segment);
ListBase anim_data = {NULL, NULL};
ANIM_animdata_filter(
ac, &anim_data, OPERATOR_DATA_FILTER, ac->data, eAnimCont_Types(ac->datatype));
LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) {
FCurve *fcu = (FCurve *)ale->key_data;
ListBase segments = find_fcurve_segments(fcu);
LISTBASE_FOREACH (FCurveSegment *, segment, &segments) {
ease_fcurve_segment(fcu, segment, factor, width);
}
ale->update |= ANIM_UPDATE_DEFAULT;
BLI_freelistN(&segments);
}
ANIM_animdata_update(ac, &anim_data);
ANIM_animdata_freelist(&anim_data);
}
static void ease_draw_status_header(bContext *C, wmOperator *op)
{
char status_str[UI_MAX_DRAW_STR];
char mode_str[32];
char slider_string[UI_MAX_DRAW_STR];
tGraphSliderOp *gso = static_cast<tGraphSliderOp *>(op->customdata);
ED_slider_status_string_get(gso->slider, slider_string, UI_MAX_DRAW_STR);
/* Operator specific functionality that extends beyond the slider. */
char op_slider_string[UI_MAX_DRAW_STR];
if (strcmp(RNA_property_identifier(gso->factor_prop), "factor") == 0) {
SNPRINTF(op_slider_string, "%s | %s", slider_string, IFACE_("[TAB] - Modify Sharpness"));
}
else {
SNPRINTF(op_slider_string, "%s | %s", slider_string, IFACE_("[TAB] - Modify Curve Bend"));
}
STRNCPY(mode_str, IFACE_("Ease Keys"));
if (hasNumInput(&gso->num)) {
char str_ofs[NUM_STR_REP_LEN];
outputNumInput(&gso->num, str_ofs, &gso->scene->unit);
SNPRINTF(status_str, "%s: %s", mode_str, str_ofs);
}
else {
SNPRINTF(status_str, "%s: %s", mode_str, op_slider_string);
}
ED_workspace_status_text(C, status_str);
}
static void ease_modal_update(bContext *C, wmOperator *op)
{
tGraphSliderOp *gso = static_cast<tGraphSliderOp *>(op->customdata);
common_draw_status_header(C, gso, "Ease Keys");
ease_draw_status_header(C, op);
/* Reset keyframes to the state at invoke. */
reset_bezts(gso);
const float factor = slider_factor_get_and_remember(op);
ease_graph_keys(&gso->ac, factor);
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, nullptr);
float factor;
float width;
if (strcmp(RNA_property_identifier(gso->factor_prop), "factor") == 0) {
factor = slider_factor_get_and_remember(op);
width = RNA_float_get(op->ptr, "sharpness");
}
else {
factor = RNA_float_get(op->ptr, "factor");
width = slider_factor_get_and_remember(op);
}
ease_graph_keys(&gso->ac, factor, width);
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
}
static int ease_modal(bContext *C, wmOperator *op, const wmEvent *event)
{
if (event->val != KM_PRESS) {
return graph_slider_modal(C, op, event);
}
switch (event->type) {
case EVT_TABKEY: {
tGraphSliderOp *gso = static_cast<tGraphSliderOp *>(op->customdata);
if (strcmp(RNA_property_identifier(gso->factor_prop), "factor") == 0) {
/* Switch to sharpness. */
ED_slider_allow_overshoot_set(gso->slider, false, true);
ED_slider_factor_bounds_set(gso->slider, 0.001f, 10);
ED_slider_factor_set(gso->slider, RNA_float_get(op->ptr, "sharpness"));
ED_slider_mode_set(gso->slider, SLIDER_MODE_FLOAT);
ED_slider_unit_set(gso->slider, "");
gso->factor_prop = RNA_struct_find_property(op->ptr, "sharpness");
}
else {
ED_slider_allow_overshoot_set(gso->slider, false, false);
ED_slider_factor_bounds_set(gso->slider, -1, 1);
ED_slider_factor_set(gso->slider, 0.0f);
ED_slider_factor_set(gso->slider, RNA_float_get(op->ptr, "factor"));
ED_slider_mode_set(gso->slider, SLIDER_MODE_PERCENT);
ED_slider_unit_set(gso->slider, "%");
gso->factor_prop = RNA_struct_find_property(op->ptr, "factor");
}
ease_modal_update(C, op);
break;
}
default:
return graph_slider_modal(C, op, event);
}
return OPERATOR_RUNNING_MODAL;
}
static int ease_invoke(bContext *C, wmOperator *op, const wmEvent *event)
@ -947,7 +1045,8 @@ static int ease_invoke(bContext *C, wmOperator *op, const wmEvent *event)
tGraphSliderOp *gso = static_cast<tGraphSliderOp *>(op->customdata);
gso->modal_update = ease_modal_update;
gso->factor_prop = RNA_struct_find_property(op->ptr, "factor");
common_draw_status_header(C, gso, "Ease Keys");
ease_draw_status_header(C, op);
ED_slider_allow_overshoot_set(gso->slider, false, false);
ED_slider_factor_bounds_set(gso->slider, -1, 1);
ED_slider_factor_set(gso->slider, 0.0f);
@ -958,17 +1057,16 @@ static int ease_exec(bContext *C, wmOperator *op)
{
bAnimContext ac;
/* Get editor data. */
if (ANIM_animdata_get_context(C, &ac) == 0) {
return OPERATOR_CANCELLED;
}
const float factor = RNA_float_get(op->ptr, "factor");
const float width = RNA_float_get(op->ptr, "sharpness");
ease_graph_keys(&ac, factor);
ease_graph_keys(&ac, factor, width);
/* Set notifier that keyframes have changed. */
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, nullptr);
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
return OPERATOR_FINISHED;
}
@ -982,7 +1080,7 @@ void GRAPH_OT_ease(wmOperatorType *ot)
/* API callbacks. */
ot->invoke = ease_invoke;
ot->modal = graph_slider_modal;
ot->modal = ease_modal;
ot->exec = ease_exec;
ot->poll = graphop_editable_keyframes_poll;
@ -995,9 +1093,19 @@ void GRAPH_OT_ease(wmOperatorType *ot)
-FLT_MAX,
FLT_MAX,
"Curve Bend",
"Control the bend of the curve",
"Defines if the keys should be aligned on an ease-in or ease-out curve",
-1.0f,
1.0f);
RNA_def_float(ot->srna,
"sharpness",
2.0f,
0.001f,
FLT_MAX,
"Sharpness",
"Higher values make the change more abrupt",
0.01f,
16.0f);
}
/** \} */
@ -2468,3 +2576,5 @@ void GRAPH_OT_scale_from_neighbor(wmOperatorType *ot)
"Reference Key",
"Which end of the segment to use as a reference to scale from");
}
/** \} */

View File

@ -387,7 +387,6 @@ PyObject *pyrna_struct_keyframe_insert(BPy_StructRNA *self, PyObject *args, PyOb
result = (blender::animrig::insert_keyframe(G_MAIN,
&reports,
id,
nullptr,
group_name,
path_full,
index,