Skip to content

Commit 23f9c25

Browse files
committed
Enable support for Bresenham lines
Bresenham lines are required by ANGLE in order to support emulation of OpenGL ES style lines on top of SwiftShader Vulkan. Bug: b/139800520 Change-Id: I8b77775af836a238d309cc19b495b61d2c3a3487 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/37428 Presubmit-Ready: Alexis Hétu <sugoi@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com> Tested-by: Alexis Hétu <sugoi@google.com> Reviewed-by: Antonio Maiorano <amaiorano@google.com>
1 parent 4100b73 commit 23f9c25

File tree

8 files changed

+75
-1
lines changed

8 files changed

+75
-1
lines changed

src/Device/Context.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ namespace sw
110110

111111
cullMode = VK_CULL_MODE_FRONT_BIT;
112112
frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
113+
lineRasterizationMode = VK_LINE_RASTERIZATION_MODE_DEFAULT_EXT;
113114

114115
depthBias = 0.0f;
115116
slopeDepthBias = 0.0f;

src/Device/Context.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ namespace sw
9797
VkCullModeFlags cullMode;
9898
VkFrontFace frontFace;
9999
VkPolygonMode polygonMode;
100+
VkLineRasterizationModeEXT lineRasterizationMode;
100101

101102
float depthBias;
102103
float slopeDepthBias;

src/Device/Renderer.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ namespace sw
261261
draw->numBatches = (count + draw->numPrimitivesPerBatch - 1) / draw->numPrimitivesPerBatch;
262262
draw->topology = context->topology;
263263
draw->indexType = indexType;
264+
draw->lineRasterizationMode = context->lineRasterizationMode;
264265

265266
draw->vertexRoutine = vertexRoutine;
266267
draw->setupRoutine = setupRoutine;
@@ -813,7 +814,15 @@ namespace sw
813814
return false;
814815
}
815816

