From a5d83011de3bd1ef8a13c1af88f1b11f4d71f2bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matth=C3=A4us=20G=2E=20Chajdas?= Date: Tue, 17 Jun 2025 16:41:57 +0200 Subject: [PATCH 1/6] First stab at 8-bit types. --- proposals/0099-8-bit-types.md | 38 +++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 proposals/0099-8-bit-types.md diff --git a/proposals/0099-8-bit-types.md b/proposals/0099-8-bit-types.md new file mode 100644 index 00000000..50505fd4 --- /dev/null +++ b/proposals/0099-8-bit-types.md @@ -0,0 +1,38 @@ + + +# Refined `cbuffer` Contexts + +## Instructions + +* Proposal: [0099](0099-8-bit-types.md) +* Author(s): [Matthäus Chajdas](https://github.com/anteru) +* Sponsor: TBD +* Status: TBD +* Planned Version: 202x +* Issues: [HLSL 334](https://github.com/microsoft/hlsl-specs/issues/337) + +## 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 cooperative vector proposal. + +## 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](https://github.com/microsoft/DirectXShaderCompiler/wiki/16-Bit-Scalar-Types), that is, new `uint8_t`. + +### DXIL changes + +[DXIL](https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst) mentions under [Primitive types](https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst#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`. + +### SPIR-V changes + +SPIR-V already supports 8-bit integers. + From 83e6e355c6e6c22e1ba1d8b6ce30435b47c2b091 Mon Sep 17 00:00:00 2001 From: Matthaeus Chajdas Date: Wed, 18 Jun 2025 09:54:25 +0200 Subject: [PATCH 2/6] Add list of supported elementwise operations. --- proposals/0099-8-bit-types.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/proposals/0099-8-bit-types.md b/proposals/0099-8-bit-types.md index 50505fd4..1fd01a0e 100644 --- a/proposals/0099-8-bit-types.md +++ b/proposals/0099-8-bit-types.md @@ -32,6 +32,35 @@ For support and conversion rules, those new types would match the [16-bit scalar [DXIL](https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst) mentions under [Primitive types](https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst#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](0030-dxil-vectors.md), the following subset would be supported: + +| Opcode | Name | Class | Note | +| ------ | -------------- | -------- | ---- | +| 30 | Bfrev | Unary | See note | +| 31 | Countbits | UnaryBits | | +| 32 | FirstBitLo | UnaryBits | | +| 33 | FirstBitHi | UnaryBits | | +| 34 | FirstBitSHi | UnaryBits | | +| 37 | IMax | Binary | `i8` only | +| 38 | IMin | Binary | `i8` only | +| 39 | UMax | Binary | `u8` only | +| 40 | UMin | Binary | `u8` only | +| 48 | IMad | Tertiary | `i8` only | +| 49 | UMad | Tertiary | `u8` only | +| 115 | WaveActiveAllEqual | WaveActiveAllEqual | | +| 117 | WaveReadLaneAt | WaveReadLaneAt | | +| 118 | WaveReadLaneFirst | WaveReadLaneFirst | | +| 119 | WaveActiveOp | WaveActiveOp | | +| 120 | WaveActiveBit | WaveActiveBit | | +| 121 | WavePrefixOp | WavePrefixOp | | +| 122 | QuadReadLaneAt | QuadReadLaneAt | | +| 123 | QuadOp | QuadOp | | +| 165 | WaveMatch | WaveMatch | | + +TODO: Do we really need `Bfrev`? + ### SPIR-V changes SPIR-V already supports 8-bit integers. From 8bb446f3b83a8d32821be20f1dfe5293845ccc25 Mon Sep 17 00:00:00 2001 From: Matthaeus Chajdas Date: Wed, 2 Jul 2025 13:31:40 +0200 Subject: [PATCH 3/6] Address first round of review feedback. --- proposals/0099-8-bit-types.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/proposals/0099-8-bit-types.md b/proposals/0099-8-bit-types.md index 1fd01a0e..9b49b913 100644 --- a/proposals/0099-8-bit-types.md +++ b/proposals/0099-8-bit-types.md @@ -1,15 +1,13 @@ -# Refined `cbuffer` Contexts - -## Instructions +# 8-bit integer support * Proposal: [0099](0099-8-bit-types.md) * Author(s): [Matthäus Chajdas](https://github.com/anteru) -* Sponsor: TBD -* Status: TBD +* Sponsor: [Chris Bieneman](https://github.com/llvm-beanz) +* Status: **Under Consideration** * Planned Version: 202x -* Issues: [HLSL 334](https://github.com/microsoft/hlsl-specs/issues/337) +* Issues: [HLSL 337](https://github.com/microsoft/hlsl-specs/issues/337) ## Introduction From 482329e459bd91311fdf53a1812d11d8bbb8a182 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matth=C3=A4us=20G=2E=20Chajdas?= Date: Wed, 27 Aug 2025 12:50:41 +0200 Subject: [PATCH 4/6] Rename file, target SM 6.x. --- proposals/{0099-8-bit-types.md => NNNN-8-bit-integers.md} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename proposals/{0099-8-bit-types.md => NNNN-8-bit-integers.md} (98%) diff --git a/proposals/0099-8-bit-types.md b/proposals/NNNN-8-bit-integers.md similarity index 98% rename from proposals/0099-8-bit-types.md rename to proposals/NNNN-8-bit-integers.md index 9b49b913..18dec843 100644 --- a/proposals/0099-8-bit-types.md +++ b/proposals/NNNN-8-bit-integers.md @@ -2,11 +2,11 @@ # 8-bit integer support -* Proposal: [0099](0099-8-bit-types.md) +* Proposal: [0099](NNNN-8-bit-integers.md) * Author(s): [Matthäus Chajdas](https://github.com/anteru) * Sponsor: [Chris Bieneman](https://github.com/llvm-beanz) * Status: **Under Consideration** -* Planned Version: 202x +* Planned Version: SM 6.x * Issues: [HLSL 337](https://github.com/microsoft/hlsl-specs/issues/337) ## Introduction From e0c93c78928b9e1d3c33164e3e13dc7c4641768e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matth=C3=A4us=20G=2E=20Chajdas?= Date: Wed, 1 Oct 2025 19:59:14 +0200 Subject: [PATCH 5/6] Update proposals/NNNN-8-bit-integers.md Co-authored-by: Damyan Pepper --- proposals/NNNN-8-bit-integers.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/proposals/NNNN-8-bit-integers.md b/proposals/NNNN-8-bit-integers.md index 18dec843..79abcd44 100644 --- a/proposals/NNNN-8-bit-integers.md +++ b/proposals/NNNN-8-bit-integers.md @@ -1,11 +1,13 @@ - +--- +title: NNNN - 8-bit integer support +params: + authors: + - anteru: Matthäus Chajdas + sponsors: + - llvm-beanz: Chris Bieneman + status: Under Consideration +--- -# 8-bit integer support - -* Proposal: [0099](NNNN-8-bit-integers.md) -* Author(s): [Matthäus Chajdas](https://github.com/anteru) -* Sponsor: [Chris Bieneman](https://github.com/llvm-beanz) -* Status: **Under Consideration** * Planned Version: SM 6.x * Issues: [HLSL 337](https://github.com/microsoft/hlsl-specs/issues/337) From 25459a3b8bbb5bcd5cc140a996219cc18986444f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matth=C3=A4us=20G=2E=20Chajdas?= Date: Thu, 23 Oct 2025 10:36:47 +0200 Subject: [PATCH 6/6] Address review feedback. --- proposals/NNNN-8-bit-integers.md | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/proposals/NNNN-8-bit-integers.md b/proposals/NNNN-8-bit-integers.md index 79abcd44..d0d96e38 100644 --- a/proposals/NNNN-8-bit-integers.md +++ b/proposals/NNNN-8-bit-integers.md @@ -13,11 +13,19 @@ params: ## 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 cooperative vector proposal. +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. +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 @@ -26,15 +34,21 @@ 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](https://github.com/microsoft/DirectXShaderCompiler/wiki/16-Bit-Scalar-Types), that is, new `uint8_t`. +For support and conversion rules, those new types would match the +[16-bit scalar types](https://github.com/microsoft/DirectXShaderCompiler/wiki/16-Bit-Scalar-Types), that is, new `uint8_t`. ### DXIL changes -[DXIL](https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst) mentions under [Primitive types](https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst#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](https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst) +mentions under [Primitive types](https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst#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. +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](0030-dxil-vectors.md), the following subset would be supported: +For the elementwise overloads defined in [DXIL vectors](0030-dxil-vectors.md), +the following subset would be supported: | Opcode | Name | Class | Note | | ------ | -------------- | -------- | ---- |