Skip to content

Commit 82859c3

Browse files
authored
Update CoPilot instructions (#613)
1 parent 824a4c0 commit 82859c3

1 file changed

Lines changed: 145 additions & 1 deletion

File tree

.github/copilot-instructions.md

Lines changed: 145 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ These instructions define how GitHub Copilot should assist with this project. Th
1919

2020
## General Guidelines
2121

22-
- **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/DirectXTK/wiki/Implementation). The code requires C++11/C++14 features.
22+
- **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/DirectXTK/wiki/Implementation). The library implementation is written to be compatible with C++14 features, but C++17 is required to build the project for the command-line tools which utilize C++17 filesystem for long file path support.
23+
> 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`.
2324
- **Documentation**: The project provides documentation in the form of wiki pages available at [Documentation](https://github.com/microsoft/DirectXTK/wiki/).
2425
- **Error Handling**: Use C++ exceptions for error handling and uses RAII smart pointers to ensure resources are properly managed. For some functions that return HRESULT error codes, they are marked `noexcept`, use `std::nothrow` for memory allocation, and should not throw exceptions.
2526
- **Testing**: Unit tests for this project are implemented in this repository [Test Suite](https://github.com/walbourn/directxtktest/) and can be run using CTest per the instructions at [Test Documentation](https://github.com/walbourn/directxtktest/wiki).
@@ -42,6 +43,7 @@ Src/ # Implementation header and source files.
4243
MakeSpriteFont/ # CLI tool for capturing sprite fonts.
4344
XWBTool/ # CLI tool for creating XACT-style wave banks.
4445
Tests/ # Tests are designed to be cloned from a separate repository at this location.
46+
wiki/ # Local clone of the GitHub wiki documentation repository.
4547
```
4648