816-
if(true) // Rectangle centered on the line segment
817+
// TODO(b/142965928): Bresenham lines should render the same with or without
818+
// multisampling, which will require a special case in the
819+
// code when multisampling is on. For now, we just use
820+
// rectangular lines when multisampling is enabled.
821+
822+
// We use rectangular lines for non Bresenham lines and
823+
// for Bresenham lines when multiSampling is enabled
824+
if((draw.setupState.multiSample > 1) ||
825+
(draw.lineRasterizationMode != VK_LINE_RASTERIZATION_MODE_BRESENHAM_EXT)) // Rectangle centered on the line segment
817826
{
818827
float4 P[4];
819828
int C[4];

src/Device/Renderer.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ namespace sw
151151

152152
VkPrimitiveTopology topology;
153153
VkIndexType indexType;
154+
VkLineRasterizationModeEXT lineRasterizationMode;
154155

155156
std::shared_ptr<Routine> vertexRoutine;
156157
std::shared_ptr<Routine> setupRoutine;

src/Vulkan/VkPhysicalDevice.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,16 @@ void PhysicalDevice::getFeatures(VkPhysicalDeviceShaderDrawParameterFeatures* fe
134134
features->shaderDrawParameters = VK_FALSE;
135135
}
136136

137+
void PhysicalDevice::getFeatures(VkPhysicalDeviceLineRasterizationFeaturesEXT* features) const
138+
{
139+
features->rectangularLines = VK_TRUE;
140+
features->bresenhamLines = VK_TRUE;
141+
features->smoothLines = VK_FALSE;
142+
features->stippledRectangularLines = VK_FALSE;
143+
features->stippledBresenhamLines = VK_FALSE;
144+
features->stippledSmoothLines = VK_FALSE;
145+
}
146+
137147
VkSampleCountFlags PhysicalDevice::getSampleCounts() const
138148
{
139149
return VK_SAMPLE_COUNT_1_BIT | VK_SAMPLE_COUNT_4_BIT;
@@ -379,6 +389,11 @@ void PhysicalDevice::getProperties(VkPhysicalDeviceDriverPropertiesKHR* properti
379389
properties->conformanceVersion = {1, 1, 3, 3};
380390
}
381391

392+
void PhysicalDevice::getProperties(VkPhysicalDeviceLineRasterizationPropertiesEXT* properties) const
393+
{
394+
properties->lineSubPixelPrecisionBits = vk::SUBPIXEL_PRECISION_BITS;
395+
}
396+
382397
bool PhysicalDevice::hasFeatures(const VkPhysicalDeviceFeatures& requestedFeatures) const
383398
{
384399
const VkPhysicalDeviceFeatures& supportedFeatures = getFeatures();

src/Vulkan/VkPhysicalDevice.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class PhysicalDevice
4343
void getFeatures(VkPhysicalDeviceMultiviewFeatures* features) const;
4444
void getFeatures(VkPhysicalDeviceProtectedMemoryFeatures* features) const;
4545
void getFeatures(VkPhysicalDeviceShaderDrawParameterFeatures* features) const;
46+
void getFeatures(VkPhysicalDeviceLineRasterizationFeaturesEXT* features) const;
4647
bool hasFeatures(const VkPhysicalDeviceFeatures& requestedFeatures) const;
4748

4849
const VkPhysicalDeviceProperties& getProperties() const;
@@ -61,6 +62,7 @@ class PhysicalDevice
6162
void getProperties(const VkPhysicalDeviceExternalFenceInfo* pExternalFenceInfo, VkExternalFenceProperties* pExternalFenceProperties) const;
6263
void getProperties(const VkPhysicalDeviceExternalSemaphoreInfo* pExternalSemaphoreInfo, VkExternalSemaphoreProperties* pExternalSemaphoreProperties) const;
6364
void getProperties(VkPhysicalDeviceDriverPropertiesKHR* properties) const;
65+
void getProperties(VkPhysicalDeviceLineRasterizationPropertiesEXT* properties) const;
6466

6567
void getFormatProperties(Format format, VkFormatProperties* pFormatProperties) const;
6668
void getImageFormatProperties(Format format, VkImageType type, VkImageTiling tiling,

src/Vulkan/VkPipeline.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,25 @@ GraphicsPipeline::GraphicsPipeline(const VkGraphicsPipelineCreateInfo* pCreateIn
397397
context.depthBias = (rasterizationState->depthBiasEnable != VK_FALSE) ? rasterizationState->depthBiasConstantFactor : 0.0f;
398398
context.slopeDepthBias = (rasterizationState->depthBiasEnable != VK_FALSE) ? rasterizationState->depthBiasSlopeFactor : 0.0f;
399399

400+
const VkBaseInStructure* extensionCreateInfo = reinterpret_cast<const VkBaseInStructure*>(rasterizationState->pNext);
401+
while(extensionCreateInfo)
402+
{
403+
switch(extensionCreateInfo->sType)
404+
{
405+
case VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_LINE_STATE_CREATE_INFO_EXT:
406+
{
407+
const VkPipelineRasterizationLineStateCreateInfoEXT* lineStateCreateInfo = reinterpret_cast<const VkPipelineRasterizationLineStateCreateInfoEXT*>(extensionCreateInfo);
408+
context.lineRasterizationMode = lineStateCreateInfo->lineRasterizationMode;
409+
}
410+
break;
411+
default:
412+
UNIMPLEMENTED("extensionCreateInfo->sType");
413+
break;
414+
}
415+
416+
extensionCreateInfo = extensionCreateInfo->pNext;
417+
}
418+
400419
const VkPipelineMultisampleStateCreateInfo* multisampleState = pCreateInfo->pMultisampleState;
401420
if(multisampleState)
402421
{

src/Vulkan/libVulkan.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ static const VkExtensionProperties deviceExtensionProperties[] =
217217
// Only 1.1 core version of this is supported. The extension has additional requirements
218218
//{ VK_KHR_VARIABLE_POINTERS_EXTENSION_NAME, VK_KHR_VARIABLE_POINTERS_SPEC_VERSION },
219219
{ VK_EXT_QUEUE_FAMILY_FOREIGN_EXTENSION_NAME, VK_EXT_QUEUE_FAMILY_FOREIGN_SPEC_VERSION },
220+
// The following extension is only used to add support for Bresenham lines
221+
{ VK_EXT_LINE_RASTERIZATION_EXTENSION_NAME, VK_EXT_LINE_RASTERIZATION_SPEC_VERSION },
220222
#ifndef __ANDROID__
221223
// We fully support the KHR_swapchain v70 additions, so just track the spec version.
222224
{ VK_KHR_SWAPCHAIN_EXTENSION_NAME, VK_KHR_SWAPCHAIN_SPEC_VERSION },
@@ -583,6 +585,18 @@ VKAPI_ATTR VkResult VKAPI_CALL vkCreateDevice(VkPhysicalDevice physicalDevice, c
583585
}
584586
}
585587
break;
588+
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_LINE_RASTERIZATION_FEATURES_EXT:
589+
{
590+
const VkPhysicalDeviceLineRasterizationFeaturesEXT* lineRasterizationFeatures = reinterpret_cast<const VkPhysicalDeviceLineRasterizationFeaturesEXT*>(extensionCreateInfo);
591+
if((lineRasterizationFeatures->smoothLines == VK_TRUE) ||
592+
(lineRasterizationFeatures->stippledBresenhamLines == VK_TRUE) ||
593+
(lineRasterizationFeatures->stippledRectangularLines == VK_TRUE) ||
594+
(lineRasterizationFeatures->stippledSmoothLines == VK_TRUE))
595+
{
596+
return VK_ERROR_FEATURE_NOT_PRESENT;
597+
}
598+
}
599+
break;
586600
default:
587601
// "the [driver] must skip over, without processing (other than reading the sType and pNext members) any structures in the chain with sType values not defined by [supported extenions]"
588602
UNIMPLEMENTED("extensionCreateInfo->sType %d", int(extensionCreateInfo->sType)); // TODO(b/119321052): UNIMPLEMENTED() should be used only for features that must still be implemented. Use a more informational macro here.
@@ -2387,6 +2401,12 @@ VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceFeatures2(VkPhysicalDevice physica
23872401
vk::Cast(physicalDevice)->getFeatures(&features);
23882402
}
23892403
break;
2404+
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_LINE_RASTERIZATION_FEATURES_EXT:
2405+
{
2406+
auto& features = *reinterpret_cast<VkPhysicalDeviceLineRasterizationFeaturesEXT*>(extensionFeatures);
2407+
vk::Cast(physicalDevice)->getFeatures(&features);
2408+
}
2409+
break;
23902410
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONDITIONAL_RENDERING_FEATURES_EXT:
23912411
ASSERT(!HasExtensionProperty(VK_EXT_CONDITIONAL_RENDERING_EXTENSION_NAME, deviceExtensionProperties,
23922412
sizeof(deviceExtensionProperties) / sizeof(deviceExtensionProperties[0])));
@@ -2477,6 +2497,12 @@ VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceProperties2(VkPhysicalDevice physi
24772497
}
24782498
break;
24792499
#endif
2500+
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_LINE_RASTERIZATION_PROPERTIES_EXT:
2501+
{
2502+
auto& properties = *reinterpret_cast<VkPhysicalDeviceLineRasterizationPropertiesEXT*>(extensionProperties);
2503+
vk::Cast(physicalDevice)->getProperties(&properties);
2504+
}
2505+
break;
24802506
default:
24812507
// "the [driver] must skip over, without processing (other than reading the sType and pNext members) any structures in the chain with sType values not defined by [supported extenions]"
24822508
UNIMPLEMENTED("extensionProperties->sType"); // TODO(b/119321052): UNIMPLEMENTED() should be used only for features that must still be implemented. Use a more informational macro here.

0 commit comments

Comments
 (0)