MCPcopy Create free account
hub / github.com/KhronosGroup/KTX-Software / writeSample

Function writeSample

external/dfdutils/createdfd.c:105–172  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

103}
104
105static void writeSample(uint32_t *DFD, int sampleNo, int channel,
106 int bits, int offset,
107 int topSample, int bottomSample, enum VkSuffix suffix)
108{
109 // Use this to avoid type-punning complaints from the gcc optimizer
110 // with -Wall.
111 union {
112 uint32_t i;
113 float f;
114 } lower, upper;
115 uint32_t *sample = DFD + 1 + KHR_DF_WORD_SAMPLESTART + sampleNo * KHR_DF_WORD_SAMPLEWORDS;
116
117 if (channel == 3) channel = KHR_DF_CHANNEL_RGBSDA_ALPHA;
118 channel = setChannelFlags(channel, suffix);
119
120 sample[KHR_DF_SAMPLEWORD_BITOFFSET] =
121 (offset << KHR_DF_SAMPLESHIFT_BITOFFSET) |
122 ((bits - 1) << KHR_DF_SAMPLESHIFT_BITLENGTH) |
123 (channel << KHR_DF_SAMPLESHIFT_CHANNELID);
124
125 sample[KHR_DF_SAMPLEWORD_SAMPLEPOSITION_ALL] = 0;
126
127 switch (suffix) {
128 case s_UNORM:
129 case s_SRGB:
130 default:
131 if (bits > 32) {
132 upper.i = 0xFFFFFFFFU;
133 } else {
134 upper.i = (uint32_t)((1U << bits) - 1U);
135 }
136 lower.i = 0U;
137 break;
138 case s_SNORM:
139 if (bits > 32) {
140 upper.i = 0x7FFFFFFF;
141 } else {
142 upper.i = topSample ? (1U << (bits - 1)) - 1 : (1U << bits) - 1;
143 }
144 lower.i = ~upper.i;
145 if (bottomSample) lower.i += 1;
146 break;
147 case s_USCALED:
148 case s_UINT:
149 upper.i = bottomSample ? 1U : 0U;
150 lower.i = 0U;
151 break;
152 case s_SSCALED:
153 case s_SINT:
154 upper.i = bottomSample ? 1U : 0U;
155 lower.i = ~0U;
156 break;
157 case s_SFLOAT:
158 upper.f = 1.0f;
159 lower.f = -1.0f;
160 break;
161 case s_UFLOAT:
162 upper.f = 1.0f;

Callers 4

createDFDUnpackedFunction · 0.85
createDFDPackedShiftedFunction · 0.85
createDFDDepthStencilFunction · 0.85
createDFDAlphaFunction · 0.85

Calls 2

setChannelFlagsFunction · 0.85
assertFunction · 0.85

Tested by

no test coverage detected