Skip to content

Commit

Permalink
Small clang-format.py fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tomadamatkinson committed Feb 5, 2024
1 parent 3573958 commit 976e593
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 59 deletions.
6 changes: 3 additions & 3 deletions app/plugins/batch_mode/batch_mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ using BatchModeTags = vkb::PluginBase<vkb::tags::Entrypoint, vkb::tags::FullCont

/**
* @brief Batch Mode
*
*
* Run a subset of samples. The next sample in the set will start after the current sample being executed has finished. Using --wrap-to-start will start again from the first sample after the last sample is executed.
*
*
* Usage: vulkan_samples batch --duration 3 --category performance --tag arm
*
*
*/
class BatchMode : public BatchModeTags
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ void DynamicRenderingLocalRead::prepare_pipelines()
VkPipelineRenderingCreateInfoKHR pipeline_rendering_create_info{VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO_KHR};
pipeline_create_info.pNext = &pipeline_rendering_create_info;
#else
pipeline_create_info.renderPass = render_pass;
pipeline_create_info.renderPass = render_pass;
#endif

/*
Expand Down Expand Up @@ -687,7 +687,7 @@ void DynamicRenderingLocalRead::prepare_pipelines()
pipeline_rendering_create_info.stencilAttachmentFormat = depth_format;
}
#else
pipeline_create_info.subpass = 0;
pipeline_create_info.subpass = 0;
#endif

shader_stages[0] = load_shader("dynamic_rendering_local_read/scene_opaque.vert", VK_SHADER_STAGE_VERTEX_BIT);
Expand Down Expand Up @@ -725,8 +725,8 @@ void DynamicRenderingLocalRead::prepare_pipelines()
pipeline_rendering_create_info.stencilAttachmentFormat = depth_format;
}
#else
blend_state.attachmentCount = 1;
pipeline_create_info.subpass = 2;
blend_state.attachmentCount = 1;
pipeline_create_info.subpass = 2;
#endif

shader_stages[0] = load_shader("dynamic_rendering_local_read/scene_transparent.vert", VK_SHADER_STAGE_VERTEX_BIT);
Expand All @@ -747,8 +747,8 @@ void DynamicRenderingLocalRead::prepare_pipelines()
pipeline_rendering_create_info.stencilAttachmentFormat = depth_format;
}
#else
blend_state.attachmentCount = 1;
pipeline_create_info.subpass = 1;
blend_state.attachmentCount = 1;
pipeline_create_info.subpass = 1;
#endif

blend_attachment_states = {
Expand Down Expand Up @@ -949,50 +949,50 @@ void DynamicRenderingLocalRead::build_command_buffers()
vkb::image_layout_transition(cmd, swapchain_buffers[i].image, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, subresource_range_color);

#else
VkRenderPassBeginInfo render_pass_begin_info = vkb::initializers::render_pass_begin_info();
render_pass_begin_info.renderPass = render_pass;
render_pass_begin_info.renderArea.offset.x = 0;
render_pass_begin_info.renderArea.offset.y = 0;
render_pass_begin_info.renderArea.extent.width = width;
render_pass_begin_info.renderArea.extent.height = height;
render_pass_begin_info.clearValueCount = 5;
render_pass_begin_info.pClearValues = clear_values;
render_pass_begin_info.framebuffer = framebuffers[i];

// Start our render pass, which contains multiple sub passes
vkCmdBeginRenderPass(cmd, &render_pass_begin_info, VK_SUBPASS_CONTENTS_INLINE);

VkViewport viewport = vkb::initializers::viewport(static_cast<float>(width), static_cast<float>(height), 0.0f, 1.0f);
vkCmdSetViewport(cmd, 0, 1, &viewport);

VkRect2D scissor = vkb::initializers::rect2D(width, height, 0, 0);
vkCmdSetScissor(cmd, 0, 1, &scissor);

// First sub pass
// Renders the components of the scene to the G-Buffer attachments
vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, scene_opaque_pass.pipeline);
vkCmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, scene_opaque_pass.pipeline_layout, 0, 1, &scene_opaque_pass.descriptor_set, 0, nullptr);
draw_scene(scenes.opaque, cmd, scene_opaque_pass.pipeline_layout);

// Second sub pass
// This subpass will use the G-Buffer components that have been filled in the first subpass as input attachment for the final compositing
vkCmdNextSubpass(cmd, VK_SUBPASS_CONTENTS_INLINE);

vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, composition_pass.pipeline);
vkCmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, composition_pass.pipeline_layout, 0, 1, &composition_pass.descriptor_set, 0, nullptr);
vkCmdDraw(cmd, 3, 1, 0, 0);

// Third subpass
// Render transparent geometry using a forward pass that compares against depth generated during G-Buffer fill
vkCmdNextSubpass(cmd, VK_SUBPASS_CONTENTS_INLINE);

vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, scene_transparent_pass.pipeline);
vkCmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, scene_transparent_pass.pipeline_layout, 0, 1, &scene_transparent_pass.descriptor_set, 0, nullptr);
draw_scene(scenes.transparent, cmd, scene_transparent_pass.pipeline_layout);

draw_ui(draw_cmd_buffers[i]);

vkCmdEndRenderPass(cmd);
VkRenderPassBeginInfo render_pass_begin_info = vkb::initializers::render_pass_begin_info();
render_pass_begin_info.renderPass = render_pass;
render_pass_begin_info.renderArea.offset.x = 0;
render_pass_begin_info.renderArea.offset.y = 0;
render_pass_begin_info.renderArea.extent.width = width;
render_pass_begin_info.renderArea.extent.height = height;
render_pass_begin_info.clearValueCount = 5;
render_pass_begin_info.pClearValues = clear_values;
render_pass_begin_info.framebuffer = framebuffers[i];

// Start our render pass, which contains multiple sub passes
vkCmdBeginRenderPass(cmd, &render_pass_begin_info, VK_SUBPASS_CONTENTS_INLINE);

VkViewport viewport = vkb::initializers::viewport(static_cast<float>(width), static_cast<float>(height), 0.0f, 1.0f);
vkCmdSetViewport(cmd, 0, 1, &viewport);

VkRect2D scissor = vkb::initializers::rect2D(width, height, 0, 0);
vkCmdSetScissor(cmd, 0, 1, &scissor);

// First sub pass
// Renders the components of the scene to the G-Buffer attachments
vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, scene_opaque_pass.pipeline);
vkCmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, scene_opaque_pass.pipeline_layout, 0, 1, &scene_opaque_pass.descriptor_set, 0, nullptr);
draw_scene(scenes.opaque, cmd, scene_opaque_pass.pipeline_layout);

// Second sub pass
// This subpass will use the G-Buffer components that have been filled in the first subpass as input attachment for the final compositing
vkCmdNextSubpass(cmd, VK_SUBPASS_CONTENTS_INLINE);

vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, composition_pass.pipeline);
vkCmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, composition_pass.pipeline_layout, 0, 1, &composition_pass.descriptor_set, 0, nullptr);
vkCmdDraw(cmd, 3, 1, 0, 0);

// Third subpass
// Render transparent geometry using a forward pass that compares against depth generated during G-Buffer fill
vkCmdNextSubpass(cmd, VK_SUBPASS_CONTENTS_INLINE);

vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, scene_transparent_pass.pipeline);
vkCmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, scene_transparent_pass.pipeline_layout, 0, 1, &scene_transparent_pass.descriptor_set, 0, nullptr);
draw_scene(scenes.transparent, cmd, scene_transparent_pass.pipeline_layout);

draw_ui(draw_cmd_buffers[i]);

vkCmdEndRenderPass(cmd);
#endif

VK_CHECK(vkEndCommandBuffer(cmd));
Expand Down
38 changes: 32 additions & 6 deletions scripts/clang_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,46 @@
from subprocess import check_output

# Get the file extension


def get_ext(file_path):
file_name = os.path.basename(file_path)
file_name, file_ext = os.path.splitext(file_name)
return file_ext


class terminal_colors:
SUCCESS = "\033[92m"
INFO = "\033[94m"
WARNING = "\033[33m"
ERROR = "\033[91m"
END = "\033[0m"


CLANG_FORMAT_VERSIONS = [14, 15, 16, 17]


def check_clang_format() -> bool:
clang_format_found = False

for version in CLANG_FORMAT_VERSIONS:
if which(f"clang-format-{version}"):
clang_format_found = True
break

if clang_format_found:
return True

return len(which("clang-format")) > 0

def get_clang_format() -> str:
for version in CLANG_FORMAT_VERSIONS:
if which(f"clang-format-{version}"):
return f"clang-format-{version}"

return "clang-format"


if __name__ == "__main__":
argument_parser = argparse.ArgumentParser(
description="Format C/C++ files using clang-format"
Expand All @@ -59,8 +87,8 @@ class terminal_colors:
print(terminal_colors.ERROR + "Missing git" + terminal_colors.END)
sys.exit(1)

if not which("clang-format"):
print(terminal_colors.ERROR + "Missing clang-format" + terminal_colors.END)
if not check_clang_format():
print(terminal_colors.ERROR + "Missing clang-format or clang-format-{14/15/16/17}" + terminal_colors.END)
sys.exit(1)

out = check_output(["git", "diff", args.branch, "--name-only"])
Expand All @@ -70,6 +98,7 @@ class terminal_colors:
files = out.decode("utf-8").split("\n")
files = [f for f in files if f and get_ext(f) in check_files]

clang_format = get_clang_format()
if files and len(files) > 0:
print(terminal_colors.INFO + "Formatting files:" + terminal_colors.END)
for f in files:
Expand All @@ -78,9 +107,6 @@ class terminal_colors:

for f in files:
if os.path.isfile(f):
check_output(["clang-format", "-i", f])
check_output([clang_format, "-i", f])
else:
print(terminal_colors.INFO + "No files to format" + terminal_colors.END)



0 comments on commit 976e593

Please sign in to comment.