示例#1
0
        public void Test()
        {
            DebugStruct[] indata  = new DebugStruct[5];
            DebugStruct[] outdata = new DebugStruct[5];

            ComputeBuffer buffer = new ComputeBuffer(indata.Length, System.Runtime.InteropServices.Marshal.SizeOf(typeof(DebugStruct)));

            buffer.SetData(indata);

            _computeShader.SetBuffer(_kernelCSTest, "debug_buffer", buffer);
            _computeShader.Dispatch(_kernelCSTest, indata.Length, 1, 1);

            buffer.GetData(outdata);

            Debug.Log(outdata[0].f4);
        }
示例#2
0
        public void RegisterDefaultInterops()
        {
            RegisterInterop("Upper", (frame) =>
            {
                var obj = frame.VM.Stack.Pop();
                var str = obj.AsString();
                str     = str.ToUpper();
                frame.VM.Stack.Push(VMObject.FromObject(str));
                return(ExecutionState.Running);
            });

            RegisterInterop("PushEnum", (frame) =>
            {
                var obj = frame.VM.Stack.Pop();
                var n   = obj.AsNumber();
                DebugEnum enm;

                switch (n.ToDecimal())
                {
                case "1":
                    enm = DebugEnum.enum1;
                    break;

                case "2":
                    enm = DebugEnum.enum2;
                    break;

                default:
                    enm = DebugEnum.enum3;
                    break;
                }

                frame.VM.Stack.Push(VMObject.FromObject(enm));
                return(ExecutionState.Running);
            });

            RegisterInterop("PushDebugClass", (frame) =>
            {
                var obj = frame.VM.Stack.Pop();
                int n   = (int)obj.AsNumber();

                DebugClass dbClass = new DebugClass(n);

                frame.VM.Stack.Push(VMObject.FromObject(dbClass));
                return(ExecutionState.Running);
            });

            RegisterInterop("IncrementDebugClass", (frame) =>
            {
                var obj     = frame.VM.Stack.Pop();
                var dbClass = obj.AsInterop <DebugClass>();

                dbClass.x++;

                frame.VM.Stack.Push(VMObject.FromObject(dbClass));
                return(ExecutionState.Running);
            });

            RegisterInterop("PushBytes", (frame) =>
            {
                var obj    = frame.VM.Stack.Pop();
                string str = obj.AsString();

                var byteArray = Encoding.ASCII.GetBytes(str);

                frame.VM.Stack.Push(VMObject.FromObject(byteArray));
                return(ExecutionState.Running);
            });

            RegisterInterop("PushDebugStruct", (frame) =>
            {
                var obj = frame.VM.Stack.Pop();
                int n   = (int)obj.AsNumber();

                DebugStruct dbStruct = new DebugStruct();
                dbStruct.x           = n;
                dbStruct.y           = n;

                frame.VM.Stack.Push(VMObject.FromObject(dbStruct));
                return(ExecutionState.Running);
            });

            RegisterInterop("IncrementDebugStruct", (frame) =>
            {
                var obj      = frame.VM.Stack.Pop();
                var dbStruct = obj.AsInterop <DebugStruct>();

                dbStruct.x++;

                frame.VM.Stack.Push(VMObject.FromObject(dbStruct));
                return(ExecutionState.Running);
            });
        }