dxbc格式完成
This commit is contained in:
@@ -73,7 +73,6 @@ class BindingManager:
|
|||||||
sampler.set = sampled_textures[i].set
|
sampler.set = sampled_textures[i].set
|
||||||
sampler.binding = sampled_textures[i].binding
|
sampler.binding = sampled_textures[i].binding
|
||||||
|
|
||||||
|
|
||||||
def assign_bindings_dxil(self, shader_info: ShaderInfo):
|
def assign_bindings_dxil(self, shader_info: ShaderInfo):
|
||||||
"""为DXIL/DXBC着色器分配绑定点"""
|
"""为DXIL/DXBC着色器分配绑定点"""
|
||||||
if shader_info.stage == ShaderStage.VERTEX:
|
if shader_info.stage == ShaderStage.VERTEX:
|
||||||
|
|||||||
@@ -102,6 +102,7 @@ class CodeGenerator:
|
|||||||
'#include <SDL3/SDL_gpu.h>',
|
'#include <SDL3/SDL_gpu.h>',
|
||||||
'#include <string>',
|
'#include <string>',
|
||||||
'#include <vector>',
|
'#include <vector>',
|
||||||
|
'#include <array>',
|
||||||
'#include <unordered_map>',
|
'#include <unordered_map>',
|
||||||
'#include <cstdint>',
|
'#include <cstdint>',
|
||||||
'#include "shader_handle.h"',
|
'#include "shader_handle.h"',
|
||||||
@@ -128,9 +129,19 @@ class CodeGenerator:
|
|||||||
# 写入二进制内容
|
# 写入二进制内容
|
||||||
for info in binding_infos:
|
for info in binding_infos:
|
||||||
entry_point = info['entry_point']
|
entry_point = info['entry_point']
|
||||||
hex_list = ', '.join(f'0x{byte:02x}' for byte in info['blob'])
|
blob_data = info['blob']
|
||||||
with writer.block(f'static constexpr uint8_t {entry_point}_blob[] = ', '};'):
|
|
||||||
writer.write(hex_list)
|
with writer.block(f'static constexpr std::array<uint8_t, {len(blob_data)}> {entry_point}_blob =', '};'):
|
||||||
|
# 每行16个字节,提高可读性
|
||||||
|
for i in range(0, len(blob_data), 16):
|
||||||
|
chunk = blob_data[i:i + 16]
|
||||||
|
hex_str = ', '.join(f'0x{byte:02x}' for byte in chunk)
|
||||||
|
if i + 16 < len(blob_data):
|
||||||
|
hex_str += ','
|
||||||
|
writer.write(hex_str)
|
||||||
|
|
||||||
|
writer.write()
|
||||||
|
|
||||||
|
|
||||||
# Resource结构体
|
# Resource结构体
|
||||||
with writer.block('struct resource_t', '};'):
|
with writer.block('struct resource_t', '};'):
|
||||||
@@ -287,8 +298,8 @@ class CodeGenerator:
|
|||||||
for info in shader_info:
|
for info in shader_info:
|
||||||
with writer.indent(f'virtual SDL_GPUShader* create_{info['stage'].lower()}_shader(SDL_GPUDevice* in_gpu_device) override ''{', '}'):
|
with writer.indent(f'virtual SDL_GPUShader* create_{info['stage'].lower()}_shader(SDL_GPUDevice* in_gpu_device) override ''{', '}'):
|
||||||
writer.write('SDL_GPUShaderCreateInfo info{};')
|
writer.write('SDL_GPUShaderCreateInfo info{};')
|
||||||
writer.write(f'info.code = {global_vars.source_file_name}_shader_bindings::{info["entry_point"]}_blob;')
|
writer.write(f'info.code = {global_vars.source_file_name}_shader_bindings::{info["entry_point"]}_blob.data();')
|
||||||
writer.write(f'info.code_size = sizeof({global_vars.source_file_name}_shader_bindings::{info["entry_point"]}_blob);')
|
writer.write(f'info.code_size = {global_vars.source_file_name}_shader_bindings::{info["entry_point"]}_blob.size();')
|
||||||
writer.write(f'info.entrypoint = "{info["entry_point"]}";')
|
writer.write(f'info.entrypoint = "{info["entry_point"]}";')
|
||||||
writer.write(f'info.format = SDL_GPU_SHADERFORMAT_{global_vars.target.value.upper()};')
|
writer.write(f'info.format = SDL_GPU_SHADERFORMAT_{global_vars.target.value.upper()};')
|
||||||
writer.write(f'info.stage = SDL_GPU_SHADERSTAGE_{info['stage'].upper()};')
|
writer.write(f'info.stage = SDL_GPU_SHADERSTAGE_{info['stage'].upper()};')
|
||||||
@@ -297,3 +308,4 @@ class CodeGenerator:
|
|||||||
writer.write(f'info.num_storage_buffers = {info['num_resources'][ResourceType.STORAGE_BUFFER]};')
|
writer.write(f'info.num_storage_buffers = {info['num_resources'][ResourceType.STORAGE_BUFFER]};')
|
||||||
writer.write(f'info.num_uniform_buffers = {info['num_resources'][ResourceType.UNIFORM_BUFFER]};')
|
writer.write(f'info.num_uniform_buffers = {info['num_resources'][ResourceType.UNIFORM_BUFFER]};')
|
||||||
writer.write('return SDL_CreateGPUShader(in_gpu_device, &info);')
|
writer.write('return SDL_CreateGPUShader(in_gpu_device, &info);')
|
||||||
|
writer.write()
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ def make_cmd(source_file: str, target: TargetFormat, stage: ShaderStage, entry_p
|
|||||||
cmd = [
|
cmd = [
|
||||||
slangc_path,
|
slangc_path,
|
||||||
source_file,
|
source_file,
|
||||||
|
'-no-mangle',
|
||||||
'-entry', entry_point,
|
'-entry', entry_point,
|
||||||
'-o', output_path,
|
'-o', output_path,
|
||||||
'-target', target_flag,
|
'-target', target_flag,
|
||||||
@@ -34,8 +35,10 @@ def make_cmd(source_file: str, target: TargetFormat, stage: ShaderStage, entry_p
|
|||||||
for include_path in global_vars.include_dirs:
|
for include_path in global_vars.include_dirs:
|
||||||
cmd.extend(['-I', include_path])
|
cmd.extend(['-I', include_path])
|
||||||
|
|
||||||
if target in [TargetFormat.DXIL, TargetFormat.DXBC]:
|
if target == TargetFormat.DXIL:
|
||||||
cmd.extend(['-profile', 'sm_6_6'])
|
cmd.extend(['-profile', 'sm_6_0'])
|
||||||
|
elif target == TargetFormat.DXBC:
|
||||||
|
cmd.extend(['-profile', 'sm_5_1'])
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
|
|
||||||
|
|||||||
@@ -350,7 +350,7 @@ class ShaderParser:
|
|||||||
else:
|
else:
|
||||||
# SDL3 GPU似乎不支持只读storage buffer,这里可能需要特殊处理
|
# SDL3 GPU似乎不支持只读storage buffer,这里可能需要特殊处理
|
||||||
return Resource(param['name'], ResourceType.STORAGE_BUFFER)
|
return Resource(param['name'], ResourceType.STORAGE_BUFFER)
|
||||||
elif 'ConstantBuffer' in type_name or type_info.get('kind') == 'ConstantBuffer' or type_info.get('kind') == 'parameterBlock':
|
elif 'constantBuffer' in type_name or type_info.get('kind') == 'constantBuffer' or type_info.get('kind') == 'parameterBlock':
|
||||||
return Resource(param['name'], ResourceType.UNIFORM_BUFFER)
|
return Resource(param['name'], ResourceType.UNIFORM_BUFFER)
|
||||||
elif 'SamplerState' in type_name or 'Sampler' in type_name:
|
elif 'SamplerState' in type_name or 'Sampler' in type_name:
|
||||||
return Resource(param['name'], ResourceType.SAMPLER)
|
return Resource(param['name'], ResourceType.SAMPLER)
|
||||||
|
|||||||
Reference in New Issue
Block a user