4749
## Patterns
@@ -55,6 +57,83 @@ Tests/ # Tests are designed to be cloned from a separate repository at
5557
- Make use of anonymous namespaces to limit scope of functions and variables.
5658
- Make use of `assert` for debugging checks, but be sure to validate input parameters in release builds.
5759
- Make use of the `DebugTrace` helper to log diagnostic messages, particularly at the point of throwing an exception.
60+
- Explicitly `= delete` copy constructors and copy-assignment operators on all classes that use the pImpl idiom.
61+
- Explicitly utilize `= default` or `=delete` for copy constructors, assignment operators, move constructors and move-assignment operators where appropriate.
62+
- Use 16-byte alignment (`_aligned_malloc` / `_aligned_free`) to support SIMD operations in the implementation, but do not expose this requirement in public APIs.
63+
- All implementation `.cpp` files include `pch.h` as their first include (precompiled header). MinGW builds skip precompiled headers.
64+
- `Model` and related classes require RTTI (`/GR` on MSVC, `__GXX_RTTI` on GCC/Clang). The CMake build enables `/GR` automatically; do not disable RTTI when using `Model`.
65+
66+
#### SAL Annotations
67+
68+
All public API functions must use SAL annotations on every parameter. Use `_Use_decl_annotations_` at the top of each implementation that has SAL in the header declaration — never repeat the annotations in the `.cpp` or `.inl` file.
69+
70+
Common annotations:
71+
72+
| Annotation | Meaning |
73+
| --- | --- |
74+
| `_In_` | Input parameter |
75+
| `_Out_` | Output parameter |
76+
| `_Inout_` | Bidirectional parameter |
77+
| `_In_reads_bytes_(n)` | Input buffer with byte count |
78+
| `_In_reads_(n)` | Input array with element count |
79+
| `_In_z_` | Null-terminated input string |
80+
| `_In_opt_` | Optional input parameter (may be null) |
81+
| `_Out_opt_` | Optional output parameter |
82+
| `_COM_Outptr_` | Output COM interface |
83+
84+
Example:
85+
86+
```cpp
87+
// Header (BufferHelpers.h)
88+
DIRECTX_TOOLKIT_API
89+
HRESULT __cdecl CreateStaticBuffer(
90+
_In_ ID3D11Device* device,
91+
_In_reads_bytes_(count* stride) const void* ptr,
92+
size_t count,
93+
size_t stride,
94+
unsigned int bindFlags,
95+
_COM_Outptr_ ID3D11Buffer** pBuffer) noexcept;
96+
97+
// Implementation (.cpp)
98+
_Use_decl_annotations_
99+
HRESULT DirectX::CreateStaticBuffer(
100+
ID3D11Device* device,
101+
const void* ptr,
102+
size_t count,
103+
size_t stride,
104+
unsigned int bindFlags,
105+
ID3D11Buffer** pBuffer) noexcept
106+
{ ... }
107+
```
108+
109+
#### Calling Convention and DLL Export
110+
111+
- All public functions use `__cdecl` explicitly for ABI stability.
112+
- All public function declarations are prefixed with `DIRECTX_TOOLKIT_API`, which wraps `__declspec(dllexport)` / `__declspec(dllimport)` or the GCC `__attribute__` equivalent when using `BUILD_SHARED_LIBS` in CMake.
113+
114+
#### `noexcept` Rules
115+
116+
- All query and utility functions that cannot fail are marked `noexcept`.
117+
- All HRESULT-returning I/O and processing functions are also `noexcept` — errors are communicated via return code, never via exceptions.
118+
- Constructors and functions that perform heap allocation or utilize Standard C++ containers that may throw are marked `noexcept(false)`.
119+
120+
#### Enum Flags Pattern
121+
122+
Flags enums follow this pattern — a `uint32_t`-based unscoped enum with a `_DEFAULT = 0x0` base case, followed by a call to `DEFINE_ENUM_FLAG_OPERATORS` to enable `|`, `&`, and `~` operators:
123+
124+
```cpp
125+
enum DDS_LOADER_FLAGS : uint32_t
126+
{
127+
DDS_LOADER_DEFAULT = 0,
128+
DDS_LOADER_FORCE_SRGB = 0x1,
129+
DDS_LOADER_IGNORE_SRGB = 0x2,
130+
DDS_LOADER_IGNORE_MIPS = 0x20,
131+
};
132+
133+
DEFINE_ENUM_FLAG_OPERATORS(DDS_LOADER_FLAGS);
134+
```
135+
136+
See [this blog post](https://walbourn.github.io/modern-c++-bitmask-types/) for more information on this pattern.
58137

59138
### Patterns to Avoid
60139

@@ -63,6 +142,47 @@ Tests/ # Tests are designed to be cloned from a separate repository at
63142
- Don’t put implementation logic in header files unless using templates, although the SimpleMath library does use an .inl file for performance.
64143
- Avoid using `using namespace` in header files to prevent polluting the global namespace.
65144

145+
## Naming Conventions
146+
147+
| Element | Convention | Example |
148+
| --- | --- | --- |
149+
| Classes / structs | PascalCase | `VertexPosition` |
150+
| Public functions | PascalCase + `__cdecl` | `ComputeDisplayArea` |
151+
| Private data members | `m_` prefix | `m_count` |
152+
| Enum type names | UPPER_SNAKE_CASE | `DDS_LOADER_FLAGS` |
153+
| Enum values | UPPER_SNAKE_CASE | `DDS_LOADER_DEFAULT` |
154+
| Files | PascalCase | `ScreenGrab.h`, `SpriteEffect.fx` |
155+
156+
## File Header Convention
157+
158+
Every source file (`.cpp`, `.h`, `.hlsl`, `.fx`, etc.) must begin with this block:
159+
160+
```cpp
161+
//-------------------------------------------------------------------------------------
162+
// File: {FileName}
163+
//
164+
// {One-line description}
165+
//
166+
// Copyright (c) Microsoft Corporation.
167+
// Licensed under the MIT License.
168+
//
169+
// http://go.microsoft.com/fwlink/?LinkId=248929
170+
//-------------------------------------------------------------------------------------
171+
```
172+
173+
Section separators within files use:
174+
- Major sections: `//-------------------------------------------------------------------------------------`
175+
- Subsections: `//---------------------------------------------------------------------------------`
176+
177+
The project does **not** use Doxygen. API documentation is maintained exclusively on the GitHub wiki.
178+
179+
## HLSL Shader Compilation
180+
181+
Shaders in `Src/Shaders/` are compiled with **FXC**, producing embedded C++ header files (`.inc`):
182+
183+
- Use `CompileShaders.cmd` in `Src/Shaders/` to regenerate the `.inc` files.
184+
- The CMake option `USE_PREBUILT_SHADERS=ON` skips shader compilation and uses pre-built `.inc` files; requires `COMPILED_SHADERS` variable to be set.
185+
66186
## References
67187

68188
- [Source git repository on GitHub](https://github.com/microsoft/DirectXTK.git)
@@ -109,6 +229,30 @@ When creating documentation:
109229
- Remove any speculative content.
110230
- Ensure all documentation is verifiable against the current state of the codebase.
111231

232+
## Cross-platform Support Notes
233+
234+
- The code supports building for Windows.
235+
- Portability and conformance of the code is validated by building with Visual C++, clang/LLVM for Windows, and MinGW.
236+
237+
### Platform and Compiler `#ifdef` Guards
238+
239+
Use these established guards — do not invent new ones:
240+
241+
| Guard | Purpose |
242+
| --- | --- |
243+
| `_WIN32` | Windows platform (desktop, UWP, Xbox) |
244+
| `_GAMING_XBOX` | Xbox One |
245+
| `_XBOX_ONE && _TITLE` | Xbox One XDK (legacy) |
246+
| `_MSC_VER` | MSVC-specific pragmas and warning suppression |
247+
| `__clang__` | Clang/LLVM diagnostic suppressions |
248+
| `_MSC_VER` | MSVC-specific (and MSVC-like clang-cl) pragmas and warning suppression |
249+
| `__GNUC__` | MinGW/GCC DLL attribute equivalents |
250+
| `_M_ARM64` / `_M_X64` / `_M_IX86` | Architecture-specific code paths for MSVC (`#ifdef`) |
251+
| `_M_ARM64EC` | ARM64EC ABI (ARM64 code with x64 interop) for MSVC |
252+
| `__aarch64__` / `__x86_64__` / `__i386__` | Additional architecture-specific symbols for MinGW/GNUC (`#if`) |
253+
254+
> `_M_ARM`/ `__arm__` is legacy 32-bit ARM which is deprecated.
255+
112256
## Code Review Instructions
113257

114258
When reviewing code, focus on the following aspects:

0 commit comments

Comments
 (0)