DirectXShaderCompiler icon indicating copy to clipboard operation
DirectXShaderCompiler copied to clipboard

Support built-in offsetof macro

Open tex3d opened this issue 5 years ago • 14 comments

We should consider supporting offsetof in the future. Since this normally requires stddef.h/cstddef, we should consider adding built-in version under hlsl namespace with default/auto using namespace hlsl; when compiling hlsl source.

Separating this issue from the sizeof issue #1291 to allow independent resolution.

tex3d avatar May 10 '19 20:05 tex3d

Offsetof is a macro in C/C++ and it's not expressible as a normal function, so I'm not sure it could even live in a namespace.

tristanlabelle avatar May 10 '19 21:05 tristanlabelle

I'm going to give up ownership of this issue as I'm not actively working on it.

ehsannas avatar Jun 16 '20 21:06 ehsannas

With the new addition of templated loads in ByteAddressBuffer this would be a huge win 😊

Jasper-Bekkers avatar Dec 02 '20 17:12 Jasper-Bekkers

Came looking for this so I guess +1 from me, for the same reason Jasper listed.

alextardif-zmi avatar Apr 23 '21 14:04 alextardif-zmi

Hi! Are there any news, by any chance? :) I've tried it on a recent build from the main branch, and the error I'm getting from

offsetof(SimpleStruct, uintValue)

says 'SimpleStruct' does not refer to a value, so it looks like the macro itself is recognized by dxc, but still doesn't work?

curldivergence avatar Nov 24 '21 12:11 curldivergence

+1, would love to have this :)

jshopf avatar Apr 05 '22 20:04 jshopf

Is there any update? In sight of RWStructuredBuffers not beeing supported in array bindings for spirv output, the only real alternative is RWByteAdressBuffer for vulkan users in a bindless model. Without offsetof writing and reading individual fields of a struct becomes very error prone and ugly, as one needs to define the offsets to struct members manually.

Ipotrick avatar Aug 09 '22 22:08 Ipotrick

I'll add my voice to this request as well.

+1

SakibSaikia avatar Aug 17 '22 21:08 SakibSaikia

metoo

+1

manas-kulkarni avatar Mar 31 '23 11:03 manas-kulkarni

+1 Would be super helpful when dealing with ByteAddressBuffer

mcbouterse avatar Apr 11 '23 10:04 mcbouterse

+1

ajmiles avatar Jun 10 '23 12:06 ajmiles

I'm trying to make my own BDA pointer and reference structs (because I'm impatient) and offsetof is one of the things I'm missing.

https://github.com/microsoft/hlsl-specs/pull/59#issuecomment-1693661117

and one of the things that's blocking me is the lack of decltype and offsetof, but offsetof far more.

btw __builtin_offsetof seems to be a reserved keyword in DXC, so we could have a "compiler instrinsic" like in GCC