Skip to content

Commit

Permalink
Renamed CommandListResourceStateTracker::endTrackingTextureState to s…
Browse files Browse the repository at this point in the history
…etPermanentTextureState, removed the 'permanent' argument. Same for buffers.
  • Loading branch information
apanteleev committed Feb 2, 2024
1 parent 6225145 commit 60716bf
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
12 changes: 5 additions & 7 deletions src/common/state-tracking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,14 @@ namespace nvrhi
tracking->state = stateBits;
}

void CommandListResourceStateTracker::endTrackingTextureState(TextureStateExtension* texture, TextureSubresourceSet subresources, ResourceStates stateBits, bool permanent)
void CommandListResourceStateTracker::setPermanentTextureState(TextureStateExtension* texture, TextureSubresourceSet subresources, ResourceStates stateBits)
{
const TextureDesc& desc = texture->descRef;

subresources = subresources.resolve(desc, false);

if (permanent && !subresources.isEntireTexture(desc))
bool permanent = true;
if (!subresources.isEntireTexture(desc))
{
std::stringstream ss;
ss << "Attempted to perform a permanent state transition on a subset of subresources of texture "
Expand All @@ -124,14 +125,11 @@ namespace nvrhi
}
}

void CommandListResourceStateTracker::endTrackingBufferState(BufferStateExtension* buffer, ResourceStates stateBits, bool permanent)
void CommandListResourceStateTracker::setPermanentBufferState(BufferStateExtension* buffer, ResourceStates stateBits)
{
requireBufferState(buffer, stateBits);

if (permanent)
{
m_PermanentBufferStates.push_back(std::make_pair(buffer, stateBits));
}
m_PermanentBufferStates.push_back(std::make_pair(buffer, stateBits));
}

ResourceStates CommandListResourceStateTracker::getTextureSubresourceState(TextureStateExtension* texture, ArraySlice arraySlice, MipLevel mipLevel)
Expand Down
6 changes: 3 additions & 3 deletions src/common/state-tracking.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ namespace nvrhi
void beginTrackingTextureState(TextureStateExtension* texture, TextureSubresourceSet subresources, ResourceStates stateBits);
void beginTrackingBufferState(BufferStateExtension* buffer, ResourceStates stateBits);

void endTrackingTextureState(TextureStateExtension* texture, TextureSubresourceSet subresources, ResourceStates stateBits, bool permanent);
void endTrackingBufferState(BufferStateExtension* buffer, ResourceStates stateBits, bool permanent);
void setPermanentTextureState(TextureStateExtension* texture, TextureSubresourceSet subresources, ResourceStates stateBits);
void setPermanentBufferState(BufferStateExtension* buffer, ResourceStates stateBits);

ResourceStates getTextureSubresourceState(TextureStateExtension* texture, ArraySlice arraySlice, MipLevel mipLevel);
ResourceStates getBufferState(BufferStateExtension* buffer);
Expand All @@ -124,7 +124,7 @@ namespace nvrhi
std::unordered_map<BufferStateExtension*, std::unique_ptr<BufferState>> m_BufferStates;

// Deferred transitions of textures and buffers to permanent states.
// They are executed only when the command list is executed, not when the app calls endTrackingTextureState.
// They are executed only when the command list is executed, not when the app calls setPermanentTextureState or setPermanentBufferState.
std::vector<std::pair<TextureStateExtension*, ResourceStates>> m_PermanentTextureStates;
std::vector<std::pair<BufferStateExtension*, ResourceStates>> m_PermanentBufferStates;

Expand Down
10 changes: 5 additions & 5 deletions src/d3d12/d3d12-state-tracking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,37 +229,37 @@ namespace nvrhi::d3d12
{
Texture* texture = checked_cast<Texture*>(_texture);

m_StateTracker.endTrackingTextureState(texture, subresources, stateBits, false);
m_StateTracker.requireTextureState(texture, subresources, stateBits);
}

void CommandList::setBufferState(IBuffer* _buffer, ResourceStates stateBits)
{
Buffer* buffer = checked_cast<Buffer*>(_buffer);

m_StateTracker.endTrackingBufferState(buffer, stateBits, false);
m_StateTracker.requireBufferState(buffer, stateBits);
}

void CommandList::setAccelStructState(rt::IAccelStruct* _as, ResourceStates stateBits)
{
AccelStruct* as = checked_cast<AccelStruct*>(_as);

if (as->dataBuffer)
m_StateTracker.endTrackingBufferState(as->dataBuffer, stateBits, false);
m_StateTracker.requireBufferState(as->dataBuffer, stateBits);
}

void CommandList::setPermanentTextureState(ITexture* _texture, ResourceStates stateBits)
{
Texture* texture = checked_cast<Texture*>(_texture);

m_StateTracker.endTrackingTextureState(texture, AllSubresources, stateBits, true);
m_StateTracker.setPermanentTextureState(texture, AllSubresources, stateBits);

}

void CommandList::setPermanentBufferState(IBuffer* _buffer, ResourceStates stateBits)
{
Buffer* buffer = checked_cast<Buffer*>(_buffer);

m_StateTracker.endTrackingBufferState(buffer, stateBits, true);
m_StateTracker.setPermanentBufferState(buffer, stateBits);
}

ResourceStates CommandList::getTextureSubresourceState(ITexture* _texture, ArraySlice arraySlice, MipLevel mipLevel)
Expand Down
10 changes: 5 additions & 5 deletions src/vulkan/vulkan-state-tracking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,14 +368,14 @@ namespace nvrhi::vulkan
{
Texture* texture = checked_cast<Texture*>(_texture);

m_StateTracker.endTrackingTextureState(texture, subresources, stateBits, false);
m_StateTracker.requireTextureState(texture, subresources, stateBits);
}

void CommandList::setBufferState(IBuffer* _buffer, ResourceStates stateBits)
{
Buffer* buffer = checked_cast<Buffer*>(_buffer);

m_StateTracker.endTrackingBufferState(buffer, stateBits, false);
m_StateTracker.requireBufferState(buffer, stateBits);
}

void CommandList::setAccelStructState(rt::IAccelStruct* _as, ResourceStates stateBits)
Expand All @@ -385,22 +385,22 @@ namespace nvrhi::vulkan
if (as->dataBuffer)
{
Buffer* buffer = checked_cast<Buffer*>(as->dataBuffer.Get());
m_StateTracker.endTrackingBufferState(buffer, stateBits, false);
m_StateTracker.requireBufferState(buffer, stateBits);
}
}

void CommandList::setPermanentTextureState(ITexture* _texture, ResourceStates stateBits)
{
Texture* texture = checked_cast<Texture*>(_texture);

m_StateTracker.endTrackingTextureState(texture, AllSubresources, stateBits, true);
m_StateTracker.setPermanentTextureState(texture, AllSubresources, stateBits);
}

void CommandList::setPermanentBufferState(IBuffer* _buffer, ResourceStates stateBits)
{
Buffer* buffer = checked_cast<Buffer*>(_buffer);

m_StateTracker.endTrackingBufferState(buffer, stateBits, true);
m_StateTracker.setPermanentBufferState(buffer, stateBits);
}

ResourceStates CommandList::getTextureSubresourceState(ITexture* _texture, ArraySlice arraySlice, MipLevel mipLevel)
Expand Down

0 comments on commit 60716bf

Please sign in to comment.