Skip to content

[SPIR-V] Invalid SPIR-V generated when using RW resource returned from function #4136

Closed

Description

The following shader generates invalid SPIR-V:

RWTexture2D<float2> textures[];

cbuffer CB {
	uint index;
}

RWTexture2D<float2> GetTexture() {
	return textures[index];
}

[numthreads(1, 1, 1)]
void main(uint3 tid : SV_DispatchThreadID)
{
	GetTexture()[tid.xy] = float2(1.0, 0.0);
	// workaround:
	// RWTexture2D<float2> tex = GetTexture(); tex[tid.xy] = float2(1.0, 0.0);
}

Compiled using latest release (v1.6.2112) with command line dxc.exe -E main -T cs_6_0 -Fo uav_indexing.comp.spv -spirv -fspv-target-env=vulkan1.1 uav_indexing.comp.hlsl

As commented in the code, using the returned value from the function and storing it in a resource variable works and has the intended effect.

Activity

  1. added
    spirv
    on Dec 9, 2021
  2. kuhar commented on Dec 9, 2021

    @kuhar
    Collaborator

    Thanks for reporting, Thierry Laviron (@TLaviron).

    Jaebaek Seo (@jaebaek), can you take a look?

  3. jaebaek commented on Dec 10, 2021

    @jaebaek
    Collaborator

    Sure. I will take a look.

  4. moved this from For Google to Triaged in HLSL Triageon Aug 22, 2024
  5. s-perron commented on Aug 22, 2024

    @s-perron
    Collaborator

    For some reason we have two loads of the texture. The first is in GetTexture, and another after the function call.

    I think we need to avoid the one after the function call.

  6. added a commit that references this issue on Oct 24, 2024
    4e49675
  7. added a commit that references this issue on Oct 28, 2024
    ee1f013
  8. added a commit that references this issue on Jul 24, 2025
    9cfeac4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

spirv

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions