-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Crinkler library, use it to generate report about compressed size…
… of shaders
- Loading branch information
Showing
7 changed files
with
154 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
module CompressionTests | ||
|
||
open System.Runtime.InteropServices | ||
open System.IO | ||
open System.Text | ||
|
||
#nowarn "51" // use of native pointers | ||
|
||
module Crinkler = | ||
[<DllImport(@"Compressor.dll", CallingConvention = CallingConvention.Cdecl)>] | ||
extern void InitCompressor() | ||
|
||
[<DllImport(@"Compressor.dll", CallingConvention = CallingConvention.Cdecl)>] | ||
extern single ApproximateModels4k(char* data, int datasize) | ||
|
||
|
||
let testFiles = [ | ||
"from-the-seas-to-the-stars.frag" | ||
"the_real_party_is_in_your_pocket.frag" | ||
"ed-209.frag" | ||
"valley_ball.glsl" | ||
"lunaquatic.frag" | ||
"slisesix.frag" | ||
"yx_long_way_from_home.frag" | ||
"oscars_chair.frag" | ||
"kinder_painter.frag" | ||
"ohanami.frag" | ||
"terrarium.frag" | ||
"leizex.frag" | ||
"elevated.hlsl" | ||
] | ||
|
||
let writer = new StringWriter() | ||
|
||
let log fmt = | ||
let logger str = | ||
printf "%s" str | ||
writer.Write(str) | ||
|
||
Printf.ksprintf logger fmt | ||
|
||
let testFile (file: string) = | ||
let args = if file.EndsWith("hlsl") then [|"--hlsl"|] else [||] | ||
Options.init(args) | ||
let minified = | ||
use out = new StringWriter() | ||
let shaders, exportedNames = ShaderMinifier.minifyFiles [|"tests/real/" + file|] | ||
Formatter.print out shaders exportedNames Options.Text | ||
out.ToString().ToCharArray() | ||
|
||
let pointer = &&minified.[0] | ||
log "%-40s " file | ||
log "%5d " minified.Length | ||
let compressedSize = Crinkler.ApproximateModels4k(pointer, minified.Length) | ||
log "=> %8.3f\n" compressedSize | ||
minified.Length, float compressedSize | ||
|
||
let run () = | ||
Crinkler.InitCompressor() | ||
|
||
writer.GetStringBuilder().Clear() |> ignore<StringBuilder> | ||
let sizes = List.map testFile testFiles | ||
let minifiedSum = List.sumBy fst sizes | ||
let compressedSum = List.sumBy snd sizes | ||
log "Total: %5d => %9.3f\n" minifiedSum compressedSum | ||
File.WriteAllText("tests/compression_results.log", writer.ToString()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from-the-seas-to-the-stars.frag 32480 => 2797.928 | ||
the_real_party_is_in_your_pocket.frag 17782 => 2279.606 | ||
ed-209.frag 11197 => 1479.056 | ||
valley_ball.glsl 5837 => 942.129 | ||
lunaquatic.frag 7237 => 1175.040 | ||
slisesix.frag 7115 => 1116.704 | ||
yx_long_way_from_home.frag 4494 => 712.244 | ||
oscars_chair.frag 6588 => 1166.886 | ||
kinder_painter.frag 4085 => 503.991 | ||
ohanami.frag 5019 => 846.307 | ||
terrarium.frag 5313 => 841.249 | ||
leizex.frag 3121 => 541.299 | ||
elevated.hlsl 4366 => 671.319 | ||
Total: 114634 => 15073.758 |