Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Font rendering improvements #738

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class RenderConfigReader {
var dstColorBlendFactor: Blending.BlendFactor = Blending.BlendFactor.OneMinusSrcAlpha,
var srcAlphaBlendFactor: Blending.BlendFactor = Blending.BlendFactor.SrcAlpha,
var dstAlphaBlendFactor: Blending.BlendFactor = Blending.BlendFactor.OneMinusSrcAlpha,
var samples: Int = 1,
var shaders: List<String> = listOf(),

@JsonDeserialize(contentUsing = JsonDeserialisers.BindingDeserializer::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
*
* This function also creates the necessary images, memory allocs, and image views.
*/
protected fun createAttachment(format: Int, usage: Int, attachmentWidth: Int = width, attachmentHeight: Int = height, name: String = ""): VulkanFramebufferAttachment {
protected fun createAttachment(format: Int, usage: Int, attachmentWidth: Int = width, attachmentHeight: Int = height, name: String = "", samples: Int = VK_SAMPLE_COUNT_1_BIT): VulkanFramebufferAttachment {

Check warning on line 167 in src/main/kotlin/graphics/scenery/backends/vulkan/VulkanFramebuffer.kt

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/main/kotlin/graphics/scenery/backends/vulkan/VulkanFramebuffer.kt#L167

The function createAttachment(format: Int, usage: Int, attachmentWidth: Int, attachmentHeight: Int, name: String, samples: Int) has too many parameters. The current threshold is set to 6.
val a = VulkanFramebufferAttachment()
var aspectMask: Int = 0
var imageLayout: Int = 0
Expand Down Expand Up @@ -195,7 +195,7 @@
.extent(imageExtent)
.mipLevels(1)
.arrayLayers(1)
.samples(VK_SAMPLE_COUNT_1_BIT)
.samples(samples)
.tiling(VK_IMAGE_TILING_OPTIMAL)
.usage(usage or VK_IMAGE_USAGE_SAMPLED_BIT or VK_IMAGE_USAGE_TRANSFER_SRC_BIT or VK_IMAGE_USAGE_TRANSFER_DST_BIT)

Expand Down Expand Up @@ -290,7 +290,7 @@
* Internal function to create a depth/stencil attachment of [format], with
* dimensions [attachmentWidth] x [attachmentHeight].
*/
private fun createAndAddDepthStencilAttachmentInternal(name: String, format: Int, attachmentWidth: Int, attachmentHeight: Int) {
private fun createAndAddDepthStencilAttachmentInternal(name: String, format: Int, attachmentWidth: Int, attachmentHeight: Int, samples: Int = VK_SAMPLE_COUNT_1_BIT) {
val att = createAttachment(format, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, attachmentWidth, attachmentHeight, name)

val (loadOp, stencilLoadOp) = if (!shouldClear) {
Expand All @@ -305,7 +305,7 @@
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
}

att.desc.samples(VK_SAMPLE_COUNT_1_BIT)
att.desc.samples(samples)
.loadOp(loadOp)
.storeOp(VK_ATTACHMENT_STORE_OP_STORE)
.stencilLoadOp(stencilLoadOp)
Expand All @@ -323,7 +323,7 @@
* Internal function to create a new color attachment of format [fornat], with
* dimensions [attachmentWidth] x [attachmentHeight].
*/
private fun createAndAddColorAttachmentInternal(name: String, format: Int, attachmentWidth: Int, attachmentHeight: Int) {
private fun createAndAddColorAttachmentInternal(name: String, format: Int, attachmentWidth: Int, attachmentHeight: Int, samples: Int = VK_SAMPLE_COUNT_1_BIT) {
val att = createAttachment(format, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, attachmentWidth, attachmentHeight, name)

val (loadOp, stencilLoadOp) = if (!shouldClear) {
Expand All @@ -338,7 +338,7 @@
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
}

att.desc.samples(VK_SAMPLE_COUNT_1_BIT)
att.desc.samples(samples)
.loadOp(loadOp)
.storeOp(VK_ATTACHMENT_STORE_OP_STORE)
.stencilLoadOp(stencilLoadOp)
Expand All @@ -353,67 +353,67 @@
/**
* Adds a float attachment with a bit depth of [channelDepth], and a size of [attachmentWidth] x [attachmentHeight].
*/
fun addFloatBuffer(name: String, channelDepth: Int, attachmentWidth: Int = width, attachmentHeight: Int = height): VulkanFramebuffer {
fun addFloatBuffer(name: String, channelDepth: Int, attachmentWidth: Int = width, attachmentHeight: Int = height, samples: Int = VK_SAMPLE_COUNT_1_BIT): VulkanFramebuffer {
val format: Int = when(channelDepth) {
16 -> VK_FORMAT_R16_SFLOAT
32 -> VK_FORMAT_R32_SFLOAT
else -> { logger.warn("Unsupported channel depth $channelDepth, using 16 bit."); VK_FORMAT_R16_SFLOAT }
}

createAndAddColorAttachmentInternal(name, format, attachmentWidth, attachmentHeight)
createAndAddColorAttachmentInternal(name, format, attachmentWidth, attachmentHeight, samples = samples)

return this
}

/**
* Adds a float RG attachment with a bit depth of [channelDepth], and a size of [attachmentWidth] x [attachmentHeight].
*/
fun addFloatRGBuffer(name: String, channelDepth: Int, attachmentWidth: Int = width, attachmentHeight: Int = height): VulkanFramebuffer {
fun addFloatRGBuffer(name: String, channelDepth: Int, attachmentWidth: Int = width, attachmentHeight: Int = height, samples: Int = VK_SAMPLE_COUNT_1_BIT): VulkanFramebuffer {
val format: Int = when(channelDepth) {
16 -> VK_FORMAT_R16G16_SFLOAT
32 -> VK_FORMAT_R32G32_SFLOAT
else -> { logger.warn("Unsupported channel depth $channelDepth, using 16 bit."); VK_FORMAT_R16G16_SFLOAT }
}

createAndAddColorAttachmentInternal(name, format, attachmentWidth, attachmentHeight)
createAndAddColorAttachmentInternal(name, format, attachmentWidth, attachmentHeight, samples = samples)

return this
}

/**
* Adds a float RGB attachment with a bit depth of [channelDepth], and a size of [attachmentWidth] x [attachmentHeight].
*/
fun addFloatRGBBuffer(name: String, channelDepth: Int, attachmentWidth: Int = width, attachmentHeight: Int = height): VulkanFramebuffer {
fun addFloatRGBBuffer(name: String, channelDepth: Int, attachmentWidth: Int = width, attachmentHeight: Int = height, samples: Int = VK_SAMPLE_COUNT_1_BIT): VulkanFramebuffer {
val format: Int = when(channelDepth) {
16 -> VK_FORMAT_R16G16B16_SFLOAT
32 -> VK_FORMAT_R32G32B32_SFLOAT
else -> { logger.warn("Unsupported channel depth $channelDepth, using 16 bit."); VK_FORMAT_R16G16B16A16_SFLOAT }
}

createAndAddColorAttachmentInternal(name, format, attachmentWidth, attachmentHeight)
createAndAddColorAttachmentInternal(name, format, attachmentWidth, attachmentHeight, samples = samples)

return this
}

/**
* Adds a float RGBA attachment with a bit depth of [channelDepth], and a size of [attachmentWidth] x [attachmentHeight].
*/
fun addFloatRGBABuffer(name: String, channelDepth: Int, attachmentWidth: Int = width, attachmentHeight: Int = height): VulkanFramebuffer {
fun addFloatRGBABuffer(name: String, channelDepth: Int, attachmentWidth: Int = width, attachmentHeight: Int = height, samples: Int = VK_SAMPLE_COUNT_1_BIT): VulkanFramebuffer {
val format: Int = when(channelDepth) {
16 -> VK_FORMAT_R16G16B16A16_SFLOAT
32 -> VK_FORMAT_R32G32B32A32_SFLOAT
else -> { logger.warn("Unsupported channel depth $channelDepth, using 16 bit."); VK_FORMAT_R16G16B16A16_SFLOAT }
}

createAndAddColorAttachmentInternal(name, format, attachmentWidth, attachmentHeight)
createAndAddColorAttachmentInternal(name, format, attachmentWidth, attachmentHeight, samples)

return this
}

/**
* Adds an unsigned byte RGBA attachment with a bit depth of [channelDepth], and a size of [attachmentWidth] x [attachmentHeight].
*/
fun addUnsignedByteRGBABuffer(name: String, channelDepth: Int, attachmentWidth: Int = width, attachmentHeight: Int = height): VulkanFramebuffer {
fun addUnsignedByteRGBABuffer(name: String, channelDepth: Int, attachmentWidth: Int = width, attachmentHeight: Int = height, samples: Int = VK_SAMPLE_COUNT_1_BIT): VulkanFramebuffer {
val format: Int = when(channelDepth) {
8 -> if (sRGB) {
VK_FORMAT_R8G8B8A8_SRGB
Expand All @@ -424,30 +424,30 @@
else -> { logger.warn("Unsupported channel depth $channelDepth, using 16 bit."); VK_FORMAT_R16G16B16A16_UINT }
}

createAndAddColorAttachmentInternal(name, format, attachmentWidth, attachmentHeight)
createAndAddColorAttachmentInternal(name, format, attachmentWidth, attachmentHeight, samples = samples)

return this
}

/**
* Adds an unsigned byte R attachment with a bit depth of [channelDepth], and a size of [attachmentWidth] x [attachmentHeight].
*/
fun addUnsignedByteRBuffer(name: String, channelDepth: Int, attachmentWidth: Int = width, attachmentHeight: Int = height): VulkanFramebuffer {
fun addUnsignedByteRBuffer(name: String, channelDepth: Int, attachmentWidth: Int = width, attachmentHeight: Int = height, samples: Int = VK_SAMPLE_COUNT_1_BIT): VulkanFramebuffer {
val format: Int = when(channelDepth) {
8 -> VK_FORMAT_R8_UNORM
16 -> VK_FORMAT_R16_UNORM
else -> { logger.warn("Unsupported channel depth $channelDepth, using 16 bit."); VK_FORMAT_R16_UNORM }
}

createAndAddColorAttachmentInternal(name, format, attachmentWidth, attachmentHeight)
createAndAddColorAttachmentInternal(name, format, attachmentWidth, attachmentHeight, samples = samples)

return this
}

/**
* Adds a depth buffer attachment with a bit depth of [depth], and a size of [attachmentWidth] x [attachmentHeight].
*/
fun addDepthBuffer(name: String, depth: Int, attachmentWidth: Int = width, attachmentHeight: Int = height): VulkanFramebuffer {
fun addDepthBuffer(name: String, depth: Int, attachmentWidth: Int = width, attachmentHeight: Int = height, samples: Int = VK_SAMPLE_COUNT_1_BIT): VulkanFramebuffer {
val format: Int = when(depth) {
16 -> VK_FORMAT_D16_UNORM
24 -> VK_FORMAT_D24_UNORM_S8_UINT
Expand All @@ -457,7 +457,7 @@

val bestSupportedFormat = getBestDepthFormat(format).first()

createAndAddDepthStencilAttachmentInternal(name, bestSupportedFormat, attachmentWidth, attachmentHeight)
createAndAddDepthStencilAttachmentInternal(name, bestSupportedFormat, attachmentWidth, attachmentHeight, samples = samples)

return this
}
Expand All @@ -466,7 +466,7 @@
* Adds a swapchain-based attachment from the given [swapchain]. The image will be derived
* from the swapchain's image [index].
*/
fun addSwapchainAttachment(name: String, swapchain: Swapchain, index: Int): VulkanFramebuffer {
fun addSwapchainAttachment(name: String, swapchain: Swapchain, index: Int, samples: Int = VK_SAMPLE_COUNT_1_BIT): VulkanFramebuffer {
val att = VulkanFramebufferAttachment()

att.image = swapchain.images[index]
Expand All @@ -483,7 +483,7 @@
val initialImageLayout = VK_IMAGE_LAYOUT_UNDEFINED

att.desc
.samples(VK_SAMPLE_COUNT_1_BIT)
.samples(samples)
.loadOp(loadOp)
.storeOp(VK_ATTACHMENT_STORE_OP_STORE)
.stencilLoadOp(stencilLoadOp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class VulkanPipeline(val device: VulkanDevice, val renderpass: VulkanRenderpass,
.sType(VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO)
.pNext(NULL)
.pSampleMask(null)
.rasterizationSamples(VK_SAMPLE_COUNT_1_BIT)
.rasterizationSamples(renderpass.passConfig.samples)

val shaderStages = ArrayList<VulkanShaderModule>(2)

Expand Down Expand Up @@ -164,6 +164,11 @@ class VulkanPipeline(val device: VulkanDevice, val renderpass: VulkanRenderpass,

val (p, pipelineCreateInfo) = when(type) {
PipelineType.Graphics -> {
if(device.features.sampleRateShading() && multisampleState.rasterizationSamples() > VK_SAMPLE_COUNT_1_BIT) {
multisampleState.sampleShadingEnable(true)
multisampleState.minSampleShading(0.25f)
}

val pipelineCreateInfo = VkGraphicsPipelineCreateInfo.calloc(1)
.sType(VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO)
.pNext(NULL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -954,27 +954,29 @@ open class VulkanRenderpass(val name: String, var config: RenderConfigReader.Ren
shouldClear = !passConfig.blitInputs,
sRGB = config.sRGB)

val samples = pass.passConfig.samples

rt.value.attachments.forEach { att ->
logger.info(" + attachment ${att.key}, ${att.value.name}")

when (att.value) {
RenderConfigReader.TargetFormat.RGBA_Float32 -> framebuffer.addFloatRGBABuffer(att.key, 32)
RenderConfigReader.TargetFormat.RGBA_Float16 -> framebuffer.addFloatRGBABuffer(att.key, 16)
RenderConfigReader.TargetFormat.RGBA_Float32 -> framebuffer.addFloatRGBABuffer(att.key, 32, samples = samples)
RenderConfigReader.TargetFormat.RGBA_Float16 -> framebuffer.addFloatRGBABuffer(att.key, 16, samples = samples)

RenderConfigReader.TargetFormat.RGB_Float32 -> framebuffer.addFloatRGBBuffer(att.key, 32)
RenderConfigReader.TargetFormat.RGB_Float16 -> framebuffer.addFloatRGBBuffer(att.key, 16)
RenderConfigReader.TargetFormat.RGB_Float32 -> framebuffer.addFloatRGBBuffer(att.key, 32, samples = samples)
RenderConfigReader.TargetFormat.RGB_Float16 -> framebuffer.addFloatRGBBuffer(att.key, 16, samples = samples)

RenderConfigReader.TargetFormat.RG_Float32 -> framebuffer.addFloatRGBuffer(att.key, 32)
RenderConfigReader.TargetFormat.RG_Float16 -> framebuffer.addFloatRGBuffer(att.key, 16)
RenderConfigReader.TargetFormat.RG_Float32 -> framebuffer.addFloatRGBuffer(att.key, 32, samples = samples)
RenderConfigReader.TargetFormat.RG_Float16 -> framebuffer.addFloatRGBuffer(att.key, 16, samples = samples)

RenderConfigReader.TargetFormat.RGBA_UInt16 -> framebuffer.addUnsignedByteRGBABuffer(att.key, 16)
RenderConfigReader.TargetFormat.RGBA_UInt8 -> framebuffer.addUnsignedByteRGBABuffer(att.key, 8)
RenderConfigReader.TargetFormat.R_UInt16 -> framebuffer.addUnsignedByteRBuffer(att.key, 16)
RenderConfigReader.TargetFormat.R_UInt8 -> framebuffer.addUnsignedByteRBuffer(att.key, 8)
RenderConfigReader.TargetFormat.RGBA_UInt16 -> framebuffer.addUnsignedByteRGBABuffer(att.key, 16, samples = samples)
RenderConfigReader.TargetFormat.RGBA_UInt8 -> framebuffer.addUnsignedByteRGBABuffer(att.key, 8, samples = samples)
RenderConfigReader.TargetFormat.R_UInt16 -> framebuffer.addUnsignedByteRBuffer(att.key, 16, samples = samples)
RenderConfigReader.TargetFormat.R_UInt8 -> framebuffer.addUnsignedByteRBuffer(att.key, 8, samples = samples)

RenderConfigReader.TargetFormat.Depth32 -> framebuffer.addDepthBuffer(att.key, 32)
RenderConfigReader.TargetFormat.Depth24 -> framebuffer.addDepthBuffer(att.key, 24)
RenderConfigReader.TargetFormat.R_Float16 -> framebuffer.addFloatBuffer(att.key, 16)
RenderConfigReader.TargetFormat.Depth32 -> framebuffer.addDepthBuffer(att.key, 32, samples = samples)
RenderConfigReader.TargetFormat.Depth24 -> framebuffer.addDepthBuffer(att.key, 24, samples = samples)
RenderConfigReader.TargetFormat.R_Float16 -> framebuffer.addFloatBuffer(att.key, 16, samples = samples)
}

}
Expand All @@ -1000,8 +1002,8 @@ open class VulkanRenderpass(val name: String, var config: RenderConfigReader.Ren
val fb = VulkanFramebuffer(device, commandPools.Standard,
width, height, this@with, sRGB = config.sRGB)

fb.addSwapchainAttachment("swapchain-$i", swapchain, i)
fb.addDepthBuffer("swapchain-$i-depth", 32)
fb.addSwapchainAttachment("swapchain-$i", swapchain, i, passConfig.samples)
fb.addDepthBuffer("swapchain-$i-depth", 32, samples = passConfig.samples)
fb.createRenderpassAndFramebuffer()
device.tag(fb.framebuffer.get(0), VulkanDevice.VulkanObjectType.Framebuffer, "Framebuffer for swapchain image $i")

Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/graphics/scenery/fonts/SDFFontAtlas.kt
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ open class SDFFontAtlas(var hub: Hub, val fontName: String, val distanceFieldSiz
System.arraycopy(buffer.toByteArray(), 0, a, 0, buffer.size)

// we want to arrive at 64x64 per glyph
val scale = 64.0/charSize
val scale = 128.0/charSize

val scaledImage = BufferedImage((texWidth*scale).toInt(), (texHeight*scale).toInt(), BufferedImage.TYPE_BYTE_GRAY)
val at = AffineTransform.getScaleInstance(scale, scale)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ renderpasses:
renderTransparent: true
renderOpaque: false
blitInputs: true
samples: 4
shaders:
- "DefaultForward.vert.spv"
- "DefaultForward.frag.spv"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ renderpasses:
renderTransparent: true
renderOpaque: false
blitInputs: true
samples: 4
shaders:
- "DefaultForward.vert.spv"
- "DefaultForward.frag.spv"
Expand All @@ -180,6 +181,7 @@ renderpasses:
renderTransparent: true
renderOpaque: false
blitInputs: true
samples: 4
shaders:
- "DefaultForward.vert.spv"
- "DefaultForward.frag.spv"
Expand Down
Loading
Loading