Skip to content

Commit

Permalink
Add shader argument declaration macroses to simplify program setup wi…
Browse files Browse the repository at this point in the history
…th root constants
  • Loading branch information
egorodet committed Sep 22, 2024
1 parent 38cd321 commit 4648f7c
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 31 deletions.
6 changes: 1 addition & 5 deletions Apps/02-HelloCube/HelloCubeApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,7 @@ class HelloCubeApp final // NOSONAR - destructor required
Rhi::ProgramArgumentAccessors
{
#ifdef UNIFORMS_ENABLED
{ // Uniforms argument is declared as root constant
{ Rhi::ShaderType::Vertex, "g_uniforms" },
Rhi::ProgramArgumentAccessType::FrameConstant,
Rhi::ProgramArgumentValueType::RootConstant
}
META_PROGRAM_ARG_ROOT_FRAME_CONSTANT(Rhi::ShaderType::Vertex, "g_uniforms")
#endif
},
GetScreenRenderPattern().GetAttachmentFormats()
Expand Down
14 changes: 3 additions & 11 deletions Apps/03-TexturedCube/TexturedCubeApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,9 @@ void TexturedCubeApp::Init()
}
},
rhi::ProgramArgumentAccessors
{ // Define arguments as root constants
{
{ rhi::ShaderType::Pixel, "g_constants" },
rhi::ProgramArgumentAccessType::Constant,
rhi::ProgramArgumentValueType::RootConstant
},
{
{ rhi::ShaderType::All, "g_uniforms" },
rhi::ProgramArgumentAccessType::FrameConstant,
rhi::ProgramArgumentValueType::RootConstant
}
{
META_PROGRAM_ARG_ROOT_CONSTANT(rhi::ShaderType::Pixel, "g_constants"),
META_PROGRAM_ARG_ROOT_FRAME_CONSTANT(rhi::ShaderType::All, "g_uniforms")
},
GetScreenRenderPattern().GetAttachmentFormats()
}
Expand Down
18 changes: 3 additions & 15 deletions Apps/04-ShadowCube/ShadowCubeApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,21 +147,9 @@ void ShadowCubeApp::Init()
},
rhi::ProgramArgumentAccessors
{
{
{ rhi::ShaderType::Pixel, "g_constants" },
rhi::ProgramArgumentAccessType::Constant,
rhi::ProgramArgumentValueType::RootConstant
},
{
{ rhi::ShaderType::Pixel, "g_scene_uniforms" },
rhi::ProgramArgumentAccessType::FrameConstant,
rhi::ProgramArgumentValueType::RootConstant
},
{
{ rhi::ShaderType::Vertex, "g_mesh_uniforms" },
rhi::ProgramArgumentAccessType::Mutable,
rhi::ProgramArgumentValueType::RootConstant
}
META_PROGRAM_ARG_ROOT_CONSTANT(rhi::ShaderType::Pixel, "g_constants"),
META_PROGRAM_ARG_ROOT_FRAME_CONSTANT(rhi::ShaderType::Pixel, "g_scene_uniforms"),
META_PROGRAM_ARG_ROOT_MUTABLE(rhi::ShaderType::Vertex, "g_mesh_uniforms")
},
GetScreenRenderPattern().GetAttachmentFormats()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,44 @@ using ProgramArgumentBindingValue = std::variant<ResourceView, ResourceViews,
using ProgramBindingValueByArgument = std::unordered_map<ProgramArgument, ProgramArgumentBindingValue, ProgramArgument::Hash>;

} // namespace Methane::Graphics::Rhi

// Helper macroses for program argument accessors initialization in program descriptor:

#define META_PROGRAM_ARG(shader_type, arg_name, access_type, value_type) \
Methane::Graphics::Rhi::ProgramArgumentAccessor{ { shader_type, arg_name }, access_type, value_type }

#define META_PROGRAM_ARG_ROOT(shader_type, arg_name, access_type) \
META_PROGRAM_ARG(shader_type, arg_name, access_type, Methane::Graphics::Rhi::ProgramArgumentValueType::RootConstant)

#define META_PROGRAM_ARG_ROOT_CONSTANT(shader_type, arg_name) \
META_PROGRAM_ARG_ROOT(shader_type, arg_name, Methane::Graphics::Rhi::ProgramArgumentAccessType::Constant)

#define META_PROGRAM_ARG_ROOT_FRAME_CONSTANT(shader_type, arg_name) \
META_PROGRAM_ARG_ROOT(shader_type, arg_name, Methane::Graphics::Rhi::ProgramArgumentAccessType::FrameConstant)

#define META_PROGRAM_ARG_ROOT_MUTABLE(shader_type, arg_name) \
META_PROGRAM_ARG_ROOT(shader_type, arg_name, Methane::Graphics::Rhi::ProgramArgumentAccessType::Mutable)

#define META_PROGRAM_ARG_RESOURCE(shader_type, arg_name, access_type) \
META_PROGRAM_ARG(shader_type, arg_name, access_type, Methane::Graphics::Rhi::ProgramArgumentValueType::ResourceView)

#define META_PROGRAM_ARG_RESOURCE_CONSTANT(shader_type, arg_name) \
META_PROGRAM_ARG_RESOURCE(shader_type, arg_name, Methane::Graphics::Rhi::ProgramArgumentAccessType::Constant)

#define META_PROGRAM_ARG_RESOURCE_FRAME_CONSTANT(shader_type, arg_name) \
META_PROGRAM_ARG_RESOURCE(shader_type, arg_name, Methane::Graphics::Rhi::ProgramArgumentAccessType::FrameConstant)

#define META_PROGRAM_ARG_RESOURCE_MUTABLE(shader_type, arg_name) \
META_PROGRAM_ARG_RESOURCE(shader_type, arg_name, Methane::Graphics::Rhi::ProgramArgumentAccessType::Mutable)

#define META_PROGRAM_ARG_RESOURCES(shader_type, arg_name, access_type) \
META_PROGRAM_ARG(shader_type, arg_name, access_type, Methane::Graphics::Rhi::ProgramArgumentValueType::ResourceViews)

#define META_PROGRAM_ARG_RESOURCES_CONSTANT(shader_type, arg_name) \
META_PROGRAM_ARG_RESOURCES(shader_type, arg_name, Methane::Graphics::Rhi::ProgramArgumentAccessType::Constant)

#define META_PROGRAM_ARG_RESOURCES_FRAME_CONSTANT(shader_type, arg_name) \
META_PROGRAM_ARG_RESOURCES(shader_type, arg_name, Methane::Graphics::Rhi::ProgramArgumentAccessType::FrameConstant)

#define META_PROGRAM_ARG_RESOURCES_MUTABLE(shader_type, arg_name) \
META_PROGRAM_ARG_RESOURCES(shader_type, arg_name, Methane::Graphics::Rhi::ProgramArgumentAccessType::Mutable)

0 comments on commit 4648f7c

Please sign in to comment.