Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Only instancing constant buffers can have struct variables problem on DX11/DX12

Discussion in 'Shaders' started by GuardHei, Dec 22, 2021.

  1. GuardHei

    GuardHei

    Joined:
    Feb 10, 2018
    Posts:
    89
    I have the following constant buffer codes in hlsl.
    Code (CSharp):
    1. struct RTHandleProperties {
    2.     int4 viewportSize; // xy: curr, zw: prev
    3.     int4 rtSize; // xy: curr, zw: prev
    4.     float4 rtHandleScale; // xy: curr, zw: prev
    5. };
    6.  
    7. CBUFFER_START(CameraData)
    8.     float3 _CameraPosWS;
    9.     float3 _CameraFwdWS;
    10.     float4 _ScreenSize; // { w, h, 1 / w, 1 / h }
    11.     RTHandleProperties _RTHandleProps;
    12. CBUFFER_END
    Weirdly enough, the above codes only compile on Mac under Metal (and works). When I move the platform to dx11 or dx12 on Windows, the error "Only instancing constant buffers can have struct variables problem" appears, saying "_RTHandleProps will be ignored".

    I'm not sure why I cannot have a struct var in the cbuffer on dx12. If so, what can I do?
     
  2. levano0

    levano0

    Joined:
    May 30, 2020
    Posts:
    9
  3. GuardHei

    GuardHei

    Joined:
    Feb 10, 2018
    Posts:
    89
    i also saw this, but the question is kinda different. My problem is how to fit a struct into a constant buffer, which from my understanding, should be doable on dx12.

    I have also tried this method, and it still does not work.