Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on March 30, 2023, between 5 am & 1 pm EST, in the Performance Profiling Dev Blitz Day 2023 - Q&A forum and Discord where you can connect with our teams behind the Memory and CPU Profilers.
    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:
    85
    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:
    85
    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.