diff --git a/Source/Engine/Graphics/DynamicBuffer.h b/Source/Engine/Graphics/DynamicBuffer.h
index 10afb52b8..f22143c1b 100644
--- a/Source/Engine/Graphics/DynamicBuffer.h
+++ b/Source/Engine/Graphics/DynamicBuffer.h
@@ -40,7 +40,6 @@ public:
///
/// Gets buffer (may be null since it's using 'late init' feature)
///
- /// Buffer
FORCE_INLINE GPUBuffer* GetBuffer() const
{
return _buffer;
diff --git a/Source/Engine/Graphics/GPUDevice.cpp b/Source/Engine/Graphics/GPUDevice.cpp
index 8f30dc85a..f6be31923 100644
--- a/Source/Engine/Graphics/GPUDevice.cpp
+++ b/Source/Engine/Graphics/GPUDevice.cpp
@@ -31,6 +31,39 @@ GPUPipelineState* GPUPipelineState::New()
return GPUDevice::Instance->CreatePipelineState();
}
+bool GPUPipelineState::Init(const Description& desc)
+{
+ // Cache description in debug builds
+#if BUILD_DEBUG
+ DebugDesc = desc;
+#endif
+
+ // Cache shader stages usage flags for pipeline state
+ _meta.InstructionsCount = 0;
+ _meta.UsedCBsMask = 0;
+ _meta.UsedSRsMask = 0;
+ _meta.UsedUAsMask = 0;
+#define CHECK_STAGE(stage) \
+ if (desc.stage) { \
+ _meta.UsedCBsMask |= desc.stage->GetBindings().UsedCBsMask; \
+ _meta.UsedSRsMask |= desc.stage->GetBindings().UsedSRsMask; \
+ _meta.UsedUAsMask |= desc.stage->GetBindings().UsedUAsMask; \
+ }
+ CHECK_STAGE(VS);
+ CHECK_STAGE(HS);
+ CHECK_STAGE(DS);
+ CHECK_STAGE(GS);
+ CHECK_STAGE(PS);
+#undef CHECK_STAGE
+
+ return false;
+}
+
+GPUResource::ResourceType GPUPipelineState::GetResourceType() const
+{
+ return ResourceType::PipelineState;
+}
+
GPUPipelineState::Description GPUPipelineState::Description::Default =
{
// Enable/disable depth write
@@ -122,6 +155,33 @@ GPUPipelineState::Description GPUPipelineState::Description::DefaultFullscreenTr
BlendingMode::Opaque,
};
+void GPUResource::ReleaseGPU()
+{
+ if (_memoryUsage != 0)
+ {
+ Releasing();
+ OnReleaseGPU();
+ _memoryUsage = 0;
+ }
+}
+
+void GPUResource::OnDeviceDispose()
+{
+ // By default we want to release resource data but keep it alive
+ ReleaseGPU();
+}
+
+void GPUResource::OnReleaseGPU()
+{
+}
+
+void GPUResource::OnDeleteObject()
+{
+ ReleaseGPU();
+
+ PersistentScriptingObject::OnDeleteObject();
+}
+
struct GPUDevice::PrivateData
{
AssetReference QuadShader;
diff --git a/Source/Engine/Graphics/GPUPipelineState.h b/Source/Engine/Graphics/GPUPipelineState.h
index 5e16799c8..5e7609876 100644
--- a/Source/Engine/Graphics/GPUPipelineState.h
+++ b/Source/Engine/Graphics/GPUPipelineState.h
@@ -115,12 +115,10 @@ protected:
public:
#if BUILD_DEBUG
-
///
/// The description of the pipeline state cached on creation in debug builds. Can be used to help with rendering crashes or issues and validation.
///
Description DebugDesc;
-
#endif
public:
@@ -128,7 +126,6 @@ public:
///
/// Gets constant buffers usage mask (each set bit marks usage of the constant buffer at the bit index slot). Combined from all the used shader stages.
///
- /// The constant buffers usage mask.
FORCE_INLINE uint32 GetUsedCBsMask() const
{
return _meta.UsedCBsMask;
@@ -137,7 +134,6 @@ public:
///
/// Gets shader resources usage mask (each set bit marks usage of the shader resource slot at the bit index slot). Combined from all the used shader stages.
///
- /// The shader resource usage mask.
FORCE_INLINE uint32 GetUsedSRsMask() const
{
return _meta.UsedSRsMask;
@@ -146,7 +142,6 @@ public:
///
/// Gets unordered access usage mask (each set bit marks usage of the unordered access slot at the bit index slot). Combined from all the used shader stages.
///
- /// The unordered access usage mask.
FORCE_INLINE uint32 GetUsedUAsMask() const
{
return _meta.UsedUAsMask;
@@ -157,7 +152,6 @@ public:
///
/// Returns true if pipeline state is valid and ready to use
///
- /// True if is valid
API_PROPERTY() virtual bool IsValid() const = 0;
///
@@ -165,39 +159,9 @@ public:
///
/// Full pipeline state description
/// True if cannot create state, otherwise false
- API_FUNCTION() virtual bool Init(API_PARAM(Ref) const Description& desc)
- {
- // Cache description in debug builds
-#if BUILD_DEBUG
- DebugDesc = desc;
-#endif
-
- // Cache shader stages usage flags for pipeline state
- _meta.InstructionsCount = 0;
- _meta.UsedCBsMask = 0;
- _meta.UsedSRsMask = 0;
- _meta.UsedUAsMask = 0;
-#define CHECK_STAGE(stage) \
- if(desc.stage) { \
- _meta.UsedCBsMask |= desc.stage->GetBindings().UsedCBsMask; \
- _meta.UsedSRsMask |= desc.stage->GetBindings().UsedSRsMask; \
- _meta.UsedUAsMask |= desc.stage->GetBindings().UsedUAsMask; \
- }
- CHECK_STAGE(VS);
- CHECK_STAGE(HS);
- CHECK_STAGE(DS);
- CHECK_STAGE(GS);
- CHECK_STAGE(PS);
-#undef CHECK_STAGE
-
- return false;
- }
+ API_FUNCTION() virtual bool Init(API_PARAM(Ref) const Description& desc);
public:
-
// [GPUResource]
- ResourceType GetResourceType() const final override
- {
- return ResourceType::PipelineState;
- }
+ ResourceType GetResourceType() const final override;
};
diff --git a/Source/Engine/Graphics/GPUResource.h b/Source/Engine/Graphics/GPUResource.h
index 288da6579..8f014d318 100644
--- a/Source/Engine/Graphics/GPUResource.h
+++ b/Source/Engine/Graphics/GPUResource.h
@@ -75,13 +75,11 @@ public:
///
/// Gets the resource type.
///
- /// The type.
virtual ResourceType GetResourceType() const = 0;
///
/// Gets resource object type.
///
- /// The object type.
virtual ObjectType GetObjectType() const
{
return ObjectType::Other;
@@ -91,7 +89,6 @@ public:
/// Gets amount of GPU memory used by this resource (in bytes).
/// It's a rough estimation. GPU memory may be fragmented, compressed or sub-allocated so the actual memory pressure from this resource may vary (also depends on the current graphics backend).
///
- /// The current memory usage.
API_PROPERTY() FORCE_INLINE uint64 GetMemoryUsage() const
{
return _memoryUsage;
@@ -102,7 +99,6 @@ public:
///
/// Gets the resource name.
///
- /// The name of the resource.
virtual String GetName() const
{
return String::Empty;
@@ -113,33 +109,19 @@ public:
///
/// Releases GPU resource data.
///
- API_FUNCTION() void ReleaseGPU()
- {
- if (_memoryUsage != 0)
- {
- Releasing();
- OnReleaseGPU();
- _memoryUsage = 0;
- }
- }
+ API_FUNCTION() void ReleaseGPU();
///
/// Action called when GPU device is disposing.
///
- virtual void OnDeviceDispose()
- {
- // By default we want to release resource data but keep it alive
- ReleaseGPU();
- }
+ virtual void OnDeviceDispose();
protected:
///
/// Releases GPU resource data (implementation).
///
- virtual void OnReleaseGPU()
- {
- }
+ virtual void OnReleaseGPU();
public:
@@ -152,13 +134,7 @@ public:
return TEXT("GPU Resource");
#endif
}
-
- void OnDeleteObject() override
- {
- ReleaseGPU();
-
- PersistentScriptingObject::OnDeleteObject();
- }
+ void OnDeleteObject() override;
};
///
diff --git a/Source/Engine/Graphics/RenderBuffers.cpp b/Source/Engine/Graphics/RenderBuffers.cpp
index 31ce925ee..42ad32486 100644
--- a/Source/Engine/Graphics/RenderBuffers.cpp
+++ b/Source/Engine/Graphics/RenderBuffers.cpp
@@ -98,10 +98,8 @@ GPUTexture* RenderBuffers::RequestHalfResDepth(GPUContext* context)
uint64 RenderBuffers::GetMemoryUsage() const
{
uint64 result = 0;
-
for (int32 i = 0; i < _resources.Count(); i++)
result += _resources[i]->GetMemoryUsage();
-
return result;
}
diff --git a/Source/Engine/GraphicsDevice/DirectX/DX12/DescriptorHeapDX12.h b/Source/Engine/GraphicsDevice/DirectX/DX12/DescriptorHeapDX12.h
index 8123a1ead..f7de6a9d6 100644
--- a/Source/Engine/GraphicsDevice/DirectX/DX12/DescriptorHeapDX12.h
+++ b/Source/Engine/GraphicsDevice/DirectX/DX12/DescriptorHeapDX12.h
@@ -37,26 +37,9 @@ public:
D3D12_CPU_DESCRIPTOR_HANDLE CPU() const;
D3D12_GPU_DESCRIPTOR_HANDLE GPU() const;
- // Creates shader resource view
- // @param index Descriptor index in the heap
- // @param resource Shader Resource to create view for it
- // @param desc View description
void CreateSRV(GPUDeviceDX12* device, ID3D12Resource* resource, D3D12_SHADER_RESOURCE_VIEW_DESC* desc = nullptr);
-
- // Creates render target view
- // @param index Descriptor index in the heap
- // @param resource Render Target to create view for it
void CreateRTV(GPUDeviceDX12* device, ID3D12Resource* resource, D3D12_RENDER_TARGET_VIEW_DESC* desc = nullptr);
-
- // Creates depth stencil view
- // @param index Descriptor index in the heap
- // @param resource Render Target Depth to create view for it
void CreateDSV(GPUDeviceDX12* device, ID3D12Resource* resource, D3D12_DEPTH_STENCIL_VIEW_DESC* desc = nullptr);
-
- // Creates unordered access view
- // @param index Descriptor index in the heap
- // @param resource Unordered Access to create view for it
- // @param desc View description
void CreateUAV(GPUDeviceDX12* device, ID3D12Resource* resource, D3D12_UNORDERED_ACCESS_VIEW_DESC* desc = nullptr, ID3D12Resource* counterResource = nullptr);
void Release();
diff --git a/Source/Engine/GraphicsDevice/DirectX/DX12/GPUBufferDX12.cpp b/Source/Engine/GraphicsDevice/DirectX/DX12/GPUBufferDX12.cpp
index df8ff9606..73d8111f0 100644
--- a/Source/Engine/GraphicsDevice/DirectX/DX12/GPUBufferDX12.cpp
+++ b/Source/Engine/GraphicsDevice/DirectX/DX12/GPUBufferDX12.cpp
@@ -125,13 +125,7 @@ bool GPUBufferDX12::OnInit()
// Create resource
ID3D12Resource* resource;
D3D12_RESOURCE_STATES initialState = D3D12_RESOURCE_STATE_COPY_DEST;
- VALIDATE_DIRECTX_RESULT(_device->GetDevice()->CreateCommittedResource(
- &heapProperties,
- D3D12_HEAP_FLAG_NONE,
- &resourceDesc,
- initialState,
- nullptr,
- IID_PPV_ARGS(&resource)));
+ VALIDATE_DIRECTX_RESULT(_device->GetDevice()->CreateCommittedResource(&heapProperties, D3D12_HEAP_FLAG_NONE, &resourceDesc, initialState, nullptr, IID_PPV_ARGS(&resource)));
// Set state
initResource(resource, initialState, 1);
diff --git a/Source/Engine/GraphicsDevice/DirectX/DX12/GPUBufferDX12.h b/Source/Engine/GraphicsDevice/DirectX/DX12/GPUBufferDX12.h
index 7d607f960..7c45dfe5d 100644
--- a/Source/Engine/GraphicsDevice/DirectX/DX12/GPUBufferDX12.h
+++ b/Source/Engine/GraphicsDevice/DirectX/DX12/GPUBufferDX12.h
@@ -107,17 +107,14 @@ public:
{
return false;
}
-
D3D12_CPU_DESCRIPTOR_HANDLE SRV() const override
{
return _srv.CPU();
}
-
D3D12_CPU_DESCRIPTOR_HANDLE UAV() const override
{
return _uav.CPU();
}
-
ResourceOwnerDX12* GetResourceOwner() const override
{
return _owner;
@@ -173,19 +170,16 @@ public:
///
/// Gets buffer size in a GPU memory in bytes.
///
- /// Size in bytes.
uint64 GetSizeInBytes() const;
///
/// Gets buffer location in a GPU memory.
///
- /// GPU memory location.
D3D12_GPU_VIRTUAL_ADDRESS GetLocation() const;
///
/// Gets the counter resource.
///
- /// The internal counter buffer.
FORCE_INLINE GPUBufferDX12* GetCounter() const
{
return _counter;
diff --git a/Source/Engine/GraphicsDevice/DirectX/DX12/GPUDeviceDX12.h b/Source/Engine/GraphicsDevice/DirectX/DX12/GPUDeviceDX12.h
index ee6e69002..46dab6b57 100644
--- a/Source/Engine/GraphicsDevice/DirectX/DX12/GPUDeviceDX12.h
+++ b/Source/Engine/GraphicsDevice/DirectX/DX12/GPUDeviceDX12.h
@@ -100,18 +100,16 @@ public:
public:
///
- /// Gets DX12 device
+ /// Gets DX12 device.
///
- /// DirectX 12 device
FORCE_INLINE ID3D12Device* GetDevice() const
{
return _device;
}
///
- /// Gets DXGI factory
+ /// Gets DXGI factory.
///
- /// DXGI factory object
FORCE_INLINE IDXGIFactory4* GetDXGIFactory() const
{
return _factoryDXGI;
@@ -120,28 +118,24 @@ public:
///
/// Gets DirectX 12 command list object
///
- /// Command list object (DirectX 12)
ID3D12GraphicsCommandList* GetCommandList() const;
///
- /// Gets command queue
+ /// Gets command queue.
///
- /// Command queue
FORCE_INLINE CommandQueueDX12* GetCommandQueue() const
{
return _commandQueue;
}
///
- /// Gets DirectX 12 command queue object
+ /// Gets DirectX 12 command queue object.
///
- /// Command queue object (DirectX 12)
ID3D12CommandQueue* GetCommandQueueDX12() const;
///
- /// Gets root signature of the graphics pipeline
+ /// Gets root signature of the graphics pipeline.
///
- /// Root signature
FORCE_INLINE ID3D12RootSignature* GetRootSignature() const
{
return _rootSignature;
@@ -150,7 +144,6 @@ public:
///
/// Gets main commands context (for DirectX 12)
///
- /// Main context
FORCE_INLINE GPUContextDX12* GetMainContextDX12() const
{
return _mainContext;
@@ -171,9 +164,7 @@ public:
static FORCE_INLINE uint32 GetMaxMSAAQuality(uint32 sampleCount)
{
if (sampleCount <= 8)
- {
return 0;
- }
return 0xffffffff;
}
@@ -196,12 +187,10 @@ public:
{
return reinterpret_cast(_mainContext);
}
-
void* GetNativePtr() const override
{
return _device;
}
-
bool Init() override;
void DrawBegin() override;
void RenderEnd() override;
diff --git a/Source/Engine/GraphicsDevice/DirectX/DX12/GPUTextureDX12.h b/Source/Engine/GraphicsDevice/DirectX/DX12/GPUTextureDX12.h
index e38d5a712..01e23d08c 100644
--- a/Source/Engine/GraphicsDevice/DirectX/DX12/GPUTextureDX12.h
+++ b/Source/Engine/GraphicsDevice/DirectX/DX12/GPUTextureDX12.h
@@ -22,9 +22,6 @@ private:
public:
- ///
- /// Initializes a new instance of the class.
- ///
GPUTextureViewDX12()
{
}
@@ -45,9 +42,6 @@ public:
return *this;
}
- ///
- /// Finalizes an instance of the class.
- ///
~GPUTextureViewDX12()
{
Release();
@@ -155,8 +149,7 @@ public:
///
/// Gets the CPU handle to the render target view descriptor.
///
- /// The CPU handle to the render target view descriptor.
- D3D12_CPU_DESCRIPTOR_HANDLE RTV() const
+ FORCE_INLINE D3D12_CPU_DESCRIPTOR_HANDLE RTV() const
{
return _rtv.CPU();
}
@@ -164,8 +157,7 @@ public:
///
/// Gets the CPU handle to the depth stencil view descriptor.
///
- /// The CPU handle to the depth stencil view descriptor.
- D3D12_CPU_DESCRIPTOR_HANDLE DSV() const
+ FORCE_INLINE D3D12_CPU_DESCRIPTOR_HANDLE DSV() const
{
return _dsv.CPU();
}
@@ -183,17 +175,14 @@ public:
{
return _dsv.IsValid();
}
-
D3D12_CPU_DESCRIPTOR_HANDLE SRV() const override
{
return _srv.CPU();
}
-
D3D12_CPU_DESCRIPTOR_HANDLE UAV() const override
{
return _uav.CPU();
}
-
ResourceOwnerDX12* GetResourceOwner() const override
{
return _owner;
@@ -223,11 +212,6 @@ private:
public:
- ///
- /// Initializes a new instance of the class.
- ///
- /// The device.
- /// The name.
GPUTextureDX12(GPUDeviceDX12* device, const StringView& name)
: GPUResourceDX12(device, name)
{
@@ -244,35 +228,29 @@ public:
{
return (GPUTextureView*)&_handlesPerSlice[arrayOrDepthIndex];
}
-
GPUTextureView* View(int32 arrayOrDepthIndex, int32 mipMapIndex) const override
{
return (GPUTextureView*)&_handlesPerMip[arrayOrDepthIndex][mipMapIndex];
}
-
GPUTextureView* ViewArray() const override
{
ASSERT(ArraySize() > 1);
return (GPUTextureView*)&_handleArray;
}
-
GPUTextureView* ViewVolume() const override
{
ASSERT(IsVolume());
return (GPUTextureView*)&_handleVolume;
}
-
GPUTextureView* ViewReadOnlyDepth() const override
{
ASSERT(_desc.Flags & GPUTextureFlags::ReadOnlyDepthView);
return (GPUTextureView*)&_handleReadOnlyDepth;
}
-
void* GetNativePtr() const override
{
- return (void*)nullptr;
+ return (void*)_resource;
}
-
bool GetData(int32 arrayOrDepthSliceIndex, int32 mipMapIndex, TextureMipData& data, uint32 mipRowPitch) override;
// [ResourceOwnerDX12]
@@ -286,17 +264,14 @@ public:
{
return (_desc.Flags & GPUTextureFlags::DepthStencil) != 0;
}
-
D3D12_CPU_DESCRIPTOR_HANDLE SRV() const override
{
return _srv.CPU();
}
-
D3D12_CPU_DESCRIPTOR_HANDLE UAV() const override
{
return _uav.CPU();
}
-
ResourceOwnerDX12* GetResourceOwner() const override
{
return (ResourceOwnerDX12*)this;
diff --git a/Source/Engine/GraphicsDevice/DirectX/DX12/IShaderResourceDX12.h b/Source/Engine/GraphicsDevice/DirectX/DX12/IShaderResourceDX12.h
index 155b018e3..725f1d584 100644
--- a/Source/Engine/GraphicsDevice/DirectX/DX12/IShaderResourceDX12.h
+++ b/Source/Engine/GraphicsDevice/DirectX/DX12/IShaderResourceDX12.h
@@ -36,25 +36,21 @@ public:
///
/// Determines whether this resource is depth/stencil buffer.
///
- /// True if this resource is depth/stencil buffer, otherwise false.
virtual bool IsDepthStencilResource() const = 0;
///
/// Gets CPU handle to the shader resource view descriptor.
///
- /// SRV
virtual D3D12_CPU_DESCRIPTOR_HANDLE SRV() const = 0;
///
/// Gets CPU handle to the unordered access view descriptor.
///
- /// UAV
virtual D3D12_CPU_DESCRIPTOR_HANDLE UAV() const = 0;
///
/// Gets the resource owner.
///
- /// Owner object.
virtual ResourceOwnerDX12* GetResourceOwner() const = 0;
};
diff --git a/Source/Engine/GraphicsDevice/DirectX/DX12/QueryHeapDX12.cpp b/Source/Engine/GraphicsDevice/DirectX/DX12/QueryHeapDX12.cpp
index a7bbb6f2c..b7916f9ca 100644
--- a/Source/Engine/GraphicsDevice/DirectX/DX12/QueryHeapDX12.cpp
+++ b/Source/Engine/GraphicsDevice/DirectX/DX12/QueryHeapDX12.cpp
@@ -85,27 +85,15 @@ void QueryHeapDX12::Destroy()
void QueryHeapDX12::EndQueryBatchAndResolveQueryData(GPUContextDX12* context)
{
ASSERT(_currentBatch.Open);
-
- // Skip empty batches
if (_currentBatch.Count == 0)
- {
return;
- }
// Close the current batch
_currentBatch.Open = false;
// Resolve the batch
const int32 offset = _currentBatch.Start * _resultSize;
- const int32 size = _currentBatch.Count * _resultSize;
- context->GetCommandList()->ResolveQueryData(
- _queryHeap,
- _queryType,
- _currentBatch.Start,
- _currentBatch.Count,
- _resultBuffer,
- offset
- );
+ context->GetCommandList()->ResolveQueryData(_queryHeap, _queryType, _currentBatch.Start, _currentBatch.Count, _resultBuffer, offset);
_currentBatch.Sync = _device->GetCommandQueue()->GetSyncPoint();
// Begin a new query batch
@@ -199,8 +187,7 @@ void* QueryHeapDX12::ResolveQuery(ElementHandle& handle)
Platform::MemoryCopy(_resultData.Get() + range.Begin, (byte*)mapped + range.Begin, batch.Count * _resultSize);
// Unmap with an empty range to indicate nothing was written by the CPU
- range.Begin = range.End = 0;
- _resultBuffer->Unmap(0, &range);
+ _resultBuffer->Unmap(0, nullptr);
// All elements got its results so we can remove this batch
_batches.RemoveAt(i);
diff --git a/Source/Engine/GraphicsDevice/DirectX/DX12/ResourceOwnerDX12.h b/Source/Engine/GraphicsDevice/DirectX/DX12/ResourceOwnerDX12.h
index c3e241f8d..8b140a1c7 100644
--- a/Source/Engine/GraphicsDevice/DirectX/DX12/ResourceOwnerDX12.h
+++ b/Source/Engine/GraphicsDevice/DirectX/DX12/ResourceOwnerDX12.h
@@ -35,7 +35,7 @@ public:
/// The current resource state.
/// the destination resource state.
/// True if need to perform a transition, otherwise false.
- static bool IsTransitionNeeded(D3D12_RESOURCE_STATES currentState, D3D12_RESOURCE_STATES targetState)
+ FORCE_INLINE static bool IsTransitionNeeded(D3D12_RESOURCE_STATES currentState, D3D12_RESOURCE_STATES targetState)
{
return currentState != targetState && ((currentState | targetState) != currentState || targetState == D3D12_RESOURCE_STATE_COMMON);
}
@@ -81,7 +81,6 @@ public:
///
/// Gets the subresources count.
///
- /// The subresources count.
FORCE_INLINE uint32 GetSubresourcesCount() const
{
return _subresourcesCount;
@@ -90,7 +89,6 @@ public:
///
/// Gets DirectX 12 resource object handle
///
- /// DirectX 12 resource object handle
FORCE_INLINE ID3D12Resource* GetResource() const
{
return _resource;
@@ -99,7 +97,6 @@ public:
///
/// Gets resource owner object as a GPUResource type or returns null if cannot perform cast.
///
- /// GPU Resource or null if cannot cast.
virtual GPUResource* AsGPUResource() const = 0;
protected:
diff --git a/Source/Engine/GraphicsDevice/DirectX/DX12/UploadBufferDX12.cpp b/Source/Engine/GraphicsDevice/DirectX/DX12/UploadBufferDX12.cpp
index c4680b57e..c00b5bf58 100644
--- a/Source/Engine/GraphicsDevice/DirectX/DX12/UploadBufferDX12.cpp
+++ b/Source/Engine/GraphicsDevice/DirectX/DX12/UploadBufferDX12.cpp
@@ -60,6 +60,7 @@ DynamicAllocation UploadBufferDX12::Allocate(uint64 size, uint64 align)
// Move in the page
_currentOffset += size;
+ ASSERT(_currentPage->GetResource());
return result;
}
@@ -67,12 +68,8 @@ bool UploadBufferDX12::UploadBuffer(GPUContextDX12* context, ID3D12Resource* buf
{
// Allocate data
const DynamicAllocation allocation = Allocate(size, 4);
-
- // Check if allocation is invalid
if (allocation.IsInvalid())
- {
return true;
- }
// Copy data
Platform::MemoryCopy(allocation.CPUAddress, data, static_cast(size));
@@ -85,10 +82,8 @@ bool UploadBufferDX12::UploadBuffer(GPUContextDX12* context, ID3D12Resource* buf
bool UploadBufferDX12::UploadTexture(GPUContextDX12* context, ID3D12Resource* texture, const void* srcData, uint32 srcRowPitch, uint32 srcSlicePitch, int32 mipIndex, int32 arrayIndex)
{
- // Cache resource info
D3D12_RESOURCE_DESC resourceDesc = texture->GetDesc();
const UINT subresourceIndex = RenderToolsDX::CalcSubresourceIndex(mipIndex, arrayIndex, resourceDesc.MipLevels);
-
D3D12_PLACED_SUBRESOURCE_FOOTPRINT footprint;
uint32 numRows;
uint64 rowPitchAligned, mipSizeAligned;
@@ -96,16 +91,8 @@ bool UploadBufferDX12::UploadTexture(GPUContextDX12* context, ID3D12Resource* te
rowPitchAligned = footprint.Footprint.RowPitch;
mipSizeAligned = rowPitchAligned * footprint.Footprint.Height;
- // Destination texture copy location description
- D3D12_TEXTURE_COPY_LOCATION dstLocation;
- dstLocation.pResource = texture;
- dstLocation.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
- dstLocation.SubresourceIndex = subresourceIndex;
-
// Allocate data
const DynamicAllocation allocation = Allocate(mipSizeAligned, D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT);
-
- // Check if allocation is invalid
if (allocation.Size != mipSizeAligned)
return true;
@@ -131,6 +118,12 @@ bool UploadBufferDX12::UploadTexture(GPUContextDX12* context, ID3D12Resource* te
}
}
+ // Destination texture copy location description
+ D3D12_TEXTURE_COPY_LOCATION dstLocation;
+ dstLocation.pResource = texture;
+ dstLocation.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
+ dstLocation.SubresourceIndex = subresourceIndex;
+
// Source buffer copy location description
D3D12_TEXTURE_COPY_LOCATION srcLocation;
srcLocation.pResource = allocation.Page->GetResource();
@@ -235,13 +228,7 @@ UploadBufferPageDX12::UploadBufferPageDX12(GPUDeviceDX12* device, uint64 size)
resourceDesc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
resourceDesc.Flags = D3D12_RESOURCE_FLAG_NONE;
ID3D12Resource* resource;
- VALIDATE_DIRECTX_RESULT(_device->GetDevice()->CreateCommittedResource(
- &heapProperties,
- D3D12_HEAP_FLAG_NONE,
- &resourceDesc,
- D3D12_RESOURCE_STATE_GENERIC_READ,
- nullptr,
- IID_PPV_ARGS(&resource)));
+ VALIDATE_DIRECTX_RESULT(_device->GetDevice()->CreateCommittedResource(&heapProperties, D3D12_HEAP_FLAG_NONE, &resourceDesc, D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, IID_PPV_ARGS(&resource)));
// Set state
initResource(resource, D3D12_RESOURCE_STATE_GENERIC_READ, 1);
@@ -260,6 +247,8 @@ void UploadBufferPageDX12::OnReleaseGPU()
{
_resource->Unmap(0, nullptr);
}
+ GPUAddress = 0;
+ CPUAddress = nullptr;
// Release
releaseResource();
diff --git a/Source/Engine/GraphicsDevice/DirectX/DX12/UploadBufferDX12.h b/Source/Engine/GraphicsDevice/DirectX/DX12/UploadBufferDX12.h
index 6995e5c65..605d3268c 100644
--- a/Source/Engine/GraphicsDevice/DirectX/DX12/UploadBufferDX12.h
+++ b/Source/Engine/GraphicsDevice/DirectX/DX12/UploadBufferDX12.h
@@ -183,7 +183,6 @@ public:
///
/// Gets the current generation number.
///
- /// The current generation number.
FORCE_INLINE uint64 GetCurrentGeneration() const
{
return _currentGeneration;
diff --git a/Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.cpp b/Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.cpp
index 69dd0134d..3a3e41b27 100644
--- a/Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.cpp
+++ b/Source/Engine/GraphicsDevice/Vulkan/GPUContextVulkan.cpp
@@ -160,7 +160,6 @@ void GPUContextVulkan::AddImageBarrier(GPUTextureViewVulkan* handle, VkImageLayo
for (int32 i = 0; i < state.GetSubresourcesCount(); i++)
{
const VkImageLayout srcLayout = state.GetSubresourceState(i);
-
if (srcLayout != dstLayout)
{
VkImageSubresourceRange range;
@@ -175,13 +174,11 @@ void GPUContextVulkan::AddImageBarrier(GPUTextureViewVulkan* handle, VkImageLayo
}
ASSERT(state.CheckResourceState(dstLayout));
}
-
state.SetResourceState(dstLayout);
}
else
{
const VkImageLayout srcLayout = state.GetSubresourceState(subresourceIndex);
-
if (srcLayout != dstLayout)
{
// Transition a single subresource
diff --git a/Source/Engine/Renderer/Utils/MultiScaler.cpp b/Source/Engine/Renderer/Utils/MultiScaler.cpp
index f38edab35..54995a9d4 100644
--- a/Source/Engine/Renderer/Utils/MultiScaler.cpp
+++ b/Source/Engine/Renderer/Utils/MultiScaler.cpp
@@ -182,8 +182,8 @@ void MultiScaler::Filter(const FilterMode mode, GPUContext* context, const int32
// Prepare
Data data;
- data.TexelSize.X = 1.0f / width;
- data.TexelSize.Y = 1.0f / height;
+ data.TexelSize.X = 1.0f / (float)width;
+ data.TexelSize.Y = 1.0f / (float)height;
auto cb = _shader->GetShader()->GetCB(0);
context->UpdateCB(cb, &data);
context->BindCB(0, cb);
@@ -219,8 +219,8 @@ void MultiScaler::DownscaleDepth(GPUContext* context, int32 dstWidth, int32 dstH
// Prepare
Data data;
- data.TexelSize.X = 2.0f / dstWidth;
- data.TexelSize.Y = 2.0f / dstHeight;
+ data.TexelSize.X = 2.0f / (float)dstWidth;
+ data.TexelSize.Y = 2.0f / (float)dstHeight;
auto cb = _shader->GetShader()->GetCB(0);
context->UpdateCB(cb, &data);
context->BindCB(0, cb);