Skip to content

Commit

Permalink
Validation: added missing dependency checks for some functions
Browse files Browse the repository at this point in the history
  • Loading branch information
dzhdanNV committed Nov 4, 2024
1 parent 60e70fb commit b23cfaf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Source/Validation/CommandBufferVal.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace nri {

struct DescriptorVal;
struct PipelineVal;
struct PipelineLayoutVal;

struct CommandBufferVal : public DeviceObjectVal<CommandBuffer> {
CommandBufferVal(DeviceVal& device, CommandBuffer* commandBuffer, bool isWrapped)
Expand Down Expand Up @@ -95,6 +96,7 @@ struct CommandBufferVal : public DeviceObjectVal<CommandBuffer> {
Vector<uint8_t> m_ValidationCommands;
std::array<DescriptorVal*, 16> m_RenderTargets = {};
DescriptorVal* m_DepthStencil = nullptr;
PipelineLayoutVal* m_PipelineLayout = nullptr;
PipelineVal* m_Pipeline = nullptr;
uint32_t m_RenderTargetNum = 0;
int32_t m_AnnotationStack = 0;
Expand Down
9 changes: 9 additions & 0 deletions Source/Validation/CommandBufferVal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ NRI_INLINE Result CommandBufferVal::Begin(const DescriptorPool* descriptorPool)
m_IsRecordingStarted = true;

m_ValidationCommands.clear();

m_Pipeline = nullptr;
m_PipelineLayout = nullptr;

ResetAttachments();

Expand Down Expand Up @@ -235,6 +237,7 @@ NRI_INLINE void CommandBufferVal::EndRendering() {

NRI_INLINE void CommandBufferVal::SetVertexBuffers(uint32_t baseSlot, uint32_t bufferNum, const Buffer* const* buffers, const uint64_t* offsets) {
RETURN_ON_FAILURE(&m_Device, m_IsRecordingStarted, ReturnVoid(), "the command buffer must be in the recording state");
RETURN_ON_FAILURE(&m_Device, m_Pipeline, ReturnVoid(), "'SetPipeline' has not been called");

Scratch<Buffer*> buffersImpl = AllocateScratch(m_Device, Buffer*, bufferNum);
for (uint32_t i = 0; i < bufferNum; i++)
Expand All @@ -256,6 +259,8 @@ NRI_INLINE void CommandBufferVal::SetPipelineLayout(const PipelineLayout& pipeli

PipelineLayout* pipelineLayoutImpl = NRI_GET_IMPL(PipelineLayout, &pipelineLayout);

m_PipelineLayout = (PipelineLayoutVal*)&pipelineLayout;

GetCoreInterface().CmdSetPipelineLayout(*GetImpl(), *pipelineLayoutImpl);
}

Expand All @@ -265,6 +270,7 @@ NRI_INLINE void CommandBufferVal::SetPipeline(const Pipeline& pipeline) {
Pipeline* pipelineImpl = NRI_GET_IMPL(Pipeline, &pipeline);

m_Pipeline = (PipelineVal*)&pipeline;

ValidateReadonlyDepthStencil();

GetCoreInterface().CmdSetPipeline(*GetImpl(), *pipelineImpl);
Expand All @@ -280,6 +286,7 @@ NRI_INLINE void CommandBufferVal::SetDescriptorPool(const DescriptorPool& descri

NRI_INLINE void CommandBufferVal::SetDescriptorSet(uint32_t setIndex, const DescriptorSet& descriptorSet, const uint32_t* dynamicConstantBufferOffsets) {
RETURN_ON_FAILURE(&m_Device, m_IsRecordingStarted, ReturnVoid(), "the command buffer must be in the recording state");
RETURN_ON_FAILURE(&m_Device, m_PipelineLayout, ReturnVoid(), "'SetPipelineLayout' has not been called");

DescriptorSet* descriptorSetImpl = NRI_GET_IMPL(DescriptorSet, &descriptorSet);

Expand All @@ -288,12 +295,14 @@ NRI_INLINE void CommandBufferVal::SetDescriptorSet(uint32_t setIndex, const Desc

NRI_INLINE void CommandBufferVal::SetRootConstants(uint32_t rootConstantIndex, const void* data, uint32_t size) {
RETURN_ON_FAILURE(&m_Device, m_IsRecordingStarted, ReturnVoid(), "the command buffer must be in the recording state");
RETURN_ON_FAILURE(&m_Device, m_PipelineLayout, ReturnVoid(), "'SetPipelineLayout' has not been called");

GetCoreInterface().CmdSetRootConstants(*GetImpl(), rootConstantIndex, data, size);
}

NRI_INLINE void CommandBufferVal::SetRootDescriptor(uint32_t rootDescriptorIndex, Descriptor& descriptor) {
RETURN_ON_FAILURE(&m_Device, m_IsRecordingStarted, ReturnVoid(), "the command buffer must be in the recording state");
RETURN_ON_FAILURE(&m_Device, m_PipelineLayout, ReturnVoid(), "'SetPipelineLayout' has not been called");

const DescriptorVal& descriptorVal = (DescriptorVal&)descriptor;
RETURN_ON_FAILURE(&m_Device, descriptorVal.IsBufferView(), ReturnVoid(), "'descriptor' must be a buffer view");
Expand Down

0 comments on commit b23cfaf

Please sign in to comment.