Skip to content

Commit

Permalink
Logical some device features removed, more device checks.
Browse files Browse the repository at this point in the history
  • Loading branch information
mattparks committed Mar 13, 2019
1 parent 77aae1c commit 040ae47
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Libraries/glslang
82 changes: 55 additions & 27 deletions Sources/Devices/LogicalDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,56 +142,84 @@ namespace acid
m_transferFamily = m_graphicsFamily;
}

VkPhysicalDeviceFeatures deviceFeatures = {};
deviceFeatures.sampleRateShading = VK_TRUE;
deviceFeatures.fillModeNonSolid = VK_TRUE;
deviceFeatures.wideLines = VK_TRUE;
deviceFeatures.samplerAnisotropy = VK_TRUE;
deviceFeatures.vertexPipelineStoresAndAtomics = VK_TRUE;
deviceFeatures.fragmentStoresAndAtomics = VK_TRUE;
deviceFeatures.shaderStorageImageExtendedFormats = VK_TRUE;
deviceFeatures.shaderStorageImageWriteWithoutFormat = VK_TRUE;
deviceFeatures.shaderClipDistance = VK_TRUE;
deviceFeatures.shaderCullDistance = VK_TRUE;
VkPhysicalDeviceFeatures enabledFeatures = {};

if (physicalDeviceFeatures.geometryShader)
// Enable sample rate shading filtering if supported.
if (physicalDeviceFeatures.sampleRateShading)
{
deviceFeatures.geometryShader = VK_TRUE;
}
else
{
Log::Error("Selected GPU does not support geometry shaders!");
enabledFeatures.sampleRateShading = VK_TRUE;
}

if (physicalDeviceFeatures.tessellationShader)
// Fill mode non solid is required for wireframe display.
if (physicalDeviceFeatures.fillModeNonSolid)
{
deviceFeatures.tessellationShader = VK_TRUE;
enabledFeatures.fillModeNonSolid = VK_TRUE;

// Wide lines must be present for line width > 1.0f.
if (physicalDeviceFeatures.wideLines)
{
enabledFeatures.wideLines = VK_TRUE;
}
}
else
{
Log::Error("Selected GPU does not support tessellation shaders!");
Log::Error("Selected GPU does not support wireframe pipelines!");
}

if (physicalDeviceFeatures.multiViewport)
if (physicalDeviceFeatures.samplerAnisotropy)
{
deviceFeatures.multiViewport = VK_TRUE;
enabledFeatures.samplerAnisotropy = VK_TRUE;
}
else
{
Log::Error("Selected GPU does not support multi viewports!");
Log::Error("Selected GPU does not support sampler anisotropy!");
}

if (physicalDeviceFeatures.textureCompressionBC)
{
deviceFeatures.textureCompressionBC = VK_TRUE;
enabledFeatures.textureCompressionBC = VK_TRUE;
}
else if (physicalDeviceFeatures.textureCompressionASTC_LDR)
{
deviceFeatures.textureCompressionASTC_LDR = VK_TRUE;
enabledFeatures.textureCompressionASTC_LDR = VK_TRUE;
}
else if (physicalDeviceFeatures.textureCompressionETC2)
{
deviceFeatures.textureCompressionETC2 = VK_TRUE;
enabledFeatures.textureCompressionETC2 = VK_TRUE;
}

// enabledFeatures.vertexPipelineStoresAndAtomics = VK_TRUE;
// enabledFeatures.fragmentStoresAndAtomics = VK_TRUE;
// enabledFeatures.shaderStorageImageExtendedFormats = VK_TRUE;
// enabledFeatures.shaderStorageImageWriteWithoutFormat = VK_TRUE;
// enabledFeatures.shaderClipDistance = VK_TRUE;
// enabledFeatures.shaderCullDistance = VK_TRUE;

if (physicalDeviceFeatures.geometryShader)
{
enabledFeatures.geometryShader = VK_TRUE;
}
else
{
Log::Error("Selected GPU does not support geometry shaders!");
}

