Skip to content

Commit

Permalink
Label pipeline state for easier debugging and profiling
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-Vasile committed May 26, 2024
1 parent de72f46 commit 67e1e06
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 51 deletions.
18 changes: 9 additions & 9 deletions burstphoto/align/align.swift
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import Foundation
import MetalPerformanceShaders

let avg_pool_state = try! device.makeComputePipelineState(function: mfl.makeFunction(name: "avg_pool")!)
let avg_pool_normalization_state = try! device.makeComputePipelineState(function: mfl.makeFunction(name: "avg_pool_normalization")!)
let compute_tile_differences_state = try! device.makeComputePipelineState(function: mfl.makeFunction(name: "compute_tile_differences")!)
let compute_tile_differences25_state = try! device.makeComputePipelineState(function: mfl.makeFunction(name: "compute_tile_differences25")!)
let compute_tile_differences_exposure25_state = try! device.makeComputePipelineState(function: mfl.makeFunction(name: "compute_tile_differences_exposure25")!)
let correct_upsampling_error_state = try! device.makeComputePipelineState(function: mfl.makeFunction(name: "correct_upsampling_error")!)
let find_best_tile_alignment_state = try! device.makeComputePipelineState(function: mfl.makeFunction(name: "find_best_tile_alignment")!)
let warp_texture_bayer_state = try! device.makeComputePipelineState(function: mfl.makeFunction(name: "warp_texture_bayer")!)
let warp_texture_xtrans_state = try! device.makeComputePipelineState(function: mfl.makeFunction(name: "warp_texture_xtrans")!)
let avg_pool_state = create_pipeline(with_function_name: "avg_pool", and_label: "Avg Pool")
let avg_pool_normalization_state = create_pipeline(with_function_name: "avg_pool_normalization", and_label: "Avg Pool (Normalized)")
let compute_tile_differences_state = create_pipeline(with_function_name: "compute_tile_differences", and_label: "Compute Tile Difference")
let compute_tile_differences25_state = create_pipeline(with_function_name: "compute_tile_differences25", and_label: "Compute Tile Difference (N=25)")
let compute_tile_differences_exposure25_state = create_pipeline(with_function_name: "compute_tile_differences_exposure25", and_label: "Compute Tile Difference (N=25) (Exposure)")
let correct_upsampling_error_state = create_pipeline(with_function_name: "correct_upsampling_error", and_label: "Correct Upsampling Error")
let find_best_tile_alignment_state = create_pipeline(with_function_name: "find_best_tile_alignment", and_label: "Find Best Tile Alignment")
let warp_texture_bayer_state = create_pipeline(with_function_name: "warp_texture_bayer", and_label: "Warp Texture (Bayer)")
let warp_texture_xtrans_state = create_pipeline(with_function_name: "warp_texture_xtrans", and_label: "Warp Texture (XTrans)")

