Skip to content

Commit 3702363

Browse files
bors[bot]unconed
andcommitted
Merge #82
82: Add updated texture formats r=kvark a=unconed Adds the texture formats from: https://github.com/gpuweb/gpuweb/blob/master/design/sketch.webidl Co-authored-by: Steven Wittens <steven@acko.net>
2 parents 193eec6 + b74b7fd commit 3702363

File tree

7 files changed

+180
-19
lines changed

7 files changed

+180
-19
lines changed

examples/hello_triangle_c/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ int main()
136136

137137
WGPUAttachment attachments[ATTACHMENTS_LENGTH] = {
138138
{
139-
.format = WGPUTextureFormat_B8g8r8a8Unorm,
139+
.format = WGPUTextureFormat_Bgra8Unorm,
140140
.samples = 1,
141141
},
142142
};
@@ -202,7 +202,7 @@ int main()
202202

203203
WGPUSwapChainDescriptor swap_chain_desc = {
204204
.usage = WGPUTextureUsageFlags_OUTPUT_ATTACHMENT | WGPUTextureUsageFlags_PRESENT,
205-
.format = WGPUTextureFormat_B8g8r8a8Unorm,
205+
.format = WGPUTextureFormat_Bgra8Unorm,
206206
.width = 640,
207207
.height = 480,
208208
};

