Add statically disabled tessellation on macOS/iOS

This commit is contained in:
Wojtek Figat
2024-03-30 18:46:37 +01:00
parent ce07edd1ec
commit 369c19bd5d
14 changed files with 51 additions and 20 deletions

View File

@@ -40,13 +40,23 @@
// True if allow graphics profile events and markers
#define GPU_ALLOW_PROFILE_EVENTS (!BUILD_RELEASE)
// True if allow hardware tessellation shaders (Hull and Domain shaders)
#ifndef GPU_ALLOW_TESSELLATION_SHADERS
#define GPU_ALLOW_TESSELLATION_SHADERS 1
#endif
// Enable/disable creating GPU resources on separate threads (otherwise only the main thread can be used)
#define GPU_ENABLE_ASYNC_RESOURCES_CREATION 1
// Enable/disable force shaders recompilation
#define GPU_FORCE_RECOMPILE_SHADERS 0
// Default back buffer pixel format
// Define default back buffer(s) format
#ifndef GPU_BACK_BUFFER_PIXEL_FORMAT
#define GPU_BACK_BUFFER_PIXEL_FORMAT PixelFormat::B8G8R8A8_UNorm
#endif
// Default depth buffer pixel format
#ifndef GPU_DEPTH_BUFFER_PIXEL_FORMAT
#define GPU_DEPTH_BUFFER_PIXEL_FORMAT PixelFormat::D32_Float
#endif
@@ -62,11 +72,6 @@
#define GPU_MAX_TEXTURE_MIP_LEVELS 15
#define GPU_MAX_TEXTURE_ARRAY_SIZE 1024
// Define default back buffer(s) format
#ifndef GPU_BACK_BUFFER_PIXEL_FORMAT
#define GPU_BACK_BUFFER_PIXEL_FORMAT PixelFormat::B8G8R8A8_UNorm
#endif
// Validate configuration
#if !ENABLE_ASSERTION
#undef GPU_ENABLE_ASSERTION

View File

@@ -146,6 +146,7 @@ bool DeferredMaterialShader::Load()
psDesc.DepthEnable = false;
}
#if GPU_ALLOW_TESSELLATION_SHADERS
// Check if use tessellation (both material and runtime supports it)
const bool useTess = _info.TessellationMode != TessellationMethod::None && GPUDevice::Instance->Limits.HasTessellation;
if (useTess)
@@ -153,6 +154,7 @@ bool DeferredMaterialShader::Load()
psDesc.HS = _shader->GetHS("HS");
psDesc.DS = _shader->GetDS("DS");
}
#endif
// GBuffer Pass
psDesc.VS = _shader->GetVS("VS");

View File

@@ -115,6 +115,7 @@ bool DeformableMaterialShader::Load()
psDesc.DepthEnable = (_info.FeaturesFlags & MaterialFeaturesFlags::DisableDepthTest) == MaterialFeaturesFlags::None;
psDesc.DepthWriteEnable = (_info.FeaturesFlags & MaterialFeaturesFlags::DisableDepthWrite) == MaterialFeaturesFlags::None;
#if GPU_ALLOW_TESSELLATION_SHADERS
// Check if use tessellation (both material and runtime supports it)
const bool useTess = _info.TessellationMode != TessellationMethod::None && GPUDevice::Instance->Limits.HasTessellation;
if (useTess)
@@ -122,6 +123,7 @@ bool DeformableMaterialShader::Load()
psDesc.HS = _shader->GetHS("HS");
psDesc.DS = _shader->GetDS("DS");
}
#endif
#if USE_EDITOR
if (_shader->HasShader("PS_QuadOverdraw"))

View File

@@ -133,6 +133,7 @@ bool ForwardMaterialShader::Load()
psDesc.DepthEnable = (_info.FeaturesFlags & MaterialFeaturesFlags::DisableDepthTest) == MaterialFeaturesFlags::None;
psDesc.DepthWriteEnable = (_info.FeaturesFlags & MaterialFeaturesFlags::DisableDepthWrite) == MaterialFeaturesFlags::None;
#if GPU_ALLOW_TESSELLATION_SHADERS
// Check if use tessellation (both material and runtime supports it)
const bool useTess = _info.TessellationMode != TessellationMethod::None && GPUDevice::Instance->Limits.HasTessellation;
if (useTess)
@@ -140,6 +141,7 @@ bool ForwardMaterialShader::Load()
psDesc.HS = _shader->GetHS("HS");
psDesc.DS = _shader->GetDS("DS");
}
#endif
#if USE_EDITOR
if (_shader->HasShader("PS_QuadOverdraw"))

