Skip to content

Commit

Permalink
Implement texelData for rgb9e5ufloat and add texelData unit tests (gp…
Browse files Browse the repository at this point in the history
…uweb#352)

- Adds dataType and componentType to the texture format table for encodable texture formats. dataType is the format's data representation whereas componentType is the GPUTextureComponentType - the type you get in the shader.
- Implements texelData helpers for packed format rgb9e5ufloat
- Adds unit tests for upload texel data as dataType, loading the componentType in the shader, and writing it out.
  • Loading branch information
austinEng authored Nov 18, 2020
1 parent 5988649 commit e0b76d2
Show file tree
Hide file tree
Showing 5 changed files with 655 additions and 74 deletions.
88 changes: 47 additions & 41 deletions src/webgpu/capability_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,56 +102,60 @@ type TextureFormatInfo = {
// Add fields as needed
};

export type TextureDataType = 'uint' | 'sint' | 'unorm' | 'snorm' | 'float' | 'ufloat';

export const kRegularTextureFormatInfo: {
readonly [k in RegularTextureFormat]: {
color: true;
bytesPerBlock: number;
blockWidth: 1;
blockHeight: 1;
readonly color: true;
readonly bytesPerBlock: number;
readonly blockWidth: 1;
readonly blockHeight: 1;
readonly dataType: TextureDataType;
readonly componentType: GPUTextureComponentType;
} & TextureFormatInfo;
} = /* prettier-ignore */ {
// 8-bit formats
'r8unorm': { renderable: true, color: true, depth: false, stencil: false, storage: false, copySrc: true, copyDst: true, bytesPerBlock: 1, blockWidth: 1, blockHeight: 1 },
'r8snorm': { renderable: false, color: true, depth: false, stencil: false, storage: false, copySrc: true, copyDst: true, bytesPerBlock: 1, blockWidth: 1, blockHeight: 1 },
'r8uint': { renderable: true, color: true, depth: false, stencil: false, storage: false, copySrc: true, copyDst: true, bytesPerBlock: 1, blockWidth: 1, blockHeight: 1 },
'r8sint': { renderable: true, color: true, depth: false, stencil: false, storage: false, copySrc: true, copyDst: true, bytesPerBlock: 1, blockWidth: 1, blockHeight: 1 },
'r8unorm': { renderable: true, color: true, depth: false, stencil: false, storage: false, copySrc: true, copyDst: true, bytesPerBlock: 1, blockWidth: 1, blockHeight: 1, dataType: 'unorm', componentType: 'float' },
'r8snorm': { renderable: false, color: true, depth: false, stencil: false, storage: false, copySrc: true, copyDst: true, bytesPerBlock: 1, blockWidth: 1, blockHeight: 1, dataType: 'snorm', componentType: 'float' },
'r8uint': { renderable: true, color: true, depth: false, stencil: false, storage: false, copySrc: true, copyDst: true, bytesPerBlock: 1, blockWidth: 1, blockHeight: 1, dataType: 'uint', componentType: 'uint' },
'r8sint': { renderable: true, color: true, depth: false, stencil: false, storage: false, copySrc: true, copyDst: true, bytesPerBlock: 1, blockWidth: 1, blockHeight: 1, dataType: 'sint', componentType: 'sint' },
// 16-bit formats
'r16uint': { renderable: true, color: true, depth: false, stencil: false, storage: false, copySrc: true, copyDst: true, bytesPerBlock: 2, blockWidth: 1, blockHeight: 1 },
'r16sint': { renderable: true, color: true, depth: false, stencil: false, storage: false, copySrc: true, copyDst: true, bytesPerBlock: 2, blockWidth: 1, blockHeight: 1 },
'r16float': { renderable: true, color: true, depth: false, stencil: false, storage: false, copySrc: true, copyDst: true, bytesPerBlock: 2, blockWidth: 1, blockHeight: 1 },
'rg8unorm': { renderable: true, color: true, depth: false, stencil: false, storage: false, copySrc: true, copyDst: true, bytesPerBlock: 2, blockWidth: 1, blockHeight: 1 },
'rg8snorm': { renderable: false, color: true, depth: false, stencil: false, storage: false, copySrc: true, copyDst: true, bytesPerBlock: 2, blockWidth: 1, blockHeight: 1 },
'rg8uint': { renderable: true, color: true, depth: false, stencil: false, storage: false, copySrc: true, copyDst: true, bytesPerBlock: 2, blockWidth: 1, blockHeight: 1 },
'rg8sint': { renderable: true, color: true, depth: false, stencil: false, storage: false, copySrc: true, copyDst: true, bytesPerBlock: 2, blockWidth: 1, blockHeight: 1 },
'r16uint': { renderable: true, color: true, depth: false, stencil: false, storage: false, copySrc: true, copyDst: true, bytesPerBlock: 2, blockWidth: 1, blockHeight: 1, dataType: 'uint', componentType: 'uint' },
'r16sint': { renderable: true, color: true, depth: false, stencil: false, storage: false, copySrc: true, copyDst: true, bytesPerBlock: 2, blockWidth: 1, blockHeight: 1, dataType: 'sint', componentType: 'sint' },
'r16float': { renderable: true, color: true, depth: false, stencil: false, storage: false, copySrc: true, copyDst: true, bytesPerBlock: 2, blockWidth: 1, blockHeight: 1, dataType: 'float', componentType: 'float' },
'rg8unorm': { renderable: true, color: true, depth: false, stencil: false, storage: false, copySrc: true, copyDst: true, bytesPerBlock: 2, blockWidth: 1, blockHeight: 1, dataType: 'unorm', componentType: 'float' },
'rg8snorm': { renderable: false, color: true, depth: false, stencil: false, storage: false, copySrc: true, copyDst: true, bytesPerBlock: 2, blockWidth: 1, blockHeight: 1, dataType: 'snorm', componentType: 'float' },
'rg8uint': { renderable: true, color: true, depth: false, stencil: false, storage: false, copySrc: true, copyDst: true, bytesPerBlock: 2, blockWidth: 1, blockHeight: 1, dataType: 'uint', componentType: 'uint' },
'rg8sint': { renderable: true, color: true, depth: false, stencil: false, storage: false, copySrc: true, copyDst: true, bytesPerBlock: 2, blockWidth: 1, blockHeight: 1, dataType: 'sint', componentType: 'sint' },
// 32-bit formats
'r32uint': { renderable: true, color: true, depth: false, stencil: false, storage: true, copySrc: true, copyDst: true, bytesPerBlock: 4, blockWidth: 1, blockHeight: 1 },
'r32sint': { renderable: true, color: true, depth: false, stencil: false, storage: true, copySrc: true, copyDst: true, bytesPerBlock: 4, blockWidth: 1, blockHeight: 1 },
'r32float': { renderable: true, color: true, depth: false, stencil: false, storage: true, copySrc: true, copyDst: true, bytesPerBlock: 4, blockWidth: 1, blockHeight: 1 },
'rg16uint': { renderable: true, color: true, depth: false, stencil: false, storage: false, copySrc: true, copyDst: true, bytesPerBlock: 4, blockWidth: 1, blockHeight: 1 },
'rg16sint': { renderable: true, color: true, depth: false, stencil: false, storage: false, copySrc: true, copyDst: true, bytesPerBlock: 4, blockWidth: 1, blockHeight: 1 },
'rg16float': { renderable: true, color: true, depth: false, stencil: false, storage: false, copySrc: true, copyDst: true, bytesPerBlock: 4, blockWidth: 1, blockHeight: 1 },
'rgba8unorm': { renderable: true, color: true, depth: false, stencil: false, storage: true, copySrc: true, copyDst: true, bytesPerBlock: 4, blockWidth: 1, blockHeight: 1 },
'rgba8unorm-srgb': { renderable: true, color: true, depth: false, stencil: false, storage: false, copySrc: true, copyDst: true, bytesPerBlock: 4, blockWidth: 1, blockHeight: 1 },
'rgba8snorm': { renderable: false, color: true, depth: false, stencil: false, storage: true, copySrc: true, copyDst: true, bytesPerBlock: 4, blockWidth: 1, blockHeight: 1 },
'rgba8uint': { renderable: true, color: true, depth: false, stencil: false, storage: true, copySrc: true, copyDst: true, bytesPerBlock: 4, blockWidth: 1, blockHeight: 1 },
'rgba8sint': { renderable: true, color: true, depth: false, stencil: false, storage: true, copySrc: true, copyDst: true, bytesPerBlock: 4, blockWidth: 1, blockHeight: 1 },
'bgra8unorm': { renderable: true, color: true, depth: false, stencil: false, storage: false, copySrc: true, copyDst: true, bytesPerBlock: 4, blockWidth: 1, blockHeight: 1 },
'bgra8unorm-srgb': { renderable: true, color: true, depth: false, stencil: false, storage: false, copySrc: true, copyDst: true, bytesPerBlock: 4, blockWidth: 1, blockHeight: 1 },
'r32uint': { renderable: true, color: true, depth: false, stencil: false, storage: true, copySrc: true, copyDst: true, bytesPerBlock: 4, blockWidth: 1, blockHeight: 1, dataType: 'uint', componentType: 'uint' },
'r32sint': { renderable: true, color: true, depth: false, stencil: false, storage: true, copySrc: true, copyDst: true, bytesPerBlock: 4, blockWidth: 1, blockHeight: 1, dataType: 'sint', componentType: 'sint' },
'r32float': { renderable: true, color: true, depth: false, stencil: false, storage: true, copySrc: true, copyDst: true, bytesPerBlock: 4, blockWidth: 1, blockHeight: 1, dataType: 'float', componentType: 'float' },
'rg16uint': { renderable: true, color: true, depth: false, stencil: false, storage: false, copySrc: true, copyDst: true, bytesPerBlock: 4, blockWidth: 1, blockHeight: 1, dataType: 'uint', componentType: 'uint' },
'rg16sint': { renderable: true, color: true, depth: false, stencil: false, storage: false, copySrc: true, copyDst: true, bytesPerBlock: 4, blockWidth: 1, blockHeight: 1, dataType: 'sint', componentType: 'sint' },
'rg16float': { renderable: true, color: true, depth: false, stencil: false, storage: false, copySrc: true, copyDst: true, bytesPerBlock: 4, blockWidth: 1, blockHeight: 1, dataType: 'float', componentType: 'float' },
'rgba8unorm': { renderable: true, color: true, depth: false, stencil: false, storage: true, copySrc: true, copyDst: true, bytesPerBlock: 4, blockWidth: 1, blockHeight: 1, dataType: 'unorm', componentType: 'float' },
'rgba8unorm-srgb': { renderable: true, color: true, depth: false, stencil: false, storage: false, copySrc: true, copyDst: true, bytesPerBlock: 4, blockWidth: 1, blockHeight: 1, dataType: 'unorm', componentType: 'float' },
'rgba8snorm': { renderable: false, color: true, depth: false, stencil: false, storage: true, copySrc: true, copyDst: true, bytesPerBlock: 4, blockWidth: 1, blockHeight: 1, dataType: 'snorm', componentType: 'float' },
'rgba8uint': { renderable: true, color: true, depth: false, stencil: false, storage: true, copySrc: true, copyDst: true, bytesPerBlock: 4, blockWidth: 1, blockHeight: 1, dataType: 'uint', componentType: 'uint' },
'rgba8sint': { renderable: true, color: true, depth: false, stencil: false, storage: true, copySrc: true, copyDst: true, bytesPerBlock: 4, blockWidth: 1, blockHeight: 1, dataType: 'sint', componentType: 'sint' },
'bgra8unorm': { renderable: true, color: true, depth: false, stencil: false, storage: false, copySrc: true, copyDst: true, bytesPerBlock: 4, blockWidth: 1, blockHeight: 1, dataType: 'unorm', componentType: 'float' },
'bgra8unorm-srgb': { renderable: true, color: true, depth: false, stencil: false, storage: false, copySrc: true, copyDst: true, bytesPerBlock: 4, blockWidth: 1, blockHeight: 1, dataType: 'unorm', componentType: 'float' },
// Packed 32-bit formats
'rgb10a2unorm': { renderable: true, color: true, depth: false, stencil: false, storage: false, copySrc: true, copyDst: true, bytesPerBlock: 4, blockWidth: 1, blockHeight: 1 },
'rg11b10ufloat': { renderable: false, color: true, depth: false, stencil: false, storage: false, copySrc: true, copyDst: true, bytesPerBlock: 4, blockWidth: 1, blockHeight: 1 },
'rgb9e5ufloat': { renderable: false, color: true, depth: false, stencil: false, storage: false, copySrc: true, copyDst: true, bytesPerBlock: 4, blockWidth: 1, blockHeight: 1 },
'rgb10a2unorm': { renderable: true, color: true, depth: false, stencil: false, storage: false, copySrc: true, copyDst: true, bytesPerBlock: 4, blockWidth: 1, blockHeight: 1, dataType: 'unorm', componentType: 'float' },
'rg11b10ufloat': { renderable: false, color: true, depth: false, stencil: false, storage: false, copySrc: true, copyDst: true, bytesPerBlock: 4, blockWidth: 1, blockHeight: 1, dataType: 'ufloat', componentType: 'float' },
'rgb9e5ufloat': { renderable: false, color: true, depth: false, stencil: false, storage: false, copySrc: true, copyDst: true, bytesPerBlock: 4, blockWidth: 1, blockHeight: 1, dataType: 'ufloat', componentType: 'float' },
// 64-bit formats
'rg32uint': { renderable: true, color: true, depth: false, stencil: false, storage: true, copySrc: true, copyDst: true, bytesPerBlock: 8, blockWidth: 1, blockHeight: 1 },
'rg32sint': { renderable: true, color: true, depth: false, stencil: false, storage: true, copySrc: true, copyDst: true, bytesPerBlock: 8, blockWidth: 1, blockHeight: 1 },
'rg32float': { renderable: true, color: true, depth: false, stencil: false, storage: true, copySrc: true, copyDst: true, bytesPerBlock: 8, blockWidth: 1, blockHeight: 1 },
'rgba16uint': { renderable: true, color: true, depth: false, stencil: false, storage: true, copySrc: true, copyDst: true, bytesPerBlock: 8, blockWidth: 1, blockHeight: 1 },
'rgba16sint': { renderable: true, color: true, depth: false, stencil: false, storage: true, copySrc: true, copyDst: true, bytesPerBlock: 8, blockWidth: 1, blockHeight: 1 },
'rgba16float': { renderable: true, color: true, depth: false, stencil: false, storage: true, copySrc: true, copyDst: true, bytesPerBlock: 8, blockWidth: 1, blockHeight: 1 },
'rg32uint': { renderable: true, color: true, depth: false, stencil: false, storage: true, copySrc: true, copyDst: true, bytesPerBlock: 8, blockWidth: 1, blockHeight: 1, dataType: 'uint', componentType: 'uint' },
'rg32sint': { renderable: true, color: true, depth: false, stencil: false, storage: true, copySrc: true, copyDst: true, bytesPerBlock: 8, blockWidth: 1, blockHeight: 1, dataType: 'sint', componentType: 'sint' },
'rg32float': { renderable: true, color: true, depth: false, stencil: false, storage: true, copySrc: true, copyDst: true, bytesPerBlock: 8, blockWidth: 1, blockHeight: 1, dataType: 'float', componentType: 'float' },
'rgba16uint': { renderable: true, color: true, depth: false, stencil: false, storage: true, copySrc: true, copyDst: true, bytesPerBlock: 8, blockWidth: 1, blockHeight: 1, dataType: 'uint', componentType: 'uint' },
'rgba16sint': { renderable: true, color: true, depth: false, stencil: false, storage: true, copySrc: true, copyDst: true, bytesPerBlock: 8, blockWidth: 1, blockHeight: 1, dataType: 'sint', componentType: 'sint' },
'rgba16float': { renderable: true, color: true, depth: false, stencil: false, storage: true, copySrc: true, copyDst: true, bytesPerBlock: 8, blockWidth: 1, blockHeight: 1, dataType: 'float', componentType: 'float' },
// 128-bit formats
'rgba32uint': { renderable: true, color: true, depth: false, stencil: false, storage: true, copySrc: true, copyDst: true, bytesPerBlock: 16, blockWidth: 1, blockHeight: 1 },
'rgba32sint': { renderable: true, color: true, depth: false, stencil: false, storage: true, copySrc: true, copyDst: true, bytesPerBlock: 16, blockWidth: 1, blockHeight: 1 },
'rgba32float': { renderable: true, color: true, depth: false, stencil: false, storage: true, copySrc: true, copyDst: true, bytesPerBlock: 16, blockWidth: 1, blockHeight: 1 },
'rgba32uint': { renderable: true, color: true, depth: false, stencil: false, storage: true, copySrc: true, copyDst: true, bytesPerBlock: 16, blockWidth: 1, blockHeight: 1, dataType: 'uint', componentType: 'uint' },
'rgba32sint': { renderable: true, color: true, depth: false, stencil: false, storage: true, copySrc: true, copyDst: true, bytesPerBlock: 16, blockWidth: 1, blockHeight: 1, dataType: 'sint', componentType: 'sint' },
'rgba32float': { renderable: true, color: true, depth: false, stencil: false, storage: true, copySrc: true, copyDst: true, bytesPerBlock: 16, blockWidth: 1, blockHeight: 1, dataType: 'float', componentType: 'float' },
} as const;
export const kRegularTextureFormats = keysOf(kRegularTextureFormatInfo);

Expand All @@ -162,9 +166,11 @@ export const kSizedDepthStencilFormatInfo: {
readonly bytesPerBlock: number;
readonly blockWidth: 1;
readonly blockHeight: 1;
readonly dataType: TextureDataType;
readonly componentType: GPUTextureComponentType;
} & TextureFormatInfo;
} = /* prettier-ignore */ {
'depth32float': { renderable: true, color: false, depth: true, stencil: false, storage: false, copySrc: true, copyDst: false, bytesPerBlock: 4, blockWidth: 1, blockHeight: 1 },
'depth32float': { renderable: true, color: false, depth: true, stencil: false, storage: false, copySrc: true, copyDst: false, bytesPerBlock: 4, blockWidth: 1, blockHeight: 1, dataType: 'float', componentType: 'float' },
};
export const kSizedDepthStencilFormats = keysOf(kSizedDepthStencilFormatInfo);

Expand Down
Loading

0 comments on commit e0b76d2

Please sign in to comment.