graphicsdevice fixes, removed instanceStepRate, occlusion culling updates

This commit is contained in:
Turanszki Janos
2021-03-13 12:47:14 +01:00
parent 99aa9d0f16
commit fe81bf30f3
12 changed files with 330 additions and 300 deletions
-1
View File
@@ -370,7 +370,6 @@ namespace wiGraphics
uint32_t InputSlot = 0;
uint32_t AlignedByteOffset = APPEND_ALIGNED_ELEMENT;
INPUT_CLASSIFICATION InputSlotClass = INPUT_CLASSIFICATION::INPUT_PER_VERTEX_DATA;
uint32_t InstanceDataStepRate = 0;
};
std::vector<Element> elements;
};
+19 -19
View File
@@ -32,29 +32,29 @@ namespace wiGraphics
wiEvent::Handle dpi_change_event = wiEvent::Subscribe(SYSTEM_EVENT_CHANGE_DPI, [this](uint64_t userdata) { dpi = int(userdata & 0xFFFF); });
public:
virtual bool CreateBuffer(const GPUBufferDesc *pDesc, const SubresourceData* pInitialData, GPUBuffer *pBuffer) = 0;
virtual bool CreateTexture(const TextureDesc* pDesc, const SubresourceData *pInitialData, Texture *pTexture) = 0;
virtual bool CreateShader(SHADERSTAGE stage, const void *pShaderBytecode, size_t BytecodeLength, Shader *pShader) = 0;
virtual bool CreateSampler(const SamplerDesc *pSamplerDesc, Sampler *pSamplerState) = 0;
virtual bool CreateQueryHeap(const GPUQueryHeapDesc *pDesc, GPUQueryHeap *pQueryHeap) = 0;
virtual bool CreatePipelineState(const PipelineStateDesc* pDesc, PipelineState* pso) = 0;
virtual bool CreateRenderPass(const RenderPassDesc* pDesc, RenderPass* renderpass) = 0;
virtual bool CreateRaytracingAccelerationStructure(const RaytracingAccelerationStructureDesc* pDesc, RaytracingAccelerationStructure* bvh) { return false; }
virtual bool CreateRaytracingPipelineState(const RaytracingPipelineStateDesc* pDesc, RaytracingPipelineState* rtpso) { return false; }
virtual bool CreateBuffer(const GPUBufferDesc *pDesc, const SubresourceData* pInitialData, GPUBuffer *pBuffer) const = 0;
virtual bool CreateTexture(const TextureDesc* pDesc, const SubresourceData *pInitialData, Texture *pTexture) const = 0;
virtual bool CreateShader(SHADERSTAGE stage, const void *pShaderBytecode, size_t BytecodeLength, Shader *pShader) const = 0;
virtual bool CreateSampler(const SamplerDesc *pSamplerDesc, Sampler *pSamplerState) const = 0;
virtual bool CreateQueryHeap(const GPUQueryHeapDesc *pDesc, GPUQueryHeap *pQueryHeap) const = 0;
virtual bool CreatePipelineState(const PipelineStateDesc* pDesc, PipelineState* pso) const = 0;
virtual bool CreateRenderPass(const RenderPassDesc* pDesc, RenderPass* renderpass) const = 0;
virtual bool CreateRaytracingAccelerationStructure(const RaytracingAccelerationStructureDesc* pDesc, RaytracingAccelerationStructure* bvh) const { return false; }
virtual bool CreateRaytracingPipelineState(const RaytracingPipelineStateDesc* pDesc, RaytracingPipelineState* rtpso) const { return false; }
virtual int CreateSubresource(Texture* texture, SUBRESOURCE_TYPE type, uint32_t firstSlice, uint32_t sliceCount, uint32_t firstMip, uint32_t mipCount) = 0;
virtual int CreateSubresource(GPUBuffer* buffer, SUBRESOURCE_TYPE type, uint64_t offset, uint64_t size = ~0) = 0;
virtual int CreateSubresource(Texture* texture, SUBRESOURCE_TYPE type, uint32_t firstSlice, uint32_t sliceCount, uint32_t firstMip, uint32_t mipCount) const = 0;
virtual int CreateSubresource(GPUBuffer* buffer, SUBRESOURCE_TYPE type, uint64_t offset, uint64_t size = ~0) const = 0;
virtual int GetDescriptorIndex(const GPUResource* resource, SUBRESOURCE_TYPE type, int subresource = -1) { return -1; };
virtual int GetDescriptorIndex(const Sampler* sampler) { return -1; };
virtual int GetDescriptorIndex(const GPUResource* resource, SUBRESOURCE_TYPE type, int subresource = -1) const { return -1; };
virtual int GetDescriptorIndex(const Sampler* sampler) const { return -1; };
virtual void WriteShadingRateValue(SHADING_RATE rate, void* dest) {};
virtual void WriteTopLevelAccelerationStructureInstance(const RaytracingAccelerationStructureDesc::TopLevel::Instance* instance, void* dest) {}
virtual void WriteShaderIdentifier(const RaytracingPipelineState* rtpso, uint32_t group_index, void* dest) {}
virtual void WriteShadingRateValue(SHADING_RATE rate, void* dest) const {};
virtual void WriteTopLevelAccelerationStructureInstance(const RaytracingAccelerationStructureDesc::TopLevel::Instance* instance, void* dest) const {}
virtual void WriteShaderIdentifier(const RaytracingPipelineState* rtpso, uint32_t group_index, void* dest) const {}
virtual void Map(const GPUResource* resource, Mapping* mapping) = 0;
virtual void Unmap(const GPUResource* resource) = 0;
virtual void QueryRead(const GPUQueryHeap* heap, uint32_t index, uint32_t count, uint64_t* results) = 0;
virtual void Map(const GPUResource* resource, Mapping* mapping) const = 0;
virtual void Unmap(const GPUResource* resource) const = 0;
virtual void QueryRead(const GPUQueryHeap* heap, uint32_t index, uint32_t count, uint64_t* results) const = 0;
virtual void SetCommonSampler(const StaticSampler* sam) = 0;
+17 -14
View File
@@ -1578,7 +1578,7 @@ Texture GraphicsDevice_DX11::GetBackBuffer()
return result;
}
bool GraphicsDevice_DX11::CreateBuffer(const GPUBufferDesc *pDesc, const SubresourceData* pInitialData, GPUBuffer *pBuffer)
bool GraphicsDevice_DX11::CreateBuffer(const GPUBufferDesc *pDesc, const SubresourceData* pInitialData, GPUBuffer *pBuffer) const
{
auto internal_state = std::make_shared<Resource_DX11>();
pBuffer->internal_state = internal_state;
@@ -1617,7 +1617,7 @@ bool GraphicsDevice_DX11::CreateBuffer(const GPUBufferDesc *pDesc, const Subreso
return SUCCEEDED(hr);
}
bool GraphicsDevice_DX11::CreateTexture(const TextureDesc* pDesc, const SubresourceData *pInitialData, Texture *pTexture)
bool GraphicsDevice_DX11::CreateTexture(const TextureDesc* pDesc, const SubresourceData *pInitialData, Texture *pTexture) const
{
auto internal_state = std::make_shared<Texture_DX11>();
pTexture->internal_state = internal_state;
@@ -1691,7 +1691,7 @@ bool GraphicsDevice_DX11::CreateTexture(const TextureDesc* pDesc, const Subresou
return SUCCEEDED(hr);
}
bool GraphicsDevice_DX11::CreateShader(SHADERSTAGE stage, const void *pShaderBytecode, size_t BytecodeLength, Shader *pShader)
bool GraphicsDevice_DX11::CreateShader(SHADERSTAGE stage, const void *pShaderBytecode, size_t BytecodeLength, Shader *pShader) const
{
pShader->stage = stage;
@@ -1749,7 +1749,7 @@ bool GraphicsDevice_DX11::CreateShader(SHADERSTAGE stage, const void *pShaderByt
return SUCCEEDED(hr);
}
bool GraphicsDevice_DX11::CreateSampler(const SamplerDesc *pSamplerDesc, Sampler *pSamplerState)
bool GraphicsDevice_DX11::CreateSampler(const SamplerDesc *pSamplerDesc, Sampler *pSamplerState) const
{
auto internal_state = std::make_shared<Sampler_DX11>();
pSamplerState->internal_state = internal_state;
@@ -1775,7 +1775,7 @@ bool GraphicsDevice_DX11::CreateSampler(const SamplerDesc *pSamplerDesc, Sampler
return SUCCEEDED(hr);
}
bool GraphicsDevice_DX11::CreateQueryHeap(const GPUQueryHeapDesc* pDesc, GPUQueryHeap* pQueryHeap)
bool GraphicsDevice_DX11::CreateQueryHeap(const GPUQueryHeapDesc* pDesc, GPUQueryHeap* pQueryHeap) const
{
auto internal_state = std::make_shared<QueryHeap_DX11>();
pQueryHeap->internal_state = internal_state;
@@ -1811,7 +1811,7 @@ bool GraphicsDevice_DX11::CreateQueryHeap(const GPUQueryHeapDesc* pDesc, GPUQuer
return true;
}
bool GraphicsDevice_DX11::CreatePipelineState(const PipelineStateDesc* pDesc, PipelineState* pso)
bool GraphicsDevice_DX11::CreatePipelineState(const PipelineStateDesc* pDesc, PipelineState* pso) const
{
auto internal_state = std::make_shared<PipelineState_DX11>();
pso->internal_state = internal_state;
@@ -1835,8 +1835,11 @@ bool GraphicsDevice_DX11::CreatePipelineState(const PipelineStateDesc* pDesc, Pi
if (desc[i].AlignedByteOffset == InputLayout::APPEND_ALIGNED_ELEMENT)
desc[i].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
desc[i].InputSlotClass = _ConvertInputClassification(pDesc->il->elements[i].InputSlotClass);
desc[i].InstanceDataStepRate = pDesc->il->elements[i].InstanceDataStepRate;
desc[i].InstanceDataStepRate = 0;
if (desc[i].InputSlotClass == D3D11_INPUT_PER_INSTANCE_DATA)
{
desc[i].InstanceDataStepRate = 1;
}
}
assert(pDesc->vs != nullptr);
@@ -1965,7 +1968,7 @@ bool GraphicsDevice_DX11::CreatePipelineState(const PipelineStateDesc* pDesc, Pi
return true;
}
bool GraphicsDevice_DX11::CreateRenderPass(const RenderPassDesc* pDesc, RenderPass* renderpass)
bool GraphicsDevice_DX11::CreateRenderPass(const RenderPassDesc* pDesc, RenderPass* renderpass) const
{
renderpass->internal_state = emptyresource;
@@ -1974,7 +1977,7 @@ bool GraphicsDevice_DX11::CreateRenderPass(const RenderPassDesc* pDesc, RenderPa
return true;
}
int GraphicsDevice_DX11::CreateSubresource(Texture* texture, SUBRESOURCE_TYPE type, uint32_t firstSlice, uint32_t sliceCount, uint32_t firstMip, uint32_t mipCount)
int GraphicsDevice_DX11::CreateSubresource(Texture* texture, SUBRESOURCE_TYPE type, uint32_t firstSlice, uint32_t sliceCount, uint32_t firstMip, uint32_t mipCount) const
{
auto internal_state = to_internal(texture);
@@ -2369,7 +2372,7 @@ int GraphicsDevice_DX11::CreateSubresource(Texture* texture, SUBRESOURCE_TYPE ty
}
return -1;
}
int GraphicsDevice_DX11::CreateSubresource(GPUBuffer* buffer, SUBRESOURCE_TYPE type, uint64_t offset, uint64_t size)
int GraphicsDevice_DX11::CreateSubresource(GPUBuffer* buffer, SUBRESOURCE_TYPE type, uint64_t offset, uint64_t size) const
{
auto internal_state = to_internal(buffer);
const GPUBufferDesc& desc = buffer->GetDesc();
@@ -2488,7 +2491,7 @@ int GraphicsDevice_DX11::CreateSubresource(GPUBuffer* buffer, SUBRESOURCE_TYPE t
return -1;
}
void GraphicsDevice_DX11::Map(const GPUResource* resource, Mapping* mapping)
void GraphicsDevice_DX11::Map(const GPUResource* resource, Mapping* mapping) const
{
auto internal_state = to_internal(resource);
@@ -2522,12 +2525,12 @@ void GraphicsDevice_DX11::Map(const GPUResource* resource, Mapping* mapping)
mapping->rowpitch = 0;
}
}
void GraphicsDevice_DX11::Unmap(const GPUResource* resource)
void GraphicsDevice_DX11::Unmap(const GPUResource* resource) const
{
auto internal_state = to_internal(resource);
immediateContext->Unmap(internal_state->resource.Get(), 0);
}
void GraphicsDevice_DX11::QueryRead(const GPUQueryHeap* heap, uint32_t index, uint32_t count, uint64_t* results)
void GraphicsDevice_DX11::QueryRead(const GPUQueryHeap* heap, uint32_t index, uint32_t count, uint64_t* results) const
{
if (count == 0)
return;
+12 -12
View File
@@ -84,20 +84,20 @@ namespace wiGraphics
public:
GraphicsDevice_DX11(wiPlatform::window_type window, bool fullscreen = false, bool debuglayer = false);
bool CreateBuffer(const GPUBufferDesc *pDesc, const SubresourceData* pInitialData, GPUBuffer *pBuffer) override;
bool CreateTexture(const TextureDesc* pDesc, const SubresourceData *pInitialData, Texture *pTexture) override;
bool CreateShader(SHADERSTAGE stage, const void *pShaderBytecode, size_t BytecodeLength, Shader *pShader) override;
bool CreateSampler(const SamplerDesc *pSamplerDesc, Sampler *pSamplerState) override;
bool CreateQueryHeap(const GPUQueryHeapDesc *pDesc, GPUQueryHeap *pQueryHeap) override;
bool CreatePipelineState(const PipelineStateDesc* pDesc, PipelineState* pso) override;
bool CreateRenderPass(const RenderPassDesc* pDesc, RenderPass* renderpass) override;
bool CreateBuffer(const GPUBufferDesc *pDesc, const SubresourceData* pInitialData, GPUBuffer *pBuffer) const override;
bool CreateTexture(const TextureDesc* pDesc, const SubresourceData *pInitialData, Texture *pTexture) const override;
bool CreateShader(SHADERSTAGE stage, const void *pShaderBytecode, size_t BytecodeLength, Shader *pShader) const override;
bool CreateSampler(const SamplerDesc *pSamplerDesc, Sampler *pSamplerState) const override;
bool CreateQueryHeap(const GPUQueryHeapDesc *pDesc, GPUQueryHeap *pQueryHeap) const override;
bool CreatePipelineState(const PipelineStateDesc* pDesc, PipelineState* pso) const override;
bool CreateRenderPass(const RenderPassDesc* pDesc, RenderPass* renderpass) const override;
int CreateSubresource(Texture* texture, SUBRESOURCE_TYPE type, uint32_t firstSlice, uint32_t sliceCount, uint32_t firstMip, uint32_t mipCount) override;
int CreateSubresource(GPUBuffer* buffer, SUBRESOURCE_TYPE type, uint64_t offset, uint64_t size = ~0) override;
int CreateSubresource(Texture* texture, SUBRESOURCE_TYPE type, uint32_t firstSlice, uint32_t sliceCount, uint32_t firstMip, uint32_t mipCount) const override;
int CreateSubresource(GPUBuffer* buffer, SUBRESOURCE_TYPE type, uint64_t offset, uint64_t size = ~0) const override;
void Map(const GPUResource* resource, Mapping* mapping) override;
void Unmap(const GPUResource* resource) override;
void QueryRead(const GPUQueryHeap* resource, uint32_t index, uint32_t count, uint64_t* results) override;
void Map(const GPUResource* resource, Mapping* mapping) const override;
void Unmap(const GPUResource* resource) const override;
void QueryRead(const GPUQueryHeap* resource, uint32_t index, uint32_t count, uint64_t* results) const override;
void SetCommonSampler(const StaticSampler* sam) override;
+41 -32
View File
@@ -1056,7 +1056,7 @@ namespace DX12_Internal
D3D12_DEPTH_STENCIL_VIEW_DESC dsv;
};
bool IsValid() const { return handle.ptr != 0; }
void init(GraphicsDevice_DX12* device, const D3D12_CONSTANT_BUFFER_VIEW_DESC& cbv)
void init(const GraphicsDevice_DX12* device, const D3D12_CONSTANT_BUFFER_VIEW_DESC& cbv)
{
this->cbv = cbv;
this->allocationhandler = device->allocationhandler;
@@ -1079,7 +1079,7 @@ namespace DX12_Internal
allocationhandler->device->CopyDescriptorsSimple(1, dst_bindless, handle, type);
}
}
void init(GraphicsDevice_DX12* device, const D3D12_SHADER_RESOURCE_VIEW_DESC& srv, ID3D12Resource* res)
void init(const GraphicsDevice_DX12* device, const D3D12_SHADER_RESOURCE_VIEW_DESC& srv, ID3D12Resource* res)
{
this->srv = srv;
this->allocationhandler = device->allocationhandler;
@@ -1102,7 +1102,7 @@ namespace DX12_Internal
allocationhandler->device->CopyDescriptorsSimple(1, dst_bindless, handle, type);
}
}
void init(GraphicsDevice_DX12* device, const D3D12_UNORDERED_ACCESS_VIEW_DESC& uav, ID3D12Resource* res)
void init(const GraphicsDevice_DX12* device, const D3D12_UNORDERED_ACCESS_VIEW_DESC& uav, ID3D12Resource* res)
{
this->uav = uav;
this->allocationhandler = device->allocationhandler;
@@ -1125,7 +1125,7 @@ namespace DX12_Internal
allocationhandler->device->CopyDescriptorsSimple(1, dst_bindless, handle, type);
}
}
void init(GraphicsDevice_DX12* device, const D3D12_SAMPLER_DESC& sam)
void init(const GraphicsDevice_DX12* device, const D3D12_SAMPLER_DESC& sam)
{
this->sam = sam;
this->allocationhandler = device->allocationhandler;
@@ -1148,7 +1148,7 @@ namespace DX12_Internal
allocationhandler->device->CopyDescriptorsSimple(1, dst_bindless, handle, type);
}
}
void init(GraphicsDevice_DX12* device, const D3D12_RENDER_TARGET_VIEW_DESC& rtv, ID3D12Resource* res)
void init(const GraphicsDevice_DX12* device, const D3D12_RENDER_TARGET_VIEW_DESC& rtv, ID3D12Resource* res)
{
this->rtv = rtv;
this->allocationhandler = device->allocationhandler;
@@ -1156,7 +1156,7 @@ namespace DX12_Internal
handle = allocationhandler->descriptors_rtv.allocate();
allocationhandler->device->CreateRenderTargetView(res, &rtv, handle);
}
void init(GraphicsDevice_DX12* device, const D3D12_DEPTH_STENCIL_VIEW_DESC& dsv, ID3D12Resource* res)
void init(const GraphicsDevice_DX12* device, const D3D12_DEPTH_STENCIL_VIEW_DESC& dsv, ID3D12Resource* res)
{
this->dsv = dsv;
this->allocationhandler = device->allocationhandler;
@@ -2121,11 +2121,14 @@ using namespace DX12_Internal;
i--;
}
}
GetDirectCommandList(cmd)->ResourceBarrier(
(UINT)barriers.size(),
barriers.data()
);
barriers.clear();
if (!barriers.empty())
{
GetDirectCommandList(cmd)->ResourceBarrier(
(UINT)barriers.size(),
barriers.data()
);
barriers.clear();
}
}
}
void GraphicsDevice_DX12::predraw(CommandList cmd)
@@ -2735,7 +2738,7 @@ using namespace DX12_Internal;
return result;
}
bool GraphicsDevice_DX12::CreateBuffer(const GPUBufferDesc* pDesc, const SubresourceData* pInitialData, GPUBuffer* pBuffer)
bool GraphicsDevice_DX12::CreateBuffer(const GPUBufferDesc* pDesc, const SubresourceData* pInitialData, GPUBuffer* pBuffer) const
{
auto internal_state = std::make_shared<Resource_DX12>();
internal_state->allocationhandler = allocationhandler;
@@ -2857,7 +2860,7 @@ using namespace DX12_Internal;
return SUCCEEDED(hr);
}
bool GraphicsDevice_DX12::CreateTexture(const TextureDesc* pDesc, const SubresourceData* pInitialData, Texture* pTexture)
bool GraphicsDevice_DX12::CreateTexture(const TextureDesc* pDesc, const SubresourceData* pInitialData, Texture* pTexture) const
{
auto internal_state = std::make_shared<Texture_DX12>();
internal_state->allocationhandler = allocationhandler;
@@ -3074,7 +3077,7 @@ using namespace DX12_Internal;
return SUCCEEDED(hr);
}
bool GraphicsDevice_DX12::CreateShader(SHADERSTAGE stage, const void* pShaderBytecode, size_t BytecodeLength, Shader* pShader)
bool GraphicsDevice_DX12::CreateShader(SHADERSTAGE stage, const void* pShaderBytecode, size_t BytecodeLength, Shader* pShader) const
{
auto internal_state = std::make_shared<PipelineState_DX12>();
internal_state->allocationhandler = allocationhandler;
@@ -3602,7 +3605,7 @@ using namespace DX12_Internal;
return SUCCEEDED(hr);
}
bool GraphicsDevice_DX12::CreateSampler(const SamplerDesc* pSamplerDesc, Sampler* pSamplerState)
bool GraphicsDevice_DX12::CreateSampler(const SamplerDesc* pSamplerDesc, Sampler* pSamplerState) const
{
auto internal_state = std::make_shared<Sampler_DX12>();
internal_state->allocationhandler = allocationhandler;
@@ -3629,7 +3632,7 @@ using namespace DX12_Internal;
return true;
}
bool GraphicsDevice_DX12::CreateQueryHeap(const GPUQueryHeapDesc* pDesc, GPUQueryHeap* pQueryHeap)
bool GraphicsDevice_DX12::CreateQueryHeap(const GPUQueryHeapDesc* pDesc, GPUQueryHeap* pQueryHeap) const
{
auto internal_state = std::make_shared<QueryHeap_DX12>();
internal_state->allocationhandler = allocationhandler;
@@ -3683,7 +3686,7 @@ using namespace DX12_Internal;
return SUCCEEDED(hr);
}
bool GraphicsDevice_DX12::CreatePipelineState(const PipelineStateDesc* pDesc, PipelineState* pso)
bool GraphicsDevice_DX12::CreatePipelineState(const PipelineStateDesc* pDesc, PipelineState* pso) const
{
auto internal_state = std::make_shared<PipelineState_DX12>();
internal_state->allocationhandler = allocationhandler;
@@ -4090,7 +4093,11 @@ using namespace DX12_Internal;
if (elements[i].AlignedByteOffset == InputLayout::APPEND_ALIGNED_ELEMENT)
elements[i].AlignedByteOffset = D3D12_APPEND_ALIGNED_ELEMENT;
elements[i].InputSlotClass = _ConvertInputClassification(pso->desc.il->elements[i].InputSlotClass);
elements[i].InstanceDataStepRate = pso->desc.il->elements[i].InstanceDataStepRate;
elements[i].InstanceDataStepRate = 0;
if (elements[i].InputSlotClass == D3D12_INPUT_CLASSIFICATION_PER_INSTANCE_DATA)
{
elements[i].InstanceDataStepRate = 1;
}
}
}
il.pInputElementDescs = elements.data();
@@ -4125,7 +4132,7 @@ using namespace DX12_Internal;
return SUCCEEDED(hr);
}
bool GraphicsDevice_DX12::CreateRenderPass(const RenderPassDesc* pDesc, RenderPass* renderpass)
bool GraphicsDevice_DX12::CreateRenderPass(const RenderPassDesc* pDesc, RenderPass* renderpass) const
{
auto internal_state = std::make_shared<RenderPass_DX12>();
renderpass->internal_state = internal_state;
@@ -4353,7 +4360,7 @@ using namespace DX12_Internal;
return true;
}
bool GraphicsDevice_DX12::CreateRaytracingAccelerationStructure(const RaytracingAccelerationStructureDesc* pDesc, RaytracingAccelerationStructure* bvh)
bool GraphicsDevice_DX12::CreateRaytracingAccelerationStructure(const RaytracingAccelerationStructureDesc* pDesc, RaytracingAccelerationStructure* bvh) const
{
auto internal_state = std::make_shared<BVH_DX12>();
internal_state->allocationhandler = allocationhandler;
@@ -4488,7 +4495,7 @@ using namespace DX12_Internal;
return CreateBuffer(&scratch_desc, nullptr, &internal_state->scratch);
}
bool GraphicsDevice_DX12::CreateRaytracingPipelineState(const RaytracingPipelineStateDesc* pDesc, RaytracingPipelineState* rtpso)
bool GraphicsDevice_DX12::CreateRaytracingPipelineState(const RaytracingPipelineStateDesc* pDesc, RaytracingPipelineState* rtpso) const
{
auto internal_state = std::make_shared<RTPipelineState_DX12>();
internal_state->allocationhandler = allocationhandler;
@@ -4602,7 +4609,7 @@ using namespace DX12_Internal;
return SUCCEEDED(hr);
}
int GraphicsDevice_DX12::CreateSubresource(Texture* texture, SUBRESOURCE_TYPE type, uint32_t firstSlice, uint32_t sliceCount, uint32_t firstMip, uint32_t mipCount)
int GraphicsDevice_DX12::CreateSubresource(Texture* texture, SUBRESOURCE_TYPE type, uint32_t firstSlice, uint32_t sliceCount, uint32_t firstMip, uint32_t mipCount) const
{
auto internal_state = to_internal(texture);
@@ -4974,7 +4981,7 @@ using namespace DX12_Internal;
}
return -1;
}
int GraphicsDevice_DX12::CreateSubresource(GPUBuffer* buffer, SUBRESOURCE_TYPE type, uint64_t offset, uint64_t size)
int GraphicsDevice_DX12::CreateSubresource(GPUBuffer* buffer, SUBRESOURCE_TYPE type, uint64_t offset, uint64_t size) const
{
auto internal_state = to_internal(buffer);
const GPUBufferDesc& desc = buffer->GetDesc();
@@ -5089,7 +5096,7 @@ using namespace DX12_Internal;
return -1;
}
int GraphicsDevice_DX12::GetDescriptorIndex(const GPUResource* resource, SUBRESOURCE_TYPE type, int subresource)
int GraphicsDevice_DX12::GetDescriptorIndex(const GPUResource* resource, SUBRESOURCE_TYPE type, int subresource) const
{
if (resource == nullptr || !resource->IsValid())
return -1;
@@ -5126,7 +5133,7 @@ using namespace DX12_Internal;
return -1;
}
int GraphicsDevice_DX12::GetDescriptorIndex(const Sampler* sampler)
int GraphicsDevice_DX12::GetDescriptorIndex(const Sampler* sampler) const
{
if (sampler == nullptr || !sampler->IsValid())
return -1;
@@ -5135,7 +5142,7 @@ using namespace DX12_Internal;
return internal_state->descriptor.index;
}
void GraphicsDevice_DX12::WriteShadingRateValue(SHADING_RATE rate, void* dest)
void GraphicsDevice_DX12::WriteShadingRateValue(SHADING_RATE rate, void* dest) const
{
D3D12_SHADING_RATE _rate = _ConvertShadingRate(rate);
if (!features_6.AdditionalShadingRatesSupported)
@@ -5144,7 +5151,7 @@ using namespace DX12_Internal;
}
*(uint8_t*)dest = _rate;
}
void GraphicsDevice_DX12::WriteTopLevelAccelerationStructureInstance(const RaytracingAccelerationStructureDesc::TopLevel::Instance* instance, void* dest)
void GraphicsDevice_DX12::WriteTopLevelAccelerationStructureInstance(const RaytracingAccelerationStructureDesc::TopLevel::Instance* instance, void* dest) const
{
D3D12_RAYTRACING_INSTANCE_DESC* desc = (D3D12_RAYTRACING_INSTANCE_DESC*)dest;
desc->AccelerationStructure = to_internal(&instance->bottomlevel)->gpu_address;
@@ -5154,7 +5161,7 @@ using namespace DX12_Internal;
desc->InstanceContributionToHitGroupIndex = instance->InstanceContributionToHitGroupIndex;
desc->Flags = instance->Flags;
}
void GraphicsDevice_DX12::WriteShaderIdentifier(const RaytracingPipelineState* rtpso, uint32_t group_index, void* dest)
void GraphicsDevice_DX12::WriteShaderIdentifier(const RaytracingPipelineState* rtpso, uint32_t group_index, void* dest) const
{
auto internal_state = to_internal(rtpso);
@@ -5166,7 +5173,7 @@ using namespace DX12_Internal;
memcpy(dest, identifier, D3D12_SHADER_IDENTIFIER_SIZE_IN_BYTES);
}
void GraphicsDevice_DX12::Map(const GPUResource* resource, Mapping* mapping)
void GraphicsDevice_DX12::Map(const GPUResource* resource, Mapping* mapping) const
{
auto internal_state = to_internal(resource);
D3D12_RANGE read_range = {};
@@ -5187,12 +5194,12 @@ using namespace DX12_Internal;
mapping->rowpitch = 0;
}
}
void GraphicsDevice_DX12::Unmap(const GPUResource* resource)
void GraphicsDevice_DX12::Unmap(const GPUResource* resource) const
{
auto internal_state = to_internal(resource);
internal_state->resource->Unmap(0, nullptr);
}
void GraphicsDevice_DX12::QueryRead(const GPUQueryHeap* heap, uint32_t index, uint32_t count, uint64_t* results)
void GraphicsDevice_DX12::QueryRead(const GPUQueryHeap* heap, uint32_t index, uint32_t count, uint64_t* results) const
{
if (count == 0)
return;
@@ -5240,7 +5247,9 @@ using namespace DX12_Internal;
barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_RENDER_TARGET;
barrier.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
GetDirectCommandList(cmd)->ResourceBarrier(1, &barrier);
frame_barriers[cmd].push_back(barrier);
barrier_flush(cmd);
const float clearcolor[] = { 0,0,0,1 };
+22 -22
View File
@@ -184,7 +184,7 @@ namespace wiGraphics
locker.unlock();
}
};
CopyAllocator copyAllocator;
mutable CopyAllocator copyAllocator;
Microsoft::WRL::ComPtr<ID3D12Fence> directFence;
HANDLE directFenceEvent;
@@ -254,8 +254,8 @@ namespace wiGraphics
PRIMITIVETOPOLOGY prev_pt[COMMANDLIST_COUNT] = {};
std::unordered_map<size_t, Microsoft::WRL::ComPtr<ID3D12RootSignature>> rootsignature_cache;
std::mutex rootsignature_cache_mutex;
mutable std::unordered_map<size_t, Microsoft::WRL::ComPtr<ID3D12RootSignature>> rootsignature_cache;
mutable std::mutex rootsignature_cache_mutex;
std::unordered_map<size_t, Microsoft::WRL::ComPtr<ID3D12PipelineState>> pipelines_global;
std::vector<std::pair<size_t, Microsoft::WRL::ComPtr<ID3D12PipelineState>>> pipelines_worker[COMMANDLIST_COUNT];
@@ -298,29 +298,29 @@ namespace wiGraphics
GraphicsDevice_DX12(wiPlatform::window_type window, bool fullscreen = false, bool debuglayer = false);
virtual ~GraphicsDevice_DX12();
bool CreateBuffer(const GPUBufferDesc *pDesc, const SubresourceData* pInitialData, GPUBuffer *pBuffer) override;
bool CreateTexture(const TextureDesc* pDesc, const SubresourceData *pInitialData, Texture *pTexture) override;
bool CreateShader(SHADERSTAGE stage, const void *pShaderBytecode, size_t BytecodeLength, Shader *pShader) override;
bool CreateSampler(const SamplerDesc *pSamplerDesc, Sampler *pSamplerState) override;
bool CreateQueryHeap(const GPUQueryHeapDesc* pDesc, GPUQueryHeap* pQueryHeap) override;
bool CreatePipelineState(const PipelineStateDesc* pDesc, PipelineState* pso) override;
bool CreateRenderPass(const RenderPassDesc* pDesc, RenderPass* renderpass) override;
bool CreateRaytracingAccelerationStructure(const RaytracingAccelerationStructureDesc* pDesc, RaytracingAccelerationStructure* bvh) override;
bool CreateRaytracingPipelineState(const RaytracingPipelineStateDesc* pDesc, RaytracingPipelineState* rtpso) override;
bool CreateBuffer(const GPUBufferDesc *pDesc, const SubresourceData* pInitialData, GPUBuffer *pBuffer) const override;
bool CreateTexture(const TextureDesc* pDesc, const SubresourceData *pInitialData, Texture *pTexture) const override;
bool CreateShader(SHADERSTAGE stage, const void *pShaderBytecode, size_t BytecodeLength, Shader *pShader) const override;
bool CreateSampler(const SamplerDesc *pSamplerDesc, Sampler *pSamplerState) const override;
bool CreateQueryHeap(const GPUQueryHeapDesc* pDesc, GPUQueryHeap* pQueryHeap) const override;
bool CreatePipelineState(const PipelineStateDesc* pDesc, PipelineState* pso) const override;
bool CreateRenderPass(const RenderPassDesc* pDesc, RenderPass* renderpass) const override;
bool CreateRaytracingAccelerationStructure(const RaytracingAccelerationStructureDesc* pDesc, RaytracingAccelerationStructure* bvh) const override;
bool CreateRaytracingPipelineState(const RaytracingPipelineStateDesc* pDesc, RaytracingPipelineState* rtpso) const override;
int CreateSubresource(Texture* texture, SUBRESOURCE_TYPE type, uint32_t firstSlice, uint32_t sliceCount, uint32_t firstMip, uint32_t mipCount) override;
int CreateSubresource(GPUBuffer* buffer, SUBRESOURCE_TYPE type, uint64_t offset, uint64_t size = ~0) override;
int CreateSubresource(Texture* texture, SUBRESOURCE_TYPE type, uint32_t firstSlice, uint32_t sliceCount, uint32_t firstMip, uint32_t mipCount) const override;
int CreateSubresource(GPUBuffer* buffer, SUBRESOURCE_TYPE type, uint64_t offset, uint64_t size = ~0) const override;
int GetDescriptorIndex(const GPUResource* resource, SUBRESOURCE_TYPE type, int subresource = -1) override;
int GetDescriptorIndex(const Sampler* sampler) override;
int GetDescriptorIndex(const GPUResource* resource, SUBRESOURCE_TYPE type, int subresource = -1) const override;
int GetDescriptorIndex(const Sampler* sampler) const override;
void WriteShadingRateValue(SHADING_RATE rate, void* dest) override;
void WriteTopLevelAccelerationStructureInstance(const RaytracingAccelerationStructureDesc::TopLevel::Instance* instance, void* dest) override;
void WriteShaderIdentifier(const RaytracingPipelineState* rtpso, uint32_t group_index, void* dest) override;
void WriteShadingRateValue(SHADING_RATE rate, void* dest) const override;
void WriteTopLevelAccelerationStructureInstance(const RaytracingAccelerationStructureDesc::TopLevel::Instance* instance, void* dest) const override;
void WriteShaderIdentifier(const RaytracingPipelineState* rtpso, uint32_t group_index, void* dest) const override;
void Map(const GPUResource* resource, Mapping* mapping) override;
void Unmap(const GPUResource* resource) override;
void QueryRead(const GPUQueryHeap* heap, uint32_t index, uint32_t count, uint64_t* results) override;
void Map(const GPUResource* resource, Mapping* mapping) const override;
void Unmap(const GPUResource* resource) const override;
void QueryRead(const GPUQueryHeap* heap, uint32_t index, uint32_t count, uint64_t* results) const override;
void SetCommonSampler(const StaticSampler* sam) override;
+126 -108
View File
@@ -844,9 +844,6 @@ namespace Vulkan_Internal
VkGraphicsPipelineCreateInfo pipelineInfo = {};
VkPipelineShaderStageCreateInfo shaderStages[SHADERSTAGE_COUNT] = {};
VkPipelineVertexInputStateCreateInfo vertexInputInfo = {};
std::vector<VkVertexInputBindingDescription> bindings;
std::vector<VkVertexInputAttributeDescription> attributes;
VkPipelineInputAssemblyStateCreateInfo inputAssembly = {};
VkPipelineRasterizationStateCreateInfo rasterizer = {};
VkPipelineRasterizationDepthClipStateCreateInfoEXT depthclip = {};
@@ -1551,6 +1548,7 @@ using namespace Vulkan_Internal;
const PipelineState* pso = active_pso[cmd];
size_t pipeline_hash = prev_pipeline_hash[cmd];
wiHelper::hash_combine(pipeline_hash, vb_hash[cmd]);
auto internal_state = to_internal(pso);
VkPipeline pipeline = VK_NULL_HANDLE;
@@ -1655,6 +1653,69 @@ using namespace Vulkan_Internal;
pipelineInfo.pColorBlendState = &colorBlending;
// Input layout:
VkPipelineVertexInputStateCreateInfo vertexInputInfo = {};
vertexInputInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
std::vector<VkVertexInputBindingDescription> bindings;
std::vector<VkVertexInputAttributeDescription> attributes;
if (pso->desc.il != nullptr)
{
uint32_t lastBinding = 0xFFFFFFFF;
uint32_t i = 0;
for (auto& x : pso->desc.il->elements)
{
VkVertexInputBindingDescription bind = {};
bind.binding = x.InputSlot;
bind.inputRate = x.InputSlotClass == INPUT_PER_VERTEX_DATA ? VK_VERTEX_INPUT_RATE_VERTEX : VK_VERTEX_INPUT_RATE_INSTANCE;
bind.stride = vb_strides[cmd][i];
if (lastBinding != bind.binding)
{
bindings.push_back(bind);
lastBinding = bind.binding;
}
else
{
bindings.back().stride += bind.stride;
}
i++;
}
uint32_t offset = 0;
i = 0;
lastBinding = 0xFFFFFFFF;
for (auto& x : pso->desc.il->elements)
{
VkVertexInputAttributeDescription attr = {};
attr.binding = x.InputSlot;
if (attr.binding != lastBinding)
{
lastBinding = attr.binding;
offset = 0;
}
attr.format = _ConvertFormat(x.Format);
attr.location = i;
attr.offset = x.AlignedByteOffset;
if (attr.offset == InputLayout::APPEND_ALIGNED_ELEMENT)
{
// need to manually resolve this from the format spec.
attr.offset = offset;
offset += GetFormatStride(x.Format);
}
attributes.push_back(attr);
i++;
}
vertexInputInfo.vertexBindingDescriptionCount = static_cast<uint32_t>(bindings.size());
vertexInputInfo.pVertexBindingDescriptions = bindings.data();
vertexInputInfo.vertexAttributeDescriptionCount = static_cast<uint32_t>(attributes.size());
vertexInputInfo.pVertexAttributeDescriptions = attributes.data();
}
pipelineInfo.pVertexInputState = &vertexInputInfo;
VkResult res = vkCreateGraphicsPipelines(device, VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, &pipeline);
assert(res == VK_SUCCESS);
@@ -1713,28 +1774,34 @@ using namespace Vulkan_Internal;
}
}
VkPipelineStageFlags srcStage = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
VkPipelineStageFlags dstStage = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
if (CheckCapability(GRAPHICSDEVICE_CAPABILITY_RAYTRACING))
if (!memoryBarriers.empty() ||
!bufferBarriers.empty() ||
!imageBarriers.empty()
)
{
srcStage |= VK_PIPELINE_STAGE_ACCELERATION_STRUCTURE_BUILD_BIT_KHR | VK_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR;
dstStage |= VK_PIPELINE_STAGE_ACCELERATION_STRUCTURE_BUILD_BIT_KHR | VK_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR;
VkPipelineStageFlags srcStage = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
VkPipelineStageFlags dstStage = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
if (CheckCapability(GRAPHICSDEVICE_CAPABILITY_RAYTRACING))
{
srcStage |= VK_PIPELINE_STAGE_ACCELERATION_STRUCTURE_BUILD_BIT_KHR | VK_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR;
dstStage |= VK_PIPELINE_STAGE_ACCELERATION_STRUCTURE_BUILD_BIT_KHR | VK_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR;
}
vkCmdPipelineBarrier(
GetDirectCommandList(cmd),
srcStage,
dstStage,
0,
(uint32_t)memoryBarriers.size(), memoryBarriers.data(),
(uint32_t)bufferBarriers.size(), bufferBarriers.data(),
(uint32_t)imageBarriers.size(), imageBarriers.data()
);
memoryBarriers.clear();
imageBarriers.clear();
bufferBarriers.clear();
}
vkCmdPipelineBarrier(
GetDirectCommandList(cmd),
srcStage,
dstStage,
0,
(uint32_t)memoryBarriers.size(), memoryBarriers.data(),
(uint32_t)bufferBarriers.size(), bufferBarriers.data(),
(uint32_t)imageBarriers.size(), imageBarriers.data()
);
memoryBarriers.clear();
imageBarriers.clear();
bufferBarriers.clear();
}
}
void GraphicsDevice_Vulkan::predraw(CommandList cmd)
@@ -2843,7 +2910,7 @@ using namespace Vulkan_Internal;
return result;
}
bool GraphicsDevice_Vulkan::CreateBuffer(const GPUBufferDesc *pDesc, const SubresourceData* pInitialData, GPUBuffer *pBuffer)
bool GraphicsDevice_Vulkan::CreateBuffer(const GPUBufferDesc *pDesc, const SubresourceData* pInitialData, GPUBuffer *pBuffer) const
{
auto internal_state = std::make_shared<Buffer_Vulkan>();
internal_state->allocationhandler = allocationhandler;
@@ -3092,7 +3159,7 @@ using namespace Vulkan_Internal;
return res == VK_SUCCESS;
}
bool GraphicsDevice_Vulkan::CreateTexture(const TextureDesc* pDesc, const SubresourceData *pInitialData, Texture *pTexture)
bool GraphicsDevice_Vulkan::CreateTexture(const TextureDesc* pDesc, const SubresourceData *pInitialData, Texture *pTexture) const
{
auto internal_state = std::make_shared<Texture_Vulkan>();
internal_state->allocationhandler = allocationhandler;
@@ -3382,7 +3449,7 @@ using namespace Vulkan_Internal;
return res == VK_SUCCESS;
}
bool GraphicsDevice_Vulkan::CreateShader(SHADERSTAGE stage, const void *pShaderBytecode, size_t BytecodeLength, Shader *pShader)
bool GraphicsDevice_Vulkan::CreateShader(SHADERSTAGE stage, const void *pShaderBytecode, size_t BytecodeLength, Shader *pShader) const
{
auto internal_state = std::make_shared<Shader_Vulkan>();
internal_state->allocationhandler = allocationhandler;
@@ -3695,7 +3762,7 @@ using namespace Vulkan_Internal;
return res == VK_SUCCESS;
}
bool GraphicsDevice_Vulkan::CreateSampler(const SamplerDesc *pSamplerDesc, Sampler *pSamplerState)
bool GraphicsDevice_Vulkan::CreateSampler(const SamplerDesc *pSamplerDesc, Sampler *pSamplerState) const
{
auto internal_state = std::make_shared<Sampler_Vulkan>();
internal_state->allocationhandler = allocationhandler;
@@ -3900,7 +3967,7 @@ using namespace Vulkan_Internal;
return res == VK_SUCCESS;
}
bool GraphicsDevice_Vulkan::CreateQueryHeap(const GPUQueryHeapDesc* pDesc, GPUQueryHeap* pQueryHeap)
bool GraphicsDevice_Vulkan::CreateQueryHeap(const GPUQueryHeapDesc* pDesc, GPUQueryHeap* pQueryHeap) const
{
auto internal_state = std::make_shared<QueryHeap_Vulkan>();
internal_state->allocationhandler = allocationhandler;
@@ -3929,7 +3996,7 @@ using namespace Vulkan_Internal;
return res == VK_SUCCESS;
}
bool GraphicsDevice_Vulkan::CreatePipelineState(const PipelineStateDesc* pDesc, PipelineState* pso)
bool GraphicsDevice_Vulkan::CreatePipelineState(const PipelineStateDesc* pDesc, PipelineState* pso) const
{
auto internal_state = std::make_shared<PipelineState_Vulkan>();
internal_state->allocationhandler = allocationhandler;
@@ -4186,71 +4253,6 @@ using namespace Vulkan_Internal;
// Fixed function states:
// Input layout:
VkPipelineVertexInputStateCreateInfo& vertexInputInfo = internal_state->vertexInputInfo;
vertexInputInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
auto& bindings = internal_state->bindings;
auto& attributes = internal_state->attributes;
if (pso->desc.il != nullptr)
{
uint32_t lastBinding = 0xFFFFFFFF;
for (auto& x : pso->desc.il->elements)
{
VkVertexInputBindingDescription bind = {};
bind.binding = x.InputSlot;
bind.inputRate = x.InputSlotClass == INPUT_PER_VERTEX_DATA ? VK_VERTEX_INPUT_RATE_VERTEX : VK_VERTEX_INPUT_RATE_INSTANCE;
bind.stride = x.AlignedByteOffset;
if (bind.stride == InputLayout::APPEND_ALIGNED_ELEMENT)
{
// need to manually resolve this from the format spec.
bind.stride = GetFormatStride(x.Format);
}
if (lastBinding != bind.binding)
{
bindings.push_back(bind);
lastBinding = bind.binding;
}
else
{
bindings.back().stride += bind.stride;
}
}
uint32_t offset = 0;
uint32_t i = 0;
lastBinding = 0xFFFFFFFF;
for (auto& x : pso->desc.il->elements)
{
VkVertexInputAttributeDescription attr = {};
attr.binding = x.InputSlot;
if (attr.binding != lastBinding)
{
lastBinding = attr.binding;
offset = 0;
}
attr.format = _ConvertFormat(x.Format);
attr.location = i;
attr.offset = x.AlignedByteOffset;
if (attr.offset == InputLayout::APPEND_ALIGNED_ELEMENT)
{
// need to manually resolve this from the format spec.
attr.offset = offset;
offset += GetFormatStride(x.Format);
}
attributes.push_back(attr);
i++;
}
vertexInputInfo.vertexBindingDescriptionCount = static_cast<uint32_t>(bindings.size());
vertexInputInfo.pVertexBindingDescriptions = bindings.data();
vertexInputInfo.vertexAttributeDescriptionCount = static_cast<uint32_t>(attributes.size());
vertexInputInfo.pVertexAttributeDescriptions = attributes.data();
}
pipelineInfo.pVertexInputState = &vertexInputInfo;
// Primitive type:
VkPipelineInputAssemblyStateCreateInfo& inputAssembly = internal_state->inputAssembly;
inputAssembly.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
@@ -4412,7 +4414,7 @@ using namespace Vulkan_Internal;
return res == VK_TRUE;
}
bool GraphicsDevice_Vulkan::CreateRenderPass(const RenderPassDesc* pDesc, RenderPass* renderpass)
bool GraphicsDevice_Vulkan::CreateRenderPass(const RenderPassDesc* pDesc, RenderPass* renderpass) const
{
auto internal_state = std::make_shared<RenderPass_Vulkan>();
internal_state->allocationhandler = allocationhandler;
@@ -4726,7 +4728,7 @@ using namespace Vulkan_Internal;
return res == VK_SUCCESS;
}
bool GraphicsDevice_Vulkan::CreateRaytracingAccelerationStructure(const RaytracingAccelerationStructureDesc* pDesc, RaytracingAccelerationStructure* bvh)
bool GraphicsDevice_Vulkan::CreateRaytracingAccelerationStructure(const RaytracingAccelerationStructureDesc* pDesc, RaytracingAccelerationStructure* bvh) const
{
auto internal_state = std::make_shared<BVH_Vulkan>();
internal_state->allocationhandler = allocationhandler;
@@ -4918,7 +4920,7 @@ using namespace Vulkan_Internal;
return res == VK_SUCCESS;
}
bool GraphicsDevice_Vulkan::CreateRaytracingPipelineState(const RaytracingPipelineStateDesc* pDesc, RaytracingPipelineState* rtpso)
bool GraphicsDevice_Vulkan::CreateRaytracingPipelineState(const RaytracingPipelineStateDesc* pDesc, RaytracingPipelineState* rtpso) const
{
auto internal_state = std::make_shared<RTPipelineState_Vulkan>();
internal_state->allocationhandler = allocationhandler;
@@ -5018,7 +5020,7 @@ using namespace Vulkan_Internal;
return res == VK_SUCCESS;
}
int GraphicsDevice_Vulkan::CreateSubresource(Texture* texture, SUBRESOURCE_TYPE type, uint32_t firstSlice, uint32_t sliceCount, uint32_t firstMip, uint32_t mipCount)
int GraphicsDevice_Vulkan::CreateSubresource(Texture* texture, SUBRESOURCE_TYPE type, uint32_t firstSlice, uint32_t sliceCount, uint32_t firstMip, uint32_t mipCount) const
{
auto internal_state = to_internal(texture);
@@ -5254,7 +5256,7 @@ using namespace Vulkan_Internal;
}
return -1;
}
int GraphicsDevice_Vulkan::CreateSubresource(GPUBuffer* buffer, SUBRESOURCE_TYPE type, uint64_t offset, uint64_t size)
int GraphicsDevice_Vulkan::CreateSubresource(GPUBuffer* buffer, SUBRESOURCE_TYPE type, uint64_t offset, uint64_t size) const
{
auto internal_state = to_internal(buffer);
const GPUBufferDesc& desc = buffer->GetDesc();
@@ -5415,7 +5417,7 @@ using namespace Vulkan_Internal;
return -1;
}
int GraphicsDevice_Vulkan::GetDescriptorIndex(const GPUResource* resource, SUBRESOURCE_TYPE type, int subresource)
int GraphicsDevice_Vulkan::GetDescriptorIndex(const GPUResource* resource, SUBRESOURCE_TYPE type, int subresource) const
{
if (resource == nullptr || !resource->IsValid())
return -1;
@@ -5491,7 +5493,7 @@ using namespace Vulkan_Internal;
return -1;
}
int GraphicsDevice_Vulkan::GetDescriptorIndex(const Sampler* sampler)
int GraphicsDevice_Vulkan::GetDescriptorIndex(const Sampler* sampler) const
{
if (sampler == nullptr || !sampler->IsValid())
return -1;
@@ -5500,7 +5502,7 @@ using namespace Vulkan_Internal;
return internal_state->index;
}
void GraphicsDevice_Vulkan::WriteShadingRateValue(SHADING_RATE rate, void* dest)
void GraphicsDevice_Vulkan::WriteShadingRateValue(SHADING_RATE rate, void* dest) const
{
// How to compute shading rate value texel data:
// https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#primsrast-fragment-shading-rate-attachment
@@ -5532,7 +5534,7 @@ using namespace Vulkan_Internal;
}
}
void GraphicsDevice_Vulkan::WriteTopLevelAccelerationStructureInstance(const RaytracingAccelerationStructureDesc::TopLevel::Instance* instance, void* dest)
void GraphicsDevice_Vulkan::WriteTopLevelAccelerationStructureInstance(const RaytracingAccelerationStructureDesc::TopLevel::Instance* instance, void* dest) const
{
VkAccelerationStructureInstanceKHR* desc = (VkAccelerationStructureInstanceKHR*)dest;
memcpy(&desc->transform, &instance->transform, sizeof(desc->transform));
@@ -5545,13 +5547,13 @@ using namespace Vulkan_Internal;
auto internal_state = to_internal((RaytracingAccelerationStructure*)&instance->bottomlevel);
desc->accelerationStructureReference = internal_state->as_address;
}
void GraphicsDevice_Vulkan::WriteShaderIdentifier(const RaytracingPipelineState* rtpso, uint32_t group_index, void* dest)
void GraphicsDevice_Vulkan::WriteShaderIdentifier(const RaytracingPipelineState* rtpso, uint32_t group_index, void* dest) const
{
VkResult res = vkGetRayTracingShaderGroupHandlesKHR(device, to_internal(rtpso)->pipeline, group_index, 1, SHADER_IDENTIFIER_SIZE, dest);
assert(res == VK_SUCCESS);
}
void GraphicsDevice_Vulkan::Map(const GPUResource* resource, Mapping* mapping)
void GraphicsDevice_Vulkan::Map(const GPUResource* resource, Mapping* mapping) const
{
VkDeviceMemory memory = VK_NULL_HANDLE;
@@ -5586,7 +5588,7 @@ using namespace Vulkan_Internal;
mapping->rowpitch = 0;
}
}
void GraphicsDevice_Vulkan::Unmap(const GPUResource* resource)
void GraphicsDevice_Vulkan::Unmap(const GPUResource* resource) const
{
if (resource->type == GPUResource::GPU_RESOURCE_TYPE::BUFFER)
{
@@ -5601,7 +5603,7 @@ using namespace Vulkan_Internal;
vkUnmapMemory(device, internal_state->allocation->GetMemory());
}
}
void GraphicsDevice_Vulkan::QueryRead(const GPUQueryHeap* heap, uint32_t index, uint32_t count, uint64_t* results)
void GraphicsDevice_Vulkan::QueryRead(const GPUQueryHeap* heap, uint32_t index, uint32_t count, uint64_t* results) const
{
if (count == 0)
return;
@@ -5618,7 +5620,6 @@ using namespace Vulkan_Internal;
sizeof(uint64_t),
VK_QUERY_RESULT_64_BIT
);
assert(res == VK_SUCCESS);
vkResetQueryPool(
device,
@@ -5685,6 +5686,7 @@ using namespace Vulkan_Internal;
return;
}
}
barrier_flush(cmd);
VkClearValue clearColor = { 0.0f, 0.0f, 0.0f, 1.0f };
VkRenderPassBeginInfo renderPassInfo = {};
@@ -5811,6 +5813,11 @@ using namespace Vulkan_Internal;
dirty_pso[cmd] = false;
prev_shadingrate[cmd] = SHADING_RATE_INVALID;
pushconstants[cmd] = {};
vb_hash[cmd] = 0;
for (int i = 0; i < arraysize(vb_strides[cmd]); ++i)
{
vb_strides[cmd][i] = 0;
}
return cmd;
}
@@ -6112,11 +6119,16 @@ using namespace Vulkan_Internal;
}
void GraphicsDevice_Vulkan::BindVertexBuffers(const GPUBuffer *const* vertexBuffers, uint32_t slot, uint32_t count, const uint32_t* strides, const uint32_t* offsets, CommandList cmd)
{
size_t hash = 0;
VkDeviceSize voffsets[8] = {};
VkBuffer vbuffers[8] = {};
assert(count <= 8);
for (uint32_t i = 0; i < count; ++i)
{
wiHelper::hash_combine(hash, strides[i]);
vb_strides[cmd][i] = strides[i];
if (vertexBuffers[i] == nullptr || !vertexBuffers[i]->IsValid())
{
vbuffers[i] = nullBuffer;
@@ -6133,6 +6145,12 @@ using namespace Vulkan_Internal;
}
vkCmdBindVertexBuffers(GetDirectCommandList(cmd), static_cast<uint32_t>(slot), static_cast<uint32_t>(count), vbuffers, voffsets);
if (hash != vb_hash[cmd])
{
vb_hash[cmd] = hash;
dirty_pso[cmd] = true;
}
}
void GraphicsDevice_Vulkan::BindIndexBuffer(const GPUBuffer* indexBuffer, const INDEXBUFFER_FORMAT format, uint32_t offset, CommandList cmd)
{
+28 -24
View File
@@ -47,8 +47,8 @@ namespace wiGraphics
VkQueue computeQueue = VK_NULL_HANDLE;
VkQueue copyQueue = VK_NULL_HANDLE;
std::mutex copyQueueLock;
bool copyQueueUse = false;
mutable std::mutex copyQueueLock;
mutable bool copyQueueUse = false;
VkSemaphore copySemaphore = VK_NULL_HANDLE;
VkPhysicalDeviceProperties2 properties2 = {};
@@ -116,7 +116,7 @@ namespace wiGraphics
VkCommandPool transitionCommandPool = VK_NULL_HANDLE;
VkCommandBuffer transitionCommandBuffer = VK_NULL_HANDLE;
std::vector<VkImageMemoryBarrier> loadedimagetransitions;
mutable std::vector<VkImageMemoryBarrier> loadedimagetransitions;
VkSemaphore swapchainAcquireSemaphore = VK_NULL_HANDLE;
VkSemaphore swapchainReleaseSemaphore = VK_NULL_HANDLE;
@@ -167,6 +167,7 @@ namespace wiGraphics
ResourceFrameAllocator resourceBuffer[COMMANDLIST_COUNT];
};
FrameResources frames[BACKBUFFER_COUNT];
const FrameResources& GetFrameResources() const { return frames[GetFrameCount() % BACKBUFFER_COUNT]; }
FrameResources& GetFrameResources() { return frames[GetFrameCount() % BACKBUFFER_COUNT]; }
inline VkCommandBuffer GetDirectCommandList(CommandList cmd) { return GetFrameResources().commandBuffers[cmd]; }
@@ -181,8 +182,8 @@ namespace wiGraphics
std::vector<VkDescriptorSet> bindlessSets;
uint32_t bindlessFirstSet = 0;
};
std::unordered_map<size_t, PSOLayout> pso_layout_cache;
std::mutex pso_layout_cache_mutex;
mutable std::unordered_map<size_t, PSOLayout> pso_layout_cache;
mutable std::mutex pso_layout_cache_mutex;
std::unordered_map<size_t, VkPipeline> pipelines_global;
std::vector<std::pair<size_t, VkPipeline>> pipelines_worker[COMMANDLIST_COUNT];
@@ -193,6 +194,9 @@ namespace wiGraphics
const RenderPass* active_renderpass[COMMANDLIST_COUNT] = {};
SHADING_RATE prev_shadingrate[COMMANDLIST_COUNT] = {};
uint32_t vb_strides[COMMANDLIST_COUNT][8] = {};
size_t vb_hash[COMMANDLIST_COUNT] = {};
struct DeferredPushConstantData
{
uint8_t data[128];
@@ -216,29 +220,29 @@ namespace wiGraphics
GraphicsDevice_Vulkan(wiPlatform::window_type window, bool fullscreen = false, bool debuglayer = false);
virtual ~GraphicsDevice_Vulkan();
bool CreateBuffer(const GPUBufferDesc *pDesc, const SubresourceData* pInitialData, GPUBuffer *pBuffer) override;
bool CreateTexture(const TextureDesc* pDesc, const SubresourceData *pInitialData, Texture *pTexture) override;
bool CreateShader(SHADERSTAGE stage, const void *pShaderBytecode, size_t BytecodeLength, Shader *pShader) override;
bool CreateSampler(const SamplerDesc *pSamplerDesc, Sampler *pSamplerState) override;
bool CreateQueryHeap(const GPUQueryHeapDesc* pDesc, GPUQueryHeap* pQueryHeap) override;
bool CreatePipelineState(const PipelineStateDesc* pDesc, PipelineState* pso) override;
bool CreateRenderPass(const RenderPassDesc* pDesc, RenderPass* renderpass) override;
bool CreateRaytracingAccelerationStructure(const RaytracingAccelerationStructureDesc* pDesc, RaytracingAccelerationStructure* bvh) override;
bool CreateRaytracingPipelineState(const RaytracingPipelineStateDesc* pDesc, RaytracingPipelineState* rtpso) override;
bool CreateBuffer(const GPUBufferDesc *pDesc, const SubresourceData* pInitialData, GPUBuffer *pBuffer) const override;
bool CreateTexture(const TextureDesc* pDesc, const SubresourceData *pInitialData, Texture *pTexture) const override;
bool CreateShader(SHADERSTAGE stage, const void *pShaderBytecode, size_t BytecodeLength, Shader *pShader) const override;
bool CreateSampler(const SamplerDesc *pSamplerDesc, Sampler *pSamplerState) const override;
bool CreateQueryHeap(const GPUQueryHeapDesc* pDesc, GPUQueryHeap* pQueryHeap) const override;
bool CreatePipelineState(const PipelineStateDesc* pDesc, PipelineState* pso) const override;
bool CreateRenderPass(const RenderPassDesc* pDesc, RenderPass* renderpass) const override;
bool CreateRaytracingAccelerationStructure(const RaytracingAccelerationStructureDesc* pDesc, RaytracingAccelerationStructure* bvh) const override;
bool CreateRaytracingPipelineState(const RaytracingPipelineStateDesc* pDesc, RaytracingPipelineState* rtpso) const override;
int CreateSubresource(Texture* texture, SUBRESOURCE_TYPE type, uint32_t firstSlice, uint32_t sliceCount, uint32_t firstMip, uint32_t mipCount) override;
int CreateSubresource(GPUBuffer* buffer, SUBRESOURCE_TYPE type, uint64_t offset, uint64_t size = ~0) override;
int CreateSubresource(Texture* texture, SUBRESOURCE_TYPE type, uint32_t firstSlice, uint32_t sliceCount, uint32_t firstMip, uint32_t mipCount) const override;
int CreateSubresource(GPUBuffer* buffer, SUBRESOURCE_TYPE type, uint64_t offset, uint64_t size = ~0) const override;
int GetDescriptorIndex(const GPUResource* resource, SUBRESOURCE_TYPE type, int subresource = -1) override;
int GetDescriptorIndex(const Sampler* sampler) override;
int GetDescriptorIndex(const GPUResource* resource, SUBRESOURCE_TYPE type, int subresource = -1) const override;
int GetDescriptorIndex(const Sampler* sampler) const override;
void WriteShadingRateValue(SHADING_RATE rate, void* dest) override;
void WriteTopLevelAccelerationStructureInstance(const RaytracingAccelerationStructureDesc::TopLevel::Instance* instance, void* dest) override;
void WriteShaderIdentifier(const RaytracingPipelineState* rtpso, uint32_t group_index, void* dest) override;
void WriteShadingRateValue(SHADING_RATE rate, void* dest) const override;
void WriteTopLevelAccelerationStructureInstance(const RaytracingAccelerationStructureDesc::TopLevel::Instance* instance, void* dest) const override;
void WriteShaderIdentifier(const RaytracingPipelineState* rtpso, uint32_t group_index, void* dest) const override;
void Map(const GPUResource* resource, Mapping* mapping) override;
void Unmap(const GPUResource* resource) override;
void QueryRead(const GPUQueryHeap* heap, uint32_t index, uint32_t count, uint64_t* results) override;
void Map(const GPUResource* resource, Mapping* mapping) const override;
void Unmap(const GPUResource* resource) const override;
void QueryRead(const GPUQueryHeap* heap, uint32_t index, uint32_t count, uint64_t* results) const override;
void SetCommonSampler(const StaticSampler* sam) override;
+54 -54
View File
@@ -904,7 +904,7 @@ void LoadShaders()
wiJobSystem::Execute(ctx, [](wiJobArgs args) {
inputLayouts[ILTYPE_OBJECT_DEBUG].elements =
{
{ "POSITION_NORMAL_WIND", 0, MeshComponent::Vertex_POS::FORMAT, INPUT_SLOT_POSITION_NORMAL_WIND, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 },
{ "POSITION_NORMAL_WIND", 0, MeshComponent::Vertex_POS::FORMAT, INPUT_SLOT_POSITION_NORMAL_WIND, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA },
};
LoadShader(VS, shaders[VSTYPE_OBJECT_DEBUG], "objectVS_debug.cso");
});
@@ -912,18 +912,18 @@ void LoadShaders()
wiJobSystem::Execute(ctx, [](wiJobArgs args) {
inputLayouts[ILTYPE_OBJECT_COMMON].elements =
{
{ "POSITION_NORMAL_WIND", 0, MeshComponent::Vertex_POS::FORMAT, INPUT_SLOT_POSITION_NORMAL_WIND, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 },
{ "UVSET", 0, MeshComponent::Vertex_TEX::FORMAT, INPUT_SLOT_UV0, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 },
{ "UVSET", 1, MeshComponent::Vertex_TEX::FORMAT, INPUT_SLOT_UV1, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 },
{ "ATLAS", 0, MeshComponent::Vertex_TEX::FORMAT, INPUT_SLOT_ATLAS, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 },
{ "COLOR", 0, MeshComponent::Vertex_COL::FORMAT, INPUT_SLOT_COLOR, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 },
{ "TANGENT", 0, MeshComponent::Vertex_TAN::FORMAT, INPUT_SLOT_TANGENT, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 },
{ "POSITION_NORMAL_WIND", 0, MeshComponent::Vertex_POS::FORMAT, INPUT_SLOT_POSITION_NORMAL_WIND, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA },
{ "UVSET", 0, MeshComponent::Vertex_TEX::FORMAT, INPUT_SLOT_UV0, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA },
{ "UVSET", 1, MeshComponent::Vertex_TEX::FORMAT, INPUT_SLOT_UV1, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA },
{ "ATLAS", 0, MeshComponent::Vertex_TEX::FORMAT, INPUT_SLOT_ATLAS, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA },
{ "COLOR", 0, MeshComponent::Vertex_COL::FORMAT, INPUT_SLOT_COLOR, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA },
{ "TANGENT", 0, MeshComponent::Vertex_TAN::FORMAT, INPUT_SLOT_TANGENT, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA },
{ "INSTANCEMATRIX", 0, FORMAT_R32G32B32A32_FLOAT, INPUT_SLOT_INSTANCEDATA, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
{ "INSTANCEMATRIX", 1, FORMAT_R32G32B32A32_FLOAT, INPUT_SLOT_INSTANCEDATA, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
{ "INSTANCEMATRIX", 2, FORMAT_R32G32B32A32_FLOAT, INPUT_SLOT_INSTANCEDATA, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
{ "INSTANCEUSERDATA", 0, FORMAT_R32G32B32A32_UINT, INPUT_SLOT_INSTANCEDATA, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
{ "INSTANCEATLAS", 0, FORMAT_R32G32B32A32_FLOAT, INPUT_SLOT_INSTANCEDATA, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
{ "INSTANCEMATRIX", 0, FORMAT_R32G32B32A32_FLOAT, INPUT_SLOT_INSTANCEDATA, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA },
{ "INSTANCEMATRIX", 1, FORMAT_R32G32B32A32_FLOAT, INPUT_SLOT_INSTANCEDATA, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA },
{ "INSTANCEMATRIX", 2, FORMAT_R32G32B32A32_FLOAT, INPUT_SLOT_INSTANCEDATA, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA },
{ "INSTANCEUSERDATA", 0, FORMAT_R32G32B32A32_UINT, INPUT_SLOT_INSTANCEDATA, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA },
{ "INSTANCEATLAS", 0, FORMAT_R32G32B32A32_FLOAT, INPUT_SLOT_INSTANCEDATA, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA },
};
LoadShader(VS, shaders[VSTYPE_OBJECT_COMMON], "objectVS_common.cso");
});
@@ -931,16 +931,16 @@ void LoadShaders()
wiJobSystem::Execute(ctx, [](wiJobArgs args) {
inputLayouts[ILTYPE_OBJECT_POS_PREVPOS].elements =
{
{ "POSITION_NORMAL_WIND", 0, MeshComponent::Vertex_POS::FORMAT, INPUT_SLOT_POSITION_NORMAL_WIND, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 },
{ "PREVPOS", 0, MeshComponent::Vertex_POS::FORMAT, INPUT_SLOT_PREVPOS, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 },
{ "POSITION_NORMAL_WIND", 0, MeshComponent::Vertex_POS::FORMAT, INPUT_SLOT_POSITION_NORMAL_WIND, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA },
{ "PREVPOS", 0, MeshComponent::Vertex_POS::FORMAT, INPUT_SLOT_PREVPOS, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA },
{ "INSTANCEMATRIX", 0, FORMAT_R32G32B32A32_FLOAT, INPUT_SLOT_INSTANCEDATA, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
{ "INSTANCEMATRIX", 1, FORMAT_R32G32B32A32_FLOAT, INPUT_SLOT_INSTANCEDATA, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
{ "INSTANCEMATRIX", 2, FORMAT_R32G32B32A32_FLOAT, INPUT_SLOT_INSTANCEDATA, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
{ "INSTANCEUSERDATA", 0, FORMAT_R32G32B32A32_UINT, INPUT_SLOT_INSTANCEDATA, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
{ "INSTANCEMATRIXPREV", 0, FORMAT_R32G32B32A32_FLOAT, INPUT_SLOT_INSTANCEDATA, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
{ "INSTANCEMATRIXPREV", 1, FORMAT_R32G32B32A32_FLOAT, INPUT_SLOT_INSTANCEDATA, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
{ "INSTANCEMATRIXPREV", 2, FORMAT_R32G32B32A32_FLOAT, INPUT_SLOT_INSTANCEDATA, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
{ "INSTANCEMATRIX", 0, FORMAT_R32G32B32A32_FLOAT, INPUT_SLOT_INSTANCEDATA, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA },
{ "INSTANCEMATRIX", 1, FORMAT_R32G32B32A32_FLOAT, INPUT_SLOT_INSTANCEDATA, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA },
{ "INSTANCEMATRIX", 2, FORMAT_R32G32B32A32_FLOAT, INPUT_SLOT_INSTANCEDATA, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA },
{ "INSTANCEUSERDATA", 0, FORMAT_R32G32B32A32_UINT, INPUT_SLOT_INSTANCEDATA, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA },
{ "INSTANCEMATRIXPREV", 0, FORMAT_R32G32B32A32_FLOAT, INPUT_SLOT_INSTANCEDATA, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA },
{ "INSTANCEMATRIXPREV", 1, FORMAT_R32G32B32A32_FLOAT, INPUT_SLOT_INSTANCEDATA, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA },
{ "INSTANCEMATRIXPREV", 2, FORMAT_R32G32B32A32_FLOAT, INPUT_SLOT_INSTANCEDATA, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA },
};
LoadShader(VS, shaders[VSTYPE_OBJECT_PREPASS], "objectVS_prepass.cso");
});
@@ -948,18 +948,18 @@ void LoadShaders()
wiJobSystem::Execute(ctx, [](wiJobArgs args) {
inputLayouts[ILTYPE_OBJECT_POS_PREVPOS_TEX].elements =
{
{ "POSITION_NORMAL_WIND", 0, MeshComponent::Vertex_POS::FORMAT, INPUT_SLOT_POSITION_NORMAL_WIND, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 },
{ "PREVPOS", 0, MeshComponent::Vertex_POS::FORMAT, INPUT_SLOT_PREVPOS, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 },
{ "UVSET", 0, MeshComponent::Vertex_TEX::FORMAT, INPUT_SLOT_UV0, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 },
{ "UVSET", 1, MeshComponent::Vertex_TEX::FORMAT, INPUT_SLOT_UV1, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 },
{ "POSITION_NORMAL_WIND", 0, MeshComponent::Vertex_POS::FORMAT, INPUT_SLOT_POSITION_NORMAL_WIND, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA },
{ "PREVPOS", 0, MeshComponent::Vertex_POS::FORMAT, INPUT_SLOT_PREVPOS, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA },
{ "UVSET", 0, MeshComponent::Vertex_TEX::FORMAT, INPUT_SLOT_UV0, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA },
{ "UVSET", 1, MeshComponent::Vertex_TEX::FORMAT, INPUT_SLOT_UV1, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA },
{ "INSTANCEMATRIX", 0, FORMAT_R32G32B32A32_FLOAT, INPUT_SLOT_INSTANCEDATA, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
{ "INSTANCEMATRIX", 1, FORMAT_R32G32B32A32_FLOAT, INPUT_SLOT_INSTANCEDATA, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
{ "INSTANCEMATRIX", 2, FORMAT_R32G32B32A32_FLOAT, INPUT_SLOT_INSTANCEDATA, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
{ "INSTANCEUSERDATA", 0, FORMAT_R32G32B32A32_UINT, INPUT_SLOT_INSTANCEDATA, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
{ "INSTANCEMATRIXPREV", 0, FORMAT_R32G32B32A32_FLOAT, INPUT_SLOT_INSTANCEDATA, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
{ "INSTANCEMATRIXPREV", 1, FORMAT_R32G32B32A32_FLOAT, INPUT_SLOT_INSTANCEDATA, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
{ "INSTANCEMATRIXPREV", 2, FORMAT_R32G32B32A32_FLOAT, INPUT_SLOT_INSTANCEDATA, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
{ "INSTANCEMATRIX", 0, FORMAT_R32G32B32A32_FLOAT, INPUT_SLOT_INSTANCEDATA, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA },
{ "INSTANCEMATRIX", 1, FORMAT_R32G32B32A32_FLOAT, INPUT_SLOT_INSTANCEDATA, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA },
{ "INSTANCEMATRIX", 2, FORMAT_R32G32B32A32_FLOAT, INPUT_SLOT_INSTANCEDATA, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA },
{ "INSTANCEUSERDATA", 0, FORMAT_R32G32B32A32_UINT, INPUT_SLOT_INSTANCEDATA, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA },
{ "INSTANCEMATRIXPREV", 0, FORMAT_R32G32B32A32_FLOAT, INPUT_SLOT_INSTANCEDATA, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA },
{ "INSTANCEMATRIXPREV", 1, FORMAT_R32G32B32A32_FLOAT, INPUT_SLOT_INSTANCEDATA, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA },
{ "INSTANCEMATRIXPREV", 2, FORMAT_R32G32B32A32_FLOAT, INPUT_SLOT_INSTANCEDATA, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA },
};
LoadShader(VS, shaders[VSTYPE_OBJECT_PREPASS_ALPHATEST], "objectVS_prepass_alphatest.cso");
});
@@ -967,12 +967,12 @@ void LoadShaders()
wiJobSystem::Execute(ctx, [](wiJobArgs args) {
inputLayouts[ILTYPE_OBJECT_POS].elements =
{
{ "POSITION_NORMAL_WIND", 0, MeshComponent::Vertex_POS::FORMAT, INPUT_SLOT_POSITION_NORMAL_WIND, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 },
{ "POSITION_NORMAL_WIND", 0, MeshComponent::Vertex_POS::FORMAT, INPUT_SLOT_POSITION_NORMAL_WIND, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA },
{ "INSTANCEMATRIX", 0, FORMAT_R32G32B32A32_FLOAT, INPUT_SLOT_INSTANCEDATA, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
{ "INSTANCEMATRIX", 1, FORMAT_R32G32B32A32_FLOAT, INPUT_SLOT_INSTANCEDATA, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
{ "INSTANCEMATRIX", 2, FORMAT_R32G32B32A32_FLOAT, INPUT_SLOT_INSTANCEDATA, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
{ "INSTANCEUSERDATA", 0, FORMAT_R32G32B32A32_UINT, INPUT_SLOT_INSTANCEDATA, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
{ "INSTANCEMATRIX", 0, FORMAT_R32G32B32A32_FLOAT, INPUT_SLOT_INSTANCEDATA, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA },
{ "INSTANCEMATRIX", 1, FORMAT_R32G32B32A32_FLOAT, INPUT_SLOT_INSTANCEDATA, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA },
{ "INSTANCEMATRIX", 2, FORMAT_R32G32B32A32_FLOAT, INPUT_SLOT_INSTANCEDATA, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA },
{ "INSTANCEUSERDATA", 0, FORMAT_R32G32B32A32_UINT, INPUT_SLOT_INSTANCEDATA, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA },
};
LoadShader(VS, shaders[VSTYPE_SHADOW], "shadowVS.cso");
});
@@ -980,14 +980,14 @@ void LoadShaders()
wiJobSystem::Execute(ctx, [](wiJobArgs args) {
inputLayouts[ILTYPE_OBJECT_POS_TEX].elements =
{
{ "POSITION_NORMAL_WIND", 0, MeshComponent::Vertex_POS::FORMAT, INPUT_SLOT_POSITION_NORMAL_WIND, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 },
{ "UVSET", 0, MeshComponent::Vertex_TEX::FORMAT, INPUT_SLOT_UV0, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 },
{ "UVSET", 1, MeshComponent::Vertex_TEX::FORMAT, INPUT_SLOT_UV1, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 },
{ "POSITION_NORMAL_WIND", 0, MeshComponent::Vertex_POS::FORMAT, INPUT_SLOT_POSITION_NORMAL_WIND, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA },
{ "UVSET", 0, MeshComponent::Vertex_TEX::FORMAT, INPUT_SLOT_UV0, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA },
{ "UVSET", 1, MeshComponent::Vertex_TEX::FORMAT, INPUT_SLOT_UV1, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA },
{ "INSTANCEMATRIX", 0, FORMAT_R32G32B32A32_FLOAT, INPUT_SLOT_INSTANCEDATA, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
{ "INSTANCEMATRIX", 1, FORMAT_R32G32B32A32_FLOAT, INPUT_SLOT_INSTANCEDATA, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
{ "INSTANCEMATRIX", 2, FORMAT_R32G32B32A32_FLOAT, INPUT_SLOT_INSTANCEDATA, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
{ "INSTANCEUSERDATA", 0, FORMAT_R32G32B32A32_UINT, INPUT_SLOT_INSTANCEDATA, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
{ "INSTANCEMATRIX", 0, FORMAT_R32G32B32A32_FLOAT, INPUT_SLOT_INSTANCEDATA, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA },
{ "INSTANCEMATRIX", 1, FORMAT_R32G32B32A32_FLOAT, INPUT_SLOT_INSTANCEDATA, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA },
{ "INSTANCEMATRIX", 2, FORMAT_R32G32B32A32_FLOAT, INPUT_SLOT_INSTANCEDATA, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA },
{ "INSTANCEUSERDATA", 0, FORMAT_R32G32B32A32_UINT, INPUT_SLOT_INSTANCEDATA, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA },
};
LoadShader(VS, shaders[VSTYPE_OBJECT_SIMPLE], "objectVS_simple.cso");
LoadShader(VS, shaders[VSTYPE_SHADOW_ALPHATEST], "shadowVS_alphatest.cso");
@@ -997,8 +997,8 @@ void LoadShaders()
wiJobSystem::Execute(ctx, [](wiJobArgs args) {
inputLayouts[ILTYPE_VERTEXCOLOR].elements =
{
{ "POSITION", 0, FORMAT_R32G32B32A32_FLOAT, 0, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 },
{ "TEXCOORD", 0, FORMAT_R32G32B32A32_FLOAT, 0, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 },
{ "POSITION", 0, FORMAT_R32G32B32A32_FLOAT, 0, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA },
{ "TEXCOORD", 0, FORMAT_R32G32B32A32_FLOAT, 0, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA },
};
LoadShader(VS, shaders[VSTYPE_VERTEXCOLOR], "vertexcolorVS.cso");
});
@@ -1006,12 +1006,12 @@ void LoadShaders()
wiJobSystem::Execute(ctx, [](wiJobArgs args) {
inputLayouts[ILTYPE_RENDERLIGHTMAP].elements =
{
{ "POSITION_NORMAL_WIND", 0, MeshComponent::Vertex_POS::FORMAT, 0, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 },
{ "ATLAS", 0, MeshComponent::Vertex_TEX::FORMAT, 1, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 },
{ "POSITION_NORMAL_WIND", 0, MeshComponent::Vertex_POS::FORMAT, 0, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA },
{ "ATLAS", 0, MeshComponent::Vertex_TEX::FORMAT, 1, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA },
{ "INSTANCEMATRIXPREV", 0, FORMAT_R32G32B32A32_FLOAT, 2, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
{ "INSTANCEMATRIXPREV", 1, FORMAT_R32G32B32A32_FLOAT, 2, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
{ "INSTANCEMATRIXPREV", 2, FORMAT_R32G32B32A32_FLOAT, 2, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
{ "INSTANCEMATRIXPREV", 0, FORMAT_R32G32B32A32_FLOAT, 2, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA },
{ "INSTANCEMATRIXPREV", 1, FORMAT_R32G32B32A32_FLOAT, 2, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA },
{ "INSTANCEMATRIXPREV", 2, FORMAT_R32G32B32A32_FLOAT, 2, InputLayout::APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA },
};
LoadShader(VS, shaders[VSTYPE_RENDERLIGHTMAP], "renderlightmapVS.cso");
});
@@ -3411,9 +3411,9 @@ void UpdatePerFrameData(
else
{
const uint32_t writeQuery = scene.queryAllocator.fetch_add(1); // allocate new occlusion query from heap
if (writeQuery < scene.queryHeap[scene.query_write].desc.queryCount)
if (writeQuery < scene.queryHeap[scene.queryheap_idx].desc.queryCount)
{
object.occlusionQueries[scene.query_write] = writeQuery;
object.occlusionQueries[scene.queryheap_idx] = writeQuery;
}
}
});
@@ -4117,7 +4117,7 @@ void OcclusionCulling_Render(const CameraComponent& camera_previous, const Visib
{
device->EventBegin("Occlusion Culling Render", cmd);
int query_write = vis.scene->query_write;
int query_write = vis.scene->queryheap_idx;
const GPUQueryHeap& queryHeap = vis.scene->queryHeap[query_write];
device->BindPipelineState(&PSO_occlusionquery, cmd);
+9 -11
View File
@@ -1427,19 +1427,17 @@ namespace wiScene
}
queryResults.resize(desc.queryCount);
}
query_write++;
query_read = query_write + 1;
query_write %= arraysize(queryHeap);
query_read %= arraysize(queryHeap);
writtenQueries[query_read] = std::min(queryAllocator.load(), queryHeap[query_read].desc.queryCount);
queryheap_idx++;
queryheap_idx %= arraysize(queryHeap);
writtenQueries[queryheap_idx] = std::min(queryAllocator.load(), queryHeap[queryheap_idx].desc.queryCount);
queryAllocator.store(0);
if (writtenQueries[query_read] > 0)
if (writtenQueries[queryheap_idx] > 0)
{
device->QueryRead(
&queryHeap[query_read],
&queryHeap[queryheap_idx],
0,
writtenQueries[query_read],
writtenQueries[queryheap_idx],
queryResults.data()
);
}
@@ -2849,8 +2847,8 @@ namespace wiScene
// Update occlusion culling status:
object.occlusionHistory <<= 1; // advance history by 1 frame
int query_id = object.occlusionQueries[query_read];
if (query_id >= 0 && (int)writtenQueries[query_read] > query_id)
int query_id = object.occlusionQueries[queryheap_idx];
if (query_id >= 0 && (int)writtenQueries[queryheap_idx] > query_id)
{
uint64_t visible = queryResults[query_id];
if (visible)
@@ -2862,7 +2860,7 @@ namespace wiScene
{
object.occlusionHistory |= 1; // visible
}
object.occlusionQueries[query_read] = -1; // invalidate query
object.occlusionQueries[queryheap_idx] = -1; // invalidate query
aabb = AABB();
object.rendertypeMask = 0;
+1 -2
View File
@@ -1296,8 +1296,7 @@ namespace wiScene
wiGraphics::GPUQueryHeap queryHeap[arraysize(ObjectComponent::occlusionQueries)];
std::vector<uint64_t> queryResults;
uint32_t writtenQueries[arraysize(queryHeap)] = {};
int query_write = 0;
int query_read = 0;
int queryheap_idx = 0;
std::atomic<uint32_t> queryAllocator{ 0 };
// Update all components by a given timestep (in seconds):
+1 -1
View File
@@ -9,7 +9,7 @@ namespace wiVersion
// minor features, major updates, breaking compatibility changes
const int minor = 54;
// minor bug fixes, alterations, refactors, updates
const int revision = 2;
const int revision = 3;
const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);