diff --git a/src/mirage_render/src/render/render_elements.cpp b/src/mirage_render/src/render/render_elements.cpp index 00df4e6..df96c61 100644 --- a/src/mirage_render/src/render/render_elements.cpp +++ b/src/mirage_render/src/render/render_elements.cpp @@ -7,7 +7,10 @@ #include "shaders/mirage_text.hlsl.h" #include "shaders/mirage_wireframe.hlsl.h" #include "shaders/mirage_line.hlsl.h" + #include "shaders/mirage_line.shader.h" +#include "shaders/mirage_rounded_rect.shader.h" +#include "shaders/mirage_image.shader.h" template void compute_rect_vertices(const Eigen::MatrixBase& in_pos, diff --git a/src/mirage_render/src/shaders/mirage_image.slang b/src/mirage_render/src/shaders/mirage_image.slang index 71fc470..6daef4f 100644 --- a/src/mirage_render/src/shaders/mirage_image.slang +++ b/src/mirage_render/src/shaders/mirage_image.slang @@ -6,7 +6,7 @@ cbuffer ParamBuffer }; SamplerState textureSampler; -Texture2D texture; +Texture2D inputTexture; struct PSInput { float4 position : SV_POSITION; @@ -28,8 +28,8 @@ PSInput vertex_main(VSInput input) } [shader("pixel")] -float4 pixel_main(PSInput input) +float4 pixel_main(PSInput input) : SV_Target { - float4 color = texture.Sample(textureSampler, input.uv); + float4 color = inputTexture.Sample(textureSampler, input.uv); return color * input.color; } diff --git a/tools/code_generator.py b/tools/code_generator.py index 3bac016..2ac1f7a 100644 --- a/tools/code_generator.py +++ b/tools/code_generator.py @@ -171,7 +171,7 @@ class CodeGenerator: # 对于GLSL,需要写入uniform的详细信息 if isinstance(param.type, (ConstantBufferType, ParameterBlockType)): self._write_glsl_uniforms(writer, param, index) - elif target == TargetFormat.DXBC or target == TargetFormat.HLSL_DX11: + elif target == TargetFormat.DXBC: writer.write(f'desc.uniform_blocks[{index}].hlsl_register_b_n = {param.get_register_index()};') def _write_glsl_uniforms(self, writer: IndentManager, param: Parameter, block_index: int) -> None: @@ -214,7 +214,7 @@ class CodeGenerator: target = global_vars.target if target == TargetFormat.GLSL: writer.write(f'desc.images[{index}].glsl_name = "{param.name}";') - elif target == TargetFormat.DXBC or target == TargetFormat.HLSL_DX11: + elif target == TargetFormat.DXBC: writer.write(f'desc.images[{index}].hlsl_register_t_n = {param.get_register_index()};') def _write_sampler(self, writer: IndentManager, param: Parameter, index: int, stage_name: str) -> None: @@ -226,7 +226,7 @@ class CodeGenerator: target = global_vars.target if target == TargetFormat.GLSL: writer.write(f'desc.samplers[{index}].glsl_name = "{param.name}";') - elif target == TargetFormat.DXBC or target == TargetFormat.HLSL_DX11: + elif target == TargetFormat.DXBC: writer.write(f'desc.samplers[{index}].hlsl_register_s_n = {param.get_register_index()};') def _write_storage_buffer(self, writer: IndentManager, param: Parameter, index: int, stage_name: str) -> None: @@ -238,7 +238,7 @@ class CodeGenerator: target = global_vars.target if target == TargetFormat.GLSL: writer.write(f'desc.storage_buffers[{index}].glsl_binding_n = {param.get_register_index()};') - elif target == TargetFormat.DXBC or target == TargetFormat.HLSL_DX11: + elif target == TargetFormat.DXBC: writer.write(f'desc.storage_buffers[{index}].hlsl_register_u_n = {param.get_register_index()};') def _write_get_pipeline_desc_method(self, writer: IndentManager, binding_infos: ShaderInfos) -> None: diff --git a/tools/compiler_cmd.py b/tools/compiler_cmd.py index bdd82ad..59883a0 100644 --- a/tools/compiler_cmd.py +++ b/tools/compiler_cmd.py @@ -13,7 +13,6 @@ def make_cmd(source_file: str, target: TargetFormat, stage: Stage, entry_point: TargetFormat.GLSL: 'glsl', TargetFormat.DXBC: 'dxbc', TargetFormat.MSL: 'metal', - TargetFormat.HLSL_DX11: 'hlsl', }[target] stage_flag = { @@ -26,18 +25,29 @@ def make_cmd(source_file: str, target: TargetFormat, stage: Stage, entry_point: slangc_path, source_file, '-no-mangle', + '-lang', 'slang', '-entry', entry_point, - '-o', output_path, '-target', target_flag, '-stage', stage_flag, - '-g3', # 生成调试信息 - '-O0', # 禁用优化,便于调试和验证 + '-o', output_path, ] + + if global_vars.debug: + cmd.extend([ + '-g3', # 生成调试信息 + '-O0', # 禁用优化,便于调试和验证 + ]) + else: + cmd.extend([ + '-g0', # 禁用调试信息 + '-O3' # 启用高级优化 + ]) + # 添加包含路径 for include_path in global_vars.include_dirs: cmd.extend(['-I', include_path]) - if target == TargetFormat.DXBC or target == TargetFormat.HLSL_DX11: + if target == TargetFormat.DXBC: cmd.extend(['-profile', 'sm_5_1']) return cmd diff --git a/tools/global_vars.py b/tools/global_vars.py index 19b1d92..292f683 100644 --- a/tools/global_vars.py +++ b/tools/global_vars.py @@ -7,5 +7,6 @@ class GlobalVars: source_path = '' output_dir = '' target = TargetFormat.DXBC + debug = False global_vars = GlobalVars() diff --git a/tools/main.py b/tools/main.py index 1c53eed..483724f 100644 --- a/tools/main.py +++ b/tools/main.py @@ -15,10 +15,11 @@ def main(): parser = argparse.ArgumentParser(description='SDL3 GPU Slang Compiler') parser.add_argument('input', help='Input Slang shader file') - parser.add_argument('-t', '--target', choices=['spirv', 'dxbc', 'msl'], + parser.add_argument('-t', '--target', choices=['glsl', 'dxbc', 'msl'], required=True, help='Target shader format') parser.add_argument('-o', '--output-dir', required=True, help='Output path for binding code') parser.add_argument('-i', '--include-dir', help='Include path for slang shader') + parser.add_argument('-d', '--debug', action='store_true', help='Enable debug mode') args = parser.parse_args() @@ -30,6 +31,7 @@ def main(): global_vars.source_path = os.path.dirname(input_path) global_vars.output_dir = os.path.abspath(args.output_dir) global_vars.target = TargetFormat(args.target) + global_vars.debug = args.debug shader_infos = ShaderInfos( stages={} diff --git a/tools/shader_reflection_type.py b/tools/shader_reflection_type.py index 4083fcb..4286515 100644 --- a/tools/shader_reflection_type.py +++ b/tools/shader_reflection_type.py @@ -8,7 +8,6 @@ class TargetFormat(Enum): GLSL = "glsl" DXBC = "dxbc" MSL = "msl" - HLSL_DX11 = "hlsl" class BindingKind(Enum):