15template<
typename DstType,
typename SrcType>
22 dst_value.
x = src_value;
29 dst_value = src_value.
x;
33 dst_value = src_value;
41 return (c < 0.0f) ? 0.0f : c * (1.0f / 12.92f);
44 return pow((c + 0.055f) * (1.0f / 1.055f), 2.4f);
50 return (c < 0.0f) ? 0.0f : c * 12.92f;
53 return 1.055f *
pow(c, 1.0f / 2.4f) - 0.055f;
65#define LOCAL_SIZE_X 128
66static constexpr int TILE_SIZE = MIPMAP_UPDATE_TILE_SIZE;
135 linear_color.a = srgba.a;
142 return int2(input_size.
x == 1 ? 1 : (2 | (input_size.
x & 1)),
143 input_size.
y == 1 ? 1 : (2 | (input_size.
y & 1)));
166template<enum TextureWriteFormat format,
typename SharedStorage,
typename InnerType>
196 if (dst_level == 1) {
199 else if (dst_level == 2) {
204 if (dst_level == 1) {
207 else if (dst_level == 2) {
221 if (load_from_shared) {
251 int2 mip_size =
max((mip_in_size >> level),
int2(1));
256 float a0, InnerType v0,
float a1, InnerType v1,
float a2, InnerType v2)
258 return a0 * v0 + a1 * v1 + a2 * v2;
263 return 0.5 * (v0 + v1);
277 template<
bool load_from_shared>
285 float num_dst_pixels = dst_image_size.
y;
286 float rcp = 1.0f / (2 * num_dst_pixels + 1);
287 float w0 = rcp * (num_dst_pixels - dst_coord.
y);
288 float w1 = rcp * num_dst_pixels;
289 float w2 = 1.0f - w0 - w1;
291 InnerType v0, v1, v2, h0, h1, h2, out_pixel;
294 switch (kernel_size.
x) {
296 switch (kernel_size.
y) {
307 switch (kernel_size.
y) {
320 switch (kernel_size.
y) {
331 switch (kernel_size.
y) {
344 switch (kernel_size.
y) {
355 switch (kernel_size.
y) {
369 switch (kernel_size.
x) {
371 num_dst_pixels = dst_image_size.
x;
372 rcp = 1.0f / (2 * num_dst_pixels + 1);
373 w0 = rcp * (num_dst_pixels - dst_coord.
x);
374 w1 = rcp * num_dst_pixels;
403 int2 init_shared_coord,
406 bool use_bounds_check)
408 int2 dst_coord = init_dst_coord;
409 int2 shared_coord = init_shared_coord;
411 int dst_level = src_level + 1;
416 for (
int i_ = 0; i_ < iterations; ++i_) {
417 int2 src_coord = dst_coord * 2;
419 if (use_bounds_check) {
420 if (uint(dst_coord.
x) >= uint(dst_image_size.
x)) {
423 if (uint(dst_coord.
y) >= uint(dst_image_size.
y)) {
429 src_coord, src_level, kernel_size, dst_image_size, dst_coord, dst_level);
435 shared_coord +=
step;
451 int2 init_thread_offset;
458 if (future_kernel_size.
x == 3) {
459 if (future_kernel_size.
y == 3) {
461 init_thread_offset =
int2(local_index % 17u, local_index / 17u);
463 iterations = local_index >= 7 * 17 ? 0 : local_index < 3 * 17 ? 3 : 2;
468 init_thread_offset =
int2(local_index / 16u, local_index % 16u);
470 iterations = local_index < 1 * 16 ? 3 : 2;
474 if (future_kernel_size.
y == 3) {
476 init_thread_offset =
int2(local_index % 16u, local_index / 16u);
478 iterations = local_index < 1 * 16 ? 3 : 2;
482 init_thread_offset =
int2(local_index % 16u, local_index / 16u);
506 if (local_index < 8 * 8) {
507 int2 thread_offset =
int2(local_index % 8u, local_index / 8u);
513 int2 src_shared_coord = thread_offset * 2;
515 int2 dst_coord = thread_offset + dst_tile_coord;
517 bool within_bounds =
true;
518 if (use_bounds_check) {
519 within_bounds = (uint(dst_coord.
x) < uint(dst_image_size.
x)) &&
520 (uint(dst_coord.
y) < uint(dst_image_size.
y));
524 src_shared_coord, 0, kernel_size, dst_image_size, dst_coord, dst_level);
530template<enum TextureWriteFormat format,
typename SharedStorage,
typename InnerType>
537 if (srt.num_levels == 1) {
538 uint sample_index = global_id.x + uint(srt.group_offset) * uint(
LOCAL_SIZE_X);
541 int2 dst_coord =
int2(
int(sample_index) % dst_image_size.
x,
542 int(sample_index) / dst_image_size.
x);
543 int2 src_coord = dst_coord * 2;
545 if (dst_coord.
y < dst_image_size.
y) {
546 srt.template reduce_store_sample<false>(
554 int2 level2_size = srt.level_size(level2);
556 tile_count.
x = int(uint(level2_size.
x + 7) / 8u);
557 tile_count.
y = int(uint(level2_size.
y + 7) / 8u);
561 if (srt.partial_dst_level >= 0) {
563 int2 chunk = srt.chunk_list[group_id.z].coord;
564 int2 margin =
int2(srt.margin_x, srt.margin_y);
565 int dst_level = srt.partial_dst_level;
568 int2 chunk_min = ((chunk * MIPMAP_UPDATE_CHUNK_SIZE) >> dst_level) - margin;
569 int2 chunk_max = (((chunk + 1) * MIPMAP_UPDATE_CHUNK_SIZE - 1) >> dst_level) + 1 + margin;
570 chunk_min =
max(chunk_min,
int2(0));
571 chunk_max =
min(chunk_max, level2_size);
589 if (use_bounds_check) {
592 srt.fill_intermediate_tile(local_index.x,
tile_index * 2 *
int2(8, 8),
true);
601 srt.fill_intermediate_tile(local_index.x,
tile_index * 2 *
int2(8, 8),
false);
603 srt.fill_last_tile(local_index.x,
tile_index *
int2(8, 8),
false);
608template struct Shared<float>;
609template struct Shared<float4>;
611template struct Resources<UNORM_8, SharedUnorm, float>;
612template struct Resources<UNORM_8_8_8_8, SharedSRGB, float4>;
613template struct Resources<SFLOAT_16, Shared<float>,
float>;
614template struct Resources<SFLOAT_16_16_16_16, Shared<float4>,
float4>;
615template struct Resources<SFLOAT_32, Shared<float>,
float>;
616template struct Resources<SFLOAT_32_32_32_32, Shared<float4>,
float4>;
646template float Resources<SFLOAT_16, Shared<float>,
float>::reduce_store_sample<true>(
653template float Resources<SFLOAT_16, Shared<float>,
float>::reduce_store_sample<false>(
660template float4 Resources<SFLOAT_16_16_16_16, Shared<float4>,
float4>::reduce_store_sample<true>(
667template float4 Resources<SFLOAT_16_16_16_16, Shared<float4>,
float4>::reduce_store_sample<false>(
674template float Resources<SFLOAT_32, Shared<float>,
float>::reduce_store_sample<true>(
681template float Resources<SFLOAT_32, Shared<float>,
float>::reduce_store_sample<false>(
688template float4 Resources<SFLOAT_32_32_32_32, Shared<float4>,
float4>::reduce_store_sample<true>(
695template float4 Resources<SFLOAT_32_32_32_32, Shared<float4>,
float4>::reduce_store_sample<false>(
704 const uint3 global_id,
705 const uint3 group_id,
706 const uint3 local_index,
709 const uint3 global_id,
710 const uint3 group_id,
711 const uint3 local_index,
714 const uint3 global_id,
715 const uint3 group_id,
716 const uint3 local_index,
719 const uint3 global_id,
720 const uint3 group_id,
721 const uint3 local_index,
724 const uint3 global_id,
725 const uint3 group_id,
726 const uint3 local_index,
729 const uint3 global_id,
730 const uint3 group_id,
731 const uint3 local_index,
#define storage(slot, qualifiers)
#define compilation_constant
#define global_invocation_id
#define local_invocation_id
float4 unpackUnorm4x8(uint) RET
uint packUnorm4x8(float4) RET
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
IMG_TEMPLATE DataVec imageLoad(const T &, IntCoord) RET
ImageBase< float, 2, true > image2DArray
ImageBase< float, 2 > image2D
IMG_TEMPLATE SizeVec imageSize(const T &) RET
IMG_TEMPLATE void imageStore(T &, IntCoord, DataVec)
PipelineCompute gpu_shader_2D_update_mipmaps_unorm_8_8_8_8_layered(builtin::mipmaps::update_mipmaps< UNORM_8_8_8_8, builtin::mipmaps::SharedSRGB, float4 >, builtin::mipmaps::Constants{.is_srgb_texture=false,.is_layered=true})
PipelineCompute gpu_shader_2D_update_mipmaps_unorm_8_layered(builtin::mipmaps::update_mipmaps< UNORM_8, builtin::mipmaps::SharedUnorm, float >, builtin::mipmaps::Constants{.is_srgb_texture=false,.is_layered=true})
PipelineCompute gpu_shader_2D_update_mipmaps_srgba_8_8_8_8_layered(builtin::mipmaps::update_mipmaps< UNORM_8_8_8_8, builtin::mipmaps::SharedSRGB, float4 >, builtin::mipmaps::Constants{.is_srgb_texture=true,.is_layered=true})
PipelineCompute gpu_shader_2D_update_mipmaps_sfloat_16_16_16_16_layered(builtin::mipmaps::update_mipmaps< SFLOAT_16_16_16_16, builtin::mipmaps::Shared< float4 >, float4 >, builtin::mipmaps::Constants{.is_srgb_texture=false,.is_layered=true})
PipelineCompute gpu_shader_2D_update_mipmaps_sfloat_32(builtin::mipmaps::update_mipmaps< SFLOAT_32, builtin::mipmaps::Shared< float >, float >, builtin::mipmaps::Constants{.is_srgb_texture=false,.is_layered=false})
PipelineCompute gpu_shader_2D_update_mipmaps_unorm_8(builtin::mipmaps::update_mipmaps< UNORM_8, builtin::mipmaps::SharedUnorm, float >, builtin::mipmaps::Constants{.is_srgb_texture=false,.is_layered=false})
PipelineCompute gpu_shader_2D_update_mipmaps_unorm_8_8_8_8(builtin::mipmaps::update_mipmaps< UNORM_8_8_8_8, builtin::mipmaps::SharedSRGB, float4 >, builtin::mipmaps::Constants{.is_srgb_texture=false,.is_layered=false})
PipelineCompute gpu_shader_2D_update_mipmaps_sfloat_16(builtin::mipmaps::update_mipmaps< SFLOAT_16, builtin::mipmaps::Shared< float >, float >, builtin::mipmaps::Constants{.is_srgb_texture=false,.is_layered=false})
PipelineCompute gpu_shader_2D_update_mipmaps_sfloat_16_layered(builtin::mipmaps::update_mipmaps< SFLOAT_16, builtin::mipmaps::Shared< float >, float >, builtin::mipmaps::Constants{.is_srgb_texture=false,.is_layered=true})
PipelineCompute gpu_shader_2D_update_mipmaps_sfloat_32_32_32_32_layered(builtin::mipmaps::update_mipmaps< SFLOAT_32_32_32_32, builtin::mipmaps::Shared< float4 >, float4 >, builtin::mipmaps::Constants{.is_srgb_texture=false,.is_layered=true})
PipelineCompute gpu_shader_2D_update_mipmaps_srgba_8_8_8_8(builtin::mipmaps::update_mipmaps< UNORM_8_8_8_8, builtin::mipmaps::SharedSRGB, float4 >, builtin::mipmaps::Constants{.is_srgb_texture=true,.is_layered=false})
PipelineCompute gpu_shader_2D_update_mipmaps_sfloat_16_16_16_16(builtin::mipmaps::update_mipmaps< SFLOAT_16_16_16_16, builtin::mipmaps::Shared< float4 >, float4 >, builtin::mipmaps::Constants{.is_srgb_texture=false,.is_layered=false})
PipelineCompute gpu_shader_2D_update_mipmaps_sfloat_32_layered(builtin::mipmaps::update_mipmaps< SFLOAT_32, builtin::mipmaps::Shared< float >, float >, builtin::mipmaps::Constants{.is_srgb_texture=false,.is_layered=true})
PipelineCompute gpu_shader_2D_update_mipmaps_sfloat_32_32_32_32(builtin::mipmaps::update_mipmaps< SFLOAT_32_32_32_32, builtin::mipmaps::Shared< float4 >, float4 >, builtin::mipmaps::Constants{.is_srgb_texture=false,.is_layered=false})
static constexpr int TILE_SIZE
static constexpr int INPUT_LEVEL
float linearrgb_to_srgb(float c)
static constexpr int MAX_SHARED_SAMPLES
float srgb_to_linearrgb(float c)
void update_mipmaps(const uint3 global_id, const uint3 group_id, const uint3 local_index, Resources< format, SharedStorage, InnerType > &srt)
void convert(DstType &, const SrcType)
int2 kernel_size_from_input_size(int2 input_size)
const bool is_srgb_texture
Templated struct for bindings and performing the mipmap generation.
InnerType pyramid_reduce_2(InnerType v0, InnerType v1)
InnerType load_sample(int2 src_coord, bool load_from_shared)
SharedStorage shared_storage
void store_shared_sample(int2 dst_coord, InnerType color)
InnerType pyramid_reduce_3(float a0, InnerType v0, float a1, InnerType v1, float a2, InnerType v2)
image2DArray mip_array_out1
void intermediate_level_loop(int2 init_dst_coord, int2 init_shared_coord, int2 step, int iterations, bool use_bounds_check)
int2 level_size(int level)
const int partial_dst_level
void fill_last_tile(uint local_index, int2 dst_tile_coord, bool use_bounds_check)
const MipmapChunkCoord(& chunk_list)[]
image2DArray mip_array_in
image2DArray mip_array_out2
void store_sample(int2 dst_coord, int dst_level, InnerType color)
void fill_intermediate_tile(uint local_index, int2 dst_tile_coord, bool use_bounds_check)
InnerType reduce_store_sample(int2 src_coord, int, int2 kernel_size, int2 dst_image_size, int2 dst_coord, int dst_level)
uint intermediate_level[MAX_SHARED_SAMPLES][MAX_SHARED_SAMPLES]
void store_sample(int2 dst_coord, float4 color)
float4 load_sample(int2 src_coord)
float load_sample(int2 src_coord)
void store_sample(int2 dst_coord, float color)
float intermediate_level[MAX_SHARED_SAMPLES][MAX_SHARED_SAMPLES]
T intermediate_level[MAX_SHARED_SAMPLES][MAX_SHARED_SAMPLES]
T load_sample(int2 src_coord)
void store_sample(int2 dst_coord, T color)