Skip to content

Commit

Permalink
Small tidy ups
Browse files Browse the repository at this point in the history
- Triangle demo does not need an index buffer
- enable sample rate shading
- just don't use device features if they aren't enabled (rather than throwing exception)
- only allow MSAA num samples up to 8 (more than that doesn't work on my GPU (validation errors galore)
  • Loading branch information
0xworks committed Nov 19, 2020
1 parent 6ab49e0 commit ccd05d1
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 41 deletions.
13 changes: 1 addition & 12 deletions 001 - Triangle/src/Triangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class Triangle final : public Pikzel::Application {
, m_Input {GetWindow()}
{
CreateVertexBuffer();
CreateIndexBuffer();
CreatePipeline();
}

Expand All @@ -31,7 +30,7 @@ class Triangle final : public Pikzel::Application {
Pikzel::GraphicsContext& gc = GetWindow().GetGraphicsContext();
Pikzel::GCBinder bind {gc, *m_Pipeline};
gc.PushConstant("constants.mvp"_hs, m_Transform);
gc.DrawIndexed(*m_VertexBuffer, *m_IndexBuffer);
gc.DrawTriangles(*m_VertexBuffer, 3);
}


Expand All @@ -57,15 +56,6 @@ class Triangle final : public Pikzel::Application {
}


void CreateIndexBuffer() {
uint32_t indices[] = {
0, 1, 2
};

m_IndexBuffer = Pikzel::RenderCore::CreateIndexBuffer(sizeof(indices) / sizeof(uint32_t), indices);
}


void CreatePipeline() {
Pikzel::PipelineSettings settings {
m_VertexBuffer->GetLayout(),
Expand All @@ -82,7 +72,6 @@ class Triangle final : public Pikzel::Application {
Pikzel::Input m_Input;
glm::mat4 m_Transform = glm::identity<glm::mat4>();
std::shared_ptr<Pikzel::VertexBuffer> m_VertexBuffer;
std::shared_ptr<Pikzel::IndexBuffer> m_IndexBuffer;
std::unique_ptr<Pikzel::Pipeline> m_Pipeline;
};

Expand Down
11 changes: 8 additions & 3 deletions Pikzel/src/Pikzel/Platform/Vulkan/VulkanDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ namespace Pikzel {
vk::PhysicalDeviceFeatures features;
if (availableFeatures.samplerAnisotropy) {
features.setSamplerAnisotropy(true);
} else {
// TODO: just don't use this feature if it isn't available, rather than fatal error
throw std::runtime_error {"Sampler Anisotropy is not supported on this device!"};
}
if (availableFeatures.sampleRateShading) {
features.setSampleRateShading(true);
}
return features;
}
Expand Down Expand Up @@ -242,6 +242,11 @@ namespace Pikzel {
}


vk::PhysicalDeviceFeatures VulkanDevice::GetEnabledPhysicalDeviceFeatures() const {
return m_EnabledPhysicalDeviceFeatures;
}


void VulkanDevice::SubmitSingleTimeCommands(vk::Queue queue, const std::function<void(vk::CommandBuffer)>& action) {
std::vector<vk::CommandBuffer> commandBuffers = m_Device.allocateCommandBuffers({
m_CommandPool /*commandPool*/,
Expand Down
2 changes: 2 additions & 0 deletions Pikzel/src/Pikzel/Platform/Vulkan/VulkanDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ namespace Pikzel {

uint32_t GetMSAAMaxSamples() const;

vk::PhysicalDeviceFeatures GetEnabledPhysicalDeviceFeatures() const;

void SubmitSingleTimeCommands(vk::Queue queue, const std::function<void(vk::CommandBuffer)>& action);

private:
Expand Down
1 change: 0 additions & 1 deletion Pikzel/src/Pikzel/Platform/Vulkan/VulkanFramebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ namespace Pikzel {
: m_Device {device}
, m_Settings {settings}
{
// TODO anti-aliasing
m_DepthFormat = FindSupportedFormat(
m_Device->GetVkPhysicalDevice(),
{vk::Format::eD32SfloatS8Uint, vk::Format::eD32Sfloat, vk::Format::eD24UnormS8Uint, vk::Format::eD16UnormS8Uint, vk::Format::eD16Unorm},
Expand Down
14 changes: 7 additions & 7 deletions Pikzel/src/Pikzel/Platform/Vulkan/VulkanPipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,13 +509,13 @@ namespace Pikzel {

// Multi sampling state
vk::PipelineMultisampleStateCreateInfo multisampleState = {
{} /*flags*/,
gc.GetNumSamples() /*rasterizationSamples*/,
false /*sampleShadingEnable*/, // TODO: enable (requires device features: sampleRateShading)
0.2f /*minSampleShading*/,
nullptr /*pSampleMask*/,
false /*alphaToCoverageEnable*/,
false /*alphaToOneEnable*/
{} /*flags*/,
gc.GetNumSamples() /*rasterizationSamples*/,
m_Device->GetEnabledPhysicalDeviceFeatures().sampleRateShading /*sampleShadingEnable*/,
1.0f /*minSampleShading*/,
nullptr /*pSampleMask*/,
false /*alphaToCoverageEnable*/,
false /*alphaToOneEnable*/
};
pipelineCI.pMultisampleState = &multisampleState;

Expand Down
32 changes: 16 additions & 16 deletions Pikzel/src/Pikzel/Platform/Vulkan/VulkanTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,22 +164,22 @@ namespace Pikzel {

void VulkanTexture2D::CreateSampler() {
m_TextureSampler = m_Device->GetVkDevice().createSampler({
{} /*flags*/,
vk::Filter::eLinear /*magFilter*/,
vk::Filter::eLinear /*minFilter*/,
vk::SamplerMipmapMode::eLinear /*mipmapMode*/,
vk::SamplerAddressMode::eRepeat /*addressModeU*/,
vk::SamplerAddressMode::eRepeat /*addressModeV*/,
vk::SamplerAddressMode::eRepeat /*addressModeW*/,
0.0f /*mipLodBias*/,
true /*anisotropyEnable*/,
16 /*maxAnisotropy*/,
false /*compareEnable*/,
vk::CompareOp::eNever /*compareOp*/,
0.0f /*minLod*/,
static_cast<float>(m_Image->GetMIPLevels()) /*maxLod*/,
vk::BorderColor::eFloatOpaqueBlack /*borderColor*/,
false /*unnormalizedCoordinates*/
{} /*flags*/,
vk::Filter::eLinear /*magFilter*/,
vk::Filter::eLinear /*minFilter*/,
vk::SamplerMipmapMode::eLinear /*mipmapMode*/,
vk::SamplerAddressMode::eRepeat /*addressModeU*/,
vk::SamplerAddressMode::eRepeat /*addressModeV*/,
vk::SamplerAddressMode::eRepeat /*addressModeW*/,
0.0f /*mipLodBias*/,
m_Device->GetEnabledPhysicalDeviceFeatures().samplerAnisotropy /*anisotropyEnable*/,
16 /*maxAnisotropy*/,
false /*compareEnable*/,
vk::CompareOp::eNever /*compareOp*/,
0.0f /*minLod*/,
static_cast<float>(m_Image->GetMIPLevels()) /*maxLod*/,
vk::BorderColor::eFloatOpaqueBlack /*borderColor*/,
false /*unnormalizedCoordinates*/
});
}

Expand Down
9 changes: 7 additions & 2 deletions Pikzel/src/Pikzel/Platform/Windows/WindowsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,13 @@ namespace Pikzel {
glfwWindowHint(GLFW_CLIENT_API, clientAPI);
glfwWindowHint(GLFW_RESIZABLE, m_Settings.IsResizable ? GLFW_TRUE : GLFW_FALSE);

if ((m_Settings.MSAANumSamples <= 0) || (m_Settings.MSAANumSamples > 64) || (m_Settings.MSAANumSamples & (m_Settings.MSAANumSamples - 1))) {
throw std::logic_error {"WindowSettings AANumSamples is invalid. Must be a power of 2, up to 64"};
if (!(
(settings.MSAANumSamples == 1) ||
(settings.MSAANumSamples == 2) ||
(settings.MSAANumSamples == 4) ||
(settings.MSAANumSamples == 8)
)) {
throw std::runtime_error {"Invalid MSAA sample count. Must be 1, 2, 4, or 8"};
}
glfwWindowHint(GLFW_SAMPLES, m_Settings.MSAANumSamples);
m_Window = glfwCreateWindow((int)m_Settings.Width, (int)m_Settings.Height, m_Settings.Title, monitor, nullptr);
Expand Down
8 changes: 8 additions & 0 deletions Pikzel/src/Pikzel/Renderer/RenderCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ namespace Pikzel {


std::unique_ptr<Pikzel::Framebuffer> RenderCore::CreateFramebuffer(const FramebufferSettings& settings) {
if(!(
(settings.MSAANumSamples == 1) ||
(settings.MSAANumSamples == 2) ||
(settings.MSAANumSamples == 4) ||
(settings.MSAANumSamples == 8)
)) {
throw std::runtime_error {"Invalid MSAA sample count. Must be 1, 2, 4, or 8"};
}
return s_RenderCore->CreateFramebuffer(settings);
}

Expand Down

0 comments on commit ccd05d1

Please sign in to comment.