代写代考 COMP5822M – High Perf. Graphics

Lecture 8: Framebuffer
COMP5822M – High Perf. Graphics

– Mostlycovered“pure”Vulkan

Copyright By PowCoder代写 加微信 powcoder

– Now:Shifttowardsrenderingtechniques – Still a bit of Vulkan here and there
COMP5822M – High Perf. Graphics

– Framebuffer/rasterization
– “Doublebuffering”/Swapchain – (Anti-)Aliasing(rasterization)
– Blending
COMP5822M – High Perf. Graphics

Displaying a Frame
– We have an image – how is it displayed?
– Somehow sent to the monitor
– Typical assumption: pixel-by-pixel; row-by-row
(and maybe top-down)
– This takes time
– Recall: 1920×1080 ≈ 2Mpixels = 6Mbytes*
– At 100FPS: 600Mbytes/sec = 4800Mbits/sec
– (*) RGB not RGBA
COMP5822M – High Perf. Graphics

Displaying a Frame
– DisplayPort:
– 1.0: ~ 10 Gbits/sec
– 2.0: ~ 70 Gbits/sec
– Do the math for e.g. a 4k screen at 144Hz
– Compression etc.
COMP5822M – High Perf. Graphics

Displaying a Frame
– Need to keep image intact
– While it is being transferred
– Barring tricks with very good timing
Row being sent
Image being shown
COMP5822M – High Perf. Graphics

Displaying a Frame
– Difficultevenundergoodcircumstances
– Not applicable to 3D rendering
– We don’t draw image top-down
– Draw individual meshes that can be anywhere – Overdraw
COMP5822M – High Perf. Graphics

Displaying a Frame
– Othercomplications
– Requires us to render to the full screen
– Compositor (different windows) -…
COMP5822M – High Perf. Graphics

Double buffering
– Use two buffers
– Front buffer: being shown right now
– Back buffer: image being rendered
– Swapfrontandbackbuffer
– Wait for vsync: no tearing
– Whenever: tearing
– Still less bad than half-finished parts of
images being shown.
– (Modern systems complicate this a bit. Can still
see behaviour like this, though.)
COMP5822M – High Perf. Graphics

Double buffering
– “OpenGLstyle”
– wglSwapBuffers() / glXSwapBuffers() / …
– Little control over this aspect – Triple buffering? Maybe.
COMP5822M – High Perf. Graphics

Swap Chain
– Vulkan:givesuscontrol:-)
– Swapchain(VkSwapchainKHR) – Configurable
COMP5822M – High Perf. Graphics

Swap Chain
– Number of images
– Double buffering
– Triple buffering -…
– Presentmode
– Related to “v-sync”
– Color formats & spaces
– Transformations & compositing
– Size etc etc.
COMP5822M – High Perf. Graphics

Swap Chain
– Query minimum number of images
– Vulkan-tutorial: recommends adding one
– Depends on present mode (next)
COMP5822M – High Perf. Graphics

Presentation Modes
– IMMEDIATE: show immediately, ignore vsync
– FIFO: First-in, first out. Wait for vsync.
– FIFO_RELAXED: Like FIFO, but don’t wait if we
missed last vsync
– MAILBOX: “deposit” rendered image whenever
application has one. Most recent one is shown next vblank. Needs >= 3 images.
– One is being shown, one is deposited, one we render to
COMP5822M – High Perf. Graphics

Presentation Modes
– Not all modes necessarily available – Only FIFO is required to be supported
– FIFO & FIFO_RELAXED: render at refresh rate
– MAILBOX: render faster than refresh rate
– Show most recent one (=lower latency)
– FIFO more efficient, and can have as little
latency if you get the timing right
– IMMEDIATE: avoid?
COMP5822M – High Perf. Graphics

Presentation Modes
– Note:IMMEDIATE!=singlebuffering
– minImages >= 2 very likely.
– Single buffering doesn’t really exist on
modern systems.
COMP5822M – High Perf. Graphics

Color formats & spaces
– Querywhatformats/spacesareavailable – See
https://vulkan.gpuinfo.org/listsurfaceformats.php
for data collected from various users.
COMP5822M – High Perf. Graphics

