mirror of
https://github.com/Chaoscaot/schemsearch.git
synced 2025-11-05 05:54:02 +01:00
Enable lazy initialization for OpenCL availability check
Replaced direct calls to `ocl_available()` with a `OnceLock` for thread-safe and efficient lazy initialization. This avoids redundant checks and improves performance in scenarios where OpenCL is not repeatedly required.
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
use std::sync::OnceLock;
|
||||
use math::round::ceil;
|
||||
use schemsearch_common::Match;
|
||||
use schemsearch_files::SpongeSchematic;
|
||||
@ -5,6 +6,8 @@ use schemsearch_ocl_matcher::{ocl_available, ocl_search};
|
||||
use crate::{SearchBehavior};
|
||||
use crate::pattern_mapper::{match_palette, match_palette_adapt};
|
||||
|
||||
const OPENCL_AVAILABLE: OnceLock<bool> = OnceLock::new();
|
||||
|
||||
pub fn search(
|
||||
schem: SpongeSchematic,
|
||||
pattern_schem: &SpongeSchematic,
|
||||
@ -41,7 +44,7 @@ pub fn search(
|
||||
let schem_height = schem.height as usize;
|
||||
let schem_length = schem.length as usize;
|
||||
|
||||
if !search_behavior.use_cpu && ocl_available() {
|
||||
if !search_behavior.use_cpu && *OPENCL_AVAILABLE.get_or_init(|| ocl_available()) {
|
||||
return ocl_search(schem_data.as_slice(), [schem_width, schem_height, schem_length], pattern_schem.block_data.as_slice(), [pattern_width, pattern_height, pattern_length], *air_id, search_behavior).unwrap()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user