@@ -525,7 +525,7 @@ struct vk_device_struct {
525525 vk_pipeline pipeline_add_id_f32;
526526
527527 vk_pipeline pipeline_concat_f32, pipeline_concat_f16, pipeline_concat_i32;
528- vk_pipeline pipeline_upscale_nearest_f32, pipeline_upscale_bilinear_f32, pipeline_upscale_bilinear_ac_f32 ;
528+ vk_pipeline pipeline_upscale_nearest_f32, pipeline_upscale_bilinear_f32;
529529 vk_pipeline pipeline_scale_f32;
530530 vk_pipeline pipeline_sqr_f32;
531531 vk_pipeline pipeline_sqrt_f32;
@@ -1240,6 +1240,7 @@ struct vk_op_upscale_push_constants {
12401240 uint32_t nb00; uint32_t nb01; uint32_t nb02; uint32_t nb03;
12411241 uint32_t ne10; uint32_t ne11; uint32_t ne12; uint32_t ne13;
12421242 float sf0; float sf1; float sf2; float sf3;
1243+ float pixel_offset;
12431244};
12441245
12451246struct vk_op_sum_rows_push_constants
@@ -3498,7 +3499,6 @@ static void ggml_vk_load_shaders(vk_device& device) {
34983499
34993500 ggml_vk_create_pipeline(device, device->pipeline_upscale_nearest_f32, "upscale_f32", upscale_f32_len, upscale_f32_data, "main", 2, sizeof(vk_op_upscale_push_constants), {512, 1, 1}, {GGML_SCALE_MODE_NEAREST}, 1);
35003501 ggml_vk_create_pipeline(device, device->pipeline_upscale_bilinear_f32, "upscale_f32", upscale_f32_len, upscale_f32_data, "main", 2, sizeof(vk_op_upscale_push_constants), {512, 1, 1}, {GGML_SCALE_MODE_BILINEAR}, 1);
3501- ggml_vk_create_pipeline(device, device->pipeline_upscale_bilinear_ac_f32, "upscale_f32", upscale_f32_len, upscale_f32_data, "main", 2, sizeof(vk_op_upscale_push_constants), {512, 1, 1}, {GGML_SCALE_MODE_BILINEAR | GGML_SCALE_FLAG_ALIGN_CORNERS}, 1);
35023502
35033503 ggml_vk_create_pipeline(device, device->pipeline_scale_f32, "scale_f32", scale_f32_len, scale_f32_data, "main", 2, sizeof(vk_op_unary_push_constants), {512, 1, 1}, {}, 1);
35043504
@@ -7855,14 +7855,12 @@ static vk_pipeline ggml_vk_op_get_pipeline(ggml_backend_vk_context * ctx, const
78557855 return nullptr;
78567856 case GGML_OP_UPSCALE:
78577857 if (src0->type == GGML_TYPE_F32 && dst->type == GGML_TYPE_F32) {
7858- int mode = ggml_get_op_params_i32(dst, 0);
7858+ ggml_scale_mode mode = (ggml_scale_mode)( ggml_get_op_params_i32(dst, 0) & 0xFF );
78597859 switch (mode) {
78607860 case GGML_SCALE_MODE_NEAREST:
78617861 return ctx->device->pipeline_upscale_nearest_f32;
78627862 case GGML_SCALE_MODE_BILINEAR:
78637863 return ctx->device->pipeline_upscale_bilinear_f32;
7864- case GGML_SCALE_MODE_BILINEAR | GGML_SCALE_FLAG_ALIGN_CORNERS:
7865- return ctx->device->pipeline_upscale_bilinear_ac_f32;
78667864 }
78677865 }
78687866 return nullptr;
@@ -9351,22 +9349,26 @@ static void ggml_vk_upscale(ggml_backend_vk_context * ctx, vk_context& subctx, c
93519349 const uint32_t src0_type_size = ggml_type_size(src0->type);
93529350 const uint32_t mode = (uint32_t)ggml_get_op_params_i32(dst, 0);
93539351
9354- float sf0 = (float)dst->ne[0] / src0->ne[0];
9355- float sf1 = (float)dst->ne[1] / src0->ne[1];
9356- float sf2 = (float)dst->ne[2] / src0->ne[2];
9357- float sf3 = (float)dst->ne[3] / src0->ne[3];
9352+ GGML_TENSOR_UNARY_OP_LOCALS
9353+
9354+ float sf0 = (float)ne0 / ne00;
9355+ float sf1 = (float)ne1 / ne01;
9356+ float sf2 = (float)ne2 / ne02;
9357+ float sf3 = (float)ne3 / ne03;
9358+ float pixel_offset = 0.5f;
93589359
93599360 if (mode & GGML_SCALE_FLAG_ALIGN_CORNERS) {
9360- sf0 = (float)(dst->ne[0] - 1) / (src0->ne[0] - 1);
9361- sf1 = (float)(dst->ne[1] - 1) / (src0->ne[1] - 1);
9361+ sf0 = ne0 > 1 && ne00 > 1 ? (float)(ne0 - 1) / (ne00 - 1) : sf0;
9362+ sf1 = ne1 > 1 && ne01 > 1 ? (float)(ne1 - 1) / (ne01 - 1) : sf1;
9363+ pixel_offset = 0.0f;
93629364 }
93639365
93649366 ggml_vk_op_f32<vk_op_upscale_push_constants>(ctx, subctx, src0, nullptr, nullptr, dst, GGML_OP_UPSCALE, {
93659367 (uint32_t)ggml_nelements(dst), 0, 0,
9366- (uint32_t)src0->ne[0] , (uint32_t)src0->ne[1] ,
9367- (uint32_t)src0->nb[0] / src0_type_size, (uint32_t)src0->nb[1] / src0_type_size, (uint32_t)src0->nb[2] / src0_type_size, (uint32_t)src0->nb[3] / src0_type_size,
9368- (uint32_t)dst->ne[0] , (uint32_t)dst->ne[1] , (uint32_t)dst->ne[2], (uint32_t)dst->ne[3] ,
9369- sf0, sf1, sf2, sf3,
9368+ (uint32_t)ne00 , (uint32_t)ne01 ,
9369+ (uint32_t)nb00 / src0_type_size, (uint32_t)nb01 / src0_type_size, (uint32_t)nb02 / src0_type_size, (uint32_t)nb03 / src0_type_size,
9370+ (uint32_t)ne0 , (uint32_t)ne1 , (uint32_t)ne2, (uint32_t)ne3 ,
9371+ sf0, sf1, sf2, sf3, pixel_offset
93709372 }, dryrun);
93719373}
93729374
0 commit comments