Color formats
– Typical: RGB(A) with 8 bits per channel
– B8G8R8A8_SRGB – R8B8G8A8_SRGB
– Frequent:A2R10G10B10_UNORM_PACK32
– 10 bits / channel
– Necessary but not sufficient for HDR
COMP5822M – High Perf. Graphics

Color spaces
– Typical:SRGB_NONLINEAR_KHR
– sRGB color space and display standard
– Probably want this
– HDR: HDR10_ST2084_EXT
– Requires HDR screen
– Windows only for now? (Switch to HDR mode!)
– A2R10G10B10_UNORM_PACK32 format only
COMP5822M – High Perf. Graphics

HDR10 standard
– A few things
– 10 bits/color channel
– ST2084 mapping
– Physicalinterpretationforourcolorvalues!
– 0.0f: 0 nits (cd/m^2)
– 1.0f: 10’000 nits (cd/m^2)
– Non-linear (more than sRGB)
– 1000 nits: around 0.7f
– Depends on screen (HDR1000, 600, 400 etc)
COMP5822M – High Perf. Graphics

Color spaces
– UsesRGBbydefault
– This ensures you can “round-trip” images
– If monitor is configured properly: correct
– More precision in dark colors
– Less precision for bright part
– Will return to when talking about textures.
COMP5822M – High Perf. Graphics

Transformation and compositing
– Transformation: flip/rotate rendered image – Check which one is supported / default
– Compositing:makewindowtransparent
– Tell compositor to do alpha blending
– Seems to be ignored on Windows? Only
supported value is opaque…
– Can specify when creating window instead
glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, GLFW_TRUE)
(~premultiplied alpha mode)
COMP5822M – High Perf. Graphics

Compositing
COMP5822M – High Perf. Graphics

Application Window (red)
Visual studio + Console behind it. Clear value = (0, 0, 0, 0), drone = (r,g,b, 1)
Compositing
COMP5822M – High Perf. Graphics

Compositing
COMP5822M – High Perf. Graphics

– Option:clipped(true/false)
– Controls whether pixels covered by other
windows need to be drawn.
– True: Pixels not owned, contents undefined
– False: Pixels owned, “as normal”
– Set to true by default; false if you need to
read back values from swap chain image.
– OpenGL: behaves as if this were set to true
COMP5822M – High Perf. Graphics

– Used to be a big deal 🙂
– Optimization: only draw parts of image that
are visible
– Related: “damage rectangles” to specify which
parts of the image need to be updated
– Mostly ignored in 3D graphics, 2D toolkits
may still use this information, though.
COMP5822M – High Perf. Graphics

Anti-aliasing (Part 1/N)
– Returningtopic
– Many different types of aliasing
– Now:samplingwhendrawing – SSAA, MSAA
COMP5822M – High Perf. Graphics

– Samplingproblem
– Signal has a certain (max) frequency
– We sample at a fixed rate
– If sampling rate is too low
– Miss high frequency content
– “Alias” to lower frequencies
COMP5822M – High Perf. Graphics

Aliasing – Nyquist Theorem
– Sampling rate >= 2*max frequency
– Signal uniquely determined
– Otherwise ambiguous
– Typically used in time domain
– But applies to all other domains too
COMP5822M – High Perf. Graphics

Aliasing – Screen
– Screen: fixed resolution – = Fixed sampling rate
– So what is the max. frequency of our rendered content?
COMP5822M – High Perf. Graphics

Aliasing – Screen
– Screen: fixed resolution – = Fixed sampling rate
– So what is the max. frequency of our
rendered content?
– Probably infinity
– Sharp edges = infinite frequency – Ooops?
COMP5822M – High Perf. Graphics

Aliasing – Screen
– Reason why we see “jaggies” along edges
– Limited sampling rate of screen
– Infinitely sharp edge
– Can’t represent accurately
COMP5822M – High Perf. Graphics

Aliasing – Screen
– Reason why we see “jaggies” along edges
– Limited sampling rate of screen
– Infinitely sharp edge
– Can’t represent accurately
– Otheraliasing:highfrequencytextures
– Already seen: filtering / mipmapping
– Mipmapping: reduce frequency content
COMP5822M – High Perf. Graphics

