community-shaders/skyrim-community-shaders

Add compile-time validation for GPU buffer alignment

Open

#1,426 创建于 2025年8月23日

在 GitHub 查看
 (0 评论) (1 反应) (1 负责人)C++ (134 fork)github user discovery
help wanted

仓库指标

Star
 (1,037 star)
PR 合并指标
 (PR 指标待抓取)

描述

Problem

GPU constant buffers (cbuffer structures) in HLSL must be aligned to 16-byte boundaries for optimal performance and correctness. Currently, the project relies on manual padding (e.g., uint b0pad0[2] in ClusterBuildingCS.hlsl) to ensure proper alignment, but this approach is error-prone and lacks compile-time validation.

Current State

The codebase contains various cbuffer structures across shader files that use manual padding:

cbuffer PerFrame : register(b0)
{
    float LightsNear;
    float LightsFar;
    uint b0pad0[2];  // Manual padding for alignment
}

Some settings may be combined from multiple features into a single cbuffer so misalignment may break later feature settings.

Goal

Implement a system that provides compile-time validation to ensure all GPU buffers maintain proper 16-byte alignment without relying solely on manual padding techniques.

Requirements

  • Detect misaligned buffer structures at compile time
  • Work with existing HLSL cbuffer declarations
  • Minimize impact on current shader code
  • Provide clear error messages when alignment issues are detected
  • Consider compatibility with DirectX shader compilation pipeline
  • Should be automatic or otherwise easy for developers to add

Context

This issue stems from PR #542 which attempted to add static asserts for buffer alignment. However, the solution should not be limited to static asserts and should explore various approaches to solve the compile-time alignment validation problem.

Related

/cc @alandtse

贡献者指南