DirectXShaderCompiler icon indicating copy to clipboard operation
DirectXShaderCompiler copied to clipboard

[SPIR-V] vk::static_pointer_cast and vk::reinterpret_pointer_cast fail to compile

Open Dolkar opened this issue 2 months ago • 2 comments

Description Currently these two casting functions for buffer pointers don't seem to cast at all - they behave as if their return type is the same as the input type:

<source>:17:29: error: cannot initialize a variable of type 'BufferPointer<Base>' with an rvalue of type 'BufferPointer<Derived>'
    vk::BufferPointer<Base> derivedBufAsBase = vk::static_pointer_cast<Base>(derivedBuf);
                            ^                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:19:30: error: cannot initialize a variable of type 'BufferPointer<float>' with an rvalue of type 'BufferPointer<int>'
    vk::BufferPointer<float> intBufAsFloat = vk::reinterpret_pointer_cast<float>(intBuf);
                             ^               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Steps to Reproduce https://godbolt.org/z/vTos39Wcx

Environment

  • DXC version: trunk
  • Host Operating System: Windows 11

Dolkar avatar Nov 10 '25 15:11 Dolkar

@danbrown-amd Are you able to look into this? Let me know if you cannot.

s-perron avatar Nov 10 '25 17:11 s-perron

Could we get __is_base_of btw ?

@Dolkar as for the reinterpret cast, you can steal our inline Spir-V OpBitcast and literally use that to cast between vk:: BufferPointer and any other 8 byte scalar or vector integer type

Took a look at this today, seems like we have 2 things to solve:

  1. Support reinterpret/static pointer casts in SemaHLSL This part is straightforward, add code to check the few rules listed in the spec to correctly allow those casts.

  2. fixup the intrinsic template. This cast is implemented as an HLSL specific intrinsic, but as-is, the return type is wrongly set to the source type. I need to fix this. Looking into this second part.

Keenuts avatar Dec 15 '25 17:12 Keenuts