Aliasing – Screen
– Whataboutgeometry? – No “solution”
– Improvements:sampleatahigherrate
– SSAA=supersamplinganti-aliasing
– Super-sampling=higherratesampling
COMP5822M – High Perf. Graphics

– Basically:renderathigherresolution
– Filter/scale image down to desired res.
– Low-pass filter
– Reduces frequency of content
COMP5822M – High Perf. Graphics

– Basically:renderathigherresolution
– Filter/scale image down to desired res.
– Low-pass filter
– Reduces frequency of content
COMP5822M – High Perf. Graphics

– Expensive
– Double resolution in both X and Y
=> 4x memory, 4x computations
COMP5822M – High Perf. Graphics

Sampling patterns
– Clever choices of “sampling patterns”
COMP5822M – High Perf. Graphics

Sampling patterns
– Clever choices of “sampling patterns”
– Theoreticallynotmoreinformation
– But perceptually better
– = Smoother?
COMP5822M – High Perf. Graphics
Src: Real Time Rendering,

– OK,SSAAstillexpensive
– Store more samples
– But compute once.
COMP5822M – High Perf. Graphics

– Example:
– Store 8 samples per pixel (8x MSAA)
– Rendering:
– Compute which samples are covered by
– Perform depth test per sample
– Run fragment shader once
– Store result in visible samples
(=covered and passed depth)
COMP5822M – High Perf. Graphics

– Example:
– Store 8 samples per pixel (8x MSAA)
– Rendering:
– Compute which samples are covered by
– Perform depth test per sample
– Run fragment shader once
– Store result in visible samples
(=covered and passed depth)
COMP5822M – High Perf. Graphics
Per-fragment data

– What position do we run the fragment
shader for?
– Center of pixel
– Centroid of samples
– Bothhaveproblems:
– Center of pixel outside of tri
– Centroid makes derivatives messier
(needed for mipmapping)
COMP5822M – High Perf. Graphics
Per-fragment data

– Stillmorememory
– Butnotnecessarilymorecompute
COMP5822M – High Perf. Graphics

MSAA – Vulkan
– MSAAsupported
– VkSampleCountFlagBits – VK_SAMPLE_COUNT_1_BIT
– VK_SAMPLE_COUNT_2_BIT, 4, 8, 16, .. – Specify when creating
– Renderpass – Pipeline
COMP5822M – High Perf. Graphics

Tangent – VkFooFlags vs VkFooFlagBits
– VkSampleCountFlagBits (previous slide) vs
VkSampleCountFlags
– Bits: C/C++ enum type, *single* value
– E.g. select one specific option
– Flags:combinemultiplevalues – E.g. list allowed options
COMP5822M – High Perf. Graphics

MSAA – Vulkan
– Additionally:shadingrate
– Default: run fragment shader once
– Can request it to be run more often
COMP5822M – High Perf. Graphics

MSAA – Vulkan
– Can’tshowMSAAimagedirectlyonscreen
– Need to resolve it to a normal image
– Combines sub-samples into final color
– Separate VkImage.
– Part of render pass
– “Resolve attachments”
– Also possible explicitly
– vkCmdResolveImage
– (Use render pass if possible)
COMP5822M – High Perf. Graphics