examples/hello_triangle_rust/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ fn main() {
4545
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
4646
color_states: &[
4747
wgpu::ColorStateDescriptor {
48-
format: wgpu::TextureFormat::B8g8r8a8Unorm,
48+
format: wgpu::TextureFormat::Bgra8Unorm,
4949
color: wgpu::BlendDescriptor::REPLACE,
5050
alpha: wgpu::BlendDescriptor::REPLACE,
5151
write_mask: wgpu::ColorWriteFlags::ALL,
@@ -69,7 +69,7 @@ fn main() {
6969
let surface = instance.create_surface(&window);
7070
let mut swap_chain = device.create_swap_chain(&surface, &wgpu::SwapChainDescriptor {
7171
usage: wgpu::TextureUsageFlags::OUTPUT_ATTACHMENT,
72-
format: wgpu::TextureFormat::B8g8r8a8Unorm,
72+
format: wgpu::TextureFormat::Bgra8Unorm,
7373
width: size.width as u32,
7474
height: size.height as u32,
7575
});

gfx-examples/src/cube.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ impl framework::Example for Example {
180180
size: texture_extent,
181181
array_size: 1,
182182
dimension: wgpu::TextureDimension::D2,
183-
format: wgpu::TextureFormat::R8g8b8a8Unorm,
183+
format: wgpu::TextureFormat::Rgba8Unorm,
184184
usage: wgpu::TextureUsageFlags::SAMPLED | wgpu::TextureUsageFlags::TRANSFER_DST,
185185
});
186186
let texture_view = texture.create_default_view();

gfx-examples/src/framework.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub fn run<E: Example>(title: &str) {
7878
let surface = instance.create_surface(&window);
7979
let mut sc_desc = wgpu::SwapChainDescriptor {
8080
usage: wgpu::TextureUsageFlags::OUTPUT_ATTACHMENT,
81-
format: wgpu::TextureFormat::B8g8r8a8Unorm,
81+
format: wgpu::TextureFormat::Bgra8Unorm,
8282
width: size.width as u32,
8383
height: size.height as u32,
8484
};

wgpu-bindings/wgpu.h

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,54 @@ typedef enum {
127127
} WGPUTextureDimension;
128128

129129
typedef enum {
130-
WGPUTextureFormat_R8g8b8a8Unorm = 0,
131-
WGPUTextureFormat_R8g8b8a8Uint = 1,
132-
WGPUTextureFormat_B8g8r8a8Unorm = 2,
133-
WGPUTextureFormat_D32Float = 3,
134-
WGPUTextureFormat_D32FloatS8Uint = 4,
130+
WGPUTextureFormat_R8Unorm = 0,
131+
WGPUTextureFormat_R8UnormSrgb = 1,
132+
WGPUTextureFormat_R8Snorm = 2,
133+
WGPUTextureFormat_R8Uint = 3,
134+
WGPUTextureFormat_R8Sint = 4,
135+
WGPUTextureFormat_R16Unorm = 5,
136+
WGPUTextureFormat_R16Snorm = 6,
137+
WGPUTextureFormat_R16Uint = 7,
138+
WGPUTextureFormat_R16Sint = 8,
139+
WGPUTextureFormat_R16Float = 9,
140+
WGPUTextureFormat_Rg8Unorm = 10,
141+
WGPUTextureFormat_Rg8UnormSrgb = 11,
142+
WGPUTextureFormat_Rg8Snorm = 12,
143+
WGPUTextureFormat_Rg8Uint = 13,
144+
WGPUTextureFormat_Rg8Sint = 14,
145+
WGPUTextureFormat_B5g6r5Unorm = 15,
146+
WGPUTextureFormat_R32Uint = 16,
147+
WGPUTextureFormat_R32Sint = 17,
148+
WGPUTextureFormat_R32Float = 18,
149+
WGPUTextureFormat_Rg16Unorm = 19,
150+
WGPUTextureFormat_Rg16Snorm = 20,
151+
WGPUTextureFormat_Rg16Uint = 21,
152+
WGPUTextureFormat_Rg16Sint = 22,
153+
WGPUTextureFormat_Rg16Float = 23,
154+
WGPUTextureFormat_Rgba8Unorm = 24,
155+
WGPUTextureFormat_Rgba8UnormSrgb = 25,
156+
WGPUTextureFormat_Rgba8Snorm = 26,
157+
WGPUTextureFormat_Rgba8Uint = 27,
158+
WGPUTextureFormat_Rgba8Sint = 28,
159+
WGPUTextureFormat_Bgra8Unorm = 29,
160+
WGPUTextureFormat_Bgra8UnormSrgb = 30,
161+
WGPUTextureFormat_Rgb10a2Unorm = 31,
162+
WGPUTextureFormat_Rg11b10Float = 32,
163+
WGPUTextureFormat_Rg32Uint = 33,
164+
WGPUTextureFormat_Rg32Sint = 34,
165+
WGPUTextureFormat_Rg32Float = 35,
166+
WGPUTextureFormat_Rgba16Unorm = 36,
167+
WGPUTextureFormat_Rgba16Snorm = 37,
168+
WGPUTextureFormat_Rgba16Uint = 38,
169+
WGPUTextureFormat_Rgba16Sint = 39,
170+
WGPUTextureFormat_Rgba16Float = 40,
171+
WGPUTextureFormat_Rgba32Uint = 41,
172+
WGPUTextureFormat_Rgba32Sint = 42,
173+
WGPUTextureFormat_Rgba32Float = 43,
174+
WGPUTextureFormat_D16Unorm = 44,
175+
WGPUTextureFormat_D32Float = 45,
176+
WGPUTextureFormat_D24UnormS8Uint = 46,
177+
WGPUTextureFormat_D32FloatS8Uint = 47,
135178
} WGPUTextureFormat;
136179

137180
typedef enum {

wgpu-native/src/conv.rs

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,10 +287,69 @@ pub fn map_texture_format(texture_format: resource::TextureFormat) -> hal::forma
287287
use hal::format::Format as H;
288288
use crate::resource::TextureFormat::*;
289289
match texture_format {
290-
R8g8b8a8Unorm => H::Rgba8Unorm,
291-
R8g8b8a8Uint => H::Rgba8Uint,
292-
B8g8r8a8Unorm => H::Bgra8Unorm,
290+
// Normal 8 bit formats
291+
R8Unorm => H::R8Unorm,
292+
R8UnormSrgb => H::R8Srgb,
293+
R8Snorm => H::R8Inorm,
294+
R8Uint => H::R8Uint,
295+
R8Sint => H::R8Int,
296+
297+
// Normal 16 bit formats
298+
R16Unorm => H::R16Unorm,
299+
R16Snorm => H::R16Inorm,
300+
R16Uint => H::R16Uint,
301+
R16Sint => H::R16Int,
302+
R16Float => H::R16Float,
303+
304+
Rg8Unorm => H::Rg8Unorm,
305+
Rg8UnormSrgb => H::Rg8Srgb,
306+
Rg8Snorm => H::Rg8Inorm,
307+
Rg8Uint => H::Rg8Uint,
308+
Rg8Sint => H::Rg8Int,
309+
310+
// Packed 16 bit formats
311+
B5g6r5Unorm => H::B5g6r5Unorm,
312+
313+
// Normal 32 bit formats
314+
R32Uint => H::R32Uint,
315+
R32Sint => H::R32Int,
316+
R32Float => H::R32Float,
317+
Rg16Unorm => H::Rg16Unorm,
318+
Rg16Snorm => H::Rg16Inorm,
319+
Rg16Uint => H::Rg16Uint,
320+
Rg16Sint => H::Rg16Int,
321+
Rg16Float => H::Rg16Float,
322+
Rgba8Unorm => H::Rgba8Unorm,
323+
Rgba8UnormSrgb => H::Rgba8Srgb,
324+
Rgba8Snorm => H::Rgba8Inorm,
325+
Rgba8Uint => H::Rgba8Uint,
326+
Rgba8Sint => H::Rgba8Int,
327+
Bgra8Unorm => H::Bgra8Unorm,
328+
Bgra8UnormSrgb => H::Bgra8Srgb,
329+
330+
// Packed 32 bit formats
331+
Rgb10a2Unorm => H::A2r10g10b10Unorm,
332+
Rg11b10Float => H::B10g11r11Ufloat,
333+
334+
// Normal 64 bit formats
335+
Rg32Uint => H::Rg32Uint,
336+
Rg32Sint => H::Rg32Int,
337+
Rg32Float => H::Rg32Float,
338+
Rgba16Unorm => H::Rgba16Unorm,
339+
Rgba16Snorm => H::Rgba16Inorm,
340+
Rgba16Uint => H::Rgba16Uint,
341+
Rgba16Sint => H::Rgba16Int,
342+
Rgba16Float => H::Rgba16Float,
343+
344+
// Normal 128 bit formats
345+
Rgba32Uint => H::Rgba32Uint,
346+
Rgba32Sint => H::Rgba32Int,
347+
Rgba32Float => H::Rgba32Float,
348+
349+
// Depth and stencil formats
350+
D16Unorm => H::D16Unorm,
293351
D32Float => H::D32Float,
352+
D24UnormS8Uint => H::D24UnormS8Uint,
294353
D32FloatS8Uint => H::D32FloatS8Uint,
295354
}
296355
}

wgpu-native/src/resource.rs

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,70 @@ pub enum TextureDimension {
7676
#[repr(C)]
7777
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
7878
pub enum TextureFormat {
79-
R8g8b8a8Unorm = 0,
80-
R8g8b8a8Uint = 1,
81-
B8g8r8a8Unorm = 2,
82-
D32Float = 3,
83-
D32FloatS8Uint = 4,
79+
// Normal 8 bit formats
80+
R8Unorm = 0,
81+
R8UnormSrgb = 1,
82+
R8Snorm = 2,
83+
R8Uint = 3,
84+
R8Sint = 4,
85+
86+
// Normal 16 bit formats
87+
R16Unorm = 5,
88+
R16Snorm = 6,
89+
R16Uint = 7,
90+
R16Sint = 8,
91+
R16Float = 9,
92+
93+
Rg8Unorm = 10,
94+
Rg8UnormSrgb = 11,
95+
Rg8Snorm = 12,
96+
Rg8Uint = 13,
97+
Rg8Sint = 14,
98+
99+
// Packed 16 bit formats
100+
B5g6r5Unorm = 15,
101+
102+
// Normal 32 bit formats
103+
R32Uint = 16,
104+
R32Sint = 17,
105+
R32Float = 18,
106+
Rg16Unorm = 19,
107+
Rg16Snorm = 20,
108+
Rg16Uint = 21,
109+
Rg16Sint = 22,
110+
Rg16Float = 23,
111+
Rgba8Unorm = 24,
112+
Rgba8UnormSrgb = 25,
113+
Rgba8Snorm = 26,
114+
Rgba8Uint = 27,
115+
Rgba8Sint = 28,
116+
Bgra8Unorm = 29,
117+
Bgra8UnormSrgb = 30,
118+
119+
// Packed 32 bit formats
120+
Rgb10a2Unorm = 31,
121+
Rg11b10Float = 32,
122+
123+
// Normal 64 bit formats
124+
Rg32Uint = 33,
125+
Rg32Sint = 34,
126+
Rg32Float = 35,
127+
Rgba16Unorm = 36,
128+
Rgba16Snorm = 37,
129+
Rgba16Uint = 38,
130+
Rgba16Sint = 39,
131+
Rgba16Float = 40,
132+
133+
// Normal 128 bit formats
134+
Rgba32Uint = 41,
135+
Rgba32Sint = 42,
136+
Rgba32Float = 43,
137+
138+
// Depth and stencil formats
139+
D16Unorm = 44,
140+
D32Float = 45,
141+
D24UnormS8Uint = 46,
142+
D32FloatS8Uint = 47,
84143
}
85144

86145
bitflags! {

0 commit comments

Comments
 (0)