Path: blob/21.2-virgl/src/util/format/u_format_zs.c
7178 views
/**************************************************************************1*2* Copyright 2010 VMware, Inc.3* All Rights Reserved.4*5* Permission is hereby granted, free of charge, to any person obtaining a6* copy of this software and associated documentation files (the7* "Software"), to deal in the Software without restriction, including8* without limitation the rights to use, copy, modify, merge, publish,9* distribute, sub license, and/or sell copies of the Software, and to10* permit persons to whom the Software is furnished to do so, subject to11* the following conditions:12*13* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR14* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,15* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL16* THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,17* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR18* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE19* USE OR OTHER DEALINGS IN THE SOFTWARE.20*21* The above copyright notice and this permission notice (including the22* next paragraph) shall be included in all copies or substantial portions23* of the Software.24*25**************************************************************************/262728#include "util/format/u_format_zs.h"29#include "util/u_math.h"303132/*33* z32_unorm conversion functions34*/3536static inline uint16_t37z32_unorm_to_z16_unorm(uint32_t z)38{39/* z * 0xffff / 0xffffffff */40return z >> 16;41}4243static inline uint32_t44z16_unorm_to_z32_unorm(uint16_t z)45{46/* z * 0xffffffff / 0xffff */47return ((uint32_t)z << 16) | z;48}4950static inline uint32_t51z32_unorm_to_z24_unorm(uint32_t z)52{53/* z * 0xffffff / 0xffffffff */54return z >> 8;55}5657static inline uint32_t58z24_unorm_to_z32_unorm(uint32_t z)59{60/* z * 0xffffffff / 0xffffff */61return (z << 8) | (z >> 16);62}636465/*66* z32_float conversion functions67*/6869static inline uint16_t70z32_float_to_z16_unorm(float z)71{72const float scale = 0xffff;73return (uint16_t)(z * scale + 0.5f);74}7576static inline float77z16_unorm_to_z32_float(uint16_t z)78{79const float scale = 1.0 / 0xffff;80return (float)(z * scale);81}8283static inline uint32_t84z32_float_to_z24_unorm(float z)85{86const double scale = 0xffffff;87return (uint32_t)(z * scale) & 0xffffff;88}8990static inline float91z24_unorm_to_z32_float(uint32_t z)92{93const double scale = 1.0 / 0xffffff;94return (float)(z * scale);95}9697static inline uint32_t98z32_float_to_z32_unorm(float z)99{100const double scale = 0xffffffff;101return (uint32_t)(z * scale);102}103104static inline float105z32_unorm_to_z32_float(uint32_t z)106{107const double scale = 1.0 / 0xffffffff;108return (float)(z * scale);109}110111112void113util_format_s8_uint_unpack_s_8uint(uint8_t *restrict dst_row, unsigned dst_stride,114const uint8_t *restrict src_row, unsigned src_stride,115unsigned width, unsigned height)116{117unsigned y;118for(y = 0; y < height; ++y) {119memcpy(dst_row, src_row, width);120src_row += src_stride/sizeof(*src_row);121dst_row += dst_stride/sizeof(*dst_row);122}123}124125void126util_format_s8_uint_pack_s_8uint(uint8_t *restrict dst_row, unsigned dst_stride,127const uint8_t *restrict src_row, unsigned src_stride,128unsigned width, unsigned height)129{130unsigned y;131for(y = 0; y < height; ++y) {132memcpy(dst_row, src_row, width);133src_row += src_stride/sizeof(*src_row);134dst_row += dst_stride/sizeof(*dst_row);135}136}137138void139util_format_z16_unorm_unpack_z_float(float *restrict dst_row, unsigned dst_stride,140const uint8_t *restrict src_row, unsigned src_stride,141unsigned width, unsigned height)142{143unsigned x, y;144for(y = 0; y < height; ++y) {145float *dst = dst_row;146const uint16_t *src = (const uint16_t *)src_row;147for(x = 0; x < width; ++x) {148*dst++ = z16_unorm_to_z32_float(*src++);149}150src_row += src_stride/sizeof(*src_row);151dst_row += dst_stride/sizeof(*dst_row);152}153}154155void156util_format_z16_unorm_pack_z_float(uint8_t *restrict dst_row, unsigned dst_stride,157const float *restrict src_row, unsigned src_stride,158unsigned width, unsigned height)159{160unsigned x, y;161for(y = 0; y < height; ++y) {162const float *src = src_row;163uint16_t *dst = (uint16_t *)dst_row;164for(x = 0; x < width; ++x) {165*dst++ = z32_float_to_z16_unorm(*src++);166}167dst_row += dst_stride/sizeof(*dst_row);168src_row += src_stride/sizeof(*src_row);169}170}171172void173util_format_z16_unorm_unpack_z_32unorm(uint32_t *restrict dst_row, unsigned dst_stride,174const uint8_t *restrict src_row, unsigned src_stride,175unsigned width, unsigned height)176{177unsigned x, y;178for(y = 0; y < height; ++y) {179uint32_t *dst = dst_row;180const uint16_t *src = (const uint16_t *)src_row;181for(x = 0; x < width; ++x) {182*dst++ = z16_unorm_to_z32_unorm(*src++);183}184src_row += src_stride/sizeof(*src_row);185dst_row += dst_stride/sizeof(*dst_row);186}187}188189void190util_format_z16_unorm_pack_z_32unorm(uint8_t *restrict dst_row, unsigned dst_stride,191const uint32_t *restrict src_row, unsigned src_stride,192unsigned width, unsigned height)193{194unsigned x, y;195for(y = 0; y < height; ++y) {196const uint32_t *src = src_row;197uint16_t *dst = (uint16_t *)dst_row;198for(x = 0; x < width; ++x) {199*dst++ = z32_unorm_to_z16_unorm(*src++);200}201dst_row += dst_stride/sizeof(*dst_row);202src_row += src_stride/sizeof(*src_row);203}204}205206void207util_format_z32_unorm_unpack_z_float(float *restrict dst_row, unsigned dst_stride,208const uint8_t *restrict src_row, unsigned src_stride,209unsigned width, unsigned height)210{211unsigned x, y;212for(y = 0; y < height; ++y) {213float *dst = dst_row;214const uint32_t *src = (const uint32_t *)src_row;215for(x = 0; x < width; ++x) {216*dst++ = z32_unorm_to_z32_float(*src++);217}218src_row += src_stride/sizeof(*src_row);219dst_row += dst_stride/sizeof(*dst_row);220}221}222223void224util_format_z32_unorm_pack_z_float(uint8_t *restrict dst_row, unsigned dst_stride,225const float *restrict src_row, unsigned src_stride,226unsigned width, unsigned height)227{228unsigned x, y;229for(y = 0; y < height; ++y) {230const float *src = src_row;231uint32_t *dst = (uint32_t *)dst_row;232for(x = 0; x < width; ++x) {233*dst++ =z32_float_to_z32_unorm(*src++);234}235dst_row += dst_stride/sizeof(*dst_row);236src_row += src_stride/sizeof(*src_row);237}238}239240void241util_format_z32_unorm_unpack_z_32unorm(uint32_t *restrict dst_row, unsigned dst_stride,242const uint8_t *restrict src_row, unsigned src_stride,243unsigned width, unsigned height)244{245unsigned y;246for(y = 0; y < height; ++y) {247memcpy(dst_row, src_row, width * 4);248src_row += src_stride/sizeof(*src_row);249dst_row += dst_stride/sizeof(*dst_row);250}251}252253void254util_format_z32_unorm_pack_z_32unorm(uint8_t *restrict dst_row, unsigned dst_stride,255const uint32_t *restrict src_row, unsigned src_stride,256unsigned width, unsigned height)257{258unsigned y;259for(y = 0; y < height; ++y) {260memcpy(dst_row, src_row, width * 4);261src_row += src_stride/sizeof(*src_row);262dst_row += dst_stride/sizeof(*dst_row);263}264}265266void267util_format_z32_float_unpack_z_float(float *restrict dst_row, unsigned dst_stride,268const uint8_t *restrict src_row, unsigned src_stride,269unsigned width, unsigned height)270{271unsigned y;272for(y = 0; y < height; ++y) {273memcpy(dst_row, src_row, width * 4);274src_row += src_stride/sizeof(*src_row);275dst_row += dst_stride/sizeof(*dst_row);276}277}278279void280util_format_z32_float_pack_z_float(uint8_t *restrict dst_row, unsigned dst_stride,281const float *restrict src_row, unsigned src_stride,282unsigned width, unsigned height)283{284unsigned y;285for(y = 0; y < height; ++y) {286memcpy(dst_row, src_row, width * 4);287src_row += src_stride/sizeof(*src_row);288dst_row += dst_stride/sizeof(*dst_row);289}290}291292void293util_format_z32_float_unpack_z_32unorm(uint32_t *restrict dst_row, unsigned dst_stride,294const uint8_t *restrict src_row, unsigned src_stride,295unsigned width, unsigned height)296{297unsigned x, y;298for(y = 0; y < height; ++y) {299uint32_t *dst = dst_row;300const float *src = (const float *)src_row;301for(x = 0; x < width; ++x) {302float z = *src++;303*dst++ = z32_float_to_z32_unorm(CLAMP(z, 0.0f, 1.0f));304}305src_row += src_stride/sizeof(*src_row);306dst_row += dst_stride/sizeof(*dst_row);307}308}309310void311util_format_z32_float_pack_z_32unorm(uint8_t *restrict dst_row, unsigned dst_stride,312const uint32_t *restrict src_row, unsigned src_stride,313unsigned width, unsigned height)314{315unsigned x, y;316for(y = 0; y < height; ++y) {317const uint32_t *src = src_row;318float *dst = (float *)dst_row;319for(x = 0; x < width; ++x) {320*dst++ = z32_unorm_to_z32_float(*src++);321}322dst_row += dst_stride/sizeof(*dst_row);323src_row += src_stride/sizeof(*src_row);324}325}326327void328util_format_z16_unorm_s8_uint_unpack_z_float(float *restrict dst_row, unsigned dst_stride,329const uint8_t *restrict src_row, unsigned src_stride,330unsigned width, unsigned height)331{332unreachable("z16_s8 packing/unpacking is not implemented.");333}334335void336util_format_z16_unorm_s8_uint_pack_z_float(uint8_t *restrict dst_row, unsigned dst_stride,337const float *restrict src_row, unsigned src_stride,338unsigned width, unsigned height)339{340unreachable("z16_s8 packing/unpacking is not implemented.");341}342343void344util_format_z16_unorm_s8_uint_unpack_z_32unorm(uint32_t *restrict dst_row, unsigned dst_stride,345const uint8_t *restrict src_row, unsigned src_stride,346unsigned width, unsigned height)347{348unreachable("z16_s8 packing/unpacking is not implemented.");349}350351void352util_format_z16_unorm_s8_uint_pack_z_32unorm(uint8_t *restrict dst_row, unsigned dst_stride,353const uint32_t *restrict src_row, unsigned src_stride,354unsigned width, unsigned height)355{356unreachable("z16_s8 packing/unpacking is not implemented.");357}358359void360util_format_z16_unorm_s8_uint_unpack_s_8uint(uint8_t *restrict dst_row, unsigned dst_stride,361const uint8_t *restrict src_row, unsigned src_stride,362unsigned width, unsigned height)363{364unreachable("z16_s8 packing/unpacking is not implemented.");365}366367void368util_format_z16_unorm_s8_uint_pack_s_8uint(uint8_t *restrict dst_row, unsigned dst_stride,369const uint8_t *restrict src_row, unsigned src_stride,370unsigned width, unsigned height)371{372unreachable("z16_s8 packing/unpacking is not implemented.");373}374375void376util_format_z24_unorm_s8_uint_unpack_z_float(float *restrict dst_row, unsigned dst_stride,377const uint8_t *restrict src_row, unsigned src_stride,378unsigned width, unsigned height)379{380unsigned x, y;381for(y = 0; y < height; ++y) {382float *dst = dst_row;383const uint32_t *src = (const uint32_t *)src_row;384for(x = 0; x < width; ++x) {385*dst++ = z24_unorm_to_z32_float((*src++) & 0xffffff);386}387src_row += src_stride/sizeof(*src_row);388dst_row += dst_stride/sizeof(*dst_row);389}390}391392void393util_format_z24_unorm_s8_uint_pack_z_float(uint8_t *restrict dst_row, unsigned dst_stride,394const float *restrict src_row, unsigned src_stride,395unsigned width, unsigned height)396{397unsigned x, y;398for(y = 0; y < height; ++y) {399const float *src = src_row;400uint32_t *dst = (uint32_t *)dst_row;401for(x = 0; x < width; ++x) {402uint32_t value = *dst;403value &= 0xff000000;404value |= z32_float_to_z24_unorm(*src++);405*dst++ = value;406}407dst_row += dst_stride/sizeof(*dst_row);408src_row += src_stride/sizeof(*src_row);409}410}411412413void414util_format_z24_unorm_s8_uint_unpack_z24(uint8_t *restrict dst_row, unsigned dst_stride,415const uint8_t *restrict src_row, unsigned src_stride,416unsigned width, unsigned height)417{418unsigned x, y;419for(y = 0; y < height; ++y) {420uint32_t *dst = (uint32_t *)dst_row;421const uint32_t *src = (const uint32_t *)src_row;422for(x = 0; x < width; ++x) {423*dst++ = ((*src++) & 0xffffff);424}425src_row += src_stride/sizeof(*src_row);426dst_row += dst_stride/sizeof(*dst_row);427}428}429430void431util_format_z24_unorm_s8_uint_pack_z24(uint8_t *restrict dst_row, unsigned dst_stride,432const uint8_t *restrict src_row, unsigned src_stride,433unsigned width, unsigned height)434{435unsigned x, y;436for(y = 0; y < height; ++y) {437const uint32_t *src = (const uint32_t *)src_row;438uint32_t *dst = (uint32_t *)dst_row;439for(x = 0; x < width; ++x) {440uint32_t value = *dst;441value &= 0xff000000;442value |= *src & 0xffffff;443src++;444*dst++ = value;445}446dst_row += dst_stride/sizeof(*dst_row);447src_row += src_stride/sizeof(*src_row);448}449}450451void452util_format_z24_unorm_s8_uint_unpack_z_32unorm(uint32_t *restrict dst_row, unsigned dst_stride,453const uint8_t *restrict src_row, unsigned src_stride,454unsigned width, unsigned height)455{456unsigned x, y;457for(y = 0; y < height; ++y) {458uint32_t *dst = dst_row;459const uint32_t *src = (const uint32_t *)src_row;460for(x = 0; x < width; ++x) {461*dst++ = z24_unorm_to_z32_unorm((*src++) & 0xffffff);462}463src_row += src_stride/sizeof(*src_row);464dst_row += dst_stride/sizeof(*dst_row);465}466}467468void469util_format_z24_unorm_s8_uint_pack_z_32unorm(uint8_t *restrict dst_row, unsigned dst_stride,470const uint32_t *restrict src_row, unsigned src_stride,471unsigned width, unsigned height)472{473unsigned x, y;474for(y = 0; y < height; ++y) {475const uint32_t *src = src_row;476uint32_t *dst = (uint32_t *)dst_row;477for(x = 0; x < width; ++x) {478uint32_t value = *dst;479value &= 0xff000000;480value |= z32_unorm_to_z24_unorm(*src++);481*dst++ = value;482}483dst_row += dst_stride/sizeof(*dst_row);484src_row += src_stride/sizeof(*src_row);485}486}487488void489util_format_z24_unorm_s8_uint_unpack_s_8uint(uint8_t *restrict dst_row, unsigned dst_stride,490const uint8_t *restrict src_row, unsigned src_stride,491unsigned width, unsigned height)492{493unsigned x, y;494for(y = 0; y < height; ++y) {495uint8_t *dst = dst_row;496const uint32_t *src = (const uint32_t *)src_row;497for(x = 0; x < width; ++x) {498*dst++ = (*src++) >> 24;499}500src_row += src_stride/sizeof(*src_row);501dst_row += dst_stride/sizeof(*dst_row);502}503}504505void506util_format_z24_unorm_s8_uint_pack_s_8uint(uint8_t *restrict dst_row, unsigned dst_stride,507const uint8_t *restrict src_row, unsigned src_stride,508unsigned width, unsigned height)509{510unsigned x, y;511for(y = 0; y < height; ++y) {512const uint8_t *src = src_row;513uint32_t *dst = (uint32_t *)dst_row;514for(x = 0; x < width; ++x) {515uint32_t value = util_le32_to_cpu(*dst);516value &= 0x00ffffff;517value |= (uint32_t)*src++ << 24;518*dst++ = value;519}520dst_row += dst_stride/sizeof(*dst_row);521src_row += src_stride/sizeof(*src_row);522}523}524525void526util_format_z24_unorm_s8_uint_pack_separate(uint8_t *restrict dst_row, unsigned dst_stride,527const uint32_t *z_src_row, unsigned z_src_stride,528const uint8_t *s_src_row, unsigned s_src_stride,529unsigned width, unsigned height)530{531unsigned x, y;532for (y = 0; y < height; ++y) {533const uint32_t *z_src = z_src_row;534const uint8_t *s_src = s_src_row;535uint32_t *dst = (uint32_t *)dst_row;536for (x = 0; x < width; ++x) {537*dst++ = (*z_src++ & 0x00ffffff) | ((uint32_t)*s_src++ << 24);538}539dst_row += dst_stride / sizeof(*dst_row);540z_src_row += z_src_stride / sizeof(*z_src_row);541s_src_row += s_src_stride / sizeof(*s_src_row);542}543}544545void546util_format_s8_uint_z24_unorm_unpack_z_float(float *restrict dst_row, unsigned dst_stride,547const uint8_t *restrict src_row, unsigned src_stride,548unsigned width, unsigned height)549{550unsigned x, y;551for(y = 0; y < height; ++y) {552float *dst = dst_row;553const uint32_t *src = (const uint32_t *)src_row;554for(x = 0; x < width; ++x) {555*dst++ = z24_unorm_to_z32_float((*src++) >> 8);556}557src_row += src_stride/sizeof(*src_row);558dst_row += dst_stride/sizeof(*dst_row);559}560}561562void563util_format_s8_uint_z24_unorm_pack_z_float(uint8_t *restrict dst_row, unsigned dst_stride,564const float *restrict src_row, unsigned src_stride,565unsigned width, unsigned height)566{567unsigned x, y;568for(y = 0; y < height; ++y) {569const float *src = src_row;570uint32_t *dst = (uint32_t *)dst_row;571for(x = 0; x < width; ++x) {572uint32_t value = *dst;573value &= 0x000000ff;574value |= z32_float_to_z24_unorm(*src++) << 8;575*dst++ = value;576}577dst_row += dst_stride/sizeof(*dst_row);578src_row += src_stride/sizeof(*src_row);579}580}581582void583util_format_s8_uint_z24_unorm_unpack_z_32unorm(uint32_t *restrict dst_row, unsigned dst_stride,584const uint8_t *restrict src_row, unsigned src_stride,585unsigned width, unsigned height)586{587unsigned x, y;588for(y = 0; y < height; ++y) {589uint32_t *dst = dst_row;590const uint32_t *src = (const uint32_t *)src_row;591for(x = 0; x < width; ++x) {592uint32_t value = *src++;593*dst++ = z24_unorm_to_z32_unorm(value >> 8);594}595src_row += src_stride/sizeof(*src_row);596dst_row += dst_stride/sizeof(*dst_row);597}598}599600void601util_format_s8_uint_z24_unorm_pack_z_32unorm(uint8_t *restrict dst_row, unsigned dst_stride,602const uint32_t *restrict src_row, unsigned src_stride,603unsigned width, unsigned height)604{605unsigned x, y;606for(y = 0; y < height; ++y) {607const uint32_t *src = src_row;608uint32_t *dst = (uint32_t *)dst_row;609for(x = 0; x < width; ++x) {610uint32_t value = *dst;611value &= 0x000000ff;612value |= *src++ & 0xffffff00;613*dst++ = value;614}615dst_row += dst_stride/sizeof(*dst_row);616src_row += src_stride/sizeof(*src_row);617}618}619620void621util_format_s8_uint_z24_unorm_unpack_s_8uint(uint8_t *restrict dst_row, unsigned dst_stride,622const uint8_t *restrict src_row, unsigned src_stride,623unsigned width, unsigned height)624{625unsigned x, y;626for(y = 0; y < height; ++y) {627uint8_t *dst = dst_row;628const uint32_t *src = (const uint32_t *)src_row;629for(x = 0; x < width; ++x) {630*dst++ = (*src++) & 0xff;631}632src_row += src_stride/sizeof(*src_row);633dst_row += dst_stride/sizeof(*dst_row);634}635}636637void638util_format_s8_uint_z24_unorm_pack_s_8uint(uint8_t *restrict dst_row, unsigned dst_stride,639const uint8_t *restrict src_row, unsigned src_stride,640unsigned width, unsigned height)641{642unsigned x, y;643for(y = 0; y < height; ++y) {644const uint8_t *src = src_row;645uint32_t *dst = (uint32_t *)dst_row;646for(x = 0; x < width; ++x) {647uint32_t value = *dst;648value &= 0xffffff00;649value |= *src++;650*dst++ = value;651}652dst_row += dst_stride/sizeof(*dst_row);653src_row += src_stride/sizeof(*src_row);654}655}656657void658util_format_z24x8_unorm_unpack_z_float(float *restrict dst_row, unsigned dst_stride,659const uint8_t *restrict src_row, unsigned src_stride,660unsigned width, unsigned height)661{662unsigned x, y;663for(y = 0; y < height; ++y) {664float *dst = dst_row;665const uint32_t *src = (const uint32_t *)src_row;666for(x = 0; x < width; ++x) {667*dst++ = z24_unorm_to_z32_float((*src++) & 0xffffff);668}669src_row += src_stride/sizeof(*src_row);670dst_row += dst_stride/sizeof(*dst_row);671}672}673674void675util_format_z24x8_unorm_pack_z_float(uint8_t *restrict dst_row, unsigned dst_stride,676const float *restrict src_row, unsigned src_stride,677unsigned width, unsigned height)678{679unsigned x, y;680for(y = 0; y < height; ++y) {681const float *src = src_row;682uint32_t *dst = (uint32_t *)dst_row;683for(x = 0; x < width; ++x) {684*dst++ = z32_float_to_z24_unorm(*src++);685}686dst_row += dst_stride/sizeof(*dst_row);687src_row += src_stride/sizeof(*src_row);688}689}690691void692util_format_z24x8_unorm_unpack_z_32unorm(uint32_t *restrict dst_row, unsigned dst_stride,693const uint8_t *restrict src_row, unsigned src_stride,694unsigned width, unsigned height)695{696unsigned x, y;697for(y = 0; y < height; ++y) {698uint32_t *dst = dst_row;699const uint32_t *src = (const uint32_t *)src_row;700for(x = 0; x < width; ++x) {701*dst++ = z24_unorm_to_z32_unorm((*src++) & 0xffffff);702}703src_row += src_stride/sizeof(*src_row);704dst_row += dst_stride/sizeof(*dst_row);705}706}707708void709util_format_z24x8_unorm_pack_z_32unorm(uint8_t *restrict dst_row, unsigned dst_stride,710const uint32_t *restrict src_row, unsigned src_stride,711unsigned width, unsigned height)712{713unsigned x, y;714for(y = 0; y < height; ++y) {715const uint32_t *src = src_row;716uint32_t *dst = (uint32_t *)dst_row;717for(x = 0; x < width; ++x) {718*dst++ = z32_unorm_to_z24_unorm(*src++);719}720dst_row += dst_stride/sizeof(*dst_row);721src_row += src_stride/sizeof(*src_row);722}723}724725void726util_format_x8z24_unorm_unpack_z_float(float *restrict dst_row, unsigned dst_stride,727const uint8_t *restrict src_row, unsigned src_stride,728unsigned width, unsigned height)729{730unsigned x, y;731for(y = 0; y < height; ++y) {732float *dst = dst_row;733const uint32_t *src = (uint32_t *)src_row;734for(x = 0; x < width; ++x) {735*dst++ = z24_unorm_to_z32_float((*src++) >> 8);736}737src_row += src_stride/sizeof(*src_row);738dst_row += dst_stride/sizeof(*dst_row);739}740}741742void743util_format_x8z24_unorm_pack_z_float(uint8_t *restrict dst_row, unsigned dst_stride,744const float *restrict src_row, unsigned src_stride,745unsigned width, unsigned height)746{747unsigned x, y;748for(y = 0; y < height; ++y) {749const float *src = src_row;750uint32_t *dst = (uint32_t *)dst_row;751for(x = 0; x < width; ++x) {752*dst++ = z32_float_to_z24_unorm(*src++) << 8;753}754dst_row += dst_stride/sizeof(*dst_row);755src_row += src_stride/sizeof(*src_row);756}757}758759void760util_format_x8z24_unorm_unpack_z_32unorm(uint32_t *restrict dst_row, unsigned dst_stride,761const uint8_t *restrict src_row, unsigned src_stride,762unsigned width, unsigned height)763{764unsigned x, y;765for(y = 0; y < height; ++y) {766uint32_t *dst = dst_row;767const uint32_t *src = (const uint32_t *)src_row;768for(x = 0; x < width; ++x) {769*dst++ = z24_unorm_to_z32_unorm((*src++) >> 8);770}771src_row += src_stride/sizeof(*src_row);772dst_row += dst_stride/sizeof(*dst_row);773}774}775776void777util_format_x8z24_unorm_pack_z_32unorm(uint8_t *restrict dst_row, unsigned dst_stride,778const uint32_t *restrict src_row, unsigned src_stride,779unsigned width, unsigned height)780{781unsigned x, y;782for(y = 0; y < height; ++y) {783const uint32_t *src = src_row;784uint32_t *dst = (uint32_t *)dst_row;785for(x = 0; x < width; ++x) {786*dst++ = z32_unorm_to_z24_unorm(*src++) << 8;787}788dst_row += dst_stride/sizeof(*dst_row);789src_row += src_stride/sizeof(*src_row);790}791}792793void794util_format_z32_float_s8x24_uint_unpack_z_float(float *restrict dst_row, unsigned dst_stride,795const uint8_t *restrict src_row, unsigned src_stride,796unsigned width, unsigned height)797{798unsigned x, y;799for(y = 0; y < height; ++y) {800float *dst = dst_row;801const float *src = (const float *)src_row;802for(x = 0; x < width; ++x) {803*dst = *src;804src += 2;805dst += 1;806}807src_row += src_stride/sizeof(*src_row);808dst_row += dst_stride/sizeof(*dst_row);809}810}811812void813util_format_z32_float_s8x24_uint_pack_z_float(uint8_t *restrict dst_row, unsigned dst_stride,814const float *restrict src_row, unsigned src_stride,815unsigned width, unsigned height)816{817unsigned x, y;818for(y = 0; y < height; ++y) {819const float *src = src_row;820float *dst = (float *)dst_row;821for(x = 0; x < width; ++x) {822*dst = *src;823src += 1;824dst += 2;825}826dst_row += dst_stride/sizeof(*dst_row);827src_row += src_stride/sizeof(*src_row);828}829}830831void832util_format_z32_float_s8x24_uint_unpack_z_32unorm(uint32_t *restrict dst_row, unsigned dst_stride,833const uint8_t *restrict src_row, unsigned src_stride,834unsigned width, unsigned height)835{836unsigned x, y;837for(y = 0; y < height; ++y) {838uint32_t *dst = dst_row;839const float *src = (const float *)src_row;840for(x = 0; x < width; ++x) {841*dst = z32_float_to_z32_unorm(CLAMP(*src, 0.0f, 1.0f));842src += 2;843dst += 1;844}845src_row += src_stride/sizeof(*src_row);846dst_row += dst_stride/sizeof(*dst_row);847}848}849850void851util_format_z32_float_s8x24_uint_pack_z_32unorm(uint8_t *restrict dst_row, unsigned dst_stride,852const uint32_t *restrict src_row, unsigned src_stride,853unsigned width, unsigned height)854{855unsigned x, y;856for(y = 0; y < height; ++y) {857const uint32_t *src = src_row;858float *dst = (float *)dst_row;859for(x = 0; x < width; ++x) {860*dst = z32_unorm_to_z32_float(*src++);861dst += 2;862}863dst_row += dst_stride/sizeof(*dst_row);864src_row += src_stride/sizeof(*src_row);865}866}867868void869util_format_z32_float_s8x24_uint_unpack_s_8uint(uint8_t *restrict dst_row, unsigned dst_stride,870const uint8_t *restrict src_row, unsigned src_stride,871unsigned width, unsigned height)872{873unsigned x, y;874for(y = 0; y < height; ++y) {875uint8_t *dst = dst_row;876const uint32_t *src = (uint32_t *)(src_row + 4);877for(x = 0; x < width; ++x) {878*dst = *src;879src += 2;880dst += 1;881}882src_row += src_stride/sizeof(*src_row);883dst_row += dst_stride/sizeof(*dst_row);884}885}886887void888util_format_z32_float_s8x24_uint_pack_s_8uint(uint8_t *restrict dst_row, unsigned dst_stride,889const uint8_t *restrict src_row, unsigned src_stride,890unsigned width, unsigned height)891{892unsigned x, y;893for(y = 0; y < height; ++y) {894const uint8_t *src = src_row;895uint32_t *dst = ((uint32_t *)dst_row) + 1;896for(x = 0; x < width; ++x) {897*dst = *src;898src += 1;899dst += 2;900}901dst_row += dst_stride/sizeof(*dst_row);902src_row += src_stride/sizeof(*src_row);903}904}905906907void908util_format_x24s8_uint_unpack_s_8uint(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)909{910util_format_z24_unorm_s8_uint_unpack_s_8uint(dst_row, dst_stride,911src_row, src_stride,912width, height);913}914915void916util_format_x24s8_uint_pack_s_8uint(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)917{918util_format_z24_unorm_s8_uint_pack_s_8uint(dst_row, dst_stride,919src_row, src_stride,920width, height);921}922923void924util_format_s8x24_uint_unpack_s_8uint(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)925{926util_format_s8_uint_z24_unorm_unpack_s_8uint(dst_row, dst_stride,927src_row, src_stride,928width, height);929}930931void932util_format_s8x24_uint_pack_s_8uint(uint8_t *restrict dst_row, unsigned dst_stride, const uint8_t *restrict src_row, unsigned src_stride, unsigned width, unsigned height)933{934util_format_s8_uint_z24_unorm_pack_s_8uint(dst_row, dst_stride,935src_row, src_stride,936width, height);937}938939void940util_format_x32_s8x24_uint_unpack_s_8uint(uint8_t *restrict dst_row, unsigned dst_stride,941const uint8_t *restrict src_row, unsigned src_stride,942unsigned width, unsigned height)943{944util_format_z32_float_s8x24_uint_unpack_s_8uint(dst_row, dst_stride,945src_row, src_stride,946width, height);947948}949950void951util_format_x32_s8x24_uint_pack_s_8uint(uint8_t *restrict dst_row, unsigned dst_stride,952const uint8_t *restrict src_row, unsigned src_stride,953unsigned width, unsigned height)954{955util_format_z32_float_s8x24_uint_pack_s_8uint(dst_row, dst_stride,956src_row, src_stride,957width, height);958}959960961