if (physicalDeviceFeatures.tessellationShader)
{
enabledFeatures.tessellationShader = VK_TRUE;
}
else
{
Log::Error("Selected GPU does not support tessellation shaders!");
}

if (physicalDeviceFeatures.multiViewport)
{
enabledFeatures.multiViewport = VK_TRUE;
}
else
{
Log::Error("Selected GPU does not support multi viewports!");
}

VkDeviceCreateInfo deviceCreateInfo = {};
Expand All @@ -202,7 +230,7 @@ namespace acid
deviceCreateInfo.ppEnabledLayerNames = m_instance->GetInstanceLayers().data();
deviceCreateInfo.enabledExtensionCount = static_cast<uint32_t>(m_instance->GetDeviceExtensions().size());
deviceCreateInfo.ppEnabledExtensionNames = m_instance->GetDeviceExtensions().data();
deviceCreateInfo.pEnabledFeatures = &deviceFeatures;
deviceCreateInfo.pEnabledFeatures = &enabledFeatures;
Renderer::CheckVk(vkCreateDevice(m_physicalDevice->GetPhysicalDevice(), &deviceCreateInfo, nullptr, &m_logicalDevice));

vkGetDeviceQueue(m_logicalDevice, m_graphicsFamily, 0, &m_graphicsQueue);
Expand Down
5 changes: 4 additions & 1 deletion Sources/Devices/LogicalDevice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ namespace acid
LogicalDevice(const Instance *instance, const PhysicalDevice *physicalDevice, const Surface *surface);

~LogicalDevice();

const VkDevice &GetLogicalDevice() const { return m_logicalDevice; }

const VkPhysicalDeviceFeatures &GetEnabledFeatures() const { return m_enabledFeatures; }

const VkQueue &GetGraphicsQueue() const { return m_graphicsQueue; }

const VkQueue &GetPresentQueue() const { return m_presentQueue; }
Expand Down Expand Up @@ -45,6 +47,7 @@ namespace acid
const Surface *m_surface;

VkDevice m_logicalDevice;
VkPhysicalDeviceFeatures m_enabledFeatures;

VkQueueFlags m_supportedQueues;
uint32_t m_graphicsFamily;
Expand Down
6 changes: 6 additions & 0 deletions Sources/Renderer/Pipelines/PipelineGraphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,12 @@ namespace acid
void PipelineGraphics::CreateAttributes()
{
auto physicalDevice = Renderer::Get()->GetPhysicalDevice();
auto logicalDevice = Renderer::Get()->GetLogicalDevice();

if (m_polygonMode == VK_POLYGON_MODE_LINE && !logicalDevice->GetEnabledFeatures().fillModeNonSolid)
{
throw std::runtime_error("Cannot create graphics pipeline with line polygon mode when logical device does not support non solid fills.");
}

m_inputAssemblyState.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
m_inputAssemblyState.topology = m_topology;
Expand Down
2 changes: 1 addition & 1 deletion Sources/Textures/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ namespace acid
samplerCreateInfo.addressModeW = addressMode;
samplerCreateInfo.mipLodBias = 0.0f;
samplerCreateInfo.anisotropyEnable = static_cast<VkBool32>(anisotropic);
samplerCreateInfo.maxAnisotropy = anisotropic ? std::min(ANISOTROPY, physicalDevice->GetProperties().limits.maxSamplerAnisotropy) : 1.0f;
samplerCreateInfo.maxAnisotropy = (anisotropic && logicalDevice->GetEnabledFeatures().samplerAnisotropy) ? std::min(ANISOTROPY, physicalDevice->GetProperties().limits.maxSamplerAnisotropy) : 1.0f;
// samplerCreateInfo.compareEnable = VK_FALSE;
// samplerCreateInfo.compareOp = VK_COMPARE_OP_ALWAYS;
samplerCreateInfo.minLod = 0.0f;
Expand Down
2 changes: 1 addition & 1 deletion _clang-format
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -2
AccessModifierOffset: 0
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
Expand Down

0 comments on commit 040ae47

Please sign in to comment.