Skip to content

Commit

Permalink
Add the wide_lines renderer feature
Browse files Browse the repository at this point in the history
This feature provides availability of the lineWidth property in
Vulkan pipeline configuration.
  • Loading branch information
kosude committed Dec 30, 2023
1 parent ef5ec8e commit 102292c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
1 change: 1 addition & 0 deletions include/thallium/core/pipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ typedef struct TL_PipelineRasterizerDescriptor_t {
float depth_bias_clamp;

/// @brief The width of all line primitives.
/// This value is **silently ignored** and defaults to 1.0 if the `wide_lines` feature is disabled on the relevant renderer.
float line_width;
} TL_PipelineRasterizerDescriptor_t;

Expand Down
3 changes: 3 additions & 0 deletions include/thallium/core/renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
typedef struct TL_RendererFeatures_t {
/// @brief The renderer can present images to a swapchain.
bool presentation;

/// @brief The renderer can draw line primitives with a variable line width.
bool wide_lines;
} TL_RendererFeatures_t;

/**
Expand Down
19 changes: 16 additions & 3 deletions src/lib/vulkan/vk_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ static carray_t __ValidateExtensions(const VkPhysicalDevice physical_device, con
static void __EnumerateRequiredExtensions(const TL_RendererFeatures_t requirements, uint32_t *const out_extension_count,
const char **out_extension_names);

static void __UpdateRendererFeaturesWithSupported(TL_RendererFeatures_t *const features, carray_t extensions, const TL_Debugger_t *const debugger);
static void __UpdateRendererFeaturesWithSupported(TL_RendererFeatures_t *const features, carray_t extensions,
const VkPhysicalDeviceFeatures *device_feats, const TL_Debugger_t *const debugger);

static VkPhysicalDeviceFeatures __ValidateDeviceFeatures(const VkPhysicalDevice physical_device, VkPhysicalDeviceFeatures features,
bool *const out_missing_flag, const TL_Debugger_t *const debugger);
Expand All @@ -87,7 +88,7 @@ VkDevice TLVK_LogicalDeviceCreate(const VkPhysicalDevice physical_device, const
return VK_NULL_HANDLE;
}

__UpdateRendererFeaturesWithSupported(out_rfeatures, extensions, debugger);
__UpdateRendererFeaturesWithSupported(out_rfeatures, extensions, &features, debugger);

VkDeviceCreateInfo device_create_info;
device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
Expand Down Expand Up @@ -439,7 +440,9 @@ static void __EnumerateRequiredExtensions(const TL_RendererFeatures_t requiremen
*out_extension_count = count_ret;
}

static void __UpdateRendererFeaturesWithSupported(TL_RendererFeatures_t *const features, carray_t extensions, const TL_Debugger_t *const debugger) {
static void __UpdateRendererFeaturesWithSupported(TL_RendererFeatures_t *const features, carray_t extensions,
const VkPhysicalDeviceFeatures *device_feats, const TL_Debugger_t *const debugger)
{
// presentation feature availability
{
bool pa = false;
Expand All @@ -459,6 +462,13 @@ static void __UpdateRendererFeaturesWithSupported(TL_RendererFeatures_t *const f
"When creating Vulkan device: RENDERER FEATURE UNAVAILABLE (missing device extensions) - 'presentation' was disabled!");
}
}

// wide_lines feature availability
{
if (!device_feats->wideLines) {
features->wide_lines = false;
}
}
}

static VkPhysicalDeviceFeatures __ValidateDeviceFeatures(const VkPhysicalDevice physical_device, VkPhysicalDeviceFeatures features,
Expand Down Expand Up @@ -540,6 +550,9 @@ static VkPhysicalDeviceFeatures __ValidateDeviceFeatures(const VkPhysicalDevice
static VkPhysicalDeviceFeatures __EnumerateRequiredDeviceFeatures(const TL_RendererFeatures_t requirements) {
VkPhysicalDeviceFeatures feat = { 0 };

if (requirements.wide_lines)
feat.wideLines = true;

return feat;
}

Expand Down
10 changes: 6 additions & 4 deletions src/lib/vulkan/vk_pipeline_system.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ typedef struct __GraphicsPipelineConfig {
} __GraphicsPipelineConfig;


static __GraphicsPipelineConfig __ConfigureGraphicsPipeline(const TL_PipelineDescriptor_t descriptor);
static __GraphicsPipelineConfig __ConfigureGraphicsPipeline(const TL_PipelineDescriptor_t descriptor, const TL_RendererFeatures_t *features);

static VkPipeline __CreateGraphicsPipeline(const TLVK_FuncSet_t *devfs, const VkDevice device, const __GraphicsPipelineConfig config);

Expand All @@ -45,6 +45,7 @@ TLVK_PipelineSystem_t *TLVK_PipelineSystemCreate(const TLVK_RendererSystem_t *co

const TL_Debugger_t *debugger = renderer_system->renderer->debugger;
const VkDevice device = renderer_system->vk_logical_device;
const TL_RendererFeatures_t *rfeatures = &(renderer_system->renderer->features);

TLVK_PipelineSystem_t *pipeline_system = malloc(sizeof(TLVK_PipelineSystem_t));
if (!pipeline_system) {
Expand All @@ -59,7 +60,7 @@ TLVK_PipelineSystem_t *TLVK_PipelineSystemCreate(const TLVK_RendererSystem_t *co
VkPipeline pso;
switch (descriptor.type) {
case TL_PIPELINE_TYPE_GRAPHICS:
pso = __CreateGraphicsPipeline(devfs, device, __ConfigureGraphicsPipeline(descriptor));
pso = __CreateGraphicsPipeline(devfs, device, __ConfigureGraphicsPipeline(descriptor, rfeatures));
break;
default:
TL_Error(debugger, "When creating Vulkan pipeline system: pipeline descriptor specified invalid pipeline type %d", descriptor.type);
Expand Down Expand Up @@ -92,7 +93,7 @@ void TLVK_PipelineSystemDestroy(TLVK_PipelineSystem_t *const pipeline_system) {
}


static __GraphicsPipelineConfig __ConfigureGraphicsPipeline(const TL_PipelineDescriptor_t descriptor) {
static __GraphicsPipelineConfig __ConfigureGraphicsPipeline(const TL_PipelineDescriptor_t descriptor, const TL_RendererFeatures_t *features) {
__GraphicsPipelineConfig config = { 0 };

// TODO: shader modules
Expand Down Expand Up @@ -146,7 +147,8 @@ static __GraphicsPipelineConfig __ConfigureGraphicsPipeline(const TL_PipelineDes
config.rasterizer_info.depthBiasConstantFactor = descriptor.rasterizer.depth_bias_constant_factor;
config.rasterizer_info.depthBiasClamp = descriptor.rasterizer.depth_bias_clamp;
config.rasterizer_info.depthBiasSlopeFactor = descriptor.rasterizer.depth_bias_slope_factor;
config.rasterizer_info.lineWidth = descriptor.rasterizer.line_width;
config.rasterizer_info.lineWidth =
(features->wide_lines) ? descriptor.rasterizer.line_width : 1.0f;

// TODO: when render passes are implemented, get the sample count from the render pass and use that
config.multisample_info.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Expand Down

0 comments on commit 102292c

Please sign in to comment.