You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
103 lines
3.7 KiB
103 lines
3.7 KiB
using System;
|
|
using System.Runtime.InteropServices;
|
|
using UnityEngine;
|
|
using UnityEngine.VFX;
|
|
namespace UnityEditor.VFX
|
|
{
|
|
class VFXExpressionBufferCount : VFXExpression
|
|
{
|
|
public VFXExpressionBufferCount() : this(VFXValue<GraphicsBuffer>.Default)
|
|
{
|
|
}
|
|
|
|
public VFXExpressionBufferCount(VFXExpression graphicsBuffer) : base(Flags.InvalidOnGPU, graphicsBuffer)
|
|
{
|
|
}
|
|
|
|
public override VFXExpressionOperation operation => VFXExpressionOperation.BufferCount;
|
|
|
|
protected override VFXExpression Evaluate(VFXExpression[] constParents)
|
|
{
|
|
var graphicsBuffer = constParents[0].Get<GraphicsBuffer>();
|
|
return VFXValue.Constant<uint>(graphicsBuffer != null ? (uint)graphicsBuffer.count : 0u);
|
|
}
|
|
}
|
|
|
|
class VFXExpressionBufferStride : VFXExpression
|
|
{
|
|
public VFXExpressionBufferStride() : this(VFXValue<GraphicsBuffer>.Default)
|
|
{
|
|
}
|
|
|
|
public VFXExpressionBufferStride(VFXExpression graphicsBuffer) : base(Flags.InvalidOnGPU, graphicsBuffer)
|
|
{
|
|
}
|
|
|
|
public override VFXExpressionOperation operation => VFXExpressionOperation.BufferStride;
|
|
|
|
protected override VFXExpression Evaluate(VFXExpression[] constParents)
|
|
{
|
|
var graphicsBuffer = constParents[0].Get<GraphicsBuffer>();
|
|
return VFXValue.Constant<uint>(graphicsBuffer != null ? (uint)graphicsBuffer.stride : 0u);
|
|
}
|
|
}
|
|
|
|
#pragma warning disable 0659
|
|
class VFXExpressionSampleBuffer : VFXExpression
|
|
{
|
|
public VFXExpressionSampleBuffer() : this(VFXValueType.None, string.Empty, VFXValue<GraphicsBuffer>.Default, VFXValue<uint>.Default, VFXValue<uint>.Default, VFXValue<uint>.Default)
|
|
{
|
|
}
|
|
|
|
private VFXValueType m_FieldType;
|
|
private string m_FieldPath;
|
|
|
|
public VFXExpressionSampleBuffer(VFXValueType fieldType, string path, VFXExpression graphicsBuffer, VFXExpression index, VFXExpression stride, VFXExpression count) : base(Flags.InvalidOnCPU, graphicsBuffer, index, stride, count)
|
|
{
|
|
m_FieldType = fieldType;
|
|
m_FieldPath = path;
|
|
}
|
|
|
|
public override bool Equals(object obj)
|
|
{
|
|
if (!base.Equals(obj))
|
|
return false;
|
|
|
|
var other = obj as VFXExpressionSampleBuffer;
|
|
if (other == null)
|
|
return false;
|
|
|
|
return m_FieldPath.Equals(other.m_FieldPath) && m_FieldType.Equals(other.m_FieldType);
|
|
}
|
|
|
|
protected override int GetInnerHashCode()
|
|
{
|
|
int hash = base.GetInnerHashCode();
|
|
hash = (hash * 397) ^ m_FieldPath.GetHashCode();
|
|
hash = (hash * 397) ^ m_FieldType.GetHashCode();
|
|
return hash;
|
|
}
|
|
|
|
protected override VFXExpression Reduce(VFXExpression[] reducedParents)
|
|
{
|
|
var newExpression = (VFXExpressionSampleBuffer)base.Reduce(reducedParents);
|
|
newExpression.m_FieldPath = m_FieldPath;
|
|
newExpression.m_FieldType = m_FieldType;
|
|
return newExpression;
|
|
}
|
|
|
|
sealed public override VFXValueType valueType { get { return m_FieldType; } }
|
|
|
|
sealed public override VFXExpressionOperation operation { get { return VFXExpressionOperation.None; } }
|
|
|
|
public sealed override string GetCodeString(string[] parents)
|
|
{
|
|
var buffer = parents[0];
|
|
var index = parents[1];
|
|
var stride = parents[2];
|
|
var count = parents[3];
|
|
|
|
return string.Format("SampleStructuredBuffer({0}, {1}, {2}, {3}){4}", buffer, index, stride, count, string.IsNullOrEmpty(m_FieldPath) ? "" : "." + m_FieldPath);
|
|
}
|
|
}
|
|
}
|