Improve validation for constant buffer properties
このコミットが含まれているのは:
1 親
570dc6134f
コミット
5e9ab87500
5ファイル変更
+49
-12
検索条件に一致するファイルはありません
@@ -44,6 +44,11 @@ internal unsafe partial struct PixelShaderEffect
|
||||
/// </remarks>
|
||||
private static Guid shaderId;
|
||||
|
||||
/// <summary>
|
||||
/// The size of the constant buffer for the shader.
|
||||
/// </summary>
|
||||
private static int constantBufferSize;
|
||||
|
||||
/// <summary>
|
||||
/// The number of inputs for the shader.
|
||||
/// </summary>
|
||||
@@ -129,6 +134,7 @@ internal unsafe partial struct PixelShaderEffect
|
||||
{
|
||||
// Load all shader properties
|
||||
Guid shaderId = typeof(T).GUID;
|
||||
int constantBufferSize = D2D1PixelShader.GetConstantBufferSize<T>();
|
||||
D2D1BufferPrecision bufferPrecision = D2D1PixelShader.GetOutputBufferPrecision<T>();
|
||||
D2D1ChannelDepth channelDepth = D2D1PixelShader.GetOutputBufferChannelDepth<T>();
|
||||
D2D1PixelOptions pixelOptions = D2D1PixelShader.GetPixelOptions<T>();
|
||||
@@ -165,6 +171,7 @@ internal unsafe partial struct PixelShaderEffect
|
||||
|
||||
// Set the shared state and mark the type as initialized
|
||||
For<T>.shaderId = shaderId;
|
||||
For<T>.constantBufferSize = constantBufferSize;
|
||||
For<T>.inputCount = inputCount;
|
||||
For<T>.inputTypes = inputTypes;
|
||||
For<T>.inputDescriptionCount = inputDescriptionCount;
|
||||
@@ -251,6 +258,7 @@ internal unsafe partial struct PixelShaderEffect
|
||||
|
||||
return PixelShaderEffect.Factory(
|
||||
shaderId,
|
||||
constantBufferSize,
|
||||
inputCount,
|
||||
inputTypes,
|
||||
inputDescriptionCount,
|
||||
|
||||
+1
@@ -200,6 +200,7 @@ partial struct PixelShaderEffect
|
||||
opaqueInputs[i] = inputOpaqueSubRects[i].ToRectangle();
|
||||
}
|
||||
|
||||
// TODO: shouldn't there be a check for the buffer being null?
|
||||
ReadOnlySpan<byte> buffer = new(@this->constantBuffer, @this->constantBufferSize);
|
||||
|
||||
Rectangle output;
|
||||
|
||||
@@ -69,20 +69,32 @@ unsafe partial struct PixelShaderEffect
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })]
|
||||
private static int GetConstantBufferImpl(IUnknown* effect, byte* data, uint dataSize, uint* actualSize)
|
||||
{
|
||||
if (data is null || actualSize is null)
|
||||
{
|
||||
return E.E_POINTER;
|
||||
}
|
||||
|
||||
PixelShaderEffect* @this = (PixelShaderEffect*)effect;
|
||||
|
||||
if (dataSize < @this->constantBufferSize)
|
||||
{
|
||||
return E.E_NOT_SUFFICIENT_BUFFER;
|
||||
}
|
||||
|
||||
if (@this->constantBuffer is null)
|
||||
{
|
||||
return E.E_NOT_VALID_STATE;
|
||||
}
|
||||
|
||||
if (@this->constantBufferSize == 0)
|
||||
{
|
||||
*actualSize = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: handle case with buffer not large enough
|
||||
int bytesToCopy = Math.Min((int)dataSize, @this->constantBufferSize);
|
||||
Buffer.MemoryCopy(@this->constantBuffer, data, dataSize, @this->constantBufferSize);
|
||||
|
||||
Buffer.MemoryCopy(@this->constantBuffer, data, dataSize, bytesToCopy);
|
||||
|
||||
*actualSize = (uint)bytesToCopy;
|
||||
*actualSize = (uint)@this->constantBufferSize;
|
||||
}
|
||||
|
||||
return S.S_OK;
|
||||
@@ -92,8 +104,18 @@ unsafe partial struct PixelShaderEffect
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })]
|
||||
private static int SetConstantBufferImpl(IUnknown* effect, byte* data, uint dataSize)
|
||||
{
|
||||
if (data is null)
|
||||
{
|
||||
return E.E_POINTER;
|
||||
}
|
||||
|
||||
PixelShaderEffect* @this = (PixelShaderEffect*)effect;
|
||||
|
||||
if (dataSize != (uint)@this->constantBufferSize)
|
||||
{
|
||||
return E.E_INVALIDARG;
|
||||
}
|
||||
|
||||
if (@this->constantBuffer is not null)
|
||||
{
|
||||
NativeMemory.Free(@this->constantBuffer);
|
||||
@@ -104,7 +126,6 @@ unsafe partial struct PixelShaderEffect
|
||||
Buffer.MemoryCopy(data, buffer, dataSize, dataSize);
|
||||
|
||||
@this->constantBuffer = (byte*)buffer;
|
||||
@this->constantBufferSize = (int)dataSize;
|
||||
|
||||
return S.S_OK;
|
||||
}
|
||||
|
||||
@@ -114,21 +114,21 @@ internal unsafe partial struct PixelShaderEffect
|
||||
/// </summary>
|
||||
private volatile int referenceCount;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="Guid"/> for the shader.
|
||||
/// </summary>
|
||||
private Guid shaderId;
|
||||
|
||||
/// <summary>
|
||||
/// The constant buffer data, if set.
|
||||
/// </summary>
|
||||
private byte* constantBuffer;
|
||||
|
||||
/// <summary>
|
||||
/// The size of <see cref="constantBuffer"/>, if set.
|
||||
/// The size of <see cref="constantBuffer"/>.
|
||||
/// </summary>
|
||||
private int constantBufferSize;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="Guid"/> for the shader.
|
||||
/// </summary>
|
||||
private Guid shaderId;
|
||||
|
||||
/// <summary>
|
||||
/// The number of inputs for the shader.
|
||||
/// </summary>
|
||||
@@ -219,6 +219,7 @@ internal unsafe partial struct PixelShaderEffect
|
||||
/// The factory method for <see cref="ID2D1Factory1.RegisterEffectFromString"/>.
|
||||
/// </summary>
|
||||
/// <param name="shaderId">The <see cref="Guid"/> for the shader.</param>
|
||||
/// <param name="constantBufferSize">The size of the constant buffer for the shader.</param>
|
||||
/// <param name="inputCount">The number of inputs for the shader.</param>
|
||||
/// <param name="inputTypes">The buffer with the types of inputs for the shader.</param>
|
||||
/// <param name="inputDescriptionCount">The number of available input descriptions.</param>
|
||||
@@ -235,6 +236,7 @@ internal unsafe partial struct PixelShaderEffect
|
||||
/// <returns>This always returns <c>0</c>.</returns>
|
||||
private static int Factory(
|
||||
Guid shaderId,
|
||||
int constantBufferSize,
|
||||
int inputCount,
|
||||
D2D1PixelShaderInputType* inputTypes,
|
||||
int inputDescriptionCount,
|
||||
@@ -268,6 +270,8 @@ internal unsafe partial struct PixelShaderEffect
|
||||
@this->lpVtblForID2D1DrawTransform = VtblForID2D1DrawTransform;
|
||||
@this->referenceCount = 1;
|
||||
@this->shaderId = shaderId;
|
||||
@this->constantBuffer = null;
|
||||
@this->constantBufferSize = constantBufferSize;
|
||||
@this->inputCount = inputCount;
|
||||
@this->inputTypes = inputTypes;
|
||||
@this->inputDescriptionCount = inputDescriptionCount;
|
||||
|
||||
@@ -10,6 +10,9 @@ namespace TerraFX.Interop.Windows
|
||||
[NativeTypeName("#define E_NOT_VALID_STATE HRESULT_FROM_WIN32(ERROR_INVALID_STATE)")]
|
||||
public const int E_NOT_VALID_STATE = -2147019873;
|
||||
|
||||
[NativeTypeName("#define E_NOT_SUFFICIENT_BUFFER HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER)")]
|
||||
public const int E_NOT_SUFFICIENT_BUFFER = -2147024774;
|
||||
|
||||
[NativeTypeName("#define E_NOTIMPL _HRESULT_TYPEDEF_(0x80004001L)")]
|
||||
public const int E_NOTIMPL = unchecked((int)(0x80004001));
|
||||
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする