---
title: "List HLSL resources used by one entry point in C#"
url: https://recursiveai.org/oneshader/cookbook/reflect-hlsl-entry-point-resource-usage/
description: "Use OneShader reflection in C# to list the textures and buffers used by one HLSL entry point instead of every resource in the shader file."
version: "1.7.1"
---

# List HLSL resources used by one entry point in C#

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

[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/reflect-hlsl-entry-point-resource-usage/reflect-hlsl-entry-point-resource-usage.zip)

Read `UsedResources` from shader reflection to list a function’s textures and buffers without a GPU.

```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.

```csharp
using OneShader;

var result = ShaderCompiler.CompileFile(
    "passes.hlsl");
if (result.Reflection is not { } reflection)
    throw new InvalidOperationException(
        string.Join("\n", result.Diagnostics));

var entry = reflection.EntryPoints.Single(
    entry => entry.Name == "Fill");
foreach (string name in entry.UsedResources)
    Console.WriteLine(name);
```

The snippet is the complete C# program. If you’re not using the zip, run `dotnet new console` and the install command above, paste the snippet into `Program.cs`, put `passes.hlsl` next to it, then run `dotnet run`.

Use this `passes.hlsl` (also in the zip):

```hlsl
RWStructuredBuffer<uint> Colors : register(u0);
RWStructuredBuffer<uint> Depths : register(u1);

[shader("compute")]
[numthreads(8, 1, 1)]
void Fill(uint3 id : SV_DispatchThreadID)
{
    Colors[id.x] = id.x;
}

[shader("compute")]
[numthreads(8, 1, 1)]
void ClearDepth(uint3 id : SV_DispatchThreadID)
{
    Depths[id.x] = 0;
}
```

`Fill` writes `Colors`; `ClearDepth` writes `Depths`. If compilation fails, `Reflection` is null and the program reports the diagnostics instead of looking up the entry point.

Unzip [the example](https://recursiveai.org/oneshader/cookbook/reflect-hlsl-entry-point-resource-usage/reflect-hlsl-entry-point-resource-usage.zip), then `dotnet run`.

```text
Colors
```

## Variations

To list the resources used by `ClearDepth`, replace the entry-point selection line:

```csharp
var entry = reflection.EntryPoints.Single(
    entry => entry.Name == "ClearDepth");
```

```text
Depths
```

## Related recipes

- [Export HLSL reflection as JSON](https://recursiveai.org/oneshader/cookbook/export-hlsl-reflection-json/)
- [Build a vertex input layout](https://recursiveai.org/oneshader/cookbook/build-vertex-input-layout/)
- [Combine shader pipeline layouts](https://recursiveai.org/oneshader/cookbook/union-pipeline-layouts/)

## The short answer

Compile the shader, select the entry point by name from `Reflection.EntryPoints`, and read its `UsedResources`. In OneShader’s text reflection format, those names are the `uses name=...` records under that entry point. You don’t have to parse the text format if you’re calling the C# compiler API.

## What is shader reflection for resource bindings?

Reflection describes a shader’s interface: what it reads or writes and how your application can bind those resources. OneShader’s [reflection format](https://recursiveai.org/oneshader/docs/reflection-format/) separates a file’s resource records from the usage lists of individual entry points. `UsedResources` gives names, not binding numbers. Look up a name in `Reflection.Resources` to get its kind and the binding slots for the compiled targets. A slot for SPIR-V is a set and binding; Metal’s slot uses the argument index as the binding. Keep the names and slots separate when your build targets more than one graphics API.

## How do I tell which resources one HLSL entry point uses?

Read the usage list under that entry, not the resource table for the file. Both buffers in the example appear in the resource table, but only `Colors` belongs to `Fill`’s list. Filtering by stage alone would not separate the buffers: both entry points are compute shaders. This distinction matters when building separate pipelines from one source file. For a pipeline with more than one stage, account for the resources used by all of the selected entry points, not just one.

`CompileFile` with the default options finds functions marked with `[shader(...)]`. If your source doesn’t carry those attributes, supply the names and stages through `CompileOptions.EntryPoints` instead. Check the compile result before looking up an entry; a missing function name and invalid shader code are different failures. Specialization constants are tracked separately in the text format as `specuse` records, so don’t expect them in `UsedResources`.
