godot/thirdparty/basis_universal/encoder/basisu_opencl.h

// basisu_opencl.h
// Copyright (C) 2019-2024 Binomial LLC. All Rights Reserved.
//
// Note: Undefine or set BASISU_SUPPORT_OPENCL to 0 to completely OpenCL support.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include "../transcoder/basisu.h"
#include "basisu_enc.h"
#include "basisu_etc.h"

namespace basisu
{
	bool opencl_init(bool force_serialization);
	void opencl_deinit();
	bool opencl_is_available();

	struct opencl_context;

	// Each thread calling OpenCL should have its own opencl_context_ptr. This corresponds to a OpenCL command queue. (Confusingly, we only use a single OpenCL device "context".)
	opencl_context_ptr;

	opencl_context_ptr opencl_create_context();
	void opencl_destroy_context(opencl_context_ptr context);

#pragma pack(push, 1)
	struct cl_pixel_block
	{};
#pragma pack(pop)

	// Must match BASISU_ETC1_CLUSTER_FIT_ORDER_TABLE_SIZE
	const uint32_t OPENCL_ENCODE_ETC1S_MAX_PERMS =;

	bool opencl_set_pixel_blocks(opencl_context_ptr pContext, uint32_t total_blocks, const cl_pixel_block* pPixel_blocks);

	bool opencl_encode_etc1s_blocks(opencl_context_ptr pContext, etc_block* pOutput_blocks, bool perceptual, uint32_t total_perms);

	// opencl_encode_etc1s_pixel_clusters

#pragma pack(push, 1)
	struct cl_pixel_cluster
	{};
#pragma pack(pop)

	bool opencl_encode_etc1s_pixel_clusters(
		opencl_context_ptr pContext,
		etc_block* pOutput_blocks, 
		uint32_t total_clusters,
		const cl_pixel_cluster *pClusters,
		uint64_t total_pixels,
		const color_rgba *pPixels,
		const uint32_t *pPixel_weights,
		bool perceptual, uint32_t total_perms);

	// opencl_refine_endpoint_clusterization

#pragma pack(push, 1)
	struct cl_block_info_struct
	{};

	struct cl_endpoint_cluster_struct
	{};
#pragma pack(pop)

	bool opencl_refine_endpoint_clusterization(
		opencl_context_ptr pContext,
		const cl_block_info_struct *pPixel_block_info,
		uint32_t total_clusters,
		const cl_endpoint_cluster_struct *pCluster_info,
		const uint32_t *pSorted_block_indices,
		uint32_t* pOutput_cluster_indices, 
		bool perceptual);

	// opencl_find_optimal_selector_clusters_for_each_block

#pragma pack(push, 1)
	struct fosc_selector_struct
	{};

	struct fosc_block_struct
	{};

	struct fosc_param_struct
	{};
#pragma pack(pop)

	bool opencl_find_optimal_selector_clusters_for_each_block(
		opencl_context_ptr pContext,
		const fosc_block_struct* pInput_block_info,	// one per block
		uint32_t total_input_selectors,
		const fosc_selector_struct* pInput_selectors,
		const uint32_t* pSelector_cluster_indices,
		uint32_t* pOutput_selector_cluster_indices, // one per block
		bool perceptual);

#pragma pack(push, 1)
	struct ds_param_struct
	{};
#pragma pack(pop)

	bool opencl_determine_selectors(
		opencl_context_ptr pContext,
		const color_rgba* pInput_etc_color5_and_inten,
		etc_block* pOutput_blocks,
		bool perceptual);

} // namespace basisu