Path: blob/master/thirdparty/basis_universal/encoder/basisu_opencl.h
9903 views
// basisu_opencl.h1// Copyright (C) 2019-2024 Binomial LLC. All Rights Reserved.2//3// Note: Undefine or set BASISU_SUPPORT_OPENCL to 0 to completely OpenCL support.4//5// Licensed under the Apache License, Version 2.0 (the "License");6// you may not use this file except in compliance with the License.7// You may obtain a copy of the License at8//9// http://www.apache.org/licenses/LICENSE-2.010//11// Unless required by applicable law or agreed to in writing, software12// distributed under the License is distributed on an "AS IS" BASIS,13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14// See the License for the specific language governing permissions and15// limitations under the License.16#pragma once17#include "../transcoder/basisu.h"18#include "basisu_enc.h"19#include "basisu_etc.h"2021namespace basisu22{23bool opencl_init(bool force_serialization);24void opencl_deinit();25bool opencl_is_available();2627struct opencl_context;2829// 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".)30typedef opencl_context* opencl_context_ptr;3132opencl_context_ptr opencl_create_context();33void opencl_destroy_context(opencl_context_ptr context);3435#pragma pack(push, 1)36struct cl_pixel_block37{38color_rgba m_pixels[16]; // [y*4+x]39};40#pragma pack(pop)4142// Must match BASISU_ETC1_CLUSTER_FIT_ORDER_TABLE_SIZE43const uint32_t OPENCL_ENCODE_ETC1S_MAX_PERMS = 165;4445bool opencl_set_pixel_blocks(opencl_context_ptr pContext, size_t total_blocks, const cl_pixel_block* pPixel_blocks);4647bool opencl_encode_etc1s_blocks(opencl_context_ptr pContext, etc_block* pOutput_blocks, bool perceptual, uint32_t total_perms);4849// opencl_encode_etc1s_pixel_clusters5051#pragma pack(push, 1)52struct cl_pixel_cluster53{54uint64_t m_total_pixels;55uint64_t m_first_pixel_index;56};57#pragma pack(pop)5859bool opencl_encode_etc1s_pixel_clusters(60opencl_context_ptr pContext,61etc_block* pOutput_blocks,62uint32_t total_clusters,63const cl_pixel_cluster *pClusters,64uint64_t total_pixels,65const color_rgba *pPixels,66const uint32_t *pPixel_weights,67bool perceptual, uint32_t total_perms);6869// opencl_refine_endpoint_clusterization7071#pragma pack(push, 1)72struct cl_block_info_struct73{74uint16_t m_first_cluster_ofs;75uint16_t m_num_clusters;76uint16_t m_cur_cluster_index;77uint8_t m_cur_cluster_etc_inten;78};7980struct cl_endpoint_cluster_struct81{82color_rgba m_unscaled_color;83uint8_t m_etc_inten;84uint16_t m_cluster_index;85};86#pragma pack(pop)8788bool opencl_refine_endpoint_clusterization(89opencl_context_ptr pContext,90const cl_block_info_struct *pPixel_block_info,91uint32_t total_clusters,92const cl_endpoint_cluster_struct *pCluster_info,93const uint32_t *pSorted_block_indices,94uint32_t* pOutput_cluster_indices,95bool perceptual);9697// opencl_find_optimal_selector_clusters_for_each_block9899#pragma pack(push, 1)100struct fosc_selector_struct101{102uint32_t m_packed_selectors; // 4x4 grid of 2-bit selectors103};104105struct fosc_block_struct106{107color_rgba m_etc_color5_inten; // unscaled 5-bit block color in RGB, alpha has block's intensity index108uint32_t m_first_selector; // offset into selector table109uint32_t m_num_selectors; // number of selectors to check110};111112struct fosc_param_struct113{114uint32_t m_total_blocks;115int m_perceptual;116};117#pragma pack(pop)118119bool opencl_find_optimal_selector_clusters_for_each_block(120opencl_context_ptr pContext,121const fosc_block_struct* pInput_block_info, // one per block122uint32_t total_input_selectors,123const fosc_selector_struct* pInput_selectors,124const uint32_t* pSelector_cluster_indices,125uint32_t* pOutput_selector_cluster_indices, // one per block126bool perceptual);127128#pragma pack(push, 1)129struct ds_param_struct130{131uint32_t m_total_blocks;132int m_perceptual;133};134#pragma pack(pop)135136bool opencl_determine_selectors(137opencl_context_ptr pContext,138const color_rgba* pInput_etc_color5_and_inten,139etc_block* pOutput_blocks,140bool perceptual);141142} // namespace basisu143144145