Fix crash if texture streaming fails on different texture format on Vulkan due to fallback usage
This commit is contained in:
@@ -345,8 +345,12 @@ protected:
|
||||
if (texture == nullptr)
|
||||
return Result::MissingResources;
|
||||
|
||||
// Ensure that texture has been allocated before this task
|
||||
ASSERT(texture->IsAllocated());
|
||||
// Ensure that texture has been allocated before this task and has proper format
|
||||
if (!texture->IsAllocated() || texture->Format() != _streamingTexture->GetHeader()->Format)
|
||||
{
|
||||
LOG(Error, "Cannot stream texture {0} (streaming format: {1})", texture->ToString(), (int32)_streamingTexture->GetHeader()->Format);
|
||||
return Result::Failed;
|
||||
}
|
||||
|
||||
// Get asset data
|
||||
BytesContainer data;
|
||||
@@ -385,6 +389,16 @@ protected:
|
||||
// Base
|
||||
GPUUploadTextureMipTask::OnEnd();
|
||||
}
|
||||
void OnFail() override
|
||||
{
|
||||
if (_streamingTexture)
|
||||
{
|
||||
// Stop streaming on fail
|
||||
_streamingTexture->CancelStreaming();
|
||||
}
|
||||
|
||||
GPUUploadTextureMipTask::OnFail();
|
||||
}
|
||||
};
|
||||
|
||||
Task* StreamingTexture::CreateStreamingTask(int32 residency)
|
||||
|
||||
@@ -115,10 +115,12 @@ public:
|
||||
/// <summary>
|
||||
/// Requests the streaming update for this resource during next streaming manager update.
|
||||
/// </summary>
|
||||
void RequestStreamingUpdate()
|
||||
{
|
||||
Streaming.LastUpdate = 0;
|
||||
}
|
||||
void RequestStreamingUpdate();
|
||||
|
||||
/// <summary>
|
||||
/// Stops the streaming (eg. on streaming fail).
|
||||
/// </summary>
|
||||
void CancelStreaming();
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
@@ -79,6 +79,17 @@ StreamableResource::~StreamableResource()
|
||||
StopStreaming();
|
||||
}
|
||||
|
||||
void StreamableResource::RequestStreamingUpdate()
|
||||
{
|
||||
Streaming.LastUpdate = 0;
|
||||
}
|
||||
|
||||
void StreamableResource::CancelStreaming()
|
||||
{
|
||||
Streaming.TargetResidency = 0;
|
||||
Streaming.LastUpdate = DateTime::MaxValue().Ticks;
|
||||
}
|
||||
|
||||
void StreamableResource::StartStreaming(bool isDynamic)
|
||||
{
|
||||
_isDynamic = isDynamic;
|
||||
@@ -158,8 +169,7 @@ void UpdateResource(StreamableResource* resource, DateTime now, double currentTi
|
||||
else if (resource->GetAllocatedResidency() < targetResidency)
|
||||
{
|
||||
// Allocation failed (eg. texture format is not supported or run out of memory)
|
||||
resource->Streaming.TargetResidency = 0;
|
||||
resource->Streaming.LastUpdate = DateTime::MaxValue().Ticks;
|
||||
resource->CancelStreaming();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user