Rwstructuredbuffer Access In A Vertex Shader

Shader here

Shader "RW Structured Buffer"
{
    Properties
    {
        _MainTex ("Texture", 2D) = "black" {}
    }
    Subshader
    {
        Pass
        {
            CGPROGRAM
            #pragma vertex vertex_shader
            #pragma fragment pixel_shader
            #pragma target 5.0
            sampler2D _MainTex;
             RWStructuredBuffer<float3> data : register(u4);
            struct APPDATA
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
                uint id : SV_VertexID; 
            };
            struct SHADERDATA
            {
                float4 vertex : SV_POSITION;
                float2 uv : TEXCOORD0;
            };
            SHADERDATA vertex_shader (APPDATA IN)
            {
                SHADERDATA vs;
               // IN.vertex.y = 0.0-tex2Dlod(_MainTex,float4(IN.uv,0,0)).r*(sin(_Time.g)*0.5+0.5);
                data[IN.id] =float3(3.4,2.4,3.4);
                vs.vertex = UnityObjectToClipPos(IN.vertex);
                vs.uv = IN.uv;
                return vs;
            }
            float4 pixel_shader (SHADERDATA ps) : SV_TARGET
            {
                return tex2D(_MainTex,ps.uv);
            }
            ENDCG
        }
    }
}

and script

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class tmp : MonoBehaviour {

     public Material material;
    public GameObject plane;
    ComputeBuffer compute_buffer;
    Mesh mesh;
    Vector3[] data;
    void Start()
    {
        mesh = plane.GetComponent<MeshFilter>().mesh;
        data = mesh.vertices;
        compute_buffer = new ComputeBuffer(data.Length, sizeof(float)*3, ComputeBufferType.Default);
    }
    void Update()
    {
      Graphics.ClearRandomWriteTargets();
        material.SetPass(0);
        material.SetBuffer("data", compute_buffer);
        Graphics.SetRandomWriteTarget(4, compute_buffer,false);
        compute_buffer.GetData(data);
        if(Time.frameCount%10==0)
        for (int i = 0; i < data.Length; i++)
        {
            Debug.Log(data[i]);
        }
    }
    void OnDestroy()
    {
        compute_buffer.Dispose();
    }
}

log say


Afer I set buffer in vertex shader with data[IN.id] =float3(3.4,2.4,3.4);
Anyone know what’s happen here.

  1. Make sure that you use standard 3D template Unity project. This code currently not work properly with High-Definition RP or Lightweight RP (cause to Graphics.SetRandomWriteTarget with RWStructuredBuffer).
  2. RWStructuredBuffer is supported for all types of shaders in hardware with minimum D3D_FEATURE_LEVEL_11_1.
    (minimum AMD Radeon HD 8000 or NVIDIA GeForce GTX 900 or Intel HD Graphics 5000/4x00 and Windows 8).
    For hardware with D3D_FEATURE_LEVEL_11_0 is only supported for pixel and compute shaders.

I didn’t used in High-Definition RP or Lightweight RP .i[Edit]( https://forum.unity.com/posts/4453717/ edit)t’s just unit shader and i try this on both dx11 and vulkan either not work.i also try this in dx12 it’s seems dx12 has completely differ error behaviour ,i guess dx12 still bugging .By the way My griphic card is gtx1070, so i suppose it support vulkan and dx11 dx12.Any way thanks your message. I post this thread because I am not get useful info for my problem from search,I thought may be i can get help from unity guys.