feat: initial DX12 foundation framework

This commit is contained in:
SpecialX
2026-03-19 18:27:49 +08:00
commit 60f73b525d
70 changed files with 8993 additions and 0 deletions

View File

@@ -0,0 +1,133 @@
/**
* @file ContentToEngine.h
* @brief 内容系统到运行时资源系统的数据桥接接口。
* @details
* 该文件描述资源导入后的统一输入格式与运行时句柄接口,核心能力包括:
* - 依据 asset_type 创建/销毁网格、材质、纹理等资源;
* - 管理变体着色器组并按 key 查询编译结果;
* - 提供几何 LOD 偏移与 GPU 子网格 ID 的查询能力。
*/
#pragma once
#include "CommonHeader.h"
namespace XEngine::content {
/**
* @brief 资源类型枚举容器。
*/
struct asset_type {
/**
* @brief 运行时可识别的内容资源类型。
*/
enum type : u32
{
unknown = 0,
animation,
audio,
material,
mesh,
skeleton,
texture,
count
};
};
/**
* @brief 指定某个 LOD 在子网格数组中的起始偏移与数量。
*/
struct lod_offset
{
u16 offset;
u16 count;
};
typedef struct compiled_shader {
/**
* @brief 着色器哈希的固定字节数。
*/
static constexpr u32 hash_length{ 16 };
/**
* @brief 获取字节码长度。
*/
constexpr u64 byte_code_size() const { return _byte_code_size; }
/**
* @brief 获取哈希数据首地址。
*/
constexpr const u8 *const hash() const { return &_hash[0]; }
/**
* @brief 获取字节码首地址。
*/
constexpr const u8 *const byte_code() const { return &_byte_code; }
/**
* @brief 获取当前对象对应的总缓冲区长度。
*/
constexpr const u64 buffer_size() const { return sizeof(_byte_code_size ) + hash_length + _byte_code_size; }
/**
* @brief 根据字节码大小计算总缓冲区长度。
*/
constexpr static u64 buffer_size(u64 size) { return sizeof(_byte_code_size ) + hash_length + size; }
private:
u64 _byte_code_size;
u8 _hash[hash_length];
u8 _byte_code;
}const *compiled_shader_ptr;
/**
* @brief 根据二进制内容创建对应运行时资源。
* @param data 编译后的资源二进制数据。
* @param type 资源类型。
* @return 新创建资源的 ID。
*/
id::id_type create_resource(const void *const data, asset_type::type type);
/**
* @brief 销毁指定资源类型下的运行时资源。
* @param id 资源 ID。
* @param type 资源类型。
*/
void destroy_resource(id::id_type id, asset_type::type type);
/**
* @brief 注册一组着色器变体。
* @param shaders 着色器二进制列表。
* @param num_shaders 着色器数量。
* @param keys 每个着色器对应的查询键。
* @return 着色器组 ID。
*/
id::id_type add_shader_group(const u8 *const * shaders, u32 num_shaders, const u32 *const keys);
/**
* @brief 删除着色器组及其缓存数据。
* @param id 着色器组 ID。
*/
void remove_shader_group(id::id_type id);
/**
* @brief 按组 ID 与键查询编译后着色器。
* @param id 着色器组 ID。
* @param shader_key 着色器键值。
* @return 命中时返回着色器描述,否则返回空。
*/
compiled_shader_ptr get_shader(id::id_type id, u32 shader_key);
/**
* @brief 根据几何内容 ID 批量获取子网格 GPU 资源 ID。
* @param geometry_content_id 几何内容资源 ID。
* @param id_count 输出数组长度。
* @param gpu_ids 输出的 GPU ID 数组。
*/
void get_submesh_gpu_id(id::id_type geometry_content_id, u32 id_count, id::id_type *const gpu_ids);
/**
* @brief 按阈值批量查询几何资源对应的 LOD 偏移信息。
* @param geometry_ids 几何资源 ID 数组。
* @param thresholds 每个几何对应的 LOD 阈值。
* @param id_count 查询数量。
* @param offsets 输出的 LOD 偏移信息。
*/
void get_lod_offset(const id::id_type *const geometry_ids, const f32 *const thresholds, u32 id_count, utl::vector<lod_offset>& offsets);
}