chrono_batch_render/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
26 / 34
76.5%
Branches:
23 / 36
63.9%
Functions:
2 / 2, 2 excl
100.0%

device/kernels/texture.h
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2 #pragma once
3
4 #include "chrono_batch_render/device/kernels/shared.h"
5
6 namespace chrono::batch_render {
7
8 CHRONO_BATCH_RENDER_ENUM(TexelFormat){
9 R8,
10 Rg8,
11 Rgba8,
12 R16,
13 Rg16,
14 Rgba16,
15 R16f,
16 Rg16f,
17 Rgba16f,
18 R32f,
19 Rg32f,
20 Rgba32f,
21 Bc1,
22 Bc3,
23 Bc4,
24 Bc5,
25 };
26
27 CHRONO_BATCH_RENDER_ENUM(TextureWrap){
28 Repeat,
29 Mirror,
30 Clamp,
31 Border,
32 };
33
34 CHRONO_BATCH_RENDER_ENUM(TexelColorSpace){
35 Linear,
36 Srgb,
37 };
38
39 static const uint kTextureMaxLevels = 16;
40
41 struct TextureDesc {
42 Ptr<uint> texels;
43 uint width;
44 uint height;
45 uint numLevels;
46 TexelFormat format;
47 TexelColorSpace colorSpace;
48 TextureWrap wrapS;
49 TextureWrap wrapT;
50 uint reserved;
51 uint levelOffsets[kTextureMaxLevels];
52 };
53
54 CHRONO_BATCH_RENDER_CHECK_SIZE(TextureDesc, 104);
55
56 struct TextureObjects {
57 uint64_t filtered;
58 uint64_t texels;
59 uint width;
60 uint height;
61 uint numLevels;
62 uint channels;
63 };
64
65 CHRONO_BATCH_RENDER_CHECK_SIZE(TextureObjects, 32);
66
67 struct UdimTileRecord {
68 uint tile;
69 uint texture;
70 };
71
72 CHRONO_BATCH_RENDER_CHECK_SIZE(UdimTileRecord, 8);
73
74
4/6
✗ Branch 0 not taken.
✓ Branch 1 taken 122 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 122 times.
✓ Branch 4 taken 8 times.
✓ Branch 5 taken 114 times.
340 CHRONO_BATCH_RENDER_SHARED uint TextureLevelSide(uint side, uint level) {
75
12/17
✗ Branch 0 not taken.
✓ Branch 1 taken 122 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 122 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 122 times.
✓ Branch 6 taken 8 times.
✓ Branch 7 taken 114 times.
✓ Branch 9 taken 122 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 155 times.
✓ Branch 13 taken 33 times.
✓ Branch 14 taken 122 times.
✓ Branch 15 taken 8 times.
✓ Branch 16 taken 25 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 33 times.
620 return max(side >> level, 1u);
76 }
77
78 704 CHRONO_BATCH_RENDER_SHARED uint TexelBlockSide(TexelFormat format) {
79
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28 times.
704 switch (format) {
80 case TexelFormat::Bc1:
81 case TexelFormat::Bc3:
82 case TexelFormat::Bc4:
83 case TexelFormat::Bc5:
84 return 4;
85 676 default:
86 676 return 1;
87 }
88 }
89
90 676 CHRONO_BATCH_RENDER_SHARED uint TexelBlockBytes(TexelFormat format) {
91
2/5
✗ Branch 0 not taken.
✓ Branch 1 taken 628 times.
✓ Branch 2 taken 48 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
676 switch (format) {
92 case TexelFormat::R8:
93 return 1;
94 ✗ case TexelFormat::Rg8:
95 ✗ case TexelFormat::R16:
96 ✗ case TexelFormat::R16f:
97 ✗ return 2;
98 628 case TexelFormat::Rgba8:
99 628 case TexelFormat::Rg16:
100 628 case TexelFormat::Rg16f:
101 628 case TexelFormat::R32f:
102 628 return 4;
103 48 case TexelFormat::Rgba16:
104 48 case TexelFormat::Rgba16f:
105 48 case TexelFormat::Rg32f:
106 48 case TexelFormat::Bc1:
107 48 case TexelFormat::Bc4:
108 48 return 8;
109 ✗ default:
110 ✗ return 16;
111 }
112 }
113
114 CHRONO_BATCH_RENDER_SHARED uint TexelWords(TexelFormat format) {
115 return max(TexelBlockBytes(format) / 4, 1u);
116 }
117
118 676 CHRONO_BATCH_RENDER_SHARED uint TextureLevelBytes(TexelFormat format, uint width, uint height,
119 uint level) {
120
1/2
✓ Branch 0 taken 676 times.
✗ Branch 1 not taken.
676 const uint side = TexelBlockSide(format);
121
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 676 times.
676 const uint across = (TextureLevelSide(width, level) + side - 1) / side;
122
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 652 times.
676 const uint down = (TextureLevelSide(height, level) + side - 1) / side;
123 676 return across * down * TexelBlockBytes(format);
124 }
125
126 static const uint kTextureWrapBits = 2;
127 static const uint kTextureSlotShift = 2 * kTextureWrapBits;
128
129 static const uint kTextureSamplers = 1u << kTextureSlotShift;
130
131 static const uint kTextureBinding = 1;
132 static const uint kSamplerBinding = 2;
133
134 58 CHRONO_BATCH_RENDER_SHARED uint TextureHandle(uint slot, TextureWrap wrapS, TextureWrap wrapT) {
135 28 return (slot << kTextureSlotShift) | (uint(wrapS) << kTextureWrapBits) | uint(wrapT);
136 }
137
138 }
139