CSAA – Coverage Sampling Anti-Aliasing
– Modification of MSAA
– Legacy–modernGPUsdon’tsupportit!
– Only store M < N “full” samples - Store N coverage samples that refer to one of the “full” samples COMP5822M – High Perf. Graphics CSAA – Coverage Sampling Anti-Aliasing - Modification of MSAA - Legacy–modernGPUsdon’tsupportit! - Only store M < N “full” samples - Store N coverage samples that refer to one of the “full” samples COMP5822M – High Perf. Graphics Src: Coverage Sampled Antialsing, NVIDIA CSAA – Coverage Sampling Anti-Aliasing - Modification of MSAA - Legacy–modernGPUsdon’tsupportit! - Only store M < N “full” samples - Store N coverage samples that refer to one of the “full” samples COMP5822M – High Perf. Graphics Src: Coverage Sampled Antialsing, NVIDIA Variable shading rate - Somewhat recent - Normally:samesamplecounteverywhere - Now:controllableperregion - E.g., 16x16 pixel blocks - Additional image controls shading rate - Can go from MSAA options to less than 1/sample per NxN pixels - Samememoryusage,lesscomputations COMP5822M – High Perf. Graphics Post-processing anti-aliasing - MSAA: in HW as part of rendering - Many applications use post-process AA - FXAA, TXAA, TAA, DLSS, ... - Will revist when we get to post processing! COMP5822M – High Perf. Graphics - Enabledinpipeline - Differentblendingoptions - Alpha blending is a common one COMP5822M – High Perf. Graphics Alpha Blending - Specifyalphavalueperfragment[0,1] - 0: fully “transparent” - 1: fully opaque Color Alpha COMP5822M – High Perf. Graphics Alpha Blending - Specifyalphavalueperfragment[0,1] - 0: fully “transparent” - 1: fully opaque Color Alpha COMP5822M – High Perf. Graphics Alpha Blending Functions - Typical function: linear interpolation 𝑐𝑜𝑙𝑜𝑟=𝛼⋅𝑓𝑟𝑎𝑔𝐶𝑜𝑙𝑜𝑟+ 1−𝛼 ⋅𝑏𝑔𝐶𝑜𝑙𝑜𝑟 COMP5822M – High Perf. Graphics Alpha Blending Functions - Typical function: linear interpolation 𝑐𝑜𝑙𝑜𝑟=𝛼⋅𝑓𝑟𝑎𝑔𝐶𝑜𝑙𝑜𝑟+ 1−𝛼 ⋅𝑏𝑔𝐶𝑜𝑙𝑜𝑟 - InVulkan: colorBlendOp = VK_BLEND_OP_ADD; srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA; dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; COMP5822M – High Perf. Graphics Alpha Blending Functions - Typical function: linear interpolation 𝑐𝑜𝑙𝑜𝑟=𝛼⋅𝑓𝑟𝑎𝑔𝐶𝑜𝑙𝑜𝑟+ 1−𝛼 ⋅𝑏𝑔𝐶𝑜𝑙𝑜𝑟 - InVulkan: colorBlendOp = VK_BLEND_OP_ADD; srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA; dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; COMP5822M – High Perf. Graphics - Linear alpha blending is order dependent! COMP5822M – High Perf. Graphics - Depthbufferwon’thelp. - Removes “hidden” surfaces - E.g., surfaces behind others. COMP5822M – High Perf. Graphics - Depthbufferwon’thelp. - Removes “hidden” surfaces - E.g., surfaces behind others. COMP5822M – High Perf. Graphics - Manydifferentsolutions - Render back to front? Not always possible... COMP5822M – High Perf. Graphics BIG NOTE IN UPPERCASE - Blending only applies to color targets - Never to the depth buffer! - Mixing depth buffer values is 99.999...% of the time nonsense - General rule: never try to do it - If you ever think it’s the right solution, think again. - (Repeat above step if necessary.) - Why? ... when we get to shadow mapping! COMP5822M – High Perf. Graphics - Otherblendfunctions?Yes! - Additive blending: FACTOR_ONE, FACTOR_ONE 𝑐𝑜𝑙𝑜𝑟 = 1 ⋅ 𝑓𝑟𝑎𝑔𝐶𝑜𝑙𝑜𝑟 + 1 ⋅ 𝑏𝑔𝐶𝑜𝑙𝑜𝑟 - Adds fragment to background - “Glowingparticles” - Bloom,... COMP5822M – High Perf. Graphics - Otherblendfunctions?Yes! - Additive blending: FACTOR_ONE, FACTOR_ONE 𝑐𝑜𝑙𝑜𝑟 = 1 ⋅ 𝑓𝑟𝑎𝑔𝐶𝑜𝑙𝑜𝑟 + 1 ⋅ 𝑏𝑔𝐶𝑜𝑙𝑜𝑟 - Adds fragment to background - “Glowingparticles” - Bloom,... COMP5822M – High Perf. Graphics Src: https://learnopengl.com/In-Practice/2D-Game/Particles CC BY 4.0 - Additive blending is order independent! - We can reorder additions freely. - Need to be careful about depth buffer (I.e., disable depth writes.) COMP5822M – High Perf. Graphics COMP5822M – High Perf. Graphics 程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com