HLSL Specifications

0055 - 8-bit integer support

StatusUnder Consideration
Author
Sponsor

Introduction

This proposal introduces 8-bit integer types to HLSL, to align it more closely with C/C++ and other languages, and allow tight interop with the 8-bit types used in the Linear Algebra proposal (for example, to serve as the underlying storage type for fp8 until that type is added.)

Motivation

8-bit types are very special in HLSL as they only exist for some arithmetic instructions, but aren’t generally accessible. For example, cooperative vectors allow inputs to be specified as 8-bit quantities, but only by packing them into 32-bit. This is cumbersome if for example an application needs to modify the values before passing in, for example, to add a bias – the application is now forced to unpack the value, modify it, and pack it back in.

Proposed solution

Introduce two new, native types:

  • uint8_t: 8-bit unsigned integer
  • int8_t: 8-bit signed integer

For support and conversion rules, those new types would match the 16-bit scalar types, that is, new uint8_t.

DXIL changes

DXIL mentions under Primitive types that i8 is supported only for limited operations. With this proposal: i8 gets supported for computation by shader. For memory access, we’d only support loading multiples of 4 i8.

DXIL/LLVM IR doesn’t discern between i8 and u8, so during lowering, we need to restrict/select between the I and U instructions.

For the elementwise overloads defined in DXIL vectors, the following subset would be supported:

OpcodeNameClassNote
30BfrevUnarySee note
31CountbitsUnaryBits
32FirstBitLoUnaryBits
33FirstBitHiUnaryBits
34FirstBitSHiUnaryBits
37IMaxBinaryi8 only
38IMinBinaryi8 only
39UMaxBinaryu8 only
40UMinBinaryu8 only
48IMadTertiaryi8 only
49UMadTertiaryu8 only
115WaveActiveAllEqualWaveActiveAllEqual
117WaveReadLaneAtWaveReadLaneAt
118WaveReadLaneFirstWaveReadLaneFirst
119WaveActiveOpWaveActiveOp
120WaveActiveBitWaveActiveBit
121WavePrefixOpWavePrefixOp
122QuadReadLaneAtQuadReadLaneAt
123QuadOpQuadOp
165WaveMatchWaveMatch

TODO: Do we really need Bfrev?

SPIR-V changes

SPIR-V already supports 8-bit integers.