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

[hlsl-out] Invalid hlsl for write to scalar/vector storage buffer #1902

Closed
hasali19 opened this issue May 10, 2022 · 2 comments · Fixed by #1903
Closed

[hlsl-out] Invalid hlsl for write to scalar/vector storage buffer #1902

hasali19 opened this issue May 10, 2022 · 2 comments · Fixed by #1903
Labels
area: back-end Outputs of shader conversion good first issue Good for newcomers kind: bug Something isn't working lang: HLSL High-Level Shading Language

Comments

@hasali19
Copy link
Contributor

hasali19 commented May 10, 2022

WGSL:

@group(0)
@binding(0)
var<storage, read_write> buf: vec2<i32>;

@compute
@workgroup_size(1)
fn main() {
    buf = vec2<i32>(1);
}

HLSL:

RWByteAddressBuffer buf : register(u0);

[numthreads(1, 1, 1)]
void main()
{
    buf.Store2(, asuint((1).xx));
    return;
}

The Store2 call seems to have a missing argument.

@hasali19
Copy link
Contributor Author

hasali19 commented May 10, 2022

Looks like this also affects scalars:

@group(0)
@binding(0)
var<storage, read_write> buf: i32;

@compute
@workgroup_size(1)
fn main() {
    buf = 0;
}

HLSL:

RWByteAddressBuffer buf : register(u0);

[numthreads(1, 1, 1)]
void main()
{
    buf.Store(, asuint(0));
    return;
}

@hasali19 hasali19 changed the title [hlsl-out] Invalid hlsl for write to vector storage buffer [hlsl-out] Invalid hlsl for write to scalar/vector storage buffer May 10, 2022
@teoxoy teoxoy added kind: bug Something isn't working area: back-end Outputs of shader conversion lang: HLSL High-Level Shading Language labels May 10, 2022
@teoxoy teoxoy added this to the WGSL Specification V1 milestone May 10, 2022
@teoxoy
Copy link
Member

teoxoy commented May 10, 2022

The WGSL spec and also naga used to only allow structs for global variables in uniform and storage address spaces.
Following the spec we recently relaxed this requirement (in #1682) but it looks like the Writer::write_storage_address method still assumes there is a non empty chain of accesses.

I think to get this working we just need to write a 0 if the chain is empty here

pub(super) fn write_storage_address(
&mut self,
module: &crate::Module,
chain: &[SubAccess],
func_ctx: &FunctionCtx,
) -> BackendResult {
for (i, access) in chain.iter().enumerate() {
if i != 0 {
write!(self.out, "+")?;
}
match *access {
SubAccess::Offset(offset) => {
write!(self.out, "{}", offset)?;
}
SubAccess::Index { value, stride } => {
self.write_expr(module, value, func_ctx)?;
write!(self.out, "*{}", stride)?;
}
}
}
Ok(())
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: back-end Outputs of shader conversion good first issue Good for newcomers kind: bug Something isn't working lang: HLSL High-Level Shading Language
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants