Skip to content

Commit

Permalink
Zephyr: GPU: third refactoring pass
Browse files Browse the repository at this point in the history
  • Loading branch information
fleroviux committed Nov 21, 2023
1 parent 0c26d68 commit 73433ad
Show file tree
Hide file tree
Showing 19 changed files with 94 additions and 94 deletions.
4 changes: 2 additions & 2 deletions zephyr/gpu/include/zephyr/gpu/buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ namespace zephyr {
virtual void Flush(size_t offset, size_t size) = 0;

template<typename T>
void Update(T const* data, size_t count = 1, size_t index = 0) {
void Update(const T* data, size_t count = 1, size_t index = 0) {
auto offset = index * sizeof(T);
auto size = count * sizeof(T);
auto range_end = offset + size;

Map();

if (range_end <= Size()) {
if(range_end <= Size()) {
std::memcpy((u8*)Data() + offset, data, size);
}

Expand Down
2 changes: 1 addition & 1 deletion zephyr/gpu/include/zephyr/gpu/command_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace zephyr {
PipelineLayout* pipeline_layout,
u32 offset,
u32 size,
void const* data
const void* data
) = 0;

virtual void BeginRenderPass(
Expand Down
2 changes: 1 addition & 1 deletion zephyr/gpu/include/zephyr/gpu/render_device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace zephyr {

virtual std::unique_ptr<Buffer> CreateBuffer(Buffer::Usage usage, Buffer::Flags flags, size_t size) = 0;

virtual std::shared_ptr<ShaderModule> CreateShaderModule(u32 const* spirv, size_t size) = 0;
virtual std::shared_ptr<ShaderModule> CreateShaderModule(const u32* spirv, size_t size) = 0;

virtual std::unique_ptr<Texture> CreateTexture2D(
u32 width,
Expand Down
6 changes: 3 additions & 3 deletions zephyr/gpu/include/zephyr/gpu/texture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ namespace zephyr {
: aspect{aspect}, base_mip{base_mip}, mip_count{mip_count}, base_layer{base_layer}, layer_count{layer_count} {
}

SubresourceRange(SubresourceLayers const& layers)
SubresourceRange(const SubresourceLayers& layers)
: aspect{layers.aspect}, base_mip{layers.mip_level}, mip_count{1}, base_layer{layers.base_layer}, layer_count{layers.layer_count} {
}

Expand Down Expand Up @@ -173,8 +173,8 @@ namespace zephyr {
virtual std::unique_ptr<View> CreateView(
View::Type type,
Format format,
SubresourceRange const& range,
ComponentMapping const& mapping = {}
const SubresourceRange& range,
const ComponentMapping& mapping = {}
) = 0;
};

Expand Down
6 changes: 3 additions & 3 deletions zephyr/gpu/src/vulkan/bind_group.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace zephyr {
.pSetLayouts = (const VkDescriptorSetLayout*)&layout_handle
};

if (vkAllocateDescriptorSets(device, &info, &m_descriptor_set) != VK_SUCCESS) {
if(vkAllocateDescriptorSets(device, &info, &m_descriptor_set) != VK_SUCCESS) {
ZEPHYR_PANIC("VulkanBindGroup: failed to allocate descriptor set");
}
}
Expand Down Expand Up @@ -134,7 +134,7 @@ namespace zephyr {
, m_descriptor_pool{descriptor_pool} {
std::vector<VkDescriptorSetLayoutBinding> bindings{};

for (const auto& entry : entries) {
for(const auto& entry : entries) {
bindings.push_back({
.binding = entry.binding,
.descriptorType = (VkDescriptorType)entry.type,
Expand All @@ -152,7 +152,7 @@ namespace zephyr {
.pBindings = bindings.data()
};

if (vkCreateDescriptorSetLayout(device, &info, nullptr, &m_layout) != VK_SUCCESS) {
if(vkCreateDescriptorSetLayout(device, &info, nullptr, &m_layout) != VK_SUCCESS) {
ZEPHYR_PANIC("VulkanBindGroupLayout: failed to create descriptor set layout");
}
}
Expand Down
10 changes: 5 additions & 5 deletions zephyr/gpu/src/vulkan/command_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace zephyr {
.commandBufferCount = 1
};

if (vkAllocateCommandBuffers(device, &info, &m_buffer) != VK_SUCCESS) {
if(vkAllocateCommandBuffers(device, &info, &m_buffer) != VK_SUCCESS) {
ZEPHYR_PANIC("Vulkan: failed to allocate command buffer");
}
}
Expand All @@ -36,7 +36,7 @@ namespace zephyr {
}

void Begin(OneTimeSubmit one_time_submit) override {
const auto begin_info = VkCommandBufferBeginInfo{
const VkCommandBufferBeginInfo begin_info{
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
.pNext = nullptr,
.flags = (VkCommandBufferUsageFlags)one_time_submit,
Expand Down Expand Up @@ -179,7 +179,7 @@ namespace zephyr {
PipelineLayout* pipeline_layout,
u32 offset,
u32 size,
void const* data
const void* data
) override {
vkCmdPushConstants(m_buffer, (VkPipelineLayout)pipeline_layout->Handle(), VK_SHADER_STAGE_ALL, offset, size, data);
}
Expand Down Expand Up @@ -249,11 +249,11 @@ namespace zephyr {

const VkDeviceSize buffer_offsets[32] = { 0 };

if (buffers.size() > 32) {
if(buffers.size() > 32) {
ZEPHYR_PANIC("VulkanCommandBuffer: can't bind more than 32 vertex buffers at once");
}

for (int i = 0; i < buffers.size(); i++) {
for(int i = 0; i < buffers.size(); i++) {
buffer_handles[i] = (VkBuffer)buffers[i]->Handle();
}

Expand Down
2 changes: 1 addition & 1 deletion zephyr/gpu/src/vulkan/command_pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace zephyr {
.queueFamilyIndex = queue_family_index
};

if (vkCreateCommandPool(device, &info, nullptr, &m_pool) != VK_SUCCESS) {
if(vkCreateCommandPool(device, &info, nullptr, &m_pool) != VK_SUCCESS) {
ZEPHYR_PANIC("Vulkan: failed to create a command pool");
}
}
Expand Down
2 changes: 1 addition & 1 deletion zephyr/gpu/src/vulkan/fence.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace zephyr {
.flags = (create_signalled == CreateSignalled::Yes) ? VK_FENCE_CREATE_SIGNALED_BIT : 0u
};

if (vkCreateFence(m_device, &info, nullptr, &m_fence) != VK_SUCCESS) {
if(vkCreateFence(m_device, &info, nullptr, &m_fence) != VK_SUCCESS) {
ZEPHYR_PANIC("VulkanFence: failed to create fence :(");
}
}
Expand Down
98 changes: 49 additions & 49 deletions zephyr/gpu/src/vulkan/pipeline_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ namespace zephyr {
}

void SetShaderModule(ShaderStage stage, std::shared_ptr<ShaderModule> shader_module) override {
switch (stage) {
switch(stage) {
case ShaderStage::Vertex:
m_own.shader_vert = std::move(shader_module);
break;
Expand Down Expand Up @@ -218,7 +218,7 @@ namespace zephyr {
auto Build() -> std::unique_ptr<GraphicsPipeline> override {
auto number_of_color_attachments = m_own.render_pass->GetNumberOfColorAttachments();

if (number_of_color_attachments > m_attachment_blend_state.size()) {
if(number_of_color_attachments > m_attachment_blend_state.size()) {
ZEPHYR_PANIC("VulkanGraphicsPipelineBuilder: render pass with more than 32 color attachments is unsupported.");
}

Expand Down Expand Up @@ -249,7 +249,7 @@ namespace zephyr {

auto pipeline = VkPipeline{};

if (vkCreateGraphicsPipelines(m_device, VK_NULL_HANDLE, 1, &m_pipeline_info, nullptr, &pipeline) != VK_SUCCESS) {
if(vkCreateGraphicsPipelines(m_device, VK_NULL_HANDLE, 1, &m_pipeline_info, nullptr, &pipeline) != VK_SUCCESS) {
ZEPHYR_PANIC("VulkanGraphicsPipelineBuilder: failed to create graphics pipeline");
}

Expand All @@ -258,7 +258,7 @@ namespace zephyr {

private:
void UpdatePipelineStages() {
const auto PushStage = [this](VkShaderStageFlagBits stage, std::shared_ptr<ShaderModule> const& shader) {
const auto PushStage = [this](VkShaderStageFlagBits stage, const std::shared_ptr<ShaderModule>& shader) {
m_pipeline_stages.PushBack({
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
.pNext = nullptr,
Expand Down Expand Up @@ -290,75 +290,75 @@ namespace zephyr {

auto GetVertexInputAttributeFormat(VertexDataType data_type, int components, bool normalized) -> VkFormat {
// @todo: optimise this with a lookup table
switch (data_type) {
switch(data_type) {
case VertexDataType::SInt8: {
if (normalized) {
if (components == 1) return VK_FORMAT_R8_SNORM;
if (components == 2) return VK_FORMAT_R8G8_SNORM;
if (components == 3) return VK_FORMAT_R8G8B8_SNORM;
if (components == 4) return VK_FORMAT_R8G8B8A8_SNORM;
if(normalized) {
if(components == 1) return VK_FORMAT_R8_SNORM;
if(components == 2) return VK_FORMAT_R8G8_SNORM;
if(components == 3) return VK_FORMAT_R8G8B8_SNORM;
if(components == 4) return VK_FORMAT_R8G8B8A8_SNORM;
} else {
if (components == 1) return VK_FORMAT_R8_SINT;
if (components == 2) return VK_FORMAT_R8G8_SINT;
if (components == 3) return VK_FORMAT_R8G8B8_SINT;
if (components == 4) return VK_FORMAT_R8G8B8A8_SINT;
if(components == 1) return VK_FORMAT_R8_SINT;
if(components == 2) return VK_FORMAT_R8G8_SINT;
if(components == 3) return VK_FORMAT_R8G8B8_SINT;
if(components == 4) return VK_FORMAT_R8G8B8A8_SINT;
}
break;
}
case VertexDataType::UInt8: {
if (normalized) {
if (components == 1) return VK_FORMAT_R8_UNORM;
if (components == 2) return VK_FORMAT_R8G8_UNORM;
if (components == 3) return VK_FORMAT_R8G8B8_UNORM;
if (components == 4) return VK_FORMAT_R8G8B8A8_UNORM;
if(normalized) {
if(components == 1) return VK_FORMAT_R8_UNORM;
if(components == 2) return VK_FORMAT_R8G8_UNORM;
if(components == 3) return VK_FORMAT_R8G8B8_UNORM;
if(components == 4) return VK_FORMAT_R8G8B8A8_UNORM;
} else {
if (components == 1) return VK_FORMAT_R8_UINT;
if (components == 2) return VK_FORMAT_R8G8_UINT;
if (components == 3) return VK_FORMAT_R8G8B8_UINT;
if (components == 4) return VK_FORMAT_R8G8B8A8_UINT;
if(components == 1) return VK_FORMAT_R8_UINT;
if(components == 2) return VK_FORMAT_R8G8_UINT;
if(components == 3) return VK_FORMAT_R8G8B8_UINT;
if(components == 4) return VK_FORMAT_R8G8B8A8_UINT;
}
break;
}
case VertexDataType::SInt16: {
if (normalized) {
if (components == 1) return VK_FORMAT_R16_SNORM;
if (components == 2) return VK_FORMAT_R16G16_SNORM;
if (components == 3) return VK_FORMAT_R16G16B16_SNORM;
if (components == 4) return VK_FORMAT_R16G16B16A16_SNORM;
if(normalized) {
if(components == 1) return VK_FORMAT_R16_SNORM;
if(components == 2) return VK_FORMAT_R16G16_SNORM;
if(components == 3) return VK_FORMAT_R16G16B16_SNORM;
if(components == 4) return VK_FORMAT_R16G16B16A16_SNORM;
} else {
if (components == 1) return VK_FORMAT_R16_SINT;
if (components == 2) return VK_FORMAT_R16G16_SINT;
if (components == 3) return VK_FORMAT_R16G16B16_SINT;
if (components == 4) return VK_FORMAT_R16G16B16A16_SINT;
if(components == 1) return VK_FORMAT_R16_SINT;
if(components == 2) return VK_FORMAT_R16G16_SINT;
if(components == 3) return VK_FORMAT_R16G16B16_SINT;
if(components == 4) return VK_FORMAT_R16G16B16A16_SINT;
}
break;
}
case VertexDataType::UInt16: {
if (normalized) {
if (components == 1) return VK_FORMAT_R16_UNORM;
if (components == 2) return VK_FORMAT_R16G16_UNORM;
if (components == 3) return VK_FORMAT_R16G16B16_UNORM;
if (components == 4) return VK_FORMAT_R16G16B16A16_UNORM;
if(normalized) {
if(components == 1) return VK_FORMAT_R16_UNORM;
if(components == 2) return VK_FORMAT_R16G16_UNORM;
if(components == 3) return VK_FORMAT_R16G16B16_UNORM;
if(components == 4) return VK_FORMAT_R16G16B16A16_UNORM;
} else {
if (components == 1) return VK_FORMAT_R16_UINT;
if (components == 2) return VK_FORMAT_R16G16_UINT;
if (components == 3) return VK_FORMAT_R16G16B16_UINT;
if (components == 4) return VK_FORMAT_R16G16B16A16_UINT;
if(components == 1) return VK_FORMAT_R16_UINT;
if(components == 2) return VK_FORMAT_R16G16_UINT;
if(components == 3) return VK_FORMAT_R16G16B16_UINT;
if(components == 4) return VK_FORMAT_R16G16B16A16_UINT;
}
break;
}
case VertexDataType::Float16: {
if (components == 1) return VK_FORMAT_R16_SFLOAT;
if (components == 2) return VK_FORMAT_R16G16_SFLOAT;
if (components == 3) return VK_FORMAT_R16G16B16_SFLOAT;
if (components == 4) return VK_FORMAT_R16G16B16A16_SFLOAT;
if(components == 1) return VK_FORMAT_R16_SFLOAT;
if(components == 2) return VK_FORMAT_R16G16_SFLOAT;
if(components == 3) return VK_FORMAT_R16G16B16_SFLOAT;
if(components == 4) return VK_FORMAT_R16G16B16A16_SFLOAT;
break;
}
case VertexDataType::Float32: {
if (components == 1) return VK_FORMAT_R32_SFLOAT;
if (components == 2) return VK_FORMAT_R32G32_SFLOAT;
if (components == 3) return VK_FORMAT_R32G32B32_SFLOAT;
if (components == 4) return VK_FORMAT_R32G32B32A32_SFLOAT;
if(components == 1) return VK_FORMAT_R32_SFLOAT;
if(components == 2) return VK_FORMAT_R32G32_SFLOAT;
if(components == 3) return VK_FORMAT_R32G32B32_SFLOAT;
if(components == 4) return VK_FORMAT_R32G32B32A32_SFLOAT;
break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions zephyr/gpu/src/vulkan/pipeline_layout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace zephyr {
) : m_device{device} {
std::vector<VkDescriptorSetLayout> descriptor_set_layouts{};

for (auto& bind_group_layout : bind_group_layouts) {
for(auto& bind_group_layout : bind_group_layouts) {
descriptor_set_layouts.push_back((VkDescriptorSetLayout)bind_group_layout->Handle());
}

Expand All @@ -33,7 +33,7 @@ namespace zephyr {
.pPushConstantRanges = &push_constant_rage
};

if (vkCreatePipelineLayout(device, &info, nullptr, &m_layout) != VK_SUCCESS) {
if(vkCreatePipelineLayout(device, &info, nullptr, &m_layout) != VK_SUCCESS) {
ZEPHYR_PANIC("VulkanPipelineLayout: failed to create pipeline layout");
}
}
Expand Down
2 changes: 1 addition & 1 deletion zephyr/gpu/src/vulkan/queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace zephyr {
void Submit(std::span<CommandBuffer* const> buffers, Fence* fence) override {
VkCommandBuffer handles[buffers.size()];

for (size_t i = 0; i < buffers.size(); i++) {
for(size_t i = 0; i < buffers.size(); i++) {
handles[i] = (VkCommandBuffer)buffers[i]->Handle();
}

Expand Down
8 changes: 4 additions & 4 deletions zephyr/gpu/src/vulkan/render_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ namespace zephyr {
}

Sampler* DefaultNearestSampler() override {
if (!m_default_nearest_sampler) {
if(!m_default_nearest_sampler) {
m_default_nearest_sampler = CreateSampler(Sampler::Config{
.mag_filter = Sampler::FilterMode::Nearest,
.min_filter = Sampler::FilterMode::Nearest,
Expand All @@ -98,7 +98,7 @@ namespace zephyr {
}

Sampler* DefaultLinearSampler() override {
if (!m_default_linear_sampler) {
if(!m_default_linear_sampler) {
m_default_linear_sampler = CreateSampler(Sampler::Config{
.mag_filter = Sampler::FilterMode::Linear,
.min_filter = Sampler::FilterMode::Linear,
Expand Down Expand Up @@ -187,7 +187,7 @@ namespace zephyr {
.pTypeExternalMemoryHandleTypes = nullptr
};

if (vmaCreateAllocator(&info, &m_allocator) != VK_SUCCESS) {
if(vmaCreateAllocator(&info, &m_allocator) != VK_SUCCESS) {
ZEPHYR_PANIC("VulkanRenderDevice: failed to create the VMA allocator");
}
}
Expand Down Expand Up @@ -226,7 +226,7 @@ namespace zephyr {
.pPoolSizes = pool_sizes
};

if (vkCreateDescriptorPool(m_device, &info, nullptr, &m_descriptor_pool) != VK_SUCCESS) {
if(vkCreateDescriptorPool(m_device, &info, nullptr, &m_descriptor_pool) != VK_SUCCESS) {
ZEPHYR_PANIC("VulkanRenderDevice: failed to create descriptor pool");
}
}
Expand Down
2 changes: 1 addition & 1 deletion zephyr/gpu/src/vulkan/render_pass.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace zephyr {
}

void SetClearColor(int index, float r, float g, float b, float a) override {
if (index >= m_color_attachment_count) {
if(index >= m_color_attachment_count) {
ZEPHYR_PANIC("VulkanRenderPass: SetClearColor() called with an out-of-bounds index");
}

Expand Down
Loading

0 comments on commit 73433ad

Please sign in to comment.