func align_texture(_ ref_pyramid: [MTLTexture], _ comp_texture: MTLTexture, _ downscale_factor_array: Array<Int>, _ tile_size_array: Array<Int>, _ search_dist_array: Array<Int>, _ uniform_exposure: Bool, _ black_level_mean: Double, _ color_factors3: Array<Double>) -> MTLTexture {

Expand Down
8 changes: 4 additions & 4 deletions burstphoto/exposure/exposure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import Foundation
import MetalPerformanceShaders

let correct_exposure_state = try! device.makeComputePipelineState(function: mfl.makeFunction(name: "correct_exposure")!)
let correct_exposure_linear_state = try! device.makeComputePipelineState(function: mfl.makeFunction(name: "correct_exposure_linear")!)
let max_x_state = try! device.makeComputePipelineState(function: mfl.makeFunction(name: "max_x")!)
let max_y_state = try! device.makeComputePipelineState(function: mfl.makeFunction(name: "max_y")!)
let correct_exposure_state = create_pipeline(with_function_name: "correct_exposure", and_label: "Correct Exposure (Non-linear)")
let correct_exposure_linear_state = create_pipeline(with_function_name: "correct_exposure_linear", and_label: "Correct Exposure (Linear)")
let max_x_state = create_pipeline(with_function_name: "max_x", and_label: "Maximum (X-Direction)")
let max_y_state = create_pipeline(with_function_name: "max_y", and_label: "Maximum (Y-Direction)")

/// Apply tone mapping if the reference image is underexposed.
/// A curve is applied to lift the shadows and protect the highlights from burning.
Expand Down
24 changes: 12 additions & 12 deletions burstphoto/merge/frequency.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
import Foundation
import MetalPerformanceShaders

let merge_frequency_domain_state = try! device.makeComputePipelineState(function: mfl.makeFunction(name: "merge_frequency_domain")!)
let merge_frequency_domain_state = create_pipeline(with_function_name: "merge_frequency_domain", and_label: "Frequency Domain Merge")

let calculate_abs_diff_rgba_state = try! device.makeComputePipelineState(function: mfl.makeFunction(name: "calculate_abs_diff_rgba")!)
let calculate_highlights_norm_rgba_state = try! device.makeComputePipelineState(function: mfl.makeFunction(name: "calculate_highlights_norm_rgba")!)
let calculate_mismatch_rgba_state = try! device.makeComputePipelineState(function: mfl.makeFunction(name: "calculate_mismatch_rgba")!)
let calculate_rms_rgba_state = try! device.makeComputePipelineState(function: mfl.makeFunction(name: "calculate_rms_rgba")!)
let deconvolute_frequency_domain_state = try! device.makeComputePipelineState(function: mfl.makeFunction(name: "deconvolute_frequency_domain")!)
let normalize_mismatch_state = try! device.makeComputePipelineState(function: mfl.makeFunction(name: "normalize_mismatch")!)
let reduce_artifacts_tile_border_state = try! device.makeComputePipelineState(function: mfl.makeFunction(name: "reduce_artifacts_tile_border")!)
let calculate_abs_diff_rgba_state = create_pipeline(with_function_name: "calculate_abs_diff_rgba", and_label: "Calculate Abs Diff RGBA")
let calculate_highlights_norm_rgba_state = create_pipeline(with_function_name: "calculate_highlights_norm_rgba", and_label: "Calculate Highlights Norm RGBA")
let calculate_mismatch_rgba_state = create_pipeline(with_function_name: "calculate_mismatch_rgba", and_label: "Calculate Mismatch RGBA")
let calculate_rms_rgba_state = create_pipeline(with_function_name: "calculate_rms_rgba", and_label: "Calculate RMS RGBA")
let deconvolute_frequency_domain_state = create_pipeline(with_function_name: "deconvolute_frequency_domain", and_label: "Deconvolute Frequency Domain")
let normalize_mismatch_state = create_pipeline(with_function_name: "normalize_mismatch", and_label: "Normalize Mismatch")
let reduce_artifacts_tile_border_state = create_pipeline(with_function_name: "reduce_artifacts_tile_border", and_label: "Reduce Artifacts at Tile Borders")

let backward_dft_state = try! device.makeComputePipelineState(function: mfl.makeFunction(name: "backward_dft")!)
let backward_fft_state = try! device.makeComputePipelineState(function: mfl.makeFunction(name: "backward_fft")!)
let forward_dft_state = try! device.makeComputePipelineState(function: mfl.makeFunction(name: "forward_dft")!)
let forward_fft_state = try! device.makeComputePipelineState(function: mfl.makeFunction(name: "forward_fft")!)
let backward_dft_state = create_pipeline(with_function_name: "backward_dft", and_label: "Backwards Optimized Fast Fourier Transform")
let backward_fft_state = create_pipeline(with_function_name: "backward_fft", and_label: "Backwards Discrete Fourier Transform")
let forward_dft_state = create_pipeline(with_function_name: "forward_dft", and_label: "Forwards Optimized Fast Fourier Transform")
let forward_fft_state = create_pipeline(with_function_name: "forward_fft", and_label: "Forwards Discrete Fourier Transform")


/// Convenience function for the frequency-based merging approach.
Expand Down
4 changes: 2 additions & 2 deletions burstphoto/merge/spatial.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import Foundation
import MetalPerformanceShaders


let color_difference_state = try! device.makeComputePipelineState(function: mfl.makeFunction(name: "color_difference")!)
let compute_merge_weight_state = try! device.makeComputePipelineState(function: mfl.makeFunction(name: "compute_merge_weight")!)
let color_difference_state = create_pipeline(with_function_name: "color_difference", and_label: "Color Difference")
let compute_merge_weight_state = create_pipeline(with_function_name: "compute_merge_weight", and_label: "Compute Merging Weight")


/// Convenience function for the spatial merging approach
Expand Down
8 changes: 8 additions & 0 deletions burstphoto/misc/helpers.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import MetalPerformanceShaders

/// Returns the amount of free disk space left on the system.
///
Expand All @@ -19,3 +20,10 @@ func systemFreeDiskSpace() -> Double {
return 0.0
}
}

