---
title: "Set HLSL point size for Vulkan point sprites"
url: https://recursiveai.org/oneshader/cookbook/set-hlsl-point-size-for-vulkan/
description: "Set per-vertex point size in HLSL with the PointSize built-in, compile to SPIR-V, and check Vulkan largePoints support before drawing."
version: "1.7.3"
---

# Set HLSL point size for Vulkan point sprites

**OneShader** is a free, open-source HLSL compiler library for .NET from Recursive AI. MIT or Apache-2.0.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OneShader) · [GitHub](https://github.com/recursive-ai-oss/oneshader-csharp) · [Docs](https://recursiveai.org/oneshader/docs/) · [Download example (.zip)](https://recursiveai.org/oneshader/cookbook/set-hlsl-point-size-for-vulkan/set-hlsl-point-size-for-vulkan.zip)

Write a point’s width in pixels from the vertex shader. For points larger than one pixel, Vulkan needs the `largePoints` device feature.

```shell
dotnet add package RecursiveAI.OneShader
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```hlsl
// Vertex output member in Points.hlsl
[[vk::builtin("PointSize")]]
float Size : PSIZE;
```

Set `Size` for every vertex. The sample uses 4 and 12 pixels and compiles to `points.spv`.

[The example](https://recursiveai.org/oneshader/cookbook/set-hlsl-point-size-for-vulkan/set-hlsl-point-size-for-vulkan.zip) is the full program below: unzip it and `dotnet run`.

## Full program

Save this input as `Points.hlsl` beside `Program.cs`, or use the copy in the zip.

```hlsl
struct Point
{
    float4 Position : SV_Position;
    [[vk::builtin("PointSize")]]
    float Size : PSIZE;
};

[shader("vertex")]
Point VSMain(uint vertex : SV_VertexID)
{
    Point point;
    point.Position = float4(vertex == 0 ? -0.5 : 0.5,
                            0, 0, 1);
    point.Size = vertex == 0 ? 4.0 : 12.0;
    return point;
}
```

```csharp
using OneShader;

var result = ShaderCompiler.CompileFile("Points.hlsl",
    new CompileOptions { Targets = [CompileTarget.SpirV] });
if (!result.Success)
    throw new InvalidOperationException(
        string.Join(Environment.NewLine, result.Diagnostics));

var shader = result.Find("VSMain", CompileTarget.SpirV)!;
File.WriteAllBytes("points.spv", shader.ToArray());
Console.WriteLine("Wrote points.spv");
foreach (var output in result.Reflection!.EntryPoints.Single().Outputs)
    Console.WriteLine($"Vertex output: {output.BuiltIn}");
```

```text
Wrote points.spv
Vertex output: Position
Vertex output: PointSize
```

The attribute must be on a scalar `float` vertex output. On an input, a non-float, or another shader stage, OneShader reports `OSH0340`.

## Variations

**Draw one-pixel points without `largePoints`.** In `VSMain`, replace the assignment to `point.Size` with this line; keep the built-in declaration.

```hlsl
point.Size = 1.0;
```

## Related recipes

- [Compile HLSL to SPIR-V for Vulkan](https://recursiveai.org/oneshader/cookbook/hlsl-to-spirv/)
- [Build a vertex input layout from HLSL](https://recursiveai.org/oneshader/cookbook/build-vertex-input-layout/)

## The short answer

Put `[[vk::builtin("PointSize")]]` on a `float` vertex output and write the size in pixels. OneShader 1.7.3 emits the Vulkan `PointSize` built-in, not a user-defined location. Use point-list topology and enable `largePoints` before drawing the 4- and 12-pixel points in the example. The C# program compiles the vertex stage; use it with your own graphics pipeline and fragment shader to draw.

## Why does Vulkan need PointSize in the vertex shader?

For a point-list pipeline without a geometry or tessellation evaluation shader, the last vertex stage needs to write [`PointSize`](https://docs.vulkan.org/refpages/latest/refpages/source/PointSize.html). `SV_Position` says where the point goes; it doesn’t say how wide it is. `PSIZE` is the HLSL semantic in the sample, but the `vk::builtin` attribute supplies the SPIR-V mapping. The output has no `Location`, so don’t reserve a user varying slot for it.

Set the pipeline input assembly to `VK_PRIMITIVE_TOPOLOGY_POINT_LIST`. The example reads `SV_VertexID` instead of a vertex buffer: a draw of two vertices starting at zero supplies the two positions.

To texture the point, use the fragment shader’s `PointCoord` as the texture
coordinates. The [Vulkan Samples particle recipe](https://github.com/KhronosGroup/Vulkan-Samples/blob/65d2ec562c5d34ab025e208b4588be102b9f86b7/shaders/compute_nbody/glsl/particle.frag#L29)
shows this in GLSL: it samples the sprite texture at `gl_PointCoord`.
OneShader 1.7.3 can compile the HLSL vertex stage above, but it doesn’t expose
`PointCoord` as a fragment input.

## How do you check whether Vulkan can draw large points?

Query [`VkPhysicalDeviceFeatures.largePoints`](https://docs.vulkan.org/refpages/latest/refpages/source/VkPhysicalDeviceFeatures.html) and enable it when creating the logical device. Check [`pointSizeRange` and `pointSizeGranularity`](https://docs.vulkan.org/refpages/latest/refpages/source/VkPhysicalDeviceLimits.html) for the device’s supported sizes and spacing. For a quick look on Linux with Vulkan Tools installed, run:

```shell
vulkaninfo | grep -A2 -E 'deviceName|pointSizeRange:|largePoints'
```

On a GeForce RTX 4070, the query reported `largePoints = true` and a `pointSizeRange` of 1 to 2047.94 pixels. That indicates support, not that the feature has already been enabled in your app. If it’s unavailable, use size `1.0` or render each sprite as two triangles instead. The SPIR-V built-in itself adds no capability, so seeing `PointSize` in the compiler’s output is not a substitute for checking the device.
