Merge remote-tracking branch 'origin/master' into 1.10
# Conflicts: # Source/Engine/Graphics/Materials/MaterialShader.h
This commit is contained in:
@@ -308,6 +308,17 @@ API_ENUM() enum class GPUResourceUsage
|
||||
/// - Any resources read or accessed randomly on host, e.g. CPU-side copy of vertex buffer used as source of transfer, but also used for collision detection.
|
||||
/// </remarks>
|
||||
StagingReadback = 3,
|
||||
|
||||
/// <summary>
|
||||
/// A resource that supports both read and write from the CPU.
|
||||
/// This is likely to be the common choice for read-write buffers to transfer data between GPU compute buffers and CPU memory.
|
||||
/// It usually means CPU (system) memory.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Usage:
|
||||
/// - Staging memory to upload to GPU for compute and gather results back after processing.
|
||||
/// </remarks>
|
||||
Staging = 4,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -113,6 +113,15 @@ GPUBufferDescription GPUBufferDescription::ToStagingReadback() const
|
||||
return desc;
|
||||
}
|
||||
|
||||
GPUBufferDescription GPUBufferDescription::ToStaging() const
|
||||
{
|
||||
auto desc = *this;
|
||||
desc.Usage = GPUResourceUsage::Staging;
|
||||
desc.Flags = GPUBufferFlags::None;
|
||||
desc.InitData = nullptr;
|
||||
return desc;
|
||||
}
|
||||
|
||||
bool GPUBufferDescription::Equals(const GPUBufferDescription& other) const
|
||||
{
|
||||
return Size == other.Size
|
||||
@@ -167,6 +176,16 @@ GPUBuffer::GPUBuffer()
|
||||
_desc.Size = 0;
|
||||
}
|
||||
|
||||
bool GPUBuffer::IsStaging() const
|
||||
{
|
||||
return _desc.Usage == GPUResourceUsage::StagingReadback || _desc.Usage == GPUResourceUsage::StagingUpload || _desc.Usage == GPUResourceUsage::Staging;
|
||||
}
|
||||
|
||||
bool GPUBuffer::IsDynamic() const
|
||||
{
|
||||
return _desc.Usage == GPUResourceUsage::Dynamic;
|
||||
}
|
||||
|
||||
bool GPUBuffer::Init(const GPUBufferDescription& desc)
|
||||
{
|
||||
// Validate description
|
||||
@@ -280,7 +299,7 @@ bool GPUBuffer::DownloadData(BytesContainer& result)
|
||||
LOG(Warning, "Cannot download GPU buffer data from an empty buffer.");
|
||||
return true;
|
||||
}
|
||||
if (_desc.Usage == GPUResourceUsage::StagingReadback || _desc.Usage == GPUResourceUsage::Dynamic)
|
||||
if (_desc.Usage == GPUResourceUsage::StagingReadback || _desc.Usage == GPUResourceUsage::Dynamic || _desc.Usage == GPUResourceUsage::Staging)
|
||||
{
|
||||
// Use faster path for staging resources
|
||||
return GetData(result);
|
||||
|
||||
@@ -94,20 +94,14 @@ public:
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if buffer is a staging buffer (supports CPU readback).
|
||||
/// Checks if buffer is a staging buffer (supports CPU access).
|
||||
/// </summary>
|
||||
API_PROPERTY() FORCE_INLINE bool IsStaging() const
|
||||
{
|
||||
return _desc.Usage == GPUResourceUsage::StagingReadback || _desc.Usage == GPUResourceUsage::StagingUpload;
|
||||
}
|
||||
API_PROPERTY() bool IsStaging() const;
|
||||
|
||||
/// <summary>
|
||||
/// Checks if buffer is a staging buffer (supports CPU readback).
|
||||
/// Checks if buffer is a dynamic buffer.
|
||||
/// </summary>
|
||||
API_PROPERTY() FORCE_INLINE bool IsDynamic() const
|
||||
{
|
||||
return _desc.Usage == GPUResourceUsage::Dynamic;
|
||||
}
|
||||
API_PROPERTY() bool IsDynamic() const;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether this buffer is a shader resource.
|
||||
@@ -181,7 +175,7 @@ public:
|
||||
Task* DownloadDataAsync(BytesContainer& result);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the buffer data via map/memcpy/unmap sequence. Always supported for dynamic and staging readback buffers (other types support depends on graphics backend implementation).
|
||||
/// Gets the buffer data via map/memcpy/unmap sequence. Always supported for dynamic and staging buffers (other types support depends on graphics backend implementation).
|
||||
/// </summary>
|
||||
/// <param name="output">The output data container.</param>
|
||||
/// <returns>True if failed, otherwise false.</returns>
|
||||
|
||||
@@ -320,7 +320,7 @@ namespace FlaxEngine
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the staging upload description for this instance.
|
||||
/// Gets the staging upload (CPU write) description for this instance.
|
||||
/// </summary>
|
||||
/// <returns>A staging buffer description</returns>
|
||||
public GPUBufferDescription ToStagingUpload()
|
||||
@@ -333,7 +333,7 @@ namespace FlaxEngine
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the staging readback description for this instance.
|
||||
/// Gets the staging readback (CPU read) description for this instance.
|
||||
/// </summary>
|
||||
/// <returns>A staging buffer description</returns>
|
||||
public GPUBufferDescription ToStagingReadback()
|
||||
@@ -345,6 +345,19 @@ namespace FlaxEngine
|
||||
return desc;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the staging (CPU read/write) description for this instance.
|
||||
/// </summary>
|
||||
/// <returns>A staging buffer description</returns>
|
||||
public GPUBufferDescription ToStaging()
|
||||
{
|
||||
var desc = this;
|
||||
desc.Usage = GPUResourceUsage.Staging;
|
||||
desc.Flags = GPUBufferFlags.None;
|
||||
desc.InitData = IntPtr.Zero;
|
||||
return desc;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool Equals(GPUBufferDescription other)
|
||||
{
|
||||
|
||||
@@ -382,6 +382,7 @@ public:
|
||||
void Clear();
|
||||
GPUBufferDescription ToStagingUpload() const;
|
||||
GPUBufferDescription ToStagingReadback() const;
|
||||
GPUBufferDescription ToStaging() const;
|
||||
bool Equals(const GPUBufferDescription& other) const;
|
||||
String ToString() const;
|
||||
|
||||
|
||||
@@ -11,6 +11,53 @@ GPUContext::GPUContext(GPUDevice* device)
|
||||
{
|
||||
}
|
||||
|
||||
#if !BUILD_RELEASE
|
||||
|
||||
#include "Engine/Core/Log.h"
|
||||
|
||||
void GPUContext::LogInvalidResourceUsage(int32 slot, const GPUResourceView* view, InvalidBindPoint bindPoint)
|
||||
{
|
||||
GPUResource* resource = view ? view->GetParent() : nullptr;
|
||||
const Char* resourceType = TEXT("resource");
|
||||
const Char* flagType = TEXT("flags");
|
||||
if (resource)
|
||||
{
|
||||
switch (resource->GetResourceType())
|
||||
{
|
||||
case GPUResourceType::RenderTarget:
|
||||
case GPUResourceType::Texture:
|
||||
case GPUResourceType::CubeTexture:
|
||||
case GPUResourceType::VolumeTexture:
|
||||
resourceType = TEXT("texture");
|
||||
flagType = TEXT("GPUTextureFlags");
|
||||
break;
|
||||
case GPUResourceType::Buffer:
|
||||
resourceType = TEXT("buffer");
|
||||
flagType = TEXT("GPUBufferFlags");
|
||||
break;
|
||||
}
|
||||
}
|
||||
const Char* usage = TEXT("-");
|
||||
switch (bindPoint)
|
||||
{
|
||||
case InvalidBindPoint::SRV:
|
||||
usage = TEXT("shader resource");
|
||||
break;
|
||||
case InvalidBindPoint::UAV:
|
||||
usage = TEXT("unordered access");
|
||||
break;
|
||||
case InvalidBindPoint::DSV:
|
||||
usage = TEXT("depth stencil");
|
||||
break;
|
||||
case InvalidBindPoint::RTV:
|
||||
usage = TEXT("render target");
|
||||
break;
|
||||
}
|
||||
LOG(Error, "Incorrect {} bind at slot {} as {} (ensure to setup correct {} when creating that resource)", resourceType, slot, usage, flagType);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void GPUContext::FrameBegin()
|
||||
{
|
||||
_lastRenderTime = Platform::GetTimeSeconds();
|
||||
|
||||
@@ -122,6 +122,12 @@ protected:
|
||||
double _lastRenderTime = -1;
|
||||
GPUContext(GPUDevice* device);
|
||||
|
||||
#if !BUILD_RELEASE
|
||||
enum class InvalidBindPoint { SRV, UAV, DSV, RTV };
|
||||
|
||||
static void LogInvalidResourceUsage(int32 slot, const GPUResourceView* view, InvalidBindPoint bindPoint);
|
||||
#endif
|
||||
|
||||
public:
|
||||
/// <summary>
|
||||
/// Gets the graphics device.
|
||||
@@ -144,7 +150,6 @@ public:
|
||||
|
||||
public:
|
||||
#if GPU_ALLOW_PROFILE_EVENTS
|
||||
|
||||
/// <summary>
|
||||
/// Begins the profile event.
|
||||
/// </summary>
|
||||
@@ -159,7 +164,6 @@ public:
|
||||
virtual void EventEnd()
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
public:
|
||||
|
||||
@@ -190,6 +190,7 @@ API_CLASS(Abstract, NoSpawn, Attributes="HideInEditor") class FLAXENGINE_API GPU
|
||||
DECLARE_SCRIPTING_TYPE_NO_SPAWN(GPUResourceView);
|
||||
protected:
|
||||
static double DummyLastRenderTime;
|
||||
GPUResource* _parent = nullptr;
|
||||
|
||||
explicit GPUResourceView(const SpawnParams& params)
|
||||
: ScriptingObject(params)
|
||||
@@ -201,6 +202,14 @@ public:
|
||||
// Points to the cache used by the resource for the resource visibility/usage detection. Written during rendering when resource view is used.
|
||||
double* LastRenderTime;
|
||||
|
||||
/// <summary>
|
||||
/// Gets parent GPU resource owning that view.
|
||||
/// </summary>
|
||||
API_PROPERTY() FORCE_INLINE GPUResource* GetParent() const
|
||||
{
|
||||
return _parent;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the native pointer to the underlying view. It's a platform-specific handle.
|
||||
/// </summary>
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "MaterialShader.h"
|
||||
#include "Engine/Core/Log.h"
|
||||
#include "Engine/Serialization/MemoryReadStream.h"
|
||||
#include "Engine/Level/LargeWorlds.h"
|
||||
#include "Engine/Renderer/RenderList.h"
|
||||
#include "Engine/Graphics/RenderTask.h"
|
||||
#include "Engine/Graphics/GPUDevice.h"
|
||||
@@ -33,6 +34,8 @@ GPU_CB_STRUCT(MaterialShaderDataPerView {
|
||||
Float4 ViewInfo;
|
||||
Float4 ScreenSize;
|
||||
Float4 TemporalAAJitter;
|
||||
Float3 LargeWorldsChunkIndex;
|
||||
float LargeWorldsChunkSize;
|
||||
});
|
||||
|
||||
IMaterial::BindParameters::BindParameters(::GPUContext* context, const ::RenderContext& renderContext)
|
||||
@@ -78,6 +81,8 @@ void IMaterial::BindParameters::BindViewData()
|
||||
cb.ViewInfo = view.ViewInfo;
|
||||
cb.ScreenSize = view.ScreenSize;
|
||||
cb.TemporalAAJitter = view.TemporalAAJitter;
|
||||
cb.LargeWorldsChunkIndex = LargeWorlds::Enable ? (Float3)Int3(view.Origin / LargeWorlds::ChunkSize) : Float3::Zero;
|
||||
cb.LargeWorldsChunkSize = LargeWorlds::ChunkSize;
|
||||
|
||||
// Update constants
|
||||
GPUContext->UpdateCB(PerViewConstants, &cb);
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
/// <summary>
|
||||
/// Current materials shader version.
|
||||
/// </summary>
|
||||
#define MATERIAL_GRAPH_VERSION 171
|
||||
#define MATERIAL_GRAPH_VERSION 172
|
||||
|
||||
class Material;
|
||||
class GPUShader;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "RenderView.h"
|
||||
#include "Engine/Level/LargeWorlds.h"
|
||||
#include "Engine/Level/Actors/Camera.h"
|
||||
#include "Engine/Core/Math/Double4x4.h"
|
||||
#include "Engine/Renderer/RenderList.h"
|
||||
#include "Engine/Renderer/RendererPass.h"
|
||||
#include "RenderBuffers.h"
|
||||
@@ -215,6 +216,13 @@ void RenderView::GetWorldMatrix(const Transform& transform, Matrix& world) const
|
||||
Matrix::Transformation(transform.Scale, transform.Orientation, translation, world);
|
||||
}
|
||||
|
||||
void RenderView::GetWorldMatrix(Double4x4& world) const
|
||||
{
|
||||
world.M41 -= Origin.X;
|
||||
world.M42 -= Origin.Y;
|
||||
world.M43 -= Origin.Z;
|
||||
}
|
||||
|
||||
TaaJitterRemoveContext::TaaJitterRemoveContext(const RenderView& view)
|
||||
{
|
||||
if (view.IsTaaResolved)
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
#include "Engine/Core/Math/BoundingFrustum.h"
|
||||
#include "Engine/Core/Math/Matrix.h"
|
||||
#include "Engine/Core/Math/Vector3.h"
|
||||
#if USE_LARGE_WORLDS
|
||||
#include "Engine/Core/Math/Double4x4.h"
|
||||
#endif
|
||||
#include "Engine/Core/Types/LayersMask.h"
|
||||
#include "Engine/Level/Types.h"
|
||||
#include "Enums.h"
|
||||
@@ -355,6 +358,9 @@ public:
|
||||
world.M42 -= (float)Origin.Y;
|
||||
world.M43 -= (float)Origin.Z;
|
||||
}
|
||||
|
||||
// Applies the render origin to the transformation instance matrix.
|
||||
void GetWorldMatrix(Double4x4& world) const;
|
||||
};
|
||||
|
||||
// Removes TAA jitter from the RenderView when drawing geometry after TAA has been resolved to prevent unwanted jittering.
|
||||
|
||||
@@ -142,6 +142,14 @@ GPUTextureDescription GPUTextureDescription::ToStagingReadback() const
|
||||
return copy;
|
||||
}
|
||||
|
||||
GPUTextureDescription GPUTextureDescription::ToStaging() const
|
||||
{
|
||||
auto copy = *this;
|
||||
copy.Flags = GPUTextureFlags::None;
|
||||
copy.Usage = GPUResourceUsage::Staging;
|
||||
return copy;
|
||||
}
|
||||
|
||||
bool GPUTextureDescription::Equals(const GPUTextureDescription& other) const
|
||||
{
|
||||
return Dimensions == other.Dimensions
|
||||
@@ -208,6 +216,11 @@ GPUTexture::GPUTexture()
|
||||
_desc.Clear();
|
||||
}
|
||||
|
||||
bool GPUTexture::IsStaging() const
|
||||
{
|
||||
return _desc.Usage == GPUResourceUsage::StagingUpload || _desc.Usage == GPUResourceUsage::StagingReadback || _desc.Usage == GPUResourceUsage::Staging;
|
||||
}
|
||||
|
||||
Float2 GPUTexture::Size() const
|
||||
{
|
||||
return Float2(static_cast<float>(_desc.Width), static_cast<float>(_desc.Height));
|
||||
|
||||
@@ -21,7 +21,6 @@ API_CLASS(Sealed, NoSpawn) class FLAXENGINE_API GPUTextureView : public GPUResou
|
||||
{
|
||||
DECLARE_SCRIPTING_TYPE_NO_SPAWN(GPUTextureView);
|
||||
protected:
|
||||
GPUResource* _parent = nullptr;
|
||||
PixelFormat _format = PixelFormat::Unknown;
|
||||
MSAALevel _msaa = MSAALevel::None;
|
||||
|
||||
@@ -40,14 +39,6 @@ protected:
|
||||
}
|
||||
|
||||
public:
|
||||
/// <summary>
|
||||
/// Gets parent GPU resource owning that view.
|
||||
/// </summary>
|
||||
API_PROPERTY() FORCE_INLINE GPUResource* GetParent() const
|
||||
{
|
||||
return _parent;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the view format.
|
||||
/// </summary>
|
||||
@@ -294,10 +285,7 @@ public:
|
||||
/// <summary>
|
||||
/// Checks if texture is a staging buffer (supports direct CPU access).
|
||||
/// </summary>
|
||||
FORCE_INLINE bool IsStaging() const
|
||||
{
|
||||
return _desc.Usage == GPUResourceUsage::StagingUpload || _desc.Usage == GPUResourceUsage::StagingReadback;
|
||||
}
|
||||
bool IsStaging() const;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a boolean indicating whether this <see cref="GPUTexture"/> is a using a block compress format (BC1, BC2, BC3, BC4, BC5, BC6H, BC7, etc.).
|
||||
|
||||
@@ -300,7 +300,7 @@ namespace FlaxEngine
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the staging description for this instance.
|
||||
/// Gets the staging upload (CPU write) description for this instance.
|
||||
/// </summary>
|
||||
/// <returns>A staging texture description</returns>
|
||||
public GPUTextureDescription ToStagingUpload()
|
||||
@@ -312,7 +312,7 @@ namespace FlaxEngine
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the staging description for this instance.
|
||||
/// Gets the staging readback (CPU read) description for this instance.
|
||||
/// </summary>
|
||||
/// <returns>A staging texture description</returns>
|
||||
public GPUTextureDescription ToStagingReadback()
|
||||
@@ -323,6 +323,18 @@ namespace FlaxEngine
|
||||
return desc;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the staging (CPU read/write) description for this instance.
|
||||
/// </summary>
|
||||
/// <returns>A staging texture description</returns>
|
||||
public GPUTextureDescription ToStaging()
|
||||
{
|
||||
var desc = this;
|
||||
desc.Flags = GPUTextureFlags.None;
|
||||
desc.Usage = GPUResourceUsage.Staging;
|
||||
return desc;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToString()
|
||||
{
|
||||
|
||||
@@ -397,6 +397,7 @@ public:
|
||||
void Clear();
|
||||
GPUTextureDescription ToStagingUpload() const;
|
||||
GPUTextureDescription ToStagingReadback() const;
|
||||
GPUTextureDescription ToStaging() const;
|
||||
bool Equals(const GPUTextureDescription& other) const;
|
||||
String ToString() const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user