func create_pipeline(with_function_name function_name: String, and_label label: String) -> MTLComputePipelineState {
let _descriptor = MTLComputePipelineDescriptor()
_descriptor.computeFunction = mfl.makeFunction(name: function_name)
_descriptor.label = label
return try! device.makeComputePipelineState(descriptor: _descriptor, options: []).0
}
48 changes: 24 additions & 24 deletions burstphoto/texture/texture.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@
import Foundation
import MetalPerformanceShaders

let add_texture_state = try! device.makeComputePipelineState(function: mfl.makeFunction(name: "add_texture")!)
let add_texture_exposure_state = try! device.makeComputePipelineState(function: mfl.makeFunction(name: "add_texture_exposure")!)
let add_texture_highlights_state = try! device.makeComputePipelineState(function: mfl.makeFunction(name: "add_texture_highlights")!)
let add_texture_uint16_state = try! device.makeComputePipelineState(function: mfl.makeFunction(name: "add_texture_uint16")!)
let add_texture_weighted_state = try! device.makeComputePipelineState(function: mfl.makeFunction(name: "add_texture_weighted")!)
let blur_mosaic_texture_state = try! device.makeComputePipelineState(function: mfl.makeFunction(name: "blur_mosaic_texture")!)
let calculate_weight_highlights_state = try! device.makeComputePipelineState(function: mfl.makeFunction(name: "calculate_weight_highlights")!)
let convert_float_to_uint16_state = try! device.makeComputePipelineState(function: mfl.makeFunction(name: "convert_float_to_uint16")!)
let convert_to_bayer_state = try! device.makeComputePipelineState(function: mfl.makeFunction(name: "convert_to_bayer")!)
let convert_to_rgba_state = try! device.makeComputePipelineState(function: mfl.makeFunction(name: "convert_to_rgba")!)
let copy_texture_state = try! device.makeComputePipelineState(function: mfl.makeFunction(name: "copy_texture")!)
let crop_texture_state = try! device.makeComputePipelineState(function: mfl.makeFunction(name: "crop_texture")!)
let divide_buffer_state = try! device.makeComputePipelineState(function: mfl.makeFunction(name: "divide_buffer")!)
let sum_divide_buffer_state = try! device.makeComputePipelineState(function: mfl.makeFunction(name: "sum_divide_buffer")!)
let fill_with_zeros_state = try! device.makeComputePipelineState(function: mfl.makeFunction(name: "fill_with_zeros")!)
let find_hotpixels_bayer_state = try! device.makeComputePipelineState(function: mfl.makeFunction(name: "find_hotpixels_bayer")!)
let find_hotpixels_xtrans_state = try! device.makeComputePipelineState(function: mfl.makeFunction(name: "find_hotpixels_xtrans")!)
let normalize_texture_state = try! device.makeComputePipelineState(function: mfl.makeFunction(name: "normalize_texture")!)
let prepare_texture_bayer_state = try! device.makeComputePipelineState(function: mfl.makeFunction(name: "prepare_texture_bayer")!)
let sum_rect_columns_float_state = try! device.makeComputePipelineState(function: mfl.makeFunction(name: "sum_rect_columns_float")!)
let sum_rect_columns_uint_state = try! device.makeComputePipelineState(function: mfl.makeFunction(name: "sum_rect_columns_uint")!)
let sum_row_state = try! device.makeComputePipelineState(function: mfl.makeFunction(name: "sum_row")!)
let upsample_bilinear_float_state = try! device.makeComputePipelineState(function: mfl.makeFunction(name: "upsample_bilinear_float")!)
let upsample_nearest_int_state = try! device.makeComputePipelineState(function: mfl.makeFunction(name: "upsample_nearest_int")!)
let add_texture_state = create_pipeline(with_function_name: "add_texture", and_label: "Add Texture")
let add_texture_exposure_state = create_pipeline(with_function_name: "add_texture_exposure", and_label: "Add Texture (Exposure)")
let add_texture_highlights_state = create_pipeline(with_function_name: "add_texture_highlights", and_label: "Add Texture (Highlights)")
let add_texture_uint16_state = create_pipeline(with_function_name: "add_texture_uint16", and_label: "Add Texture (UInt16")
let add_texture_weighted_state = create_pipeline(with_function_name: "add_texture_weighted", and_label: "Add Texture (Weighted)")
let blur_mosaic_texture_state = create_pipeline(with_function_name: "blur_mosaic_texture", and_label: "Blur Mosaic Texture")
let calculate_weight_highlights_state = create_pipeline(with_function_name: "calculate_weight_highlights", and_label: "Calculate Highlight Weights")
let convert_float_to_uint16_state = create_pipeline(with_function_name: "convert_float_to_uint16", and_label: "Convert Float to UInt16")
let convert_to_bayer_state = create_pipeline(with_function_name: "convert_to_bayer", and_label: "Convert RGBA to Bayer")
let convert_to_rgba_state = create_pipeline(with_function_name: "convert_to_rgba", and_label: "Covert Bayer to RGBA")
let copy_texture_state = create_pipeline(with_function_name: "copy_texture", and_label: "Copy Texture")
let crop_texture_state = create_pipeline(with_function_name: "crop_texture", and_label: "Crop Texture")
let divide_buffer_state = create_pipeline(with_function_name: "divide_buffer", and_label: "Divide Buffer Per Sub Pixel")
let sum_divide_buffer_state = create_pipeline(with_function_name: "sum_divide_buffer", and_label: "Sum and Divide Buffer Total")
let fill_with_zeros_state = create_pipeline(with_function_name: "fill_with_zeros", and_label: "Fill With Zeros")
let find_hotpixels_bayer_state = create_pipeline(with_function_name: "find_hotpixels_bayer", and_label: "Find Hotpixels (Bayer)")
let find_hotpixels_xtrans_state = create_pipeline(with_function_name: "find_hotpixels_xtrans", and_label: "Find Hotpixels (XTrans)")
let normalize_texture_state = create_pipeline(with_function_name: "normalize_texture", and_label: "Normalize Texture")
let prepare_texture_bayer_state = create_pipeline(with_function_name: "prepare_texture_bayer", and_label: "Prepare Texture (Bayer)")
let sum_rect_columns_float_state = create_pipeline(with_function_name: "sum_rect_columns_float", and_label: "Sum Along Columns Inside A Rect (Float)")
let sum_rect_columns_uint_state = create_pipeline(with_function_name: "sum_rect_columns_uint", and_label: "Sum Along Columns Inside A Rect (UInt)")
let sum_row_state = create_pipeline(with_function_name: "sum_row", and_label: "Sum Along Rows")
let upsample_bilinear_float_state = create_pipeline(with_function_name: "upsample_bilinear_float", and_label: "Upsample (Bilinear) (Float)")
let upsample_nearest_int_state = create_pipeline(with_function_name: "upsample_nearest_int", and_label: "Upsample (Nearest Neighbour) (Int)")

enum UpsampleType {
case Bilinear
Expand Down

0 comments on commit 67e1e06

Please sign in to comment.