dx11, dx12, vulkan updates: common samplers, auto samplers, auto root constantbuffers (dx12)
This commit is contained in:
@@ -509,12 +509,14 @@ Unordered Access Views, in other words resources with read-write access. `GPUBuf
|
||||
- Constant buffers<br/>
|
||||
Only `GPUBuffer`s can be set as constant buffers if they were created with a `BindFlags` in their description that has the `BIND_CONSTANT_BUFFER` bit set. The resource can't be a constant buffer at the same time when it is also a shader resource or a UAV or a vertex buffer or an index buffer. Use the `GraphicsDevice::BindConstantBuffer()` function to bind constant buffers.
|
||||
- Samplers<br/>
|
||||
Only `Sampler` can be bound as sampler. Use the `GraphicsDevice::BindSampler()` function to bind samplers.
|
||||
Only `Sampler` can be bound as sampler. Use the `GraphicsDevice::BindSampler()` function to bind samplers. Additionally, you can specify auto samplers and common samplers and avoid binding them every time.
|
||||
|
||||
There are some limitations on the maximum value of slots that can be used, these are defined as compile time constants in [Graphics device SharedInternals](../WickedEngine/wiGraphicsDevice_SharedInternals.h). The user can modify these and recompile the engine if the predefined slots are not enough. This could slightly affect performance.
|
||||
|
||||
Remarks:
|
||||
- Vulkan and DX12 devices make an effort to combine descriptors across shader stages, so overlapping descriptors will not be supported with those APIs to some extent. For example it is OK, to have a constant buffer on slot 0 (b0) in a vertex shader while having a Texture2D on slot 0 (t0) in pixel shader. However, having a StructuredBuffer on vertex shader slot 0 (t0) and a Texture2D in pixel shader slot 0 (t0) will not work correctly, as only one of them will be bound to a pipeline state. This is made for performance reasons and to retain compatibility with the [advanced binding model](#resource-binding-advanced).
|
||||
- Auto samplers can be added to `Shader`s. These sasmplers will always be bound to the shader stage as static samplers. The user doesn't need to use `BindSampler()` function for these.
|
||||
- Common Samplers can be set on the graphics device. These samplers will be bound to all shaders that are created after the common sampler have been set. The user doesn't need to use `BindSampler()` function for these.
|
||||
|
||||
##### Resource Binding (Advanced)
|
||||
This resource binding model is based on a combination of DirectX 12 and Vulkan resource binding model and allows the developer to use a more fine grained resource management that can be fitted for specific use cases more optimally. For example, a bindless descriptor model could be implemented with descriptor arrays, or a system where descriptors are grouped by update frequency into tables. The developer can query whether the `GraphicsDevice` supports advanced binding model, by querying the `GRAPHICSDEVICE_CAPABILITY_DESCRIPTOR_MANAGEMENT` capability with `GraphicsDevice::CheckCapability()`.
|
||||
|
||||
@@ -434,7 +434,7 @@ void RendererWindow::Create(EditorComponent* editor)
|
||||
break;
|
||||
}
|
||||
|
||||
wiRenderer::ModifySampler(desc, SSLOT_OBJECTSHADER);
|
||||
wiRenderer::ModifyObjectSampler(desc);
|
||||
|
||||
});
|
||||
textureQualityComboBox.SetSelected(3);
|
||||
@@ -448,7 +448,7 @@ void RendererWindow::Create(EditorComponent* editor)
|
||||
mipLodBiasSlider.OnSlide([&](wiEventArgs args) {
|
||||
wiGraphics::SamplerDesc desc = wiRenderer::GetSampler(SSLOT_OBJECTSHADER)->GetDesc();
|
||||
desc.MipLODBias = wiMath::Clamp(args.fValue, -15.9f, 15.9f);
|
||||
wiRenderer::ModifySampler(desc, SSLOT_OBJECTSHADER);
|
||||
wiRenderer::ModifyObjectSampler(desc);
|
||||
});
|
||||
AddWidget(&mipLodBiasSlider);
|
||||
|
||||
|
||||
@@ -239,6 +239,11 @@ void LoadShaders()
|
||||
|
||||
wiRenderer::LoadShader(VS, vertexShader, "fontVS.cso");
|
||||
|
||||
|
||||
pixelShader.auto_samplers.emplace_back();
|
||||
pixelShader.auto_samplers.back().sampler = sampler;
|
||||
pixelShader.auto_samplers.back().slot = SSLOT_ONDEMAND1;
|
||||
|
||||
wiRenderer::LoadShader(PS, pixelShader, "fontPS.cso");
|
||||
|
||||
|
||||
@@ -593,7 +598,6 @@ void Draw_internal(const T* text, size_t text_length, const wiFontParams& params
|
||||
device->BindConstantBuffer(VS, &constantBuffer, CB_GETBINDSLOT(FontCB), cmd);
|
||||
device->BindConstantBuffer(PS, &constantBuffer, CB_GETBINDSLOT(FontCB), cmd);
|
||||
device->BindResource(PS, &texture, TEXSLOT_FONTATLAS, cmd);
|
||||
device->BindSampler(PS, &sampler, SSLOT_ONDEMAND1, cmd);
|
||||
|
||||
device->BindResource(VS, mem.buffer, 0, cmd);
|
||||
|
||||
|
||||
+13
-12
@@ -731,19 +731,25 @@ namespace wiGraphics
|
||||
inline bool IsValid() const { return internal_state.get() != nullptr; }
|
||||
};
|
||||
|
||||
struct Shader : public GraphicsDeviceChild
|
||||
{
|
||||
SHADERSTAGE stage = SHADERSTAGE_COUNT;
|
||||
std::vector<uint8_t> code;
|
||||
const RootSignature* rootSignature = nullptr;
|
||||
};
|
||||
|
||||
struct Sampler : public GraphicsDeviceChild
|
||||
{
|
||||
SamplerDesc desc;
|
||||
|
||||
const SamplerDesc& GetDesc() const { return desc; }
|
||||
};
|
||||
struct StaticSampler
|
||||
{
|
||||
Sampler sampler;
|
||||
uint32_t slot = 0;
|
||||
};
|
||||
|
||||
struct Shader : public GraphicsDeviceChild
|
||||
{
|
||||
SHADERSTAGE stage = SHADERSTAGE_COUNT;
|
||||
std::vector<uint8_t> code;
|
||||
const RootSignature* rootSignature = nullptr;
|
||||
std::vector<StaticSampler> auto_samplers; // ability to set static samplers without explicit root signature
|
||||
};
|
||||
|
||||
struct GPUResource : public GraphicsDeviceChild
|
||||
{
|
||||
@@ -993,11 +999,6 @@ namespace wiGraphics
|
||||
uint32_t slot = 0;
|
||||
uint32_t count = 1;
|
||||
};
|
||||
struct StaticSampler
|
||||
{
|
||||
Sampler sampler;
|
||||
uint32_t slot = 0;
|
||||
};
|
||||
struct DescriptorTable : public GraphicsDeviceChild
|
||||
{
|
||||
SHADERSTAGE stage = SHADERSTAGE_COUNT;
|
||||
|
||||
@@ -51,6 +51,8 @@ namespace wiGraphics
|
||||
virtual void Unmap(const GPUResource* resource) = 0;
|
||||
virtual bool QueryRead(const GPUQuery* query, GPUQueryResult* result) = 0;
|
||||
|
||||
virtual void SetCommonSampler(const StaticSampler* sam) = 0;
|
||||
|
||||
virtual void SetName(GPUResource* pResource, const char* name) = 0;
|
||||
|
||||
virtual void PresentBegin(CommandList cmd) = 0;
|
||||
|
||||
@@ -6,14 +6,6 @@
|
||||
#include "ResourceMapping.h"
|
||||
#include "wiBackLog.h"
|
||||
|
||||
#ifdef PLATFORM_UWP
|
||||
// UWP will use static link + /DELAYLOAD linker feature for the dlls (optionally)
|
||||
#pragma comment(lib,"d3d11.lib")
|
||||
#define dll_D3D11CreateDevice D3D11CreateDevice
|
||||
#else
|
||||
static PFN_D3D11_CREATE_DEVICE dll_D3D11CreateDevice = nullptr;
|
||||
#endif // PLATFORM_UWP
|
||||
|
||||
#pragma comment(lib,"dxguid.lib")
|
||||
|
||||
#include <sstream>
|
||||
@@ -32,6 +24,14 @@ namespace wiGraphics
|
||||
|
||||
namespace DX11_Internal
|
||||
{
|
||||
|
||||
#ifdef PLATFORM_UWP
|
||||
// UWP will use static link + /DELAYLOAD linker feature for the dlls (optionally)
|
||||
#pragma comment(lib,"d3d11.lib")
|
||||
#else
|
||||
static PFN_D3D11_CREATE_DEVICE D3D11CreateDevice = nullptr;
|
||||
#endif // PLATFORM_UWP
|
||||
|
||||
// Engine -> Native converters
|
||||
|
||||
constexpr uint32_t _ParseBindFlags(uint32_t value)
|
||||
@@ -1188,30 +1188,70 @@ void GraphicsDevice_DX11::pso_validate(CommandList cmd)
|
||||
{
|
||||
deviceContexts[cmd]->VSSetShader(vs, nullptr, 0);
|
||||
prev_vs[cmd] = vs;
|
||||
|
||||
if (desc.vs != nullptr)
|
||||
{
|
||||
for (auto& x : desc.vs->auto_samplers)
|
||||
{
|
||||
BindSampler(VS, &x.sampler, x.slot, cmd);
|
||||
}
|
||||
}
|
||||
}
|
||||
ID3D11PixelShader* ps = desc.ps == nullptr ? nullptr : static_cast<PixelShader_DX11*>(desc.ps->internal_state.get())->resource.Get();
|
||||
if (ps != prev_ps[cmd])
|
||||
{
|
||||
deviceContexts[cmd]->PSSetShader(ps, nullptr, 0);
|
||||
prev_ps[cmd] = ps;
|
||||
|
||||
if (desc.ps != nullptr)
|
||||
{
|
||||
for (auto& x : desc.ps->auto_samplers)
|
||||
{
|
||||
BindSampler(PS, &x.sampler, x.slot, cmd);
|
||||
}
|
||||
}
|
||||
}
|
||||
ID3D11HullShader* hs = desc.hs == nullptr ? nullptr : static_cast<HullShader_DX11*>(desc.hs->internal_state.get())->resource.Get();
|
||||
if (hs != prev_hs[cmd])
|
||||
{
|
||||
deviceContexts[cmd]->HSSetShader(hs, nullptr, 0);
|
||||
prev_hs[cmd] = hs;
|
||||
|
||||
if (desc.hs != nullptr)
|
||||
{
|
||||
for (auto& x : desc.hs->auto_samplers)
|
||||
{
|
||||
BindSampler(HS, &x.sampler, x.slot, cmd);
|
||||
}
|
||||
}
|
||||
}
|
||||
ID3D11DomainShader* ds = desc.ds == nullptr ? nullptr : static_cast<DomainShader_DX11*>(desc.ds->internal_state.get())->resource.Get();
|
||||
if (ds != prev_ds[cmd])
|
||||
{
|
||||
deviceContexts[cmd]->DSSetShader(ds, nullptr, 0);
|
||||
prev_ds[cmd] = ds;
|
||||
|
||||
if (desc.ds != nullptr)
|
||||
{
|
||||
for (auto& x : desc.ds->auto_samplers)
|
||||
{
|
||||
BindSampler(DS, &x.sampler, x.slot, cmd);
|
||||
}
|
||||
}
|
||||
}
|
||||
ID3D11GeometryShader* gs = desc.gs == nullptr ? nullptr : static_cast<GeometryShader_DX11*>(desc.gs->internal_state.get())->resource.Get();
|
||||
if (gs != prev_gs[cmd])
|
||||
{
|
||||
deviceContexts[cmd]->GSSetShader(gs, nullptr, 0);
|
||||
prev_gs[cmd] = gs;
|
||||
|
||||
if (desc.gs != nullptr)
|
||||
{
|
||||
for (auto& x : desc.gs->auto_samplers)
|
||||
{
|
||||
BindSampler(GS, &x.sampler, x.slot, cmd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ID3D11BlendState* bs = desc.bs == nullptr ? nullptr : internal_state->bs.Get();
|
||||
@@ -1305,8 +1345,8 @@ GraphicsDevice_DX11::GraphicsDevice_DX11(wiPlatform::window_type window, bool fu
|
||||
#ifndef PLATFORM_UWP
|
||||
HMODULE dx11 = LoadLibraryEx(L"d3d11.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
|
||||
|
||||
dll_D3D11CreateDevice = (PFN_D3D11_CREATE_DEVICE)GetProcAddress(dx11, "D3D11CreateDevice");
|
||||
assert(dll_D3D11CreateDevice != nullptr);
|
||||
D3D11CreateDevice = (PFN_D3D11_CREATE_DEVICE)GetProcAddress(dx11, "D3D11CreateDevice");
|
||||
assert(D3D11CreateDevice != nullptr);
|
||||
#endif // PLATFORM_UWP
|
||||
|
||||
HRESULT hr = E_FAIL;
|
||||
@@ -1336,7 +1376,7 @@ GraphicsDevice_DX11::GraphicsDevice_DX11(wiPlatform::window_type window, bool fu
|
||||
for (uint32_t driverTypeIndex = 0; driverTypeIndex < numDriverTypes; driverTypeIndex++)
|
||||
{
|
||||
driverType = driverTypes[driverTypeIndex];
|
||||
hr = dll_D3D11CreateDevice(nullptr, driverType, nullptr, createDeviceFlags, featureLevels, numFeatureLevels, D3D11_SDK_VERSION, &device
|
||||
hr = D3D11CreateDevice(nullptr, driverType, nullptr, createDeviceFlags, featureLevels, numFeatureLevels, D3D11_SDK_VERSION, &device
|
||||
, &featureLevel, &immediateContext);
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
@@ -2515,6 +2555,11 @@ bool GraphicsDevice_DX11::QueryRead(const GPUQuery* query, GPUQueryResult* resul
|
||||
return hr != S_FALSE;
|
||||
}
|
||||
|
||||
void GraphicsDevice_DX11::SetCommonSampler(const StaticSampler* sam)
|
||||
{
|
||||
common_samplers.push_back(*sam);
|
||||
}
|
||||
|
||||
void GraphicsDevice_DX11::SetName(GPUResource* pResource, const char* name)
|
||||
{
|
||||
auto internal_state = to_internal(pResource);
|
||||
@@ -2566,6 +2611,14 @@ CommandList GraphicsDevice_DX11::BeginCommandList()
|
||||
BindPipelineState(nullptr, cmd);
|
||||
BindComputeShader(nullptr, cmd);
|
||||
|
||||
for (int stage = 0; stage < SHADERSTAGE_COUNT; ++stage)
|
||||
{
|
||||
for (auto& sam : common_samplers)
|
||||
{
|
||||
BindSampler((SHADERSTAGE)stage, &sam.sampler, sam.slot, cmd);
|
||||
}
|
||||
}
|
||||
|
||||
D3D11_VIEWPORT vp = {};
|
||||
vp.Width = (float)RESOLUTIONWIDTH;
|
||||
vp.Height = (float)RESOLUTIONHEIGHT;
|
||||
@@ -3048,6 +3101,14 @@ void GraphicsDevice_DX11::BindComputeShader(const Shader* cs, CommandList cmd)
|
||||
{
|
||||
deviceContexts[cmd]->CSSetShader(_cs, nullptr, 0);
|
||||
prev_cs[cmd] = _cs;
|
||||
|
||||
if (cs != nullptr)
|
||||
{
|
||||
for (auto& x : cs->auto_samplers)
|
||||
{
|
||||
BindSampler(CS, &x.sampler, x.slot, cmd);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
void GraphicsDevice_DX11::Draw(uint32_t vertexCount, uint32_t startVertexLocation, CommandList cmd)
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace wiGraphics
|
||||
|
||||
class GraphicsDevice_DX11 : public GraphicsDevice
|
||||
{
|
||||
private:
|
||||
protected:
|
||||
D3D_DRIVER_TYPE driverType;
|
||||
D3D_FEATURE_LEVEL featureLevel;
|
||||
Microsoft::WRL::ComPtr<ID3D11Device> device;
|
||||
@@ -74,6 +74,8 @@ namespace wiGraphics
|
||||
|
||||
std::atomic<CommandList> cmd_count{ 0 };
|
||||
|
||||
std::vector<StaticSampler> common_samplers;
|
||||
|
||||
struct EmptyResourceHandle {}; // only care about control-block
|
||||
std::shared_ptr<EmptyResourceHandle> emptyresource;
|
||||
|
||||
@@ -95,6 +97,8 @@ namespace wiGraphics
|
||||
void Unmap(const GPUResource* resource) override;
|
||||
bool QueryRead(const GPUQuery* query, GPUQueryResult* result) override;
|
||||
|
||||
void SetCommonSampler(const StaticSampler* sam) override;
|
||||
|
||||
void SetName(GPUResource* pResource, const char* name) override;
|
||||
|
||||
void PresentBegin(CommandList cmd) override;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -28,7 +28,7 @@ namespace wiGraphics
|
||||
{
|
||||
class GraphicsDevice_DX12 : public GraphicsDevice
|
||||
{
|
||||
public:
|
||||
protected:
|
||||
Microsoft::WRL::ComPtr<ID3D12Device5> device;
|
||||
Microsoft::WRL::ComPtr<IDXGIAdapter4> adapter;
|
||||
Microsoft::WRL::ComPtr<IDXGIFactory6> factory;
|
||||
@@ -74,6 +74,8 @@ namespace wiGraphics
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE nullUAV_texture2darray = {};
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE nullUAV_texture3d = {};
|
||||
|
||||
std::vector<D3D12_STATIC_SAMPLER_DESC> common_samplers;
|
||||
|
||||
Microsoft::WRL::ComPtr<ID3D12CommandQueue> copyQueue;
|
||||
std::mutex copyQueueLock;
|
||||
bool copyQueueUse = false;
|
||||
@@ -99,8 +101,8 @@ namespace wiGraphics
|
||||
|
||||
// GPU status:
|
||||
Microsoft::WRL::ComPtr<ID3D12Fence> fence;
|
||||
HANDLE fenceEvent;
|
||||
uint64_t fenceValue = 0;
|
||||
uint64_t cached_completedValue = 0;
|
||||
};
|
||||
DescriptorHeap descriptorheap_res;
|
||||
DescriptorHeap descriptorheap_sam;
|
||||
@@ -128,6 +130,9 @@ namespace wiGraphics
|
||||
int UAV_index[GPU_RESOURCE_HEAP_UAV_COUNT];
|
||||
const Sampler* SAM[GPU_SAMPLER_HEAP_COUNT];
|
||||
|
||||
uint32_t dirty_root_cbvs_gfx = 0; // bitmask
|
||||
uint32_t dirty_root_cbvs_compute = 0; // bitmask
|
||||
|
||||
struct DescriptorHandles
|
||||
{
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE sampler_handle = {};
|
||||
@@ -226,6 +231,8 @@ namespace wiGraphics
|
||||
void Unmap(const GPUResource* resource) override;
|
||||
bool QueryRead(const GPUQuery* query, GPUQueryResult* result) override;
|
||||
|
||||
void SetCommonSampler(const StaticSampler* sam) override;
|
||||
|
||||
void SetName(GPUResource* pResource, const char* name) override;
|
||||
|
||||
void PresentBegin(CommandList cmd) override;
|
||||
|
||||
@@ -571,17 +571,15 @@ namespace Vulkan_Internal
|
||||
return flags;
|
||||
}
|
||||
|
||||
bool checkDeviceExtensionSupport(const char* checkExtension,
|
||||
const std::vector<VkExtensionProperties>& available_deviceExtensions) {
|
||||
|
||||
for (const auto& x : available_deviceExtensions)
|
||||
bool checkExtensionSupport(const char* checkExtension, const std::vector<VkExtensionProperties>& available_extensions)
|
||||
{
|
||||
for (const auto& x : available_extensions)
|
||||
{
|
||||
if (strcmp(x.extensionName, checkExtension) == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -589,7 +587,8 @@ namespace Vulkan_Internal
|
||||
const std::vector<const char*> validationLayers = {
|
||||
"VK_LAYER_KHRONOS_validation"
|
||||
};
|
||||
bool checkValidationLayerSupport() {
|
||||
bool checkValidationLayerSupport()
|
||||
{
|
||||
uint32_t layerCount;
|
||||
VkResult res = vkEnumerateInstanceLayerProperties(&layerCount, nullptr);
|
||||
assert(res == VK_SUCCESS);
|
||||
@@ -642,62 +641,6 @@ namespace Vulkan_Internal
|
||||
return VK_FALSE;
|
||||
}
|
||||
|
||||
static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(
|
||||
VkDebugReportFlagsEXT flags,
|
||||
VkDebugReportObjectTypeEXT objType,
|
||||
uint64_t obj,
|
||||
size_t location,
|
||||
int32_t code,
|
||||
const char* layerPrefix,
|
||||
const char* msg,
|
||||
void* userData) {
|
||||
|
||||
std::stringstream ss("");
|
||||
ss << "[VULKAN validation layer]: " << msg << std::endl;
|
||||
|
||||
std::clog << ss.str();
|
||||
#ifdef _WIN32
|
||||
OutputDebugStringA(ss.str().c_str());
|
||||
#endif
|
||||
|
||||
return VK_FALSE;
|
||||
}
|
||||
VkResult CreateDebugUtilsMessengerEXT(VkInstance instance, const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDebugUtilsMessengerEXT* pMessenger)
|
||||
{
|
||||
auto func = (PFN_vkCreateDebugUtilsMessengerEXT)vkGetInstanceProcAddr(instance, "vkCreateDebugUtilsMessengerEXT");
|
||||
if (func != nullptr)
|
||||
{
|
||||
return func(instance, pCreateInfo, pAllocator, pMessenger);
|
||||
}
|
||||
|
||||
return VK_ERROR_EXTENSION_NOT_PRESENT;
|
||||
}
|
||||
void DestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT messenger, const VkAllocationCallbacks* pAllocator)
|
||||
{
|
||||
auto func = (PFN_vkDestroyDebugUtilsMessengerEXT)vkGetInstanceProcAddr(instance, "vkDestroyDebugUtilsMessengerEXT");
|
||||
if (func != nullptr)
|
||||
{
|
||||
func(instance, messenger, pAllocator);
|
||||
}
|
||||
}
|
||||
|
||||
VkResult CreateDebugReportCallbackEXT(VkInstance instance, const VkDebugReportCallbackCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDebugReportCallbackEXT* pCallback) {
|
||||
auto func = (PFN_vkCreateDebugReportCallbackEXT)vkGetInstanceProcAddr(instance, "vkCreateDebugReportCallbackEXT");
|
||||
if (func != nullptr) {
|
||||
return func(instance, pCreateInfo, pAllocator, pCallback);
|
||||
}
|
||||
else {
|
||||
return VK_ERROR_EXTENSION_NOT_PRESENT;
|
||||
}
|
||||
}
|
||||
void DestroyDebugReportCallbackEXT(VkInstance instance, VkDebugReportCallbackEXT callback, const VkAllocationCallbacks* pAllocator) {
|
||||
auto func = (PFN_vkDestroyDebugReportCallbackEXT)vkGetInstanceProcAddr(instance, "vkDestroyDebugReportCallbackEXT");
|
||||
if (func != nullptr) {
|
||||
func(instance, callback, pAllocator);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Memory tools:
|
||||
|
||||
inline size_t Align(size_t uLocation, size_t uAlign)
|
||||
@@ -1266,6 +1209,12 @@ using namespace Vulkan_Internal;
|
||||
int i = 0;
|
||||
for (auto& x : layoutBindings)
|
||||
{
|
||||
if (x.pImmutableSamplers != nullptr)
|
||||
{
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
descriptorWrites.emplace_back();
|
||||
auto& write = descriptorWrites.back();
|
||||
write = {};
|
||||
@@ -2156,27 +2105,14 @@ using namespace Vulkan_Internal;
|
||||
|
||||
std::vector<const char*> extensionNames;
|
||||
|
||||
// Check if VK_EXT_debug_utils is supported, which supersedes VK_EXT_Debug_Report
|
||||
bool debugUtils = false;
|
||||
if (debuglayer)
|
||||
if (checkExtensionSupport(VK_EXT_DEBUG_UTILS_EXTENSION_NAME, availableInstanceExtensions))
|
||||
{
|
||||
for (auto& available_extension : availableInstanceExtensions)
|
||||
{
|
||||
if (strcmp(available_extension.extensionName, VK_EXT_DEBUG_UTILS_EXTENSION_NAME) == 0)
|
||||
{
|
||||
debugUtils = true;
|
||||
extensionNames.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!debugUtils)
|
||||
{
|
||||
extensionNames.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
|
||||
}
|
||||
// This is needed for not only debug layer, but also debug markers, object naming, etc:
|
||||
extensionNames.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
|
||||
}
|
||||
|
||||
extensionNames.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
|
||||
|
||||
#ifdef _WIN32
|
||||
extensionNames.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
|
||||
#elif SDL2
|
||||
@@ -2219,24 +2155,12 @@ using namespace Vulkan_Internal;
|
||||
// Register validation layer callback:
|
||||
if (debuglayer)
|
||||
{
|
||||
if(debugUtils)
|
||||
{
|
||||
VkDebugUtilsMessengerCreateInfoEXT createInfo = {VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT};
|
||||
createInfo.messageSeverity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT;
|
||||
createInfo.messageType = VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT;
|
||||
createInfo.pfnUserCallback = debugUtilsMessengerCallback;
|
||||
res = CreateDebugUtilsMessengerEXT(instance, &createInfo, nullptr, &debugUtilsMessenger);
|
||||
assert(res == VK_SUCCESS);
|
||||
}
|
||||
else
|
||||
{
|
||||
VkDebugReportCallbackCreateInfoEXT createInfo = {};
|
||||
createInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT;
|
||||
createInfo.flags = VK_DEBUG_REPORT_ERROR_BIT_EXT | VK_DEBUG_REPORT_WARNING_BIT_EXT;
|
||||
createInfo.pfnCallback = debugCallback;
|
||||
res = CreateDebugReportCallbackEXT(instance, &createInfo, nullptr, &debugReportCallback);
|
||||
assert(res == VK_SUCCESS);
|
||||
}
|
||||
VkDebugUtilsMessengerCreateInfoEXT createInfo = {VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT};
|
||||
createInfo.messageSeverity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT;
|
||||
createInfo.messageType = VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT;
|
||||
createInfo.pfnUserCallback = debugUtilsMessengerCallback;
|
||||
res = vkCreateDebugUtilsMessengerEXT(instance, &createInfo, nullptr, &debugUtilsMessenger);
|
||||
assert(res == VK_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
@@ -2312,7 +2236,7 @@ using namespace Vulkan_Internal;
|
||||
|
||||
for (auto& x : required_deviceExtensions)
|
||||
{
|
||||
if (!checkDeviceExtensionSupport(x, available))
|
||||
if (!checkExtensionSupport(x, available))
|
||||
{
|
||||
suitable = false; // device doesn't have a required extension
|
||||
}
|
||||
@@ -2419,7 +2343,7 @@ using namespace Vulkan_Internal;
|
||||
res = vkEnumerateDeviceExtensionProperties(physicalDevice, nullptr, &extensionCount, available_deviceExtensions.data());
|
||||
assert(res == VK_SUCCESS);
|
||||
|
||||
if (checkDeviceExtensionSupport(VK_KHR_SPIRV_1_4_EXTENSION_NAME, available_deviceExtensions))
|
||||
if (checkExtensionSupport(VK_KHR_SPIRV_1_4_EXTENSION_NAME, available_deviceExtensions))
|
||||
{
|
||||
enabled_deviceExtensions.push_back(VK_KHR_SPIRV_1_4_EXTENSION_NAME);
|
||||
}
|
||||
@@ -2433,14 +2357,14 @@ using namespace Vulkan_Internal;
|
||||
|
||||
void** features_chain = &features_1_2.pNext;
|
||||
|
||||
if (checkDeviceExtensionSupport(VK_KHR_ACCELERATION_STRUCTURE_EXTENSION_NAME, available_deviceExtensions))
|
||||
if (checkExtensionSupport(VK_KHR_ACCELERATION_STRUCTURE_EXTENSION_NAME, available_deviceExtensions))
|
||||
{
|
||||
enabled_deviceExtensions.push_back(VK_KHR_ACCELERATION_STRUCTURE_EXTENSION_NAME);
|
||||
acceleration_structure_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ACCELERATION_STRUCTURE_FEATURES_KHR;
|
||||
*features_chain = &acceleration_structure_features;
|
||||
features_chain = &acceleration_structure_features.pNext;
|
||||
|
||||
if (checkDeviceExtensionSupport(VK_KHR_RAY_TRACING_PIPELINE_EXTENSION_NAME, available_deviceExtensions))
|
||||
if (checkExtensionSupport(VK_KHR_RAY_TRACING_PIPELINE_EXTENSION_NAME, available_deviceExtensions))
|
||||
{
|
||||
SHADER_IDENTIFIER_SIZE = raytracing_properties.shaderGroupHandleSize;
|
||||
enabled_deviceExtensions.push_back(VK_KHR_RAY_TRACING_PIPELINE_EXTENSION_NAME);
|
||||
@@ -2450,7 +2374,7 @@ using namespace Vulkan_Internal;
|
||||
features_chain = &raytracing_features.pNext;
|
||||
}
|
||||
|
||||
if (checkDeviceExtensionSupport(VK_KHR_RAY_QUERY_EXTENSION_NAME, available_deviceExtensions))
|
||||
if (checkExtensionSupport(VK_KHR_RAY_QUERY_EXTENSION_NAME, available_deviceExtensions))
|
||||
{
|
||||
enabled_deviceExtensions.push_back(VK_KHR_RAY_QUERY_EXTENSION_NAME);
|
||||
enabled_deviceExtensions.push_back(VK_KHR_DEFERRED_HOST_OPERATIONS_EXTENSION_NAME);
|
||||
@@ -2460,7 +2384,7 @@ using namespace Vulkan_Internal;
|
||||
}
|
||||
}
|
||||
|
||||
if (checkDeviceExtensionSupport(VK_KHR_FRAGMENT_SHADING_RATE_EXTENSION_NAME, available_deviceExtensions))
|
||||
if (checkExtensionSupport(VK_KHR_FRAGMENT_SHADING_RATE_EXTENSION_NAME, available_deviceExtensions))
|
||||
{
|
||||
VARIABLE_RATE_SHADING_TILE_SIZE = std::min(fragment_shading_rate_properties.maxFragmentShadingRateAttachmentTexelSize.width, fragment_shading_rate_properties.maxFragmentShadingRateAttachmentTexelSize.height);
|
||||
enabled_deviceExtensions.push_back(VK_KHR_FRAGMENT_SHADING_RATE_EXTENSION_NAME);
|
||||
@@ -2469,7 +2393,7 @@ using namespace Vulkan_Internal;
|
||||
features_chain = &fragment_shading_rate_features.pNext;
|
||||
}
|
||||
|
||||
if (checkDeviceExtensionSupport(VK_NV_MESH_SHADER_EXTENSION_NAME, available_deviceExtensions))
|
||||
if (checkExtensionSupport(VK_NV_MESH_SHADER_EXTENSION_NAME, available_deviceExtensions))
|
||||
{
|
||||
enabled_deviceExtensions.push_back(VK_NV_MESH_SHADER_EXTENSION_NAME);
|
||||
mesh_shader_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MESH_SHADER_FEATURES_NV;
|
||||
@@ -2586,12 +2510,6 @@ using namespace Vulkan_Internal;
|
||||
res = vmaCreateAllocator(&allocatorInfo, &allocationhandler->allocator);
|
||||
assert(res == VK_SUCCESS);
|
||||
|
||||
// looks like volk doesn't get these properly:
|
||||
vkSetDebugUtilsObjectNameEXT = (PFN_vkSetDebugUtilsObjectNameEXT)vkGetDeviceProcAddr(device, "vkSetDebugUtilsObjectNameEXT");
|
||||
vkCmdBeginDebugUtilsLabelEXT = (PFN_vkCmdBeginDebugUtilsLabelEXT)vkGetDeviceProcAddr(device, "vkCmdBeginDebugUtilsLabelEXT");
|
||||
vkCmdEndDebugUtilsLabelEXT = (PFN_vkCmdEndDebugUtilsLabelEXT)vkGetDeviceProcAddr(device, "vkCmdEndDebugUtilsLabelEXT");
|
||||
vkCmdInsertDebugUtilsLabelEXT = (PFN_vkCmdInsertDebugUtilsLabelEXT)vkGetDeviceProcAddr(device, "vkCmdInsertDebugUtilsLabelEXT");
|
||||
|
||||
CreateBackBufferResources();
|
||||
|
||||
vkGetDeviceQueue(device, copyFamily, 0, ©Queue);
|
||||
@@ -2914,12 +2832,7 @@ using namespace Vulkan_Internal;
|
||||
|
||||
if (debugUtilsMessenger != VK_NULL_HANDLE)
|
||||
{
|
||||
DestroyDebugUtilsMessengerEXT(instance, debugUtilsMessenger, nullptr);
|
||||
}
|
||||
|
||||
if (debugReportCallback != VK_NULL_HANDLE)
|
||||
{
|
||||
DestroyDebugReportCallbackEXT(instance, debugReportCallback, nullptr);
|
||||
vkDestroyDebugUtilsMessengerEXT(instance, debugUtilsMessenger, nullptr);
|
||||
}
|
||||
|
||||
vkDestroySurfaceKHR(instance, surface, nullptr);
|
||||
@@ -3013,16 +2926,19 @@ using namespace Vulkan_Internal;
|
||||
assert(res == VK_SUCCESS);
|
||||
swapChainImageFormat = surfaceFormat.format;
|
||||
|
||||
VkDebugUtilsObjectNameInfoEXT info = {};
|
||||
info.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT;
|
||||
info.pObjectName = "SWAPCHAIN";
|
||||
info.objectType = VK_OBJECT_TYPE_IMAGE;
|
||||
for (auto& x : swapChainImages)
|
||||
if (vkSetDebugUtilsObjectNameEXT != nullptr)
|
||||
{
|
||||
info.objectHandle = (uint64_t)x;
|
||||
VkDebugUtilsObjectNameInfoEXT info = {};
|
||||
info.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT;
|
||||
info.pObjectName = "SWAPCHAIN";
|
||||
info.objectType = VK_OBJECT_TYPE_IMAGE;
|
||||
for (auto& x : swapChainImages)
|
||||
{
|
||||
info.objectHandle = (uint64_t)x;
|
||||
|
||||
res = vkSetDebugUtilsObjectNameEXT(device, &info);
|
||||
assert(res == VK_SUCCESS);
|
||||
res = vkSetDebugUtilsObjectNameEXT(device, &info);
|
||||
assert(res == VK_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
// Create default render pass:
|
||||
@@ -3758,6 +3674,8 @@ using namespace Vulkan_Internal;
|
||||
std::vector<VkDescriptorSetLayoutBinding>& layoutBindings = internal_state->layoutBindings;
|
||||
std::vector<VkImageViewType>& imageViewTypes = internal_state->imageViewTypes;
|
||||
|
||||
std::vector<VkSampler> staticsamplers;
|
||||
|
||||
for (auto& x : bindings)
|
||||
{
|
||||
imageViewTypes.push_back(VK_IMAGE_VIEW_TYPE_MAX_ENUM);
|
||||
@@ -3766,6 +3684,36 @@ using namespace Vulkan_Internal;
|
||||
layoutBindings.back().binding = x->binding;
|
||||
layoutBindings.back().descriptorCount = 1;
|
||||
|
||||
if (x->descriptor_type == SPV_REFLECT_DESCRIPTOR_TYPE_SAMPLER)
|
||||
{
|
||||
bool staticsampler = false;
|
||||
for (auto& sam : pShader->auto_samplers)
|
||||
{
|
||||
if (x->binding == sam.slot + VULKAN_BINDING_SHIFT_S)
|
||||
{
|
||||
layoutBindings.back().pImmutableSamplers = &to_internal(&sam.sampler)->resource;
|
||||
staticsampler = true;
|
||||
break; // static sampler will be used instead
|
||||
}
|
||||
}
|
||||
if (!staticsampler)
|
||||
{
|
||||
for (auto& sam : common_samplers)
|
||||
{
|
||||
if (x->binding == sam.slot + VULKAN_BINDING_SHIFT_S)
|
||||
{
|
||||
layoutBindings.back().pImmutableSamplers = &to_internal(&sam.sampler)->resource;
|
||||
staticsampler = true;
|
||||
break; // static sampler will be used instead
|
||||
}
|
||||
}
|
||||
}
|
||||
if (staticsampler)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
switch (x->descriptor_type)
|
||||
{
|
||||
default:
|
||||
@@ -5692,34 +5640,42 @@ using namespace Vulkan_Internal;
|
||||
return res == VK_SUCCESS;
|
||||
}
|
||||
|
||||
void GraphicsDevice_Vulkan::SetCommonSampler(const StaticSampler* sam)
|
||||
{
|
||||
common_samplers.push_back(*sam);
|
||||
}
|
||||
|
||||
void GraphicsDevice_Vulkan::SetName(GPUResource* pResource, const char* name)
|
||||
{
|
||||
VkDebugUtilsObjectNameInfoEXT info = {};
|
||||
info.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT;
|
||||
info.pObjectName = name;
|
||||
if (pResource->IsTexture())
|
||||
if (vkSetDebugUtilsObjectNameEXT != nullptr)
|
||||
{
|
||||
info.objectType = VK_OBJECT_TYPE_IMAGE;
|
||||
info.objectHandle = (uint64_t)to_internal((const Texture*)pResource)->resource;
|
||||
}
|
||||
else if (pResource->IsBuffer())
|
||||
{
|
||||
info.objectType = VK_OBJECT_TYPE_BUFFER;
|
||||
info.objectHandle = (uint64_t)to_internal((const GPUBuffer*)pResource)->resource;
|
||||
}
|
||||
else if (pResource->IsAccelerationStructure())
|
||||
{
|
||||
info.objectType = VK_OBJECT_TYPE_ACCELERATION_STRUCTURE_KHR;
|
||||
info.objectHandle = (uint64_t)to_internal((const RaytracingAccelerationStructure*)pResource)->resource;
|
||||
}
|
||||
VkDebugUtilsObjectNameInfoEXT info = {};
|
||||
info.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT;
|
||||
info.pObjectName = name;
|
||||
if (pResource->IsTexture())
|
||||
{
|
||||
info.objectType = VK_OBJECT_TYPE_IMAGE;
|
||||
info.objectHandle = (uint64_t)to_internal((const Texture*)pResource)->resource;
|
||||
}
|
||||
else if (pResource->IsBuffer())
|
||||
{
|
||||
info.objectType = VK_OBJECT_TYPE_BUFFER;
|
||||
info.objectHandle = (uint64_t)to_internal((const GPUBuffer*)pResource)->resource;
|
||||
}
|
||||
else if (pResource->IsAccelerationStructure())
|
||||
{
|
||||
info.objectType = VK_OBJECT_TYPE_ACCELERATION_STRUCTURE_KHR;
|
||||
info.objectHandle = (uint64_t)to_internal((const RaytracingAccelerationStructure*)pResource)->resource;
|
||||
}
|
||||
|
||||
if (info.objectHandle == VK_NULL_HANDLE)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (info.objectHandle == VK_NULL_HANDLE)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
VkResult res = vkSetDebugUtilsObjectNameEXT(device, &info);
|
||||
assert(res == VK_SUCCESS);
|
||||
VkResult res = vkSetDebugUtilsObjectNameEXT(device, &info);
|
||||
assert(res == VK_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
void GraphicsDevice_Vulkan::PresentBegin(CommandList cmd)
|
||||
|
||||
@@ -30,10 +30,9 @@ namespace wiGraphics
|
||||
{
|
||||
class GraphicsDevice_Vulkan : public GraphicsDevice
|
||||
{
|
||||
private:
|
||||
protected:
|
||||
VkInstance instance = VK_NULL_HANDLE;
|
||||
VkDebugUtilsMessengerEXT debugUtilsMessenger = VK_NULL_HANDLE;
|
||||
VkDebugReportCallbackEXT debugReportCallback = VK_NULL_HANDLE; // Deprecated
|
||||
VkSurfaceKHR surface = VK_NULL_HANDLE;
|
||||
VkPhysicalDevice physicalDevice = VK_NULL_HANDLE;
|
||||
VkDevice device = VK_NULL_HANDLE;
|
||||
@@ -186,6 +185,8 @@ namespace wiGraphics
|
||||
|
||||
std::atomic<CommandList> cmd_count{ 0 };
|
||||
|
||||
std::vector<StaticSampler> common_samplers;
|
||||
|
||||
public:
|
||||
GraphicsDevice_Vulkan(wiPlatform::window_type window, bool fullscreen = false, bool debuglayer = false);
|
||||
virtual ~GraphicsDevice_Vulkan();
|
||||
@@ -215,6 +216,8 @@ namespace wiGraphics
|
||||
void Unmap(const GPUResource* resource) override;
|
||||
bool QueryRead(const GPUQuery* query, GPUQueryResult* result) override;
|
||||
|
||||
void SetCommonSampler(const StaticSampler* sam) override;
|
||||
|
||||
void SetName(GPUResource* pResource, const char* name) override;
|
||||
|
||||
void PresentBegin(CommandList cmd) override;
|
||||
|
||||
+146
-96
@@ -156,6 +156,133 @@ unordered_map<const void*, wiRectPacker::rect_xywh> packedLightmaps;
|
||||
void SetDevice(std::shared_ptr<GraphicsDevice> newDevice)
|
||||
{
|
||||
device = newDevice;
|
||||
|
||||
SamplerDesc samplerDesc;
|
||||
samplerDesc.Filter = FILTER_MIN_MAG_MIP_LINEAR;
|
||||
samplerDesc.AddressU = TEXTURE_ADDRESS_MIRROR;
|
||||
samplerDesc.AddressV = TEXTURE_ADDRESS_MIRROR;
|
||||
samplerDesc.AddressW = TEXTURE_ADDRESS_MIRROR;
|
||||
samplerDesc.MipLODBias = 0.0f;
|
||||
samplerDesc.MaxAnisotropy = 0;
|
||||
samplerDesc.ComparisonFunc = COMPARISON_NEVER;
|
||||
samplerDesc.BorderColor[0] = 0;
|
||||
samplerDesc.BorderColor[1] = 0;
|
||||
samplerDesc.BorderColor[2] = 0;
|
||||
samplerDesc.BorderColor[3] = 0;
|
||||
samplerDesc.MinLOD = 0;
|
||||
samplerDesc.MaxLOD = FLT_MAX;
|
||||
device->CreateSampler(&samplerDesc, &samplers[SSLOT_LINEAR_MIRROR]);
|
||||
|
||||
samplerDesc.Filter = FILTER_MIN_MAG_MIP_LINEAR;
|
||||
samplerDesc.AddressU = TEXTURE_ADDRESS_CLAMP;
|
||||
samplerDesc.AddressV = TEXTURE_ADDRESS_CLAMP;
|
||||
samplerDesc.AddressW = TEXTURE_ADDRESS_CLAMP;
|
||||
device->CreateSampler(&samplerDesc, &samplers[SSLOT_LINEAR_CLAMP]);
|
||||
|
||||
samplerDesc.Filter = FILTER_MIN_MAG_MIP_LINEAR;
|
||||
samplerDesc.AddressU = TEXTURE_ADDRESS_WRAP;
|
||||
samplerDesc.AddressV = TEXTURE_ADDRESS_WRAP;
|
||||
samplerDesc.AddressW = TEXTURE_ADDRESS_WRAP;
|
||||
device->CreateSampler(&samplerDesc, &samplers[SSLOT_LINEAR_WRAP]);
|
||||
|
||||
samplerDesc.Filter = FILTER_MIN_MAG_MIP_POINT;
|
||||
samplerDesc.AddressU = TEXTURE_ADDRESS_MIRROR;
|
||||
samplerDesc.AddressV = TEXTURE_ADDRESS_MIRROR;
|
||||
samplerDesc.AddressW = TEXTURE_ADDRESS_MIRROR;
|
||||
device->CreateSampler(&samplerDesc, &samplers[SSLOT_POINT_MIRROR]);
|
||||
|
||||
samplerDesc.Filter = FILTER_MIN_MAG_MIP_POINT;
|
||||
samplerDesc.AddressU = TEXTURE_ADDRESS_WRAP;
|
||||
samplerDesc.AddressV = TEXTURE_ADDRESS_WRAP;
|
||||
samplerDesc.AddressW = TEXTURE_ADDRESS_WRAP;
|
||||
device->CreateSampler(&samplerDesc, &samplers[SSLOT_POINT_WRAP]);
|
||||
|
||||
|
||||
samplerDesc.Filter = FILTER_MIN_MAG_MIP_POINT;
|
||||
samplerDesc.AddressU = TEXTURE_ADDRESS_CLAMP;
|
||||
samplerDesc.AddressV = TEXTURE_ADDRESS_CLAMP;
|
||||
samplerDesc.AddressW = TEXTURE_ADDRESS_CLAMP;
|
||||
device->CreateSampler(&samplerDesc, &samplers[SSLOT_POINT_CLAMP]);
|
||||
|
||||
samplerDesc.Filter = FILTER_ANISOTROPIC;
|
||||
samplerDesc.AddressU = TEXTURE_ADDRESS_CLAMP;
|
||||
samplerDesc.AddressV = TEXTURE_ADDRESS_CLAMP;
|
||||
samplerDesc.AddressW = TEXTURE_ADDRESS_CLAMP;
|
||||
samplerDesc.MaxAnisotropy = 16;
|
||||
device->CreateSampler(&samplerDesc, &samplers[SSLOT_ANISO_CLAMP]);
|
||||
|
||||
samplerDesc.Filter = FILTER_ANISOTROPIC;
|
||||
samplerDesc.AddressU = TEXTURE_ADDRESS_WRAP;
|
||||
samplerDesc.AddressV = TEXTURE_ADDRESS_WRAP;
|
||||
samplerDesc.AddressW = TEXTURE_ADDRESS_WRAP;
|
||||
samplerDesc.MaxAnisotropy = 16;
|
||||
device->CreateSampler(&samplerDesc, &samplers[SSLOT_ANISO_WRAP]);
|
||||
|
||||
samplerDesc.Filter = FILTER_ANISOTROPIC;
|
||||
samplerDesc.AddressU = TEXTURE_ADDRESS_MIRROR;
|
||||
samplerDesc.AddressV = TEXTURE_ADDRESS_MIRROR;
|
||||
samplerDesc.AddressW = TEXTURE_ADDRESS_MIRROR;
|
||||
samplerDesc.MaxAnisotropy = 16;
|
||||
device->CreateSampler(&samplerDesc, &samplers[SSLOT_ANISO_MIRROR]);
|
||||
|
||||
samplerDesc.Filter = FILTER_ANISOTROPIC;
|
||||
samplerDesc.AddressU = TEXTURE_ADDRESS_WRAP;
|
||||
samplerDesc.AddressV = TEXTURE_ADDRESS_WRAP;
|
||||
samplerDesc.AddressW = TEXTURE_ADDRESS_WRAP;
|
||||
samplerDesc.MaxAnisotropy = 16;
|
||||
device->CreateSampler(&samplerDesc, &samplers[SSLOT_OBJECTSHADER]);
|
||||
|
||||
samplerDesc.Filter = FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT;
|
||||
samplerDesc.AddressU = TEXTURE_ADDRESS_CLAMP;
|
||||
samplerDesc.AddressV = TEXTURE_ADDRESS_CLAMP;
|
||||
samplerDesc.AddressW = TEXTURE_ADDRESS_CLAMP;
|
||||
samplerDesc.MipLODBias = 0.0f;
|
||||
samplerDesc.MaxAnisotropy = 0;
|
||||
samplerDesc.ComparisonFunc = COMPARISON_GREATER_EQUAL;
|
||||
device->CreateSampler(&samplerDesc, &samplers[SSLOT_CMP_DEPTH]);
|
||||
|
||||
|
||||
StaticSampler sam;
|
||||
|
||||
sam.sampler = samplers[SSLOT_CMP_DEPTH];
|
||||
sam.slot = SSLOT_CMP_DEPTH;
|
||||
device->SetCommonSampler(&sam);
|
||||
|
||||
sam.sampler = samplers[SSLOT_LINEAR_MIRROR];
|
||||
sam.slot = SSLOT_LINEAR_MIRROR;
|
||||
device->SetCommonSampler(&sam);
|
||||
|
||||
sam.sampler = samplers[SSLOT_LINEAR_CLAMP];
|
||||
sam.slot = SSLOT_LINEAR_CLAMP;
|
||||
device->SetCommonSampler(&sam);
|
||||
|
||||
sam.sampler = samplers[SSLOT_LINEAR_WRAP];
|
||||
sam.slot = SSLOT_LINEAR_WRAP;
|
||||
device->SetCommonSampler(&sam);
|
||||
|
||||
sam.sampler = samplers[SSLOT_POINT_MIRROR];
|
||||
sam.slot = SSLOT_POINT_MIRROR;
|
||||
device->SetCommonSampler(&sam);
|
||||
|
||||
sam.sampler = samplers[SSLOT_POINT_WRAP];
|
||||
sam.slot = SSLOT_POINT_WRAP;
|
||||
device->SetCommonSampler(&sam);
|
||||
|
||||
sam.sampler = samplers[SSLOT_POINT_CLAMP];
|
||||
sam.slot = SSLOT_POINT_CLAMP;
|
||||
device->SetCommonSampler(&sam);
|
||||
|
||||
sam.sampler = samplers[SSLOT_ANISO_CLAMP];
|
||||
sam.slot = SSLOT_ANISO_CLAMP;
|
||||
device->SetCommonSampler(&sam);
|
||||
|
||||
sam.sampler = samplers[SSLOT_ANISO_WRAP];
|
||||
sam.slot = SSLOT_ANISO_WRAP;
|
||||
device->SetCommonSampler(&sam);
|
||||
|
||||
sam.sampler = samplers[SSLOT_ANISO_MIRROR];
|
||||
sam.slot = SSLOT_ANISO_MIRROR;
|
||||
device->SetCommonSampler(&sam);
|
||||
}
|
||||
GraphicsDevice* GetDevice()
|
||||
{
|
||||
@@ -1834,92 +1961,6 @@ void LoadBuffers()
|
||||
}
|
||||
void SetUpStates()
|
||||
{
|
||||
SamplerDesc samplerDesc;
|
||||
samplerDesc.Filter = FILTER_MIN_MAG_MIP_LINEAR;
|
||||
samplerDesc.AddressU = TEXTURE_ADDRESS_MIRROR;
|
||||
samplerDesc.AddressV = TEXTURE_ADDRESS_MIRROR;
|
||||
samplerDesc.AddressW = TEXTURE_ADDRESS_MIRROR;
|
||||
samplerDesc.MipLODBias = 0.0f;
|
||||
samplerDesc.MaxAnisotropy = 0;
|
||||
samplerDesc.ComparisonFunc = COMPARISON_NEVER;
|
||||
samplerDesc.BorderColor[0] = 0;
|
||||
samplerDesc.BorderColor[1] = 0;
|
||||
samplerDesc.BorderColor[2] = 0;
|
||||
samplerDesc.BorderColor[3] = 0;
|
||||
samplerDesc.MinLOD = 0;
|
||||
samplerDesc.MaxLOD = FLT_MAX;
|
||||
device->CreateSampler(&samplerDesc, &samplers[SSLOT_LINEAR_MIRROR]);
|
||||
|
||||
samplerDesc.Filter = FILTER_MIN_MAG_MIP_LINEAR;
|
||||
samplerDesc.AddressU = TEXTURE_ADDRESS_CLAMP;
|
||||
samplerDesc.AddressV = TEXTURE_ADDRESS_CLAMP;
|
||||
samplerDesc.AddressW = TEXTURE_ADDRESS_CLAMP;
|
||||
device->CreateSampler(&samplerDesc, &samplers[SSLOT_LINEAR_CLAMP]);
|
||||
|
||||
samplerDesc.Filter = FILTER_MIN_MAG_MIP_LINEAR;
|
||||
samplerDesc.AddressU = TEXTURE_ADDRESS_WRAP;
|
||||
samplerDesc.AddressV = TEXTURE_ADDRESS_WRAP;
|
||||
samplerDesc.AddressW = TEXTURE_ADDRESS_WRAP;
|
||||
device->CreateSampler(&samplerDesc, &samplers[SSLOT_LINEAR_WRAP]);
|
||||
|
||||
samplerDesc.Filter = FILTER_MIN_MAG_MIP_POINT;
|
||||
samplerDesc.AddressU = TEXTURE_ADDRESS_MIRROR;
|
||||
samplerDesc.AddressV = TEXTURE_ADDRESS_MIRROR;
|
||||
samplerDesc.AddressW = TEXTURE_ADDRESS_MIRROR;
|
||||
device->CreateSampler(&samplerDesc, &samplers[SSLOT_POINT_MIRROR]);
|
||||
|
||||
samplerDesc.Filter = FILTER_MIN_MAG_MIP_POINT;
|
||||
samplerDesc.AddressU = TEXTURE_ADDRESS_WRAP;
|
||||
samplerDesc.AddressV = TEXTURE_ADDRESS_WRAP;
|
||||
samplerDesc.AddressW = TEXTURE_ADDRESS_WRAP;
|
||||
device->CreateSampler(&samplerDesc, &samplers[SSLOT_POINT_WRAP]);
|
||||
|
||||
|
||||
samplerDesc.Filter = FILTER_MIN_MAG_MIP_POINT;
|
||||
samplerDesc.AddressU = TEXTURE_ADDRESS_CLAMP;
|
||||
samplerDesc.AddressV = TEXTURE_ADDRESS_CLAMP;
|
||||
samplerDesc.AddressW = TEXTURE_ADDRESS_CLAMP;
|
||||
device->CreateSampler(&samplerDesc, &samplers[SSLOT_POINT_CLAMP]);
|
||||
|
||||
samplerDesc.Filter = FILTER_ANISOTROPIC;
|
||||
samplerDesc.AddressU = TEXTURE_ADDRESS_CLAMP;
|
||||
samplerDesc.AddressV = TEXTURE_ADDRESS_CLAMP;
|
||||
samplerDesc.AddressW = TEXTURE_ADDRESS_CLAMP;
|
||||
samplerDesc.MaxAnisotropy = 16;
|
||||
device->CreateSampler(&samplerDesc, &samplers[SSLOT_ANISO_CLAMP]);
|
||||
|
||||
samplerDesc.Filter = FILTER_ANISOTROPIC;
|
||||
samplerDesc.AddressU = TEXTURE_ADDRESS_WRAP;
|
||||
samplerDesc.AddressV = TEXTURE_ADDRESS_WRAP;
|
||||
samplerDesc.AddressW = TEXTURE_ADDRESS_WRAP;
|
||||
samplerDesc.MaxAnisotropy = 16;
|
||||
device->CreateSampler(&samplerDesc, &samplers[SSLOT_ANISO_WRAP]);
|
||||
|
||||
samplerDesc.Filter = FILTER_ANISOTROPIC;
|
||||
samplerDesc.AddressU = TEXTURE_ADDRESS_MIRROR;
|
||||
samplerDesc.AddressV = TEXTURE_ADDRESS_MIRROR;
|
||||
samplerDesc.AddressW = TEXTURE_ADDRESS_MIRROR;
|
||||
samplerDesc.MaxAnisotropy = 16;
|
||||
device->CreateSampler(&samplerDesc, &samplers[SSLOT_ANISO_MIRROR]);
|
||||
|
||||
samplerDesc.Filter = FILTER_ANISOTROPIC;
|
||||
samplerDesc.AddressU = TEXTURE_ADDRESS_WRAP;
|
||||
samplerDesc.AddressV = TEXTURE_ADDRESS_WRAP;
|
||||
samplerDesc.AddressW = TEXTURE_ADDRESS_WRAP;
|
||||
samplerDesc.MaxAnisotropy = 16;
|
||||
device->CreateSampler(&samplerDesc, &samplers[SSLOT_OBJECTSHADER]);
|
||||
|
||||
samplerDesc.Filter = FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT;
|
||||
samplerDesc.AddressU = TEXTURE_ADDRESS_CLAMP;
|
||||
samplerDesc.AddressV = TEXTURE_ADDRESS_CLAMP;
|
||||
samplerDesc.AddressW = TEXTURE_ADDRESS_CLAMP;
|
||||
samplerDesc.MipLODBias = 0.0f;
|
||||
samplerDesc.MaxAnisotropy = 0;
|
||||
samplerDesc.ComparisonFunc = COMPARISON_GREATER_EQUAL;
|
||||
device->CreateSampler(&samplerDesc, &samplers[SSLOT_CMP_DEPTH]);
|
||||
|
||||
|
||||
|
||||
RasterizerState rs;
|
||||
rs.FillMode = FILL_SOLID;
|
||||
rs.CullMode = CULL_BACK;
|
||||
@@ -2237,9 +2278,9 @@ void SetUpStates()
|
||||
blendStates[BSTYPE_TRANSPARENTSHADOW] = bd;
|
||||
}
|
||||
|
||||
void ModifySampler(const SamplerDesc& desc, int slot)
|
||||
void ModifyObjectSampler(const SamplerDesc& desc)
|
||||
{
|
||||
device->CreateSampler(&desc, &samplers[slot]);
|
||||
device->CreateSampler(&desc, &samplers[SSLOT_OBJECTSHADER]);
|
||||
}
|
||||
|
||||
const std::string& GetShaderPath()
|
||||
@@ -8402,10 +8443,7 @@ void BindCommonResources(CommandList cmd)
|
||||
{
|
||||
SHADERSTAGE stage = (SHADERSTAGE)i;
|
||||
|
||||
for (int i = 0; i < SSLOT_COUNT; ++i)
|
||||
{
|
||||
device->BindSampler(stage, &samplers[i], i, cmd);
|
||||
}
|
||||
device->BindSampler(stage, &samplers[SSLOT_OBJECTSHADER], SSLOT_OBJECTSHADER, cmd);
|
||||
|
||||
BindConstantBuffers(stage, cmd);
|
||||
}
|
||||
@@ -11477,6 +11515,14 @@ void Postprocess_Lineardepth(
|
||||
)
|
||||
{
|
||||
device->EventBegin("Postprocess_Lineardepth", cmd);
|
||||
auto range = wiProfiler::BeginRangeGPU("Linear Depth Pyramid", cmd);
|
||||
|
||||
{
|
||||
GPUBarrier barriers[] = {
|
||||
GPUBarrier::Image(&output, IMAGE_LAYOUT_SHADER_RESOURCE, IMAGE_LAYOUT_UNORDERED_ACCESS)
|
||||
};
|
||||
device->Barrier(barriers, arraysize(barriers), cmd);
|
||||
}
|
||||
|
||||
const TextureDesc& desc = output.GetDesc();
|
||||
|
||||
@@ -11509,13 +11555,17 @@ void Postprocess_Lineardepth(
|
||||
cmd
|
||||
);
|
||||
|
||||
GPUBarrier barriers[] = {
|
||||
GPUBarrier::Memory(),
|
||||
};
|
||||
device->Barrier(barriers, arraysize(barriers), cmd);
|
||||
{
|
||||
GPUBarrier barriers[] = {
|
||||
GPUBarrier::Memory(),
|
||||
GPUBarrier::Image(&output, IMAGE_LAYOUT_UNORDERED_ACCESS, IMAGE_LAYOUT_SHADER_RESOURCE)
|
||||
};
|
||||
device->Barrier(barriers, arraysize(barriers), cmd);
|
||||
}
|
||||
|
||||
device->UnbindUAVs(0, 6, cmd);
|
||||
|
||||
wiProfiler::EndRange(range);
|
||||
device->EventEnd(cmd);
|
||||
}
|
||||
void Postprocess_Sharpen(
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace wiRenderer
|
||||
const wiGraphics::GPUBuffer* GetConstantBuffer(CBTYPES id);
|
||||
const wiGraphics::Texture* GetTexture(TEXTYPES id);
|
||||
|
||||
void ModifySampler(const wiGraphics::SamplerDesc& desc, int slot);
|
||||
void ModifyObjectSampler(const wiGraphics::SamplerDesc& desc);
|
||||
|
||||
|
||||
void Initialize();
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace wiVersion
|
||||
// minor features, major updates, breaking compatibility changes
|
||||
const int minor = 51;
|
||||
// minor bug fixes, alterations, refactors, updates
|
||||
const int revision = 49;
|
||||
const int revision = 50;
|
||||
|
||||
const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user