View File

@@ -136,6 +136,7 @@ bool TerrainMaterialShader::Load()
psDesc.DepthEnable = (_info.FeaturesFlags & MaterialFeaturesFlags::DisableDepthTest) == MaterialFeaturesFlags::None;
psDesc.DepthWriteEnable = (_info.FeaturesFlags & MaterialFeaturesFlags::DisableDepthWrite) == MaterialFeaturesFlags::None;
#if GPU_ALLOW_TESSELLATION_SHADERS
// Check if use tessellation (both material and runtime supports it)
const bool useTess = _info.TessellationMode != TessellationMethod::None && GPUDevice::Instance->Limits.HasTessellation;
if (useTess)
@@ -143,6 +144,7 @@ bool TerrainMaterialShader::Load()
psDesc.HS = _shader->GetHS("HS");
psDesc.DS = _shader->GetDS("DS");
}
#endif
// Support blending but then use only emissive channel
switch (_info.BlendMode)

View File

@@ -126,6 +126,10 @@ bool GPUShader::Create(MemoryReadStream& stream)
LOG(Warning, "Failed to create {} Shader program '{}' ({}).", ::ToString(type), String(initializer.Name), name);
continue;
}
#if !GPU_ALLOW_TESSELLATION_SHADERS
if (type == ShaderStage::Hull || type == ShaderStage::Domain)
continue;
#endif
GPUShaderProgram* shader = CreateGPUShaderProgram(type, initializer, cache, cacheSize, stream);
if (shader == nullptr)
{

View File

@@ -351,7 +351,7 @@ bool GPUDeviceDX11::Init()
D3D11_FEATURE_DATA_D3D11_OPTIONS2 featureDataD3D11Options2 = {};
_device->CheckFeatureSupport(D3D11_FEATURE_D3D11_OPTIONS2, &featureDataD3D11Options2, sizeof(featureDataD3D11Options2));
limits.HasCompute = d3D10XHardwareOptions.ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x != 0;
limits.HasTessellation = true;
limits.HasTessellation = GPU_ALLOW_TESSELLATION_SHADERS;
limits.HasGeometryShaders = true;
limits.HasInstancing = true;
limits.HasVolumeTextureRendering = true;

View File

@@ -373,7 +373,7 @@ bool GPUDeviceDX12::Init()
{
auto& limits = Limits;
limits.HasCompute = true;
limits.HasTessellation = true;
limits.HasTessellation = GPU_ALLOW_TESSELLATION_SHADERS;
limits.HasGeometryShaders = true;
limits.HasInstancing = true;
limits.HasVolumeTextureRendering = true;

View File

@@ -25,21 +25,23 @@ namespace DescriptorSet
enum Stage
{
// Vertex shader stage
Vertex = 0,
Vertex,
// Pixel shader stage
Pixel = 1,
Pixel,
// Geometry shader stage
Geometry = 2,
Geometry,
#if GPU_ALLOW_TESSELLATION_SHADERS
// Hull shader stage
Hull = 3,
Hull,
// Domain shader stage
Domain = 4,
Domain,
#endif
// Graphics pipeline stages count
GraphicsStagesCount = 5,
GraphicsStagesCount,
// Compute pipeline slot
Compute = 0,
// The maximum amount of slots for all stages
Max = 5,
Max = GraphicsStagesCount,
};
template<typename T>

View File

@@ -1686,10 +1686,10 @@ bool GPUDeviceVulkan::Init()
auto& limits = Limits;
limits.HasCompute = GetShaderProfile() == ShaderProfile::Vulkan_SM5 && PhysicalDeviceLimits.maxComputeWorkGroupCount[0] >= GPU_MAX_CS_DISPATCH_THREAD_GROUPS && PhysicalDeviceLimits.maxComputeWorkGroupCount[1] >= GPU_MAX_CS_DISPATCH_THREAD_GROUPS;
#if PLATFORM_MAC || PLATFORM_IOS
limits.HasTessellation = false; // MoltenVK has artifacts when using tess
#else
#if GPU_ALLOW_TESSELLATION_SHADERS
limits.HasTessellation = !!PhysicalDeviceFeatures.tessellationShader && PhysicalDeviceLimits.maxBoundDescriptorSets > (uint32_t)DescriptorSet::Domain;
#else
limits.HasTessellation = false;
#endif
#if PLATFORM_ANDROID || PLATFORM_IOS
limits.HasGeometryShaders = false; // Don't even try GS on mobile

View File

@@ -133,17 +133,17 @@ PipelineLayoutVulkan* GPUPipelineStateVulkan::GetLayout()
return _layout;
DescriptorSetLayoutInfoVulkan descriptorSetLayoutInfo;
#define INIT_SHADER_STAGE(set, bit) \
if (DescriptorInfoPerStage[DescriptorSet::set]) \
descriptorSetLayoutInfo.AddBindingsForStage(bit, DescriptorSet::set, DescriptorInfoPerStage[DescriptorSet::set])
INIT_SHADER_STAGE(Vertex, VK_SHADER_STAGE_VERTEX_BIT);
#if GPU_ALLOW_TESSELLATION_SHADERS
INIT_SHADER_STAGE(Hull, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT);
INIT_SHADER_STAGE(Domain, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT);
#endif
INIT_SHADER_STAGE(Geometry, VK_SHADER_STAGE_GEOMETRY_BIT);
INIT_SHADER_STAGE(Pixel, VK_SHADER_STAGE_FRAGMENT_BIT);
#undef INIT_SHADER_STAGE
_layout = _device->GetOrCreateLayout(descriptorSetLayoutInfo);
ASSERT(_layout);
DescriptorSetsLayout = &_layout->DescriptorSetLayout;
@@ -253,8 +253,10 @@ bool GPUPipelineStateVulkan::Init(const Description& desc)
stage.pName = desc.type->GetName().Get(); \
}
INIT_SHADER_STAGE(VS, Vertex, VK_SHADER_STAGE_VERTEX_BIT);
#if GPU_ALLOW_TESSELLATION_SHADERS
INIT_SHADER_STAGE(HS, Hull, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT);
INIT_SHADER_STAGE(DS, Domain, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT);
#endif
INIT_SHADER_STAGE(GS, Geometry, VK_SHADER_STAGE_GEOMETRY_BIT);
INIT_SHADER_STAGE(PS, Pixel, VK_SHADER_STAGE_FRAGMENT_BIT);
#undef INIT_SHADER_STAGE
@@ -278,6 +280,7 @@ bool GPUPipelineStateVulkan::Init(const Description& desc)
_descInputAssembly.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
_desc.pInputAssemblyState = &_descInputAssembly;
#if GPU_ALLOW_TESSELLATION_SHADERS
// Tessellation
if (desc.HS)
{
@@ -285,6 +288,7 @@ bool GPUPipelineStateVulkan::Init(const Description& desc)
_descTessellation.patchControlPoints = desc.HS->GetControlPointsCount();
_desc.pTessellationState = &_descTessellation;
}
#endif
// Viewport
RenderToolsVulkan::ZeroStruct(_descViewport, VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO);

View File

@@ -93,7 +93,9 @@ private:
VkGraphicsPipelineCreateInfo _desc;
VkPipelineShaderStageCreateInfo _shaderStages[ShaderStage_Count - 1];
VkPipelineInputAssemblyStateCreateInfo _descInputAssembly;
#if GPU_ALLOW_TESSELLATION_SHADERS
VkPipelineTessellationStateCreateInfo _descTessellation;
#endif
VkPipelineViewportStateCreateInfo _descViewport;
VkPipelineDynamicStateCreateInfo _descDynamic;
VkDynamicState _dynamicStates[3];

View File

@@ -22,4 +22,7 @@
#define PLATFORM_HAS_HEADLESS_MODE 1
#define PLATFORM_DEBUG_BREAK __builtin_trap()
// MoltenVK has artifacts when using tess so disable it
#define GPU_ALLOW_TESSELLATION_SHADERS 0
#endif

View File

@@ -18,4 +18,7 @@
#define USE_MONO_AOT 1
#define USE_MONO_AOT_MODE MONO_AOT_MODE_FULL
// MoltenVK has artifacts when using tess so disable it
#define GPU_ALLOW_TESSELLATION_SHADERS 0
#endif