Skip to content

Commit 81fdf25

Browse files
authored
CoPilot instruction improvements (#295)
1 parent 7dd2c2d commit 81fdf25

19 files changed

Lines changed: 199 additions & 46 deletions

.editorconfig

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,6 @@ insert_final_newline = true
88
end_of_line = crlf
99
charset = latin1
1010

11-
[*.{fx,fxh,hlsl,hlsli}]
12-
indent_size = 4
13-
indent_style = space
14-
trim_trailing_whitespace = true
15-
insert_final_newline = true
16-
end_of_line = crlf
17-
charset = latin1
18-
cpp_space_before_function_open_parenthesis = remove
19-
cpp_space_around_binary_operator = ignore
20-
cpp_space_pointer_reference_alignment = ignore
21-
2211
[*.{cpp,h,hpp,inl}]
2312
indent_size = 4
2413
indent_style = space

.github/copilot-instructions.md

Lines changed: 146 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ These instructions define how GitHub Copilot should assist with this project. Th
2121
## General Guidelines
2222

2323
- **Code Style**: The project uses an .editorconfig file to enforce coding standards. Follow the rules defined in `.editorconfig` for indentation, line endings, and other formatting. Additional information can be found on the wiki at [Implementation](https://github.com/microsoft/DirectXMath/wiki/Implementation). The code requires C++11/C++14 features.
24-
> Notable `.editorconfig` rules: C/C++ files use 4-space indentation, `crlf` line endings, and `latin1` charset — avoid non-ASCII characters in source files. HLSL files have separate indent/spacing rules defined in `.editorconfig`.
25-
- **Documentation**: The project provides documentation on [Microsoft Learn](https://learn.microsoft.com/windows/win32/dxmath/directxmath-portal) with additional wiki pages available on [GitHub](https://github.com/microsoft/DirectXMath/wiki/).
24+
> Notable `.editorconfig` rules: C/C++ files use 4-space indentation, `crlf` line endings, and `latin1` charset — avoid non-ASCII characters in source files.
25+
- **Documentation**: The project provides documentation on [Microsoft Learn](https://learn.microsoft.com/windows/win32/dxmath/directxmath-portal) with additional wiki pages available on [GitHub](https://github.com/microsoft/DirectXMath/wiki/). The project does **not** use Doxygen.
2626
- **Error Handling**: The majority of functions have no error conditions and do not throw C++ exceptions which is why they are marked `noexcept`. A few functions have `bool` results to indicate success or failure.
27-
- **Testing**: Unit tests for this project are implemented in this repository [Test Suite](https://github.com/walbourn/directxmathtest/) and can be run using CTest per the instructions at [Test Documentation](https://github.com/walbourn/directxmathtest/wiki).
27+
- **Testing**: Unit tests for this project are implemented in this repository [Test Suite](https://github.com/walbourn/directxmathtest/) and can be run using CTest per the instructions at [Test Documentation](https://github.com/walbourn/directxmathtest/wiki). See [test copilot instructions](https://github.com/walbourn/directxmathtest/blob/main/.github/copilot-instructions.md) for additional information on the tests.
2828
- **Security**: This project uses secure coding practices from the Microsoft Secure Coding Guidelines, and is subject to the `SECURITY.md` file in the root of the repository.
2929
- **Dependencies**: The project has minimal dependencies, primarily relying on compiler intrinsics. It is designed to be self-contained and portable across different platforms and toolsets.
30-
- **Continuous Integration**: This project implements GitHub Actions for continuous integration, ensuring that all code changes are tested and validated before merging. This includes building the project for a number of configurations and toolsets, running unit tests, and static code analysis including GitHub super-linter, CodeQL, and MSVC Code Analysis.
30+
- **Continuous Integration**: This project has 18 GitHub Actions workflows covering MSVC, Clang/LLVM, GCC (WSL), ARM64, Address Sanitizer, CodeQL, and super-linter. Workflows are in `.github/workflows/` and include compiler-specific builds (`msvc.yml`, `clangcl.yml`, `cxx.yml`), platform-specific builds (`arm64.yml`, `wsl.yml`), extension tests (`shmath.yml`, `xdsp.yml`), and static analysis (`codeql.yml`, `lint.yml`, `asan.yml`). Azure DevOps pipeline configurations are in `.azuredevops/`.
3131
- **Code of Conduct**: The project adheres to the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). All contributors are expected to follow this code of conduct in all interactions related to the project.
3232

3333
## File Structure
@@ -87,7 +87,7 @@ All types and functions are in the `DirectX` namespace. Sub-namespaces are used
8787
| `DirectX::PackedVector` | GPU-friendly packed types from `DirectXPackedVector.h` |
8888
| `DirectX::Colors` | sRGB named color constants from `DirectXColors.h` |
8989
| `DirectX::ColorsLinear` | Linear-space color constants from `DirectXColors.h` |
90-
| `DirectX::MathInternal` | Private implementation details (do not use directly) |
90+
| `DirectX::MathInternal` | Private implementation details (do not use directly); renamed from `DirectX::Internal` in v3.20 |
9191
| `DirectX::SSE3`, `::SSE4`, `::AVX`, `::AVX2`, `::FMA3`, `::FMA4`, `::F16C`, `::BEMath` | Extension-specific optimized overrides |
9292

9393
## SIMD Intrinsic Macro Hierarchy
@@ -99,13 +99,13 @@ _XM_AVX2_INTRINSICS_ -> enables _XM_FMA3_INTRINSICS_ + _XM_F16C_INTRINSICS_
9999
_XM_AVX_INTRINSICS_ -> enables _XM_SSE4_INTRINSICS_
100100
_XM_SSE4_INTRINSICS_ -> enables _XM_SSE3_INTRINSICS_
101101
_XM_SSE3_INTRINSICS_ -> enables _XM_SSE_INTRINSICS_
102-
_XM_SSE_INTRINSICS_ (auto-enabled for x86/x64)
103-
_XM_ARM_NEON_INTRINSICS_ (auto-enabled for ARM/ARM64)
102+
_XM_SSE_INTRINSICS_ (auto-enabled for x86/x64/PowerPC64)
103+
_XM_ARM_NEON_INTRINSICS_ (auto-enabled for ARM/ARM64/ARM64EC)
104104
_XM_NO_INTRINSICS_ (pure C++ fallback; force with this define)
105105
```
106106
107107
Optional macros:
108-
- `_XM_SVML_INTRINSICS_` — Intel Short Vector Math Library (auto-enabled with MSVC 2019+; opt-out with `_XM_DISABLE_INTEL_SVML_`)
108+
- `_XM_SVML_INTRINSICS_` — Intel Short Vector Math Library (auto-enabled for SSE paths with MSVC 2019+ / `_MSC_VER >= 1920`, excluding Clang and IntelLLVM; opt-out with `_XM_DISABLE_INTEL_SVML_`)
109109
- `_XM_NO_MOVNT_` — Disables non-temporal store instructions (`_mm_stream_ps`, etc.)
110110
- `_XM_FAVOR_INTEL_` — Uses `_mm_permute_ps` (AVX) over `_mm_shuffle_ps` when available
111111
- `_XM_NO_XMVECTOR_OVERLOADS_` — Disables `XMVECTOR` arithmetic operators (auto-set for GCC/Clang)
@@ -141,8 +141,8 @@ Storage types hold data in memory. Use `XMLoad*` / `XMStore*` to move between st
141141
| `XMFLOAT2` / `XMFLOAT2A` | 2D float vector (A = 16-byte aligned) |
142142
| `XMFLOAT3` / `XMFLOAT3A` | 3D float vector |
143143
| `XMFLOAT4` / `XMFLOAT4A` | 4D float vector |
144-
| `XMINT2/3/4` | 2/3/4D signed int32 vector |
145-
| `XMUINT2/3/4` | 2/3/4D unsigned int32 vector |
144+
| `XMINT2` / `XMINT3` / `XMINT4` | 2/3/4D signed int32 vector |
145+
| `XMUINT2` / `XMUINT3` / `XMUINT4` | 2/3/4D unsigned int32 vector |
146146
| `XMFLOAT3X3`, `XMFLOAT4X3`, `XMFLOAT4X4`, `XMFLOAT4X4A` | Matrix storage types |
147147

148148
### Constant Helper Types
@@ -229,7 +229,7 @@ XMMATRIX XM_CALLCONV XMLoadFloat4x4(_In_ const XMFLOAT4X4* pSource) noexcept;
229229
void XM_CALLCONV XMStoreFloat4x4(_Out_ XMFLOAT4X4* pDestination, _In_ FXMMATRIX M) noexcept;
230230
```
231231

232-
SAL annotations compile to no-ops unless `/analyze` is used; they never affect code generation.
232+
SAL annotations compile to no-ops unless `/analyze` is used; they never affect code generation. On non-Windows platforms, a `sal.h` compatibility header must be provided (e.g., from the DirectX-Headers package).
233233

234234
## Key Macros
235235

@@ -244,6 +244,8 @@ SAL annotations compile to no-ops unless `/analyze` is used; they never affect c
244244
| `XM_STREAM_PS` / `XM_SFENCE` | Non-temporal stores (controlled by `_XM_NO_MOVNT_`) |
245245
| `XM_FMADD_PS` / `XM_FNMADD_PS` | FMA ops when `_XM_FMA3_INTRINSICS_` is active, else expanded to mul+add |
246246
| `XM_PERMUTE_PS` | `_mm_permute_ps` (AVX) or `_mm_shuffle_ps` (SSE) |
247+
| `XM_LOADU_SI16` | SSE: loads 16-bit integer; workaround for GCC < 11 and PowerPC64 |
248+
| `XM_PREFETCH` | ARM NEON only: `__builtin_prefetch` (Clang/GCC) or `__prefetch` (MSVC) |
247249

248250
## CMake Build Options
249251

@@ -256,9 +258,12 @@ SAL annotations compile to no-ops unless `/analyze` is used; they never affect c
256258
| `BUILD_AVX2_TEST` | `OFF` | Test preset: enable AVX2 instruction set |
257259
| `BUILD_F16C_TEST` | `OFF` | Test preset: enable F16C instruction set |
258260
| `BUILD_NO_INTRINSICS` | `OFF` | Test preset: force `_XM_NO_INTRINSICS_` mode |
261+
| `BUILD_FOR_ONECORE` | `OFF` | Build for OneCore using APISets |
259262

260263
The CMake library exports as `Microsoft::DirectXMath` and requires **CMake 3.21+**.
261264

265+
Standardized build configurations are provided in `CMakePresets.json` with 20+ presets covering MSVC, Clang, MinGW, and Intel compilers across x86, x64, ARM64, and ARM64EC architectures. Use `cmake --preset <name>` to configure (e.g., `cmake --preset x64-Debug`).
266+
262267
## C++ Standard Feature Usage
263268

264269
The library uses conditional C++ standard feature guards:
@@ -273,10 +278,11 @@ The library uses conditional C++ standard feature guards:
273278
#endif
274279

275280
#if (__cplusplus >= 202002L)
276-
// C++20 features (e.g., spaceship <=> operator on XMFLOAT2/3/4)
281+
// C++20 features (e.g., spaceship <=> operator on storage types)
277282
#include <compare>
278283
bool operator == (const XMFLOAT2&) const = default;
279284
auto operator <=> (const XMFLOAT2&) const = default;
285+
// Applied to: XMFLOAT2/3/4, XMINT2/3/4, XMUINT2/3/4, and other storage types
280286
#endif
281287
```
282288

@@ -288,9 +294,7 @@ Every source file (`.h`, `.inl`, etc.) must begin with this block:
288294

289295
```cpp
290296
//-------------------------------------------------------------------------------------
291-
// {FileName}
292-
//
293-
// {One-line description}
297+
// {FileName} -- {One-line description}
294298
//
295299
// Copyright (c) Microsoft Corporation.
296300
// Licensed under the MIT License.
@@ -302,8 +306,134 @@ Every source file (`.h`, `.inl`, etc.) must begin with this block:
302306
Section separators within files use:
303307
- Major sections: `//-------------------------------------------------------------------------------------`
304308
- Subsections: `//---------------------------------------------------------------------------------`
309+
- C-style block headers for top-level groupings:
310+
311+
```cpp
312+
/****************************************************************************
313+
*
314+
* {Section Name}
315+
*
316+
****************************************************************************/
317+
```
305318

306319
The project does **not** use Doxygen. API documentation is maintained exclusively on the GitHub wiki.
320+
321+
## Assertion Patterns
322+
323+
The library uses `assert()` extensively for precondition validation in debug builds. Follow these patterns in new code:
324+
325+
```cpp
326+
// Pointer validation (all load/store functions)
327+
assert(pSource);
328+
329+
// Alignment validation (aligned load/store variants)
330+
assert((reinterpret_cast<uintptr_t>(pSource) & 0xF) == 0);
331+
332+
// Semantic constraints (unit quaternion, unit direction, non-zero vector)
333+
assert(DirectX::MathInternal::XMQuaternionIsUnit(Orientation));
334+
assert(DirectX::MathInternal::XMVector3IsUnit(Direction));
335+
assert(!XMVector3Equal(N, XMVectorZero()));
336+
337+
// Range/bounds validation
338+
assert(DivExponent < 32);
339+
assert(NearZ > 0.f && FarZ > 0.f);
340+
```
341+
342+
## Pragma Conventions
343+
344+
The codebase uses compiler-specific pragmas that should be followed in new code:
345+
346+
**MSVC warning suppression** (push/pop around affected blocks):
347+
348+
```cpp
349+
#ifdef _MSC_VER
350+
#pragma warning(push)
351+
#pragma warning(disable : 4701)
352+
// code that triggers the warning
353+
#pragma warning(pop)
354+
#endif
355+
```
356+
357+
**Clang diagnostic suppression**:
358+
359+
```cpp
360+
#ifdef __clang__
361+
#pragma clang diagnostic push
362+
#pragma clang diagnostic ignored "-Wgnu-anonymous-struct"
363+
#pragma clang diagnostic ignored "-Wnested-anon-types"
364+
// code
365+
#pragma clang diagnostic pop
366+
#endif
367+
```
368+
369+
**Floating-point precision** (MSVC-only, for mathematically sensitive code):
370+
371+
```cpp
372+
#ifdef _MSC_VER
373+
#pragma float_control(push)
374+
#pragma float_control(precise, on)
375+
// sensitive floating-point calculations
376+
#pragma float_control(pop)
377+
#endif
378+
```
379+
380+
**PREfast static analysis suppression**:
381+
382+
```cpp
383+
#ifdef _PREFAST_
384+
#pragma prefast(push)
385+
#pragma prefast(disable : 25000, "FXMVECTOR is 16 bytes")
386+
// code
387+
#pragma prefast(pop)
388+
#endif
389+
```
390+
391+
## Template Specialization Patterns
392+
393+
Performance-critical functions like `XMVectorPermute` and `XMVectorSwizzle` use template specialization to map compile-time constants to optimal SIMD instructions:
394+
395+
```cpp
396+
// General template (fallback)
397+
template<uint32_t PermuteX, uint32_t PermuteY, uint32_t PermuteZ, uint32_t PermuteW>
398+
inline XMVECTOR XM_CALLCONV XMVectorPermute(FXMVECTOR V1, FXMVECTOR V2) noexcept;
399+
400+
// Specializations for common patterns that map to single instructions
401+
template<> constexpr XMVECTOR XM_CALLCONV XMVectorPermute<0,1,2,3>(...) { return V1; }
402+
template<> inline XMVECTOR XM_CALLCONV XMVectorPermute<0,1,4,5>(...) { return _mm_movelh_ps(V1, V2); }
403+
```
404+
405+
There are 50+ such specializations. Use `static_assert` to validate template parameters at compile time (e.g., `PermuteX <= 7`).
406+
407+
## Constexpr Usage
408+
409+
Mark utility functions and constructors `constexpr` where possible:
410+
411+
```cpp
412+
// Utility functions
413+
constexpr float XMConvertToRadians(float fDegrees) noexcept { ... }
414+
constexpr float XMConvertToDegrees(float fRadians) noexcept { ... }
415+
416+
// Comparison result helpers
417+
constexpr bool XMComparisonAllTrue(uint32_t CR) noexcept { ... }
418+
419+
// Storage type and bounding volume constructors
420+
constexpr XMFLOAT3(float _x, float _y, float _z) noexcept : x(_x), y(_y), z(_z) {}
421+
```
422+
423+
## Deprecated Types
424+
425+
The following packed vector types in `DirectXPackedVector.h` are deprecated and should not be used in new code. They are marked with `XM_DEPRECATED`:
426+
427+
- `XMXDEC4`
428+
- `XMDECN4`
429+
- `XMDEC4`
430+
431+
These were legacy types originally from xboxmath on the Xbox 360 which no longer have any GPU format equivalents.
432+
433+
## XNAMath Compatibility
434+
435+
`DirectXMath.h` contains a block of `#undef` statements (guarded by `__XNAMATH_H__`) that prevent macro conflicts with the legacy XNA Math library. Do not remove these.
436+
307437
## References
308438

309439
- [Source git repository on GitHub](https://github.com/microsoft/DirectXMath.git)
@@ -361,7 +491,7 @@ Use these established guards — do not invent new ones:
361491
| `__MINGW32__` | MinGW compatibility headers |
362492
| `_M_ARM64` / `_M_X64` / `_M_IX86` | Architecture-specific code paths for MSVC (`#ifdef`) |
363493
| `_M_ARM64EC` | ARM64EC ABI (ARM64 code with x64 interop using ARM-NEON) for MSVC |
364-
| `__aarch64__` / `__x86_64__` / `__i386__` | Additional architecture-specific symbols for MinGW/GNUC (`#if`) |
494+
| `__aarch64__` / `__x86_64__` / `__i386__` / `__powerpc64__` | Additional architecture-specific symbols for MinGW/GNUC (`#if`) |
365495

366496
> `_M_ARM`/ `__arm__` is legacy 32-bit ARM which is deprecated.
367497

.github/workflows/arm64.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ on:
1212
- '*.md'
1313
- LICENSE
1414
- '.azuredevops/**'
15+
- '.github/*.md'
1516
- '.nuget/*'
1617
- build/*.ps1
1718
pull_request:
@@ -20,6 +21,7 @@ on:
2021
- '*.md'
2122
- LICENSE
2223
- '.azuredevops/**'
24+
- '.github/*.md'
2325
- '.nuget/*'
2426
- build/*.ps1
2527

@@ -37,10 +39,10 @@ jobs:
3739
build_type: [arm64-Debug, arm64-Release]
3840

3941
steps:
40-
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
42+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
4143

4244
- name: Clone test repository
43-
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
45+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
4446
with:
4547
repository: walbourn/directxmathtest
4648
path: Tests

.github/workflows/arm64test.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ on:
1212
- '*.md'
1313
- LICENSE
1414
- '.azuredevops/**'
15+
- '.github/*.md'
1516
- '.nuget/*'
1617
- build/*.ps1
1718
pull_request:
@@ -20,6 +21,7 @@ on:
2021
- '*.md'
2122
- LICENSE
2223
- '.azuredevops/**'
24+
- '.github/*.md'
2325
- '.nuget/*'
2426
- build/*.ps1
2527

@@ -38,10 +40,10 @@ jobs:
3840
build_type: [arm64-Release]
3941

4042
steps:
41-
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
43+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
4244

4345
- name: Clone test repository
44-
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
46+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
4547
with:
4648
repository: walbourn/directxmathtest
4749
path: Tests

.github/workflows/asan.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ on:
1212
- '*.md'
1313
- LICENSE
1414
- '.azuredevops/**'
15+
- '.github/*.md'
1516
- '.nuget/*'
1617
- build/*.cmd
1718
- build/*.json
@@ -24,6 +25,7 @@ on:
2425
- '*.md'
2526
- LICENSE
2627
- '.azuredevops/**'
28+
- '.github/*.md'
2729
- '.nuget/*'
2830
- build/*.cmd
2931
- build/*.json
@@ -48,10 +50,10 @@ jobs:
4850
arch: [amd64]
4951

5052
steps:
51-
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
53+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
5254

5355
- name: Clone test repository
54-
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
56+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
5557
with:
5658
repository: walbourn/directxmathtest
5759
path: Tests

.github/workflows/clangcl.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ on:
1212
- '*.md'
1313
- LICENSE
1414
- '.azuredevops/**'
15+
- '.github/*.md'
1516
- '.nuget/*'
1617
- build/*.ps1
1718
pull_request:
@@ -20,6 +21,7 @@ on:
2021
- '*.md'
2122
- LICENSE
2223
- '.azuredevops/**'
24+
- '.github/*.md'
2325
- '.nuget/*'
2426
- build/*.ps1
2527

0 commit comments

Comments
 (0)