Skip to content

Instantly share code, notes, and snippets.

@rygorous
rygorous / bc7_single_color.cpp
Created July 7, 2023 03:09
BC7 encoding for single-color blocks
void bc7_encode_single_color_block(U8 * output_bc7, const U8 rgba[4])
{
U64 r = rgba[0];
U64 g = rgba[1];
U64 b = rgba[2];
U64 a = rgba[3];
const U64 bit6_mask = (0x40 << 8) | (0x40 << 22) | (0x40ull << 36);
const U64 lo7_mask = (0x7f << 8) | (0x7f << 22) | (0x7full << 36);
U64 color_bits;
@rygorous
rygorous / gist:efc460d0154347ebe17bde7275070d9b
Created July 7, 2023 03:05
Oodle Texture BC7 mode stats on some test images (some game textures, some other)
reading: c:\devel\media\bc1speedlevel/M_MED_Kurohomura_Backpack_Textures_T_Kurohomura_BP_backpack_D.uasset_build.mip0.png
CompressBC7 : 65.720 millis, 3.51 kc/B, rate= 997.20 kB/s
per-pixel rmse : 0.6425
mode stats (8=invalid 9=solid):
[0] 567 ( 0.87%)
[1] 5465 ( 8.34%)
[2] 126 ( 0.19%)
[3] 15855 ( 24.19%)
[4] 909 ( 1.39%)
[5] 15072 ( 23.00%)
Cixin Liu, "The Three-Body Problem", Chapter 4 "The Frontriers of Science"
Page numbers given from trade paperback, ISBN 978 0-7653-8203-0
Pg. 53:
Shi and the young cop said nothing. Both turned and went down the stairs. The two
army officers watched them leave and seemed to sigh with relief.
"What's wrong with that guy?" the major whispered to the other officer.
@rygorous
rygorous / c_dct_repro_block.glsl
Created February 11, 2023 00:27
Another old repro from 2014
#version 430 core
layout(local_size_x=1) in;
layout(binding=0) uniform isamplerBuffer coeff_data;
layout(binding=0, std430) restrict buffer debug_buf {
uint debug[];
};
@rygorous
rygorous / nvgl_kmd_crash.cpp
Created February 11, 2023 00:22
Old bug repros from 2014.
#include <stdio.h>
#include <stdlib.h>
#include <GL/gl3w.h>
#include "util.h"
#include "radglx.h"
#define CHECK_RESULTS // turn this off and we'll keep running until the driver crashes.
#define MIN_ALIGN 1 // setting this to 128 (or higher) fixes the bug (both incorrect results and crash)
typedef unsigned char U8;
@rygorous
rygorous / gist:5c8aad95ef36c9cab3c9f2d6cfeedd8d
Created February 4, 2023 04:05
Estimate of work to finish bitstreams
mov rax, [codewords]
pext rax, [masks] ; coalesce code words
shlx rax, rax, rDestBitPos ; still need something like this
or rOut, rax ; and this
add rDestBitPos, [total] ; this and make SIMD code emit it, or load masks to a reg then do popcnt on it?
; so 5-6 insns per 4 codewords = 1.25-1.5 insns per codeword
; leaves 2.5-2.75 insns per codeword to assemble codewords SIMD
; our best bet here is, I guess, 8 16-bit codewords at once (AVX2)
;
@rygorous
rygorous / simd_multigetbits.cpp
Created February 3, 2023 08:37
Multigetbits, the second
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <smmintrin.h>
#ifdef __RADAVX__
#include <immintrin.h>
#endif
@rygorous
rygorous / simple_multigetbits.cpp
Created February 3, 2023 07:50
Multigetbits, the first
// Returns 8 bit fields at the given positions (in bits) and of the
// given widths as 16-bit integers, with the values aligned with the
// MSB at the top and garbage in the lower-order bits.
//
// The individual lens must be <=8, the positions are bit offsets
// into the 128-bit "bytes".
template<
int pos0, int len0,
int pos1, int len1,
int pos2, int len2,
@rygorous
rygorous / results.txt
Created November 9, 2022 09:56
Oodle Texture BC1 + RDO
C:\devel\libs\icbc>\devel\projects\oodle2\cdepbuild\win64_release\textest bc1 c:\devel\media\blops3bc1\t7_decal_grunge_dust_wall_01_c_BC1_UNORM_sRGB.tga out_baseline.dds
test_framework 2.9.9 built Nov 8 2022 16:18:59 on Win-x64 msvc-1929
test_bc1
reading: c:\devel\media\blops3bc1\t7_decal_grunge_dust_wall_01_c_BC1_UNORM_sRGB.tga
auto alpha : RGBA with all Opaque : no alpha
CompressBCN : 64.330 millis, 858.90 c/B, rate= 4.07 MB/s
writing: out_baseline.dds
t7_decal_grunge_dust_wall_01_c_BC1_UNORM_sRGB.tga BC1: rmse=3.4901 hash=0x7b37fc442d36f112
vendor rmse: 3.4953(AMD), 3.4948(NV), 3.4929(Intel), 3.5382(D3D)
rmse_total = 3.490, combined hash=0xe31c1ffb4f7950d3
@rygorous
rygorous / results.txt
Created November 9, 2022 09:44
Oodle Texture BC1 encoder at "Normal" and "High" levels vs ICBC (ICBC RMSEs when decoding for Intel)
C:\devel\libs\icbc>cl /nologo icbc_test.cpp /O2 /arch:AVX2 && icbc_test -dec intel
icbc_test.cpp
Using 32 threads.
Encoding 'c:/devel/media/blops3bc1/t7_decal_grunge_dust_wall_01_c_BC1_UNORM_sRGB.tga': RMSE = 3.510 PSNR = 37.224 TIME = 0.052029 (0.052029)
Encoding 'c:/devel/media/blops3bc1/c_hro_sarah_armor_c_BC1_UNORM_sRGB.tga': RMSE = 4.406 PSNR = 35.251 TIME = 0.012941 (0.012941)
Average Results:
RMSE = 3.707 PSNR = 36.751 TIME = 0.064970 (0.064970)
C:\devel\libs\icbc>\devel\projects\oodle2\cdepbuild\win64_release\textest bc1 c:\devel\media\blops3bc1\t7_decal_grunge_dust_wall_01_c_BC1_UNORM_sRGB.tga -e2
test_framework 2.9.9 built Nov 8 2022 16:18:59 on Win-x64 msvc-1929