diff --git a/Editor/Editor.cpp b/Editor/Editor.cpp index fe1cf17f5..88e55f147 100644 --- a/Editor/Editor.cpp +++ b/Editor/Editor.cpp @@ -172,17 +172,17 @@ void EditorComponent::ResizeBuffers() desc.BindFlags = BIND_RENDER_TARGET | BIND_SHADER_RESOURCE; if (renderPath->getMSAASampleCount() > 1) { - desc.SampleDesc.Count = renderPath->getMSAASampleCount(); - hr = device->CreateTexture2D(&desc, nullptr, &rt_selectionOutline_MSAA); + desc.SampleCount = renderPath->getMSAASampleCount(); + hr = device->CreateTexture(&desc, nullptr, &rt_selectionOutline_MSAA); assert(SUCCEEDED(hr)); - desc.SampleDesc.Count = 1; + desc.SampleCount = 1; } - hr = device->CreateTexture2D(&desc, nullptr, &rt_selectionOutline[0]); + hr = device->CreateTexture(&desc, nullptr, &rt_selectionOutline[0]); assert(SUCCEEDED(hr)); desc.Format = wiRenderer::RTFormat_hdr; desc.BindFlags = BIND_RENDER_TARGET | BIND_SHADER_RESOURCE | BIND_UNORDERED_ACCESS; - hr = device->CreateTexture2D(&desc, nullptr, &rt_selectionOutline[1]); + hr = device->CreateTexture(&desc, nullptr, &rt_selectionOutline[1]); assert(SUCCEEDED(hr)); } @@ -719,17 +719,17 @@ void EditorComponent::Load() - pointLightTex = *(Texture2D*)Content.add("images/pointlight.dds"); - spotLightTex = *(Texture2D*)Content.add("images/spotlight.dds"); - dirLightTex = *(Texture2D*)Content.add("images/directional_light.dds"); - areaLightTex = *(Texture2D*)Content.add("images/arealight.dds"); - decalTex = *(Texture2D*)Content.add("images/decal.dds"); - forceFieldTex = *(Texture2D*)Content.add("images/forcefield.dds"); - emitterTex = *(Texture2D*)Content.add("images/emitter.dds"); - hairTex = *(Texture2D*)Content.add("images/hair.dds"); - cameraTex = *(Texture2D*)Content.add("images/camera.dds"); - armatureTex = *(Texture2D*)Content.add("images/armature.dds"); - soundTex = *(Texture2D*)Content.add("images/sound.dds"); + pointLightTex = *(Texture*)Content.add("images/pointlight.dds"); + spotLightTex = *(Texture*)Content.add("images/spotlight.dds"); + dirLightTex = *(Texture*)Content.add("images/directional_light.dds"); + areaLightTex = *(Texture*)Content.add("images/arealight.dds"); + decalTex = *(Texture*)Content.add("images/decal.dds"); + forceFieldTex = *(Texture*)Content.add("images/forcefield.dds"); + emitterTex = *(Texture*)Content.add("images/emitter.dds"); + hairTex = *(Texture*)Content.add("images/hair.dds"); + cameraTex = *(Texture*)Content.add("images/camera.dds"); + armatureTex = *(Texture*)Content.add("images/armature.dds"); + soundTex = *(Texture*)Content.add("images/sound.dds"); } void EditorComponent::Start() { diff --git a/Editor/Editor.h b/Editor/Editor.h index ed1d75dc3..4da981f64 100644 --- a/Editor/Editor.h +++ b/Editor/Editor.h @@ -34,7 +34,7 @@ class Editor; class EditorComponent : public RenderPath2D { private: - wiGraphics::Texture2D pointLightTex, spotLightTex, dirLightTex, areaLightTex, decalTex, forceFieldTex, emitterTex, hairTex, cameraTex, armatureTex, soundTex; + wiGraphics::Texture pointLightTex, spotLightTex, dirLightTex, areaLightTex, decalTex, forceFieldTex, emitterTex, hairTex, cameraTex, armatureTex, soundTex; public: std::unique_ptr materialWnd; std::unique_ptr postprocessWnd; @@ -86,8 +86,8 @@ public: EDITORSTENCILREF_HIGHLIGHT_MATERIAL = 0x02, EDITORSTENCILREF_LAST = 0x0F, }; - wiGraphics::Texture2D rt_selectionOutline_MSAA; - wiGraphics::Texture2D rt_selectionOutline[2]; + wiGraphics::Texture rt_selectionOutline_MSAA; + wiGraphics::Texture rt_selectionOutline[2]; wiGraphics::RenderPass renderpass_selectionOutline[2]; float selectionOutlineTimer = 0; const XMFLOAT4 selectionColor = XMFLOAT4(1, 0.6f, 0, 1); diff --git a/Editor/LightWindow.cpp b/Editor/LightWindow.cpp index 2b064b9f8..ffc1c779e 100644 --- a/Editor/LightWindow.cpp +++ b/Editor/LightWindow.cpp @@ -277,7 +277,7 @@ LightWindow::LightWindow(wiGUI* gui) : GUI(gui) if (result.ok) { std::string fileName = result.filenames.front(); - light->lensFlareRimTextures[i] = (Texture2D*)wiResourceManager::GetGlobal().add(fileName); + light->lensFlareRimTextures[i] = (Texture*)wiResourceManager::GetGlobal().add(fileName); light->lensFlareNames[i] = fileName; fileName = wiHelper::GetFileNameFromPath(fileName); lensflare_Button[i]->SetText(fileName); diff --git a/Editor/MaterialWindow.cpp b/Editor/MaterialWindow.cpp index ebfffef11..b2acb9295 100644 --- a/Editor/MaterialWindow.cpp +++ b/Editor/MaterialWindow.cpp @@ -419,7 +419,7 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) if (result.ok) { string fileName = result.filenames.front(); - material->baseColorMap = (Texture2D*)wiResourceManager::GetGlobal().add(fileName); + material->baseColorMap = (Texture*)wiResourceManager::GetGlobal().add(fileName); material->baseColorMapName = fileName; material->SetDirty(); fileName = wiHelper::GetFileNameFromPath(fileName); @@ -481,7 +481,7 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) if (result.ok) { string fileName = result.filenames.front(); - material->normalMap = (Texture2D*)wiResourceManager::GetGlobal().add(fileName); + material->normalMap = (Texture*)wiResourceManager::GetGlobal().add(fileName); material->normalMapName = fileName; material->SetDirty(); fileName = wiHelper::GetFileNameFromPath(fileName); @@ -543,7 +543,7 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) if (result.ok) { string fileName = result.filenames.front(); - material->surfaceMap = (Texture2D*)wiResourceManager::GetGlobal().add(fileName); + material->surfaceMap = (Texture*)wiResourceManager::GetGlobal().add(fileName); material->surfaceMapName = fileName; material->SetDirty(); fileName = wiHelper::GetFileNameFromPath(fileName); @@ -605,7 +605,7 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) if (result.ok) { string fileName = result.filenames.front(); - material->displacementMap = (Texture2D*)wiResourceManager::GetGlobal().add(fileName); + material->displacementMap = (Texture*)wiResourceManager::GetGlobal().add(fileName); material->displacementMapName = fileName; material->SetDirty(); fileName = wiHelper::GetFileNameFromPath(fileName); @@ -667,7 +667,7 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) if (result.ok) { string fileName = result.filenames.front(); - material->emissiveMap = (Texture2D*)wiResourceManager::GetGlobal().add(fileName); + material->emissiveMap = (Texture*)wiResourceManager::GetGlobal().add(fileName); material->emissiveMapName = fileName; material->SetDirty(); fileName = wiHelper::GetFileNameFromPath(fileName); @@ -730,7 +730,7 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) if (result.ok) { string fileName = result.filenames.front(); - material->occlusionMap = (Texture2D*)wiResourceManager::GetGlobal().add(fileName); + material->occlusionMap = (Texture*)wiResourceManager::GetGlobal().add(fileName); material->occlusionMapName = fileName; material->SetDirty(); fileName = wiHelper::GetFileNameFromPath(fileName); diff --git a/Editor/ModelImporter_GLTF.cpp b/Editor/ModelImporter_GLTF.cpp index 5d09ae664..e08af4cf5 100644 --- a/Editor/ModelImporter_GLTF.cpp +++ b/Editor/ModelImporter_GLTF.cpp @@ -91,7 +91,7 @@ namespace tinygltf } } -void RegisterTexture2D(tinygltf::Image *image, const string& type_name) +void RegisterTexture(tinygltf::Image *image, const string& type_name) { // We will load the texture2d by hand here and register to the resource manager (if it was not already registered) if (wiResourceManager::GetGlobal().get(wiHashString(image->uri)).data == nullptr) @@ -124,8 +124,8 @@ void RegisterTexture2D(tinygltf::Image *image, const string& type_name) mipwidth = std::max(1u, mipwidth / 2); } - Texture2D* tex = new Texture2D; - HRESULT hr = device->CreateTexture2D(&desc, InitData.data(), tex); + Texture* tex = new Texture; + HRESULT hr = device->CreateTexture(&desc, InitData.data(), tex); assert(SUCCEEDED(hr)); for (UINT i = 0; i < tex->GetDesc().MipLevels; ++i) @@ -155,7 +155,7 @@ void RegisterTexture2D(tinygltf::Image *image, const string& type_name) } // We loaded the texture2d, so register to the resource manager to be retrieved later: - wiResourceManager::GetGlobal().Register(image->uri, tex, wiResourceManager::IMAGE_2D); + wiResourceManager::GetGlobal().Register(image->uri, tex, wiResourceManager::IMAGE); } } } @@ -347,7 +347,7 @@ void ImportModel_GLTF(const std::string& fileName, Scene& scene) { auto& tex = state.gltfModel.textures[baseColorTexture->second.TextureIndex()]; auto& img = state.gltfModel.images[tex.source]; - RegisterTexture2D(&img, "basecolor"); + RegisterTexture(&img, "basecolor"); material.baseColorMapName = img.uri; material.uvset_baseColorMap = baseColorTexture->second.TextureTexCoord(); } @@ -355,7 +355,7 @@ void ImportModel_GLTF(const std::string& fileName, Scene& scene) { auto& tex = state.gltfModel.textures[normalTexture->second.TextureIndex()]; auto& img = state.gltfModel.images[tex.source]; - RegisterTexture2D(&img, "normal"); + RegisterTexture(&img, "normal"); material.normalMapName = img.uri; material.SetFlipNormalMap(true); // gltf import will always flip normal map by default material.uvset_normalMap = normalTexture->second.TextureTexCoord(); @@ -364,7 +364,7 @@ void ImportModel_GLTF(const std::string& fileName, Scene& scene) { auto& tex = state.gltfModel.textures[metallicRoughnessTexture->second.TextureIndex()]; auto& img = state.gltfModel.images[tex.source]; - RegisterTexture2D(&img, "roughness_metallic"); + RegisterTexture(&img, "roughness_metallic"); material.surfaceMapName = img.uri; material.uvset_surfaceMap = metallicRoughnessTexture->second.TextureTexCoord(); } @@ -372,7 +372,7 @@ void ImportModel_GLTF(const std::string& fileName, Scene& scene) { auto& tex = state.gltfModel.textures[emissiveTexture->second.TextureIndex()]; auto& img = state.gltfModel.images[tex.source]; - RegisterTexture2D(&img, "emissive"); + RegisterTexture(&img, "emissive"); material.emissiveMapName = img.uri; material.uvset_emissiveMap = emissiveTexture->second.TextureTexCoord(); } @@ -380,7 +380,7 @@ void ImportModel_GLTF(const std::string& fileName, Scene& scene) { auto& tex = state.gltfModel.textures[occlusionTexture->second.TextureIndex()]; auto& img = state.gltfModel.images[tex.source]; - RegisterTexture2D(&img, "occlusion"); + RegisterTexture(&img, "occlusion"); material.occlusionMapName = img.uri; material.uvset_occlusionMap = occlusionTexture->second.TextureTexCoord(); material.SetOcclusionEnabled_Secondary(true); @@ -431,7 +431,7 @@ void ImportModel_GLTF(const std::string& fileName, Scene& scene) int index = specularGlossinessWorkflow->second.Get("diffuseTexture").Get("index").Get(); auto& tex = state.gltfModel.textures[index]; auto& img = state.gltfModel.images[tex.source]; - RegisterTexture2D(&img, "diffuse"); + RegisterTexture(&img, "diffuse"); material.baseColorMapName = img.uri; material.uvset_baseColorMap = (uint32_t)specularGlossinessWorkflow->second.Get("diffuseTexture").Get("texCoord").Get(); } @@ -440,7 +440,7 @@ void ImportModel_GLTF(const std::string& fileName, Scene& scene) int index = specularGlossinessWorkflow->second.Get("specularGlossinessTexture").Get("index").Get(); auto& tex = state.gltfModel.textures[index]; auto& img = state.gltfModel.images[tex.source]; - RegisterTexture2D(&img, "specular_glossiness"); + RegisterTexture(&img, "specular_glossiness"); material.surfaceMapName = img.uri; material.uvset_surfaceMap = (uint32_t)specularGlossinessWorkflow->second.Get("specularGlossinessTexture").Get("texCoord").Get(); } @@ -473,15 +473,15 @@ void ImportModel_GLTF(const std::string& fileName, Scene& scene) // Retrieve textures by name: if (!material.baseColorMapName.empty()) - material.baseColorMap = (Texture2D*)wiResourceManager::GetGlobal().add(material.baseColorMapName); + material.baseColorMap = (Texture*)wiResourceManager::GetGlobal().add(material.baseColorMapName); if (!material.normalMapName.empty()) - material.normalMap = (Texture2D*)wiResourceManager::GetGlobal().add(material.normalMapName); + material.normalMap = (Texture*)wiResourceManager::GetGlobal().add(material.normalMapName); if (!material.surfaceMapName.empty()) - material.surfaceMap = (Texture2D*)wiResourceManager::GetGlobal().add(material.surfaceMapName); + material.surfaceMap = (Texture*)wiResourceManager::GetGlobal().add(material.surfaceMapName); if (!material.emissiveMapName.empty()) - material.emissiveMap = (Texture2D*)wiResourceManager::GetGlobal().add(material.emissiveMapName); + material.emissiveMap = (Texture*)wiResourceManager::GetGlobal().add(material.emissiveMapName); if (!material.occlusionMapName.empty()) - material.occlusionMap = (Texture2D*)wiResourceManager::GetGlobal().add(material.occlusionMapName); + material.occlusionMap = (Texture*)wiResourceManager::GetGlobal().add(material.occlusionMapName); } diff --git a/Editor/ModelImporter_OBJ.cpp b/Editor/ModelImporter_OBJ.cpp index 8d129c698..290445b6a 100644 --- a/Editor/ModelImporter_OBJ.cpp +++ b/Editor/ModelImporter_OBJ.cpp @@ -66,19 +66,19 @@ void ImportModel_OBJ(const std::string& fileName, Scene& scene) if (!material.surfaceMapName.empty()) { - material.surfaceMap = (Texture2D*)wiResourceManager::GetGlobal().add(directory + material.surfaceMapName); + material.surfaceMap = (Texture*)wiResourceManager::GetGlobal().add(directory + material.surfaceMapName); } if (!material.baseColorMapName.empty()) { - material.baseColorMap = (Texture2D*)wiResourceManager::GetGlobal().add(directory + material.baseColorMapName); + material.baseColorMap = (Texture*)wiResourceManager::GetGlobal().add(directory + material.baseColorMapName); } if (!material.normalMapName.empty()) { - material.normalMap = (Texture2D*)wiResourceManager::GetGlobal().add(directory + material.normalMapName); + material.normalMap = (Texture*)wiResourceManager::GetGlobal().add(directory + material.normalMapName); } if (!material.displacementMapName.empty()) { - material.displacementMap = (Texture2D*)wiResourceManager::GetGlobal().add(directory + material.displacementMapName); + material.displacementMap = (Texture*)wiResourceManager::GetGlobal().add(directory + material.displacementMapName); } materialLibrary.push_back(materialEntity); // for subset-indexing... diff --git a/Editor/PostprocessWindow.cpp b/Editor/PostprocessWindow.cpp index a9f47c287..542167667 100644 --- a/Editor/PostprocessWindow.cpp +++ b/Editor/PostprocessWindow.cpp @@ -217,7 +217,7 @@ PostprocessWindow::PostprocessWindow(wiGUI* gui, RenderPath3D* comp) : GUI(gui), if (result.ok) { string fileName = result.filenames.front(); - component->setColorGradingTexture((Texture2D*)wiResourceManager::GetGlobal().add(fileName)); + component->setColorGradingTexture((Texture*)wiResourceManager::GetGlobal().add(fileName)); if (component->getColorGradingTexture() != nullptr) { colorGradingButton->SetText(fileName); diff --git a/Editor/WeatherWindow.cpp b/Editor/WeatherWindow.cpp index 23403ca81..cfb0a2335 100644 --- a/Editor/WeatherWindow.cpp +++ b/Editor/WeatherWindow.cpp @@ -108,7 +108,7 @@ WeatherWindow::WeatherWindow(wiGUI* gui) : GUI(gui) if (result.ok) { string fileName = result.filenames.front(); - wiRenderer::SetEnvironmentMap((Texture2D*)wiResourceManager::GetGlobal().add(fileName)); + wiRenderer::SetEnvironmentMap((Texture*)wiResourceManager::GetGlobal().add(fileName)); skyButton->SetText(fileName); } } diff --git a/WickedEngine/RenderPath2D.cpp b/WickedEngine/RenderPath2D.cpp index 3deefe46a..390828c6c 100644 --- a/WickedEngine/RenderPath2D.cpp +++ b/WickedEngine/RenderPath2D.cpp @@ -28,7 +28,7 @@ void RenderPath2D::ResizeBuffers() desc.Format = defaultTextureFormat; desc.Width = wiRenderer::GetInternalResolution().x; desc.Height = wiRenderer::GetInternalResolution().y; - device->CreateTexture2D(&desc, nullptr, &rtStenciled); + device->CreateTexture(&desc, nullptr, &rtStenciled); device->SetName(&rtStenciled, "rtStenciled"); } { @@ -37,11 +37,11 @@ void RenderPath2D::ResizeBuffers() desc.Format = defaultTextureFormat; desc.Width = device->GetScreenWidth(); desc.Height = device->GetScreenHeight(); - device->CreateTexture2D(&desc, nullptr, &rtFinal); + device->CreateTexture(&desc, nullptr, &rtFinal); device->SetName(&rtFinal, "rtFinal"); } - const Texture2D* dsv = GetDepthStencil(); + const Texture* dsv = GetDepthStencil(); if (dsv != nullptr && wiRenderer::GetResolutionScale() != 1.0f) { RenderPassDesc desc; diff --git a/WickedEngine/RenderPath2D.h b/WickedEngine/RenderPath2D.h index 6aa8b0dc3..833e897a3 100644 --- a/WickedEngine/RenderPath2D.h +++ b/WickedEngine/RenderPath2D.h @@ -33,8 +33,8 @@ class RenderPath2D : public RenderPath { private: - wiGraphics::Texture2D rtStenciled; - wiGraphics::Texture2D rtFinal; + wiGraphics::Texture rtStenciled; + wiGraphics::Texture rtFinal; wiGraphics::RenderPass renderpass_stenciled; wiGraphics::RenderPass renderpass_final; @@ -56,8 +56,8 @@ public: void Render() const override; void Compose(wiGraphics::CommandList cmd) const override; - const wiGraphics::Texture2D& GetRenderResult() const { return rtFinal; } - virtual const wiGraphics::Texture2D* GetDepthStencil() const { return nullptr; } + const wiGraphics::Texture& GetRenderResult() const { return rtFinal; } + virtual const wiGraphics::Texture* GetDepthStencil() const { return nullptr; } void addSprite(wiSprite* sprite, const std::string& layer = DEFAULT_RENDERLAYER); void removeSprite(wiSprite* sprite); diff --git a/WickedEngine/RenderPath3D.cpp b/WickedEngine/RenderPath3D.cpp index 2bc65991a..ff8cd004a 100644 --- a/WickedEngine/RenderPath3D.cpp +++ b/WickedEngine/RenderPath3D.cpp @@ -24,7 +24,7 @@ void RenderPath3D::ResizeBuffers() desc.Width = wiRenderer::GetInternalResolution().x / 2; desc.Height = wiRenderer::GetInternalResolution().y / 2; desc.MipLevels = 5; - device->CreateTexture2D(&desc, nullptr, &rtSSR); + device->CreateTexture(&desc, nullptr, &rtSSR); device->SetName(&rtSSR, "rtSSR"); for (UINT i = 0; i < rtSSR.GetDesc().MipLevels; ++i) @@ -42,13 +42,13 @@ void RenderPath3D::ResizeBuffers() desc.Format = wiRenderer::RTFormat_hdr; desc.Width = wiRenderer::GetInternalResolution().x; desc.Height = wiRenderer::GetInternalResolution().y; - desc.SampleDesc.Count = getMSAASampleCount(); - device->CreateTexture2D(&desc, nullptr, &rtParticleDistortion); + desc.SampleCount = getMSAASampleCount(); + device->CreateTexture(&desc, nullptr, &rtParticleDistortion); device->SetName(&rtParticleDistortion, "rtParticleDistortion"); if (getMSAASampleCount() > 1) { - desc.SampleDesc.Count = 1; - device->CreateTexture2D(&desc, nullptr, &rtParticleDistortion_Resolved); + desc.SampleCount = 1; + device->CreateTexture(&desc, nullptr, &rtParticleDistortion_Resolved); device->SetName(&rtParticleDistortion_Resolved, "rtParticleDistortion_Resolved"); } } @@ -58,7 +58,7 @@ void RenderPath3D::ResizeBuffers() desc.Format = wiRenderer::RTFormat_hdr; desc.Width = wiRenderer::GetInternalResolution().x / 4; desc.Height = wiRenderer::GetInternalResolution().y / 4; - device->CreateTexture2D(&desc, nullptr, &rtVolumetricLights); + device->CreateTexture(&desc, nullptr, &rtVolumetricLights); device->SetName(&rtVolumetricLights, "rtVolumetricLights"); } { @@ -67,7 +67,7 @@ void RenderPath3D::ResizeBuffers() desc.Format = wiRenderer::RTFormat_waterripple; desc.Width = wiRenderer::GetInternalResolution().x; desc.Height = wiRenderer::GetInternalResolution().y; - device->CreateTexture2D(&desc, nullptr, &rtWaterRipple); + device->CreateTexture(&desc, nullptr, &rtWaterRipple); device->SetName(&rtWaterRipple, "rtWaterRipple"); } { @@ -77,7 +77,7 @@ void RenderPath3D::ResizeBuffers() desc.Width = wiRenderer::GetInternalResolution().x; desc.Height = wiRenderer::GetInternalResolution().y; desc.MipLevels = 8; - device->CreateTexture2D(&desc, nullptr, &rtSceneCopy); + device->CreateTexture(&desc, nullptr, &rtSceneCopy); device->SetName(&rtSceneCopy, "rtSceneCopy"); for (UINT i = 0; i < rtSceneCopy.GetDesc().MipLevels; ++i) @@ -96,7 +96,7 @@ void RenderPath3D::ResizeBuffers() desc.Width = wiRenderer::GetInternalResolution().x / 4; desc.Height = wiRenderer::GetInternalResolution().y / 4; desc.layout = IMAGE_LAYOUT_SHADER_RESOURCE; - device->CreateTexture2D(&desc, nullptr, &rtReflection); + device->CreateTexture(&desc, nullptr, &rtReflection); device->SetName(&rtReflection, "rtReflection"); } { @@ -105,9 +105,9 @@ void RenderPath3D::ResizeBuffers() desc.Format = wiRenderer::RTFormat_hdr; desc.Width = wiRenderer::GetInternalResolution().x / 2; desc.Height = wiRenderer::GetInternalResolution().y / 2; - device->CreateTexture2D(&desc, nullptr, &rtDof[0]); + device->CreateTexture(&desc, nullptr, &rtDof[0]); device->SetName(&rtDof[0], "rtDof[0]"); - device->CreateTexture2D(&desc, nullptr, &rtDof[1]); + device->CreateTexture(&desc, nullptr, &rtDof[1]); device->SetName(&rtDof[1], "rtDof[1]"); } { @@ -116,9 +116,9 @@ void RenderPath3D::ResizeBuffers() desc.Format = wiRenderer::RTFormat_ssao; desc.Width = wiRenderer::GetInternalResolution().x / 2; desc.Height = wiRenderer::GetInternalResolution().y / 2; - device->CreateTexture2D(&desc, nullptr, &rtSSAO[0]); + device->CreateTexture(&desc, nullptr, &rtSSAO[0]); device->SetName(&rtSSAO[0], "rtSSAO[0]"); - device->CreateTexture2D(&desc, nullptr, &rtSSAO[1]); + device->CreateTexture(&desc, nullptr, &rtSSAO[1]); device->SetName(&rtSSAO[1], "rtSSAO[1]"); } { @@ -127,23 +127,23 @@ void RenderPath3D::ResizeBuffers() desc.Format = defaultTextureFormat; desc.Width = wiRenderer::GetInternalResolution().x; desc.Height = wiRenderer::GetInternalResolution().y; - desc.SampleDesc.Count = getMSAASampleCount(); - device->CreateTexture2D(&desc, nullptr, &rtSun[0]); + desc.SampleCount = getMSAASampleCount(); + device->CreateTexture(&desc, nullptr, &rtSun[0]); device->SetName(&rtSun[0], "rtSun[0]"); desc.BindFlags = BIND_SHADER_RESOURCE | BIND_UNORDERED_ACCESS; - desc.SampleDesc.Count = 1; + desc.SampleCount = 1; desc.Width = wiRenderer::GetInternalResolution().x / 2; desc.Height = wiRenderer::GetInternalResolution().y / 2; - device->CreateTexture2D(&desc, nullptr, &rtSun[1]); + device->CreateTexture(&desc, nullptr, &rtSun[1]); device->SetName(&rtSun[1], "rtSun[1]"); if (getMSAASampleCount() > 1) { desc.Width = wiRenderer::GetInternalResolution().x; desc.Height = wiRenderer::GetInternalResolution().y; - desc.SampleDesc.Count = 1; - device->CreateTexture2D(&desc, nullptr, &rtSun_resolved); + desc.SampleCount = 1; + device->CreateTexture(&desc, nullptr, &rtSun_resolved); device->SetName(&rtSun_resolved, "rtSun_resolved"); } } @@ -154,7 +154,7 @@ void RenderPath3D::ResizeBuffers() desc.Width = wiRenderer::GetInternalResolution().x / 4; desc.Height = wiRenderer::GetInternalResolution().y / 4; desc.MipLevels = 5; - device->CreateTexture2D(&desc, nullptr, &rtBloom); + device->CreateTexture(&desc, nullptr, &rtBloom); device->SetName(&rtBloom, "rtBloom"); for (UINT i = 0; i < rtBloom.GetDesc().MipLevels; ++i) @@ -172,9 +172,9 @@ void RenderPath3D::ResizeBuffers() desc.Format = wiRenderer::RTFormat_hdr; desc.Width = wiRenderer::GetInternalResolution().x; desc.Height = wiRenderer::GetInternalResolution().y; - device->CreateTexture2D(&desc, nullptr, &rtTemporalAA[0]); + device->CreateTexture(&desc, nullptr, &rtTemporalAA[0]); device->SetName(&rtTemporalAA[0], "rtTemporalAA[0]"); - device->CreateTexture2D(&desc, nullptr, &rtTemporalAA[1]); + device->CreateTexture(&desc, nullptr, &rtTemporalAA[1]); device->SetName(&rtTemporalAA[1], "rtTemporalAA[1]"); } { @@ -183,7 +183,7 @@ void RenderPath3D::ResizeBuffers() desc.Format = wiRenderer::RTFormat_hdr; desc.Width = wiRenderer::GetInternalResolution().x; desc.Height = wiRenderer::GetInternalResolution().y; - device->CreateTexture2D(&desc, nullptr, &rtPostprocess_HDR); + device->CreateTexture(&desc, nullptr, &rtPostprocess_HDR); device->SetName(&rtPostprocess_HDR, "rtPostprocess_HDR"); } { @@ -192,9 +192,9 @@ void RenderPath3D::ResizeBuffers() desc.Format = defaultTextureFormat; desc.Width = wiRenderer::GetInternalResolution().x; desc.Height = wiRenderer::GetInternalResolution().y; - device->CreateTexture2D(&desc, nullptr, &rtPostprocess_LDR[0]); + device->CreateTexture(&desc, nullptr, &rtPostprocess_LDR[0]); device->SetName(&rtPostprocess_LDR[0], "rtPostprocess_LDR[0]"); - device->CreateTexture2D(&desc, nullptr, &rtPostprocess_LDR[1]); + device->CreateTexture(&desc, nullptr, &rtPostprocess_LDR[1]); device->SetName(&rtPostprocess_LDR[1], "rtPostprocess_LDR[1]"); } @@ -206,8 +206,8 @@ void RenderPath3D::ResizeBuffers() desc.Format = wiRenderer::DSFormat_full_alias; desc.BindFlags = BIND_DEPTH_STENCIL | BIND_SHADER_RESOURCE; - desc.SampleDesc.Count = getMSAASampleCount(); - device->CreateTexture2D(&desc, nullptr, &depthBuffer); + desc.SampleCount = getMSAASampleCount(); + device->CreateTexture(&desc, nullptr, &depthBuffer); device->SetName(&depthBuffer, "depthBuffer"); if (getMSAASampleCount() > 1) @@ -219,8 +219,8 @@ void RenderPath3D::ResizeBuffers() { desc.Format = wiRenderer::DSFormat_full_alias; } - desc.SampleDesc.Count = 1; - device->CreateTexture2D(&desc, nullptr, &depthBuffer_Copy); + desc.SampleCount = 1; + device->CreateTexture(&desc, nullptr, &depthBuffer_Copy); device->SetName(&depthBuffer_Copy, "depthBuffer_Copy"); } { @@ -230,7 +230,7 @@ void RenderPath3D::ResizeBuffers() desc.Width = wiRenderer::GetInternalResolution().x / 4; desc.Height = wiRenderer::GetInternalResolution().y / 4; desc.layout = IMAGE_LAYOUT_DEPTHSTENCIL; - device->CreateTexture2D(&desc, nullptr, &depthBuffer_Reflection); + device->CreateTexture(&desc, nullptr, &depthBuffer_Reflection); device->SetName(&depthBuffer_Reflection, "depthBuffer_Reflection"); } { @@ -239,7 +239,7 @@ void RenderPath3D::ResizeBuffers() desc.Format = wiRenderer::RTFormat_lineardepth; desc.Width = wiRenderer::GetInternalResolution().x; desc.Height = wiRenderer::GetInternalResolution().y; - device->CreateTexture2D(&desc, nullptr, &rtLinearDepth); + device->CreateTexture(&desc, nullptr, &rtLinearDepth); device->SetName(&rtLinearDepth, "rtLinearDepth"); } { @@ -249,7 +249,7 @@ void RenderPath3D::ResizeBuffers() desc.Width = wiRenderer::GetInternalResolution().x / 4; desc.Height = wiRenderer::GetInternalResolution().y / 4; desc.layout = IMAGE_LAYOUT_DEPTHSTENCIL_READONLY; - device->CreateTexture2D(&desc, nullptr, &smallDepth); + device->CreateTexture(&desc, nullptr, &smallDepth); device->SetName(&smallDepth, "smallDepth"); } @@ -332,7 +332,7 @@ void RenderPath3D::Compose(CommandList cmd) const if (wiRenderer::GetDebugLightCulling()) { - wiImage::Draw((Texture2D*)wiRenderer::GetTexture(TEXTYPE_2D_DEBUGUAV), wiImageParams((float)wiRenderer::GetDevice()->GetScreenWidth(), (float)wiRenderer::GetDevice()->GetScreenHeight()), cmd); + wiImage::Draw((Texture*)wiRenderer::GetTexture(TEXTYPE_2D_DEBUGUAV), wiImageParams((float)wiRenderer::GetDevice()->GetScreenWidth(), (float)wiRenderer::GetDevice()->GetScreenHeight()), cmd); } RenderPath2D::Compose(cmd); @@ -427,7 +427,7 @@ void RenderPath3D::RenderSSAO(CommandList cmd) const ); } } -void RenderPath3D::RenderSSR(const Texture2D& srcSceneRT, const wiGraphics::Texture2D& gbuffer1, CommandList cmd) const +void RenderPath3D::RenderSSR(const Texture& srcSceneRT, const wiGraphics::Texture& gbuffer1, CommandList cmd) const { if (getSSREnabled()) { @@ -449,7 +449,7 @@ void RenderPath3D::DownsampleDepthBuffer(CommandList cmd) const device->RenderPassEnd(cmd); } -void RenderPath3D::RenderOutline(const Texture2D& dstSceneRT, CommandList cmd) const +void RenderPath3D::RenderOutline(const Texture& dstSceneRT, CommandList cmd) const { if (getOutlineEnabled()) { @@ -480,7 +480,7 @@ void RenderPath3D::RenderLightShafts(CommandList cmd) const device->RenderPassEnd(cmd); } - const Texture2D* sunSource = &rtSun[0]; + const Texture* sunSource = &rtSun[0]; if (getMSAASampleCount() > 1) { device->MSAAResolve(&rtSun_resolved, sunSource, cmd); @@ -519,7 +519,7 @@ void RenderPath3D::RenderVolumetrics(CommandList cmd) const device->RenderPassEnd(cmd); } } -void RenderPath3D::RenderRefractionSource(const Texture2D& srcSceneRT, CommandList cmd) const +void RenderPath3D::RenderRefractionSource(const Texture& srcSceneRT, CommandList cmd) const { GraphicsDevice* device = wiRenderer::GetDevice(); @@ -625,7 +625,7 @@ void RenderPath3D::RenderTransparents(const RenderPass& renderpass_transparent, } } } -void RenderPath3D::TemporalAAResolve(const Texture2D& srcdstSceneRT, const Texture2D& srcGbuffer1, CommandList cmd) const +void RenderPath3D::TemporalAAResolve(const Texture& srcdstSceneRT, const Texture& srcGbuffer1, CommandList cmd) const { if (wiRenderer::GetTemporalAAEnabled() && !wiRenderer::GetTemporalAADebugEnabled()) { @@ -682,12 +682,12 @@ void RenderPath3D::RenderBloom(const RenderPass& renderpass_bloom, CommandList c device->EventEnd(cmd); } } -void RenderPath3D::RenderPostprocessChain(const Texture2D& srcSceneRT, const Texture2D& srcGbuffer1, CommandList cmd) const +void RenderPath3D::RenderPostprocessChain(const Texture& srcSceneRT, const Texture& srcGbuffer1, CommandList cmd) const { GraphicsDevice* device = wiRenderer::GetDevice(); - const Texture2D* rt_read = &srcSceneRT; - const Texture2D* rt_write = &rtPostprocess_HDR; + const Texture* rt_read = &srcSceneRT; + const Texture* rt_write = &rtPostprocess_HDR; // 1.) HDR post process chain { diff --git a/WickedEngine/RenderPath3D.h b/WickedEngine/RenderPath3D.h index 01f1a49fb..9b3db0ae2 100644 --- a/WickedEngine/RenderPath3D.h +++ b/WickedEngine/RenderPath3D.h @@ -39,33 +39,33 @@ private: bool outlineEnabled = false; bool chromaticAberrationEnabled = false; - const wiGraphics::Texture2D* colorGradingTex = nullptr; + const wiGraphics::Texture* colorGradingTex = nullptr; UINT msaaSampleCount = 1; protected: - wiGraphics::Texture2D rtReflection; // conains the scene rendered for planar reflections - wiGraphics::Texture2D rtSSR; // screen-space reflection results - wiGraphics::Texture2D rtSceneCopy; // contains the rendered scene that can be fed into transparent pass for distortion effect - wiGraphics::Texture2D rtWaterRipple; // water ripple sprite normal maps are rendered into this - wiGraphics::Texture2D rtParticleDistortion; // contains distortive particles - wiGraphics::Texture2D rtParticleDistortion_Resolved; // contains distortive particles - wiGraphics::Texture2D rtVolumetricLights; // contains the volumetric light results - wiGraphics::Texture2D rtDof[2]; // depth of field blurred out-of focus part - wiGraphics::Texture2D rtTemporalAA[2]; // temporal AA history buffer - wiGraphics::Texture2D rtBloom; // contains the bright parts of the image + mipchain - wiGraphics::Texture2D rtSSAO[2]; // ping-pong when rendering and blurring SSAO - wiGraphics::Texture2D rtSun[2]; // 0: sun render target used for lightshafts (can be MSAA), 1: radial blurred lightshafts - wiGraphics::Texture2D rtSun_resolved; // sun render target, but the resolved version if MSAA is enabled + wiGraphics::Texture rtReflection; // conains the scene rendered for planar reflections + wiGraphics::Texture rtSSR; // screen-space reflection results + wiGraphics::Texture rtSceneCopy; // contains the rendered scene that can be fed into transparent pass for distortion effect + wiGraphics::Texture rtWaterRipple; // water ripple sprite normal maps are rendered into this + wiGraphics::Texture rtParticleDistortion; // contains distortive particles + wiGraphics::Texture rtParticleDistortion_Resolved; // contains distortive particles + wiGraphics::Texture rtVolumetricLights; // contains the volumetric light results + wiGraphics::Texture rtDof[2]; // depth of field blurred out-of focus part + wiGraphics::Texture rtTemporalAA[2]; // temporal AA history buffer + wiGraphics::Texture rtBloom; // contains the bright parts of the image + mipchain + wiGraphics::Texture rtSSAO[2]; // ping-pong when rendering and blurring SSAO + wiGraphics::Texture rtSun[2]; // 0: sun render target used for lightshafts (can be MSAA), 1: radial blurred lightshafts + wiGraphics::Texture rtSun_resolved; // sun render target, but the resolved version if MSAA is enabled - wiGraphics::Texture2D rtPostprocess_HDR; // ping-pong with main scene RT in HDR post-process chain - wiGraphics::Texture2D rtPostprocess_LDR[2]; // ping-pong with itself in LDR post-process chain + wiGraphics::Texture rtPostprocess_HDR; // ping-pong with main scene RT in HDR post-process chain + wiGraphics::Texture rtPostprocess_LDR[2]; // ping-pong with itself in LDR post-process chain - wiGraphics::Texture2D depthBuffer; // used for depth-testing, can be MSAA - wiGraphics::Texture2D depthBuffer_Copy; // used for shader resource, single sample - wiGraphics::Texture2D depthBuffer_Reflection; // used for reflection, single sample - wiGraphics::Texture2D rtLinearDepth; // linear depth result - wiGraphics::Texture2D smallDepth; // downsampled depth buffer + wiGraphics::Texture depthBuffer; // used for depth-testing, can be MSAA + wiGraphics::Texture depthBuffer_Copy; // used for shader resource, single sample + wiGraphics::Texture depthBuffer_Reflection; // used for reflection, single sample + wiGraphics::Texture rtLinearDepth; // linear depth result + wiGraphics::Texture smallDepth; // downsampled depth buffer wiGraphics::RenderPass renderpass_occlusionculling; wiGraphics::RenderPass renderpass_reflection; @@ -76,7 +76,7 @@ protected: wiGraphics::RenderPass renderpass_waterripples; // Post-processes are ping-ponged, this function helps to obtain the last postprocess render target that was written - const wiGraphics::Texture2D* GetLastPostprocessRT() const + const wiGraphics::Texture* GetLastPostprocessRT() const { int ldr_postprocess_count = 0; ldr_postprocess_count += sharpenFilterEnabled ? 1 : 0; @@ -95,19 +95,19 @@ protected: virtual void RenderLinearDepth(wiGraphics::CommandList cmd) const; virtual void RenderSSAO(wiGraphics::CommandList cmd) const; - virtual void RenderSSR(const wiGraphics::Texture2D& srcSceneRT, const wiGraphics::Texture2D& gbuffer1, wiGraphics::CommandList cmd) const; + virtual void RenderSSR(const wiGraphics::Texture& srcSceneRT, const wiGraphics::Texture& gbuffer1, wiGraphics::CommandList cmd) const; virtual void DownsampleDepthBuffer(wiGraphics::CommandList cmd) const; - virtual void RenderOutline(const wiGraphics::Texture2D& dstSceneRT, wiGraphics::CommandList cmd) const; + virtual void RenderOutline(const wiGraphics::Texture& dstSceneRT, wiGraphics::CommandList cmd) const; virtual void RenderLightShafts(wiGraphics::CommandList cmd) const; virtual void RenderVolumetrics(wiGraphics::CommandList cmd) const; - virtual void RenderRefractionSource(const wiGraphics::Texture2D& srcSceneRT, wiGraphics::CommandList cmd) const; + virtual void RenderRefractionSource(const wiGraphics::Texture& srcSceneRT, wiGraphics::CommandList cmd) const; virtual void RenderTransparents(const wiGraphics::RenderPass& renderpass_transparent, RENDERPASS renderPass, wiGraphics::CommandList cmd) const; - virtual void TemporalAAResolve(const wiGraphics::Texture2D& srcdstSceneRT, const wiGraphics::Texture2D& srcGbuffer1, wiGraphics::CommandList cmd) const; + virtual void TemporalAAResolve(const wiGraphics::Texture& srcdstSceneRT, const wiGraphics::Texture& srcGbuffer1, wiGraphics::CommandList cmd) const; virtual void RenderBloom(const wiGraphics::RenderPass& renderpass_bloom, wiGraphics::CommandList cmd) const; - virtual void RenderPostprocessChain(const wiGraphics::Texture2D& srcSceneRT, const wiGraphics::Texture2D& srcGbuffer1, wiGraphics::CommandList cmd) const; + virtual void RenderPostprocessChain(const wiGraphics::Texture& srcSceneRT, const wiGraphics::Texture& srcGbuffer1, wiGraphics::CommandList cmd) const; public: - const wiGraphics::Texture2D* GetDepthStencil() const override { return &depthBuffer; } + const wiGraphics::Texture* GetDepthStencil() const override { return &depthBuffer; } constexpr float getExposure() const { return exposure; } constexpr float getBloomThreshold() const { return bloomThreshold; } @@ -141,7 +141,7 @@ public: constexpr bool getOutlineEnabled() const { return outlineEnabled; } constexpr bool getChromaticAberrationEnabled() const { return chromaticAberrationEnabled; } - constexpr const wiGraphics::Texture2D* getColorGradingTexture() const { return colorGradingTex; } + constexpr const wiGraphics::Texture* getColorGradingTexture() const { return colorGradingTex; } constexpr UINT getMSAASampleCount() const { return msaaSampleCount; } @@ -177,7 +177,7 @@ public: constexpr void setOutlineEnabled(bool value) { outlineEnabled = value; } constexpr void setChromaticAberrationEnabled(bool value) { chromaticAberrationEnabled = value; } - constexpr void setColorGradingTexture(const wiGraphics::Texture2D* tex) { colorGradingTex = tex; } + constexpr void setColorGradingTexture(const wiGraphics::Texture* tex) { colorGradingTex = tex; } virtual void setMSAASampleCount(UINT value) { if (msaaSampleCount != value) { msaaSampleCount = value; ResizeBuffers(); } } diff --git a/WickedEngine/RenderPath3D_Deferred.cpp b/WickedEngine/RenderPath3D_Deferred.cpp index cee08a621..72f02a65d 100644 --- a/WickedEngine/RenderPath3D_Deferred.cpp +++ b/WickedEngine/RenderPath3D_Deferred.cpp @@ -25,15 +25,15 @@ void RenderPath3D_Deferred::ResizeBuffers() desc.Height = wiRenderer::GetInternalResolution().y; desc.Format = wiRenderer::RTFormat_gbuffer_0; - device->CreateTexture2D(&desc, nullptr, &rtGBuffer[0]); + device->CreateTexture(&desc, nullptr, &rtGBuffer[0]); device->SetName(&rtGBuffer[0], "rtGBuffer[0]"); desc.Format = wiRenderer::RTFormat_gbuffer_1; - device->CreateTexture2D(&desc, nullptr, &rtGBuffer[1]); + device->CreateTexture(&desc, nullptr, &rtGBuffer[1]); device->SetName(&rtGBuffer[1], "rtGBuffer[1]"); desc.Format = wiRenderer::RTFormat_gbuffer_2; - device->CreateTexture2D(&desc, nullptr, &rtGBuffer[2]); + device->CreateTexture(&desc, nullptr, &rtGBuffer[2]); device->SetName(&rtGBuffer[2], "rtGBuffer[2]"); } { @@ -42,7 +42,7 @@ void RenderPath3D_Deferred::ResizeBuffers() desc.Format = wiRenderer::RTFormat_hdr; desc.Width = wiRenderer::GetInternalResolution().x; desc.Height = wiRenderer::GetInternalResolution().y; - device->CreateTexture2D(&desc, nullptr, &rtDeferred); + device->CreateTexture(&desc, nullptr, &rtDeferred); device->SetName(&rtDeferred, "rtDeferred"); } { @@ -51,9 +51,9 @@ void RenderPath3D_Deferred::ResizeBuffers() desc.Format = wiRenderer::RTFormat_deferred_lightbuffer; desc.Width = wiRenderer::GetInternalResolution().x; desc.Height = wiRenderer::GetInternalResolution().y; - device->CreateTexture2D(&desc, nullptr, &lightbuffer_diffuse); + device->CreateTexture(&desc, nullptr, &lightbuffer_diffuse); device->SetName(&lightbuffer_diffuse, "lightbuffer_diffuse"); - device->CreateTexture2D(&desc, nullptr, &lightbuffer_specular); + device->CreateTexture(&desc, nullptr, &lightbuffer_specular); device->SetName(&lightbuffer_specular, "lightbuffer_specular"); } { @@ -62,9 +62,9 @@ void RenderPath3D_Deferred::ResizeBuffers() desc.Format = wiRenderer::RTFormat_deferred_lightbuffer; desc.Width = wiRenderer::GetInternalResolution().x; desc.Height = wiRenderer::GetInternalResolution().y; - device->CreateTexture2D(&desc, nullptr, &rtSSS[0]); + device->CreateTexture(&desc, nullptr, &rtSSS[0]); device->SetName(&rtSSS[0], "rtSSS[0]"); - device->CreateTexture2D(&desc, nullptr, &rtSSS[1]); + device->CreateTexture(&desc, nullptr, &rtSSS[1]); device->SetName(&rtSSS[1], "rtSSS[1]"); } @@ -175,9 +175,23 @@ void RenderPath3D_Deferred::Render() const wiProfiler::EndRange(range); // Opaque Scene } - device->Barrier(&GPUBarrier::Image(&depthBuffer, IMAGE_LAYOUT_DEPTHSTENCIL, IMAGE_LAYOUT_COPY_SRC), 1, cmd); - device->CopyTexture2D(&depthBuffer_Copy, &depthBuffer, cmd); - device->Barrier(&GPUBarrier::Image(&depthBuffer, IMAGE_LAYOUT_COPY_SRC, IMAGE_LAYOUT_DEPTHSTENCIL_READONLY), 1, cmd); + { + GPUBarrier barriers[] = { + GPUBarrier::Image(&depthBuffer, IMAGE_LAYOUT_DEPTHSTENCIL, IMAGE_LAYOUT_COPY_SRC), + GPUBarrier::Image(&depthBuffer_Copy, IMAGE_LAYOUT_SHADER_RESOURCE, IMAGE_LAYOUT_COPY_DST) + }; + device->Barrier(barriers, ARRAYSIZE(barriers), cmd); + } + + device->CopyResource(&depthBuffer_Copy, &depthBuffer, cmd); + + { + GPUBarrier barriers[] = { + GPUBarrier::Image(&depthBuffer, IMAGE_LAYOUT_COPY_SRC, IMAGE_LAYOUT_DEPTHSTENCIL_READONLY), + GPUBarrier::Image(&depthBuffer_Copy, IMAGE_LAYOUT_COPY_DST, IMAGE_LAYOUT_SHADER_RESOURCE) + }; + device->Barrier(barriers, ARRAYSIZE(barriers), cmd); + } RenderLinearDepth(cmd); diff --git a/WickedEngine/RenderPath3D_Deferred.h b/WickedEngine/RenderPath3D_Deferred.h index de0b31bd0..4aa31a35b 100644 --- a/WickedEngine/RenderPath3D_Deferred.h +++ b/WickedEngine/RenderPath3D_Deferred.h @@ -6,11 +6,11 @@ class RenderPath3D_Deferred : public RenderPath3D { protected: - wiGraphics::Texture2D rtGBuffer[3]; - wiGraphics::Texture2D rtDeferred; - wiGraphics::Texture2D rtSSS[2]; - wiGraphics::Texture2D lightbuffer_diffuse; - wiGraphics::Texture2D lightbuffer_specular; + wiGraphics::Texture rtGBuffer[3]; + wiGraphics::Texture rtDeferred; + wiGraphics::Texture rtSSS[2]; + wiGraphics::Texture lightbuffer_diffuse; + wiGraphics::Texture lightbuffer_specular; wiGraphics::RenderPass renderpass_gbuffer; wiGraphics::RenderPass renderpass_lights; diff --git a/WickedEngine/RenderPath3D_Forward.cpp b/WickedEngine/RenderPath3D_Forward.cpp index d4bf10d3b..8d9da0f4b 100644 --- a/WickedEngine/RenderPath3D_Forward.cpp +++ b/WickedEngine/RenderPath3D_Forward.cpp @@ -25,27 +25,27 @@ void RenderPath3D_Forward::ResizeBuffers() } desc.Width = wiRenderer::GetInternalResolution().x; desc.Height = wiRenderer::GetInternalResolution().y; - desc.SampleDesc.Count = getMSAASampleCount(); + desc.SampleCount = getMSAASampleCount(); desc.Format = wiRenderer::RTFormat_hdr; - device->CreateTexture2D(&desc, nullptr, &rtMain[0]); + device->CreateTexture(&desc, nullptr, &rtMain[0]); device->SetName(&rtMain[0], "rtMain[0]"); desc.Format = wiRenderer::RTFormat_gbuffer_1; - device->CreateTexture2D(&desc, nullptr, &rtMain[1]); + device->CreateTexture(&desc, nullptr, &rtMain[1]); device->SetName(&rtMain[1], "rtMain[1]"); if (getMSAASampleCount() > 1) { - desc.SampleDesc.Count = 1; + desc.SampleCount = 1; desc.BindFlags = BIND_RENDER_TARGET | BIND_SHADER_RESOURCE | BIND_UNORDERED_ACCESS; desc.Format = wiRenderer::RTFormat_hdr; - device->CreateTexture2D(&desc, nullptr, &rtMain_resolved[0]); + device->CreateTexture(&desc, nullptr, &rtMain_resolved[0]); device->SetName(&rtMain_resolved[0], "rtMain_resolved[0]"); desc.Format = wiRenderer::RTFormat_gbuffer_1; - device->CreateTexture2D(&desc, nullptr, &rtMain_resolved[1]); + device->CreateTexture(&desc, nullptr, &rtMain_resolved[1]); device->SetName(&rtMain_resolved[1], "rtMain_resolved[1]"); } } @@ -127,9 +127,23 @@ void RenderPath3D_Forward::Render() const } else { - device->Barrier(&GPUBarrier::Image(&depthBuffer, IMAGE_LAYOUT_DEPTHSTENCIL, IMAGE_LAYOUT_COPY_SRC), 1, cmd); - device->CopyTexture2D(&depthBuffer_Copy, &depthBuffer, cmd); - device->Barrier(&GPUBarrier::Image(&depthBuffer, IMAGE_LAYOUT_COPY_SRC, IMAGE_LAYOUT_DEPTHSTENCIL_READONLY), 1, cmd); + { + GPUBarrier barriers[] = { + GPUBarrier::Image(&depthBuffer, IMAGE_LAYOUT_DEPTHSTENCIL, IMAGE_LAYOUT_COPY_SRC), + GPUBarrier::Image(&depthBuffer_Copy, IMAGE_LAYOUT_SHADER_RESOURCE, IMAGE_LAYOUT_COPY_DST) + }; + device->Barrier(barriers, ARRAYSIZE(barriers), cmd); + } + + device->CopyResource(&depthBuffer_Copy, &depthBuffer, cmd); + + { + GPUBarrier barriers[] = { + GPUBarrier::Image(&depthBuffer, IMAGE_LAYOUT_COPY_SRC, IMAGE_LAYOUT_DEPTHSTENCIL_READONLY), + GPUBarrier::Image(&depthBuffer_Copy, IMAGE_LAYOUT_COPY_DST, IMAGE_LAYOUT_SHADER_RESOURCE) + }; + device->Barrier(barriers, ARRAYSIZE(barriers), cmd); + } } RenderLinearDepth(cmd); diff --git a/WickedEngine/RenderPath3D_Forward.h b/WickedEngine/RenderPath3D_Forward.h index c7fb2a5a6..3ed6248d2 100644 --- a/WickedEngine/RenderPath3D_Forward.h +++ b/WickedEngine/RenderPath3D_Forward.h @@ -7,15 +7,15 @@ class RenderPath3D_Forward : { protected: - wiGraphics::Texture2D rtMain[2]; - wiGraphics::Texture2D rtMain_resolved[2]; + wiGraphics::Texture rtMain[2]; + wiGraphics::Texture rtMain_resolved[2]; wiGraphics::RenderPass renderpass_depthprepass; wiGraphics::RenderPass renderpass_main; wiGraphics::RenderPass renderpass_transparent; wiGraphics::RenderPass renderpass_bloom; - const constexpr wiGraphics::Texture2D* GetSceneRT_Read(int i) const + const constexpr wiGraphics::Texture* GetSceneRT_Read(int i) const { if (getMSAASampleCount() > 1) { diff --git a/WickedEngine/RenderPath3D_PathTracing.cpp b/WickedEngine/RenderPath3D_PathTracing.cpp index af611cebd..fe3610206 100644 --- a/WickedEngine/RenderPath3D_PathTracing.cpp +++ b/WickedEngine/RenderPath3D_PathTracing.cpp @@ -26,7 +26,7 @@ void RenderPath3D_PathTracing::ResizeBuffers() desc.Format = FORMAT_R32G32B32A32_FLOAT; desc.Width = wiRenderer::GetInternalResolution().x; desc.Height = wiRenderer::GetInternalResolution().y; - device->CreateTexture2D(&desc, nullptr, &traceResult); + device->CreateTexture(&desc, nullptr, &traceResult); device->SetName(&traceResult, "traceResult"); } { @@ -35,7 +35,7 @@ void RenderPath3D_PathTracing::ResizeBuffers() desc.Format = defaultTextureFormat; desc.Width = wiRenderer::GetInternalResolution().x; desc.Height = wiRenderer::GetInternalResolution().y; - device->CreateTexture2D(&desc, nullptr, &rtPostprocess_LDR[0]); + device->CreateTexture(&desc, nullptr, &rtPostprocess_LDR[0]); device->SetName(&rtPostprocess_LDR[0], "rtPostprocess_LDR[0]"); } diff --git a/WickedEngine/RenderPath3D_PathTracing.h b/WickedEngine/RenderPath3D_PathTracing.h index a5f6163ae..78891f2b4 100644 --- a/WickedEngine/RenderPath3D_PathTracing.h +++ b/WickedEngine/RenderPath3D_PathTracing.h @@ -9,14 +9,14 @@ private: int sam = -1; protected: - wiGraphics::Texture2D traceResult; + wiGraphics::Texture traceResult; wiGraphics::RenderPass renderpass_debugbvh; void ResizeBuffers() override; public: - const wiGraphics::Texture2D* GetDepthStencil() const override { return nullptr; }; + const wiGraphics::Texture* GetDepthStencil() const override { return nullptr; }; void Update(float dt) override; void Render() const override; diff --git a/WickedEngine/RenderPath3D_TiledDeferred.cpp b/WickedEngine/RenderPath3D_TiledDeferred.cpp index db0070f1c..ab653a6a8 100644 --- a/WickedEngine/RenderPath3D_TiledDeferred.cpp +++ b/WickedEngine/RenderPath3D_TiledDeferred.cpp @@ -24,12 +24,12 @@ void RenderPath3D_TiledDeferred::ResizeBuffers() TextureDesc desc; desc = lightbuffer_diffuse.GetDesc(); desc.Format = FORMAT_R16G16B16A16_FLOAT; - device->CreateTexture2D(&desc, nullptr, &lightbuffer_diffuse_noR11G11B10supportavailable); + device->CreateTexture(&desc, nullptr, &lightbuffer_diffuse_noR11G11B10supportavailable); device->SetName(&lightbuffer_diffuse_noR11G11B10supportavailable, "lightbuffer_diffuse_noR11G11B10supportavailable"); desc = lightbuffer_specular.GetDesc(); desc.Format = FORMAT_R16G16B16A16_FLOAT; - device->CreateTexture2D(&desc, nullptr, &lightbuffer_specular_noR11G11B10supportavailable); + device->CreateTexture(&desc, nullptr, &lightbuffer_specular_noR11G11B10supportavailable); device->SetName(&lightbuffer_specular_noR11G11B10supportavailable, "lightbuffer_specular_noR11G11B10supportavailable"); } } @@ -73,9 +73,23 @@ void RenderPath3D_TiledDeferred::Render() const wiProfiler::EndRange(range); // Opaque Scene } - device->Barrier(&GPUBarrier::Image(&depthBuffer, IMAGE_LAYOUT_DEPTHSTENCIL, IMAGE_LAYOUT_COPY_SRC), 1, cmd); - device->CopyTexture2D(&depthBuffer_Copy, &depthBuffer, cmd); - device->Barrier(&GPUBarrier::Image(&depthBuffer, IMAGE_LAYOUT_COPY_SRC, IMAGE_LAYOUT_DEPTHSTENCIL_READONLY), 1, cmd); + { + GPUBarrier barriers[] = { + GPUBarrier::Image(&depthBuffer, IMAGE_LAYOUT_DEPTHSTENCIL, IMAGE_LAYOUT_COPY_SRC), + GPUBarrier::Image(&depthBuffer_Copy, IMAGE_LAYOUT_SHADER_RESOURCE, IMAGE_LAYOUT_COPY_DST) + }; + device->Barrier(barriers, ARRAYSIZE(barriers), cmd); + } + + device->CopyResource(&depthBuffer_Copy, &depthBuffer, cmd); + + { + GPUBarrier barriers[] = { + GPUBarrier::Image(&depthBuffer, IMAGE_LAYOUT_COPY_SRC, IMAGE_LAYOUT_DEPTHSTENCIL_READONLY), + GPUBarrier::Image(&depthBuffer_Copy, IMAGE_LAYOUT_COPY_DST, IMAGE_LAYOUT_SHADER_RESOURCE) + }; + device->Barrier(barriers, ARRAYSIZE(barriers), cmd); + } RenderLinearDepth(cmd); diff --git a/WickedEngine/RenderPath3D_TiledDeferred.h b/WickedEngine/RenderPath3D_TiledDeferred.h index 0cc24d7a7..06f9c1184 100644 --- a/WickedEngine/RenderPath3D_TiledDeferred.h +++ b/WickedEngine/RenderPath3D_TiledDeferred.h @@ -5,8 +5,8 @@ class RenderPath3D_TiledDeferred : public RenderPath3D_Deferred { private: - wiGraphics::Texture2D lightbuffer_diffuse_noR11G11B10supportavailable; - wiGraphics::Texture2D lightbuffer_specular_noR11G11B10supportavailable; + wiGraphics::Texture lightbuffer_diffuse_noR11G11B10supportavailable; + wiGraphics::Texture lightbuffer_specular_noR11G11B10supportavailable; protected: void ResizeBuffers() override; public: diff --git a/WickedEngine/RenderPath3D_TiledForward.cpp b/WickedEngine/RenderPath3D_TiledForward.cpp index 13dbcec3d..b719c2fd2 100644 --- a/WickedEngine/RenderPath3D_TiledForward.cpp +++ b/WickedEngine/RenderPath3D_TiledForward.cpp @@ -54,9 +54,23 @@ void RenderPath3D_TiledForward::Render() const } else { - device->Barrier(&GPUBarrier::Image(&depthBuffer, IMAGE_LAYOUT_DEPTHSTENCIL, IMAGE_LAYOUT_COPY_SRC), 1, cmd); - device->CopyTexture2D(&depthBuffer_Copy, &depthBuffer, cmd); - device->Barrier(&GPUBarrier::Image(&depthBuffer, IMAGE_LAYOUT_COPY_SRC, IMAGE_LAYOUT_DEPTHSTENCIL_READONLY), 1, cmd); + { + GPUBarrier barriers[] = { + GPUBarrier::Image(&depthBuffer, IMAGE_LAYOUT_DEPTHSTENCIL, IMAGE_LAYOUT_COPY_SRC), + GPUBarrier::Image(&depthBuffer_Copy, IMAGE_LAYOUT_SHADER_RESOURCE, IMAGE_LAYOUT_COPY_DST) + }; + device->Barrier(barriers, ARRAYSIZE(barriers), cmd); + } + + device->CopyResource(&depthBuffer_Copy, &depthBuffer, cmd); + + { + GPUBarrier barriers[] = { + GPUBarrier::Image(&depthBuffer, IMAGE_LAYOUT_COPY_SRC, IMAGE_LAYOUT_DEPTHSTENCIL_READONLY), + GPUBarrier::Image(&depthBuffer_Copy, IMAGE_LAYOUT_COPY_DST, IMAGE_LAYOUT_SHADER_RESOURCE) + }; + device->Barrier(barriers, ARRAYSIZE(barriers), cmd); + } } RenderLinearDepth(cmd); diff --git a/WickedEngine/Texture_BindLua.cpp b/WickedEngine/Texture_BindLua.cpp index 695bd2a38..c1bdd107c 100644 --- a/WickedEngine/Texture_BindLua.cpp +++ b/WickedEngine/Texture_BindLua.cpp @@ -11,7 +11,7 @@ Luna::PropertyType Texture_BindLua::properties[] = { { NULL, NULL } }; -Texture_BindLua::Texture_BindLua(Texture2D* texture) :texture(texture) +Texture_BindLua::Texture_BindLua(Texture* texture) :texture(texture) { } Texture_BindLua::Texture_BindLua(lua_State *L) diff --git a/WickedEngine/Texture_BindLua.h b/WickedEngine/Texture_BindLua.h index d150f2eb7..c778a92b2 100644 --- a/WickedEngine/Texture_BindLua.h +++ b/WickedEngine/Texture_BindLua.h @@ -6,13 +6,13 @@ class Texture_BindLua { public: - wiGraphics::Texture2D* texture; + wiGraphics::Texture* texture; static const char className[]; static Luna::FunctionType methods[]; static Luna::PropertyType properties[]; - Texture_BindLua(wiGraphics::Texture2D* texture = nullptr); + Texture_BindLua(wiGraphics::Texture* texture = nullptr); Texture_BindLua(lua_State *L); ~Texture_BindLua(); diff --git a/WickedEngine/wiBackLog.cpp b/WickedEngine/wiBackLog.cpp index 36d11e212..c95106cd8 100644 --- a/WickedEngine/wiBackLog.cpp +++ b/WickedEngine/wiBackLog.cpp @@ -38,7 +38,7 @@ namespace wiBackLog wiFont font; wiSpinLock logLock; - std::unique_ptr backgroundTex; + std::unique_ptr backgroundTex; void Toggle() { @@ -86,7 +86,7 @@ namespace wiBackLog if (backgroundTex == nullptr) { const uint8_t colorData[] = { 0, 0, 43, 200, 43, 31, 141, 223 }; - backgroundTex.reset(new Texture2D); + backgroundTex.reset(new Texture); HRESULT hr = wiTextureHelper::CreateTexture(*backgroundTex.get(), colorData, 1, 2); assert(SUCCEEDED(hr)); } @@ -181,7 +181,7 @@ namespace wiBackLog } } - void setBackground(Texture2D* texture) + void setBackground(Texture* texture) { backgroundTex.reset(texture); } diff --git a/WickedEngine/wiBackLog.h b/WickedEngine/wiBackLog.h index f0f2b7c7f..1688b94e2 100644 --- a/WickedEngine/wiBackLog.h +++ b/WickedEngine/wiBackLog.h @@ -25,7 +25,7 @@ namespace wiBackLog bool isActive(); - void setBackground(wiGraphics::Texture2D* texture); + void setBackground(wiGraphics::Texture* texture); void setFontSize(int value); void setFontRowspacing(int value); }; diff --git a/WickedEngine/wiFont.cpp b/WickedEngine/wiFont.cpp index 0b2914847..69b79a443 100644 --- a/WickedEngine/wiFont.cpp +++ b/WickedEngine/wiFont.cpp @@ -44,7 +44,7 @@ namespace wiFont_Internal atomic_bool initialized = false; - Texture2D texture; + Texture texture; struct Glyph { @@ -432,7 +432,7 @@ void UpdatePendingGlyphs() } } } -const Texture2D* wiFont::GetAtlas() +const Texture* wiFont::GetAtlas() { return &texture; } diff --git a/WickedEngine/wiFont.h b/WickedEngine/wiFont.h index 7775b513c..b32f2fe09 100644 --- a/WickedEngine/wiFont.h +++ b/WickedEngine/wiFont.h @@ -39,7 +39,7 @@ public: static void CleanUp(); static void LoadShaders(); - static const wiGraphics::Texture2D* GetAtlas(); + static const wiGraphics::Texture* GetAtlas(); // Returns the font path that can be modified static std::string& GetFontPath(); diff --git a/WickedEngine/wiGPUBVH.cpp b/WickedEngine/wiGPUBVH.cpp index 13804726e..738a2ac7d 100644 --- a/WickedEngine/wiGPUBVH.cpp +++ b/WickedEngine/wiGPUBVH.cpp @@ -65,7 +65,7 @@ void wiGPUBVH::UpdateGlobalMaterialResources(const Scene& scene, CommandList cmd bool repackAtlas = false; const int atlasWrapBorder = 1; - for (const Texture2D* tex : sceneTextures) + for (const Texture* tex : sceneTextures) { if (tex == nullptr) { @@ -104,14 +104,13 @@ void wiGPUBVH::UpdateGlobalMaterialResources(const Scene& scene, CommandList cmd desc.MipLevels = 1; desc.ArraySize = 1; desc.Format = FORMAT_R8G8B8A8_UNORM; - desc.SampleDesc.Count = 1; - desc.SampleDesc.Quality = 0; + desc.SampleCount = 1; desc.Usage = USAGE_DEFAULT; desc.BindFlags = BIND_SHADER_RESOURCE | BIND_UNORDERED_ACCESS; desc.CPUAccessFlags = 0; desc.MiscFlags = 0; - device->CreateTexture2D(&desc, nullptr, &globalMaterialAtlas); + device->CreateTexture(&desc, nullptr, &globalMaterialAtlas); device->SetName(&globalMaterialAtlas, "globalMaterialAtlas"); for (auto& it : storedTextures) diff --git a/WickedEngine/wiGPUBVH.h b/WickedEngine/wiGPUBVH.h index e609bb622..bbb389276 100644 --- a/WickedEngine/wiGPUBVH.h +++ b/WickedEngine/wiGPUBVH.h @@ -26,10 +26,10 @@ private: // Scene material resources: wiGraphics::GPUBuffer globalMaterialBuffer; - wiGraphics::Texture2D globalMaterialAtlas; + wiGraphics::Texture globalMaterialAtlas; std::vector materialArray; - std::unordered_map storedTextures; - std::unordered_set sceneTextures; + std::unordered_map storedTextures; + std::unordered_set sceneTextures; void UpdateGlobalMaterialResources(const wiSceneSystem::Scene& scene, wiGraphics::CommandList cmd); public: diff --git a/WickedEngine/wiGraphicsDescriptors.h b/WickedEngine/wiGraphicsDescriptors.h index b5f75bca9..b099ebfc9 100644 --- a/WickedEngine/wiGraphicsDescriptors.h +++ b/WickedEngine/wiGraphicsDescriptors.h @@ -16,7 +16,6 @@ namespace wiGraphics struct GPUResource; struct GPUBuffer; struct Texture; - struct Texture2D; enum SHADERSTAGE { @@ -271,6 +270,30 @@ namespace wiGraphics RTV, DSV, }; + enum IMAGE_LAYOUT + { + IMAGE_LAYOUT_UNDEFINED, // discard contents + IMAGE_LAYOUT_GENERAL, // supports everything + IMAGE_LAYOUT_RENDERTARGET, // render target, write enabled + IMAGE_LAYOUT_DEPTHSTENCIL, // depth stencil, write enabled + IMAGE_LAYOUT_DEPTHSTENCIL_READONLY, // depth stencil, read only + IMAGE_LAYOUT_SHADER_RESOURCE, // shader resource, read only + IMAGE_LAYOUT_UNORDERED_ACCESS, // shader resource, write enabled + IMAGE_LAYOUT_COPY_SRC, // copy from + IMAGE_LAYOUT_COPY_DST, // copy to + }; + enum BUFFER_STATE + { + BUFFER_STATE_GENERAL, // supports everything + BUFFER_STATE_VERTEX_BUFFER, // vertex buffer, read only + BUFFER_STATE_INDEX_BUFFER, // index buffer, read only + BUFFER_STATE_CONSTANT_BUFFER, // constant buffer, read only + BUFFER_STATE_INDIRECT_ARGUMENT, // argument buffer to DrawIndirect() or DispatchIndirect() + BUFFER_STATE_SHADER_RESOURCE, // shader resource, read only + BUFFER_STATE_UNORDERED_ACCESS, // shader resource, write enabled + BUFFER_STATE_COPY_SRC, // copy from + BUFFER_STATE_COPY_DST, // copy to + }; // Flags //////////////////////////////////////////// enum BIND_FLAG @@ -298,30 +321,6 @@ namespace wiGraphics RESOURCE_MISC_BUFFER_STRUCTURED = 0x40L, RESOURCE_MISC_TILED = 0x40000L, }; - enum IMAGE_LAYOUT - { - IMAGE_LAYOUT_UNDEFINED, // discard contents - IMAGE_LAYOUT_GENERAL, // supports everything - IMAGE_LAYOUT_RENDERTARGET, // render target, write enabled - IMAGE_LAYOUT_DEPTHSTENCIL, // depth stencil, write enabled - IMAGE_LAYOUT_DEPTHSTENCIL_READONLY, // depth stencil, read only - IMAGE_LAYOUT_SHADER_RESOURCE, // shader resource, read only - IMAGE_LAYOUT_UNORDERED_ACCESS, // shader resource, write enabled - IMAGE_LAYOUT_COPY_SRC, // copy from - IMAGE_LAYOUT_COPY_DST, // copy to - }; - enum BUFFER_STATE - { - BUFFER_STATE_GENERAL, // supports everything - BUFFER_STATE_VERTEX_BUFFER, // vertex buffer, read only - BUFFER_STATE_INDEX_BUFFER, // index buffer, read only - BUFFER_STATE_CONSTANT_BUFFER, // constant buffer, read only - BUFFER_STATE_INDIRECT_ARGUMENT, // argument buffer to DrawIndirect() or DispatchIndirect() - BUFFER_STATE_SHADER_RESOURCE, // shader resource, read only - BUFFER_STATE_UNORDERED_ACCESS, // shader resource, write enabled - BUFFER_STATE_COPY_SRC, // copy from - BUFFER_STATE_COPY_DST, // copy to - }; // Structs ///////////////////////////////////////////// @@ -346,11 +345,6 @@ namespace wiGraphics INPUT_CLASSIFICATION InputSlotClass = INPUT_CLASSIFICATION::INPUT_PER_VERTEX_DATA; UINT InstanceDataStepRate = 0; }; - struct SampleDesc - { - UINT Count = 1; - UINT Quality = 0; - }; union ClearValue { float color[4]; @@ -362,13 +356,19 @@ namespace wiGraphics }; struct TextureDesc { + enum TEXTURE_TYPE + { + TEXTURE_1D, + TEXTURE_2D, + TEXTURE_3D, + } type = TEXTURE_2D; UINT Width = 0; UINT Height = 0; UINT Depth = 0; UINT ArraySize = 1; UINT MipLevels = 1; FORMAT Format = FORMAT_UNKNOWN; - SampleDesc SampleDesc; + UINT SampleCount = 1; USAGE Usage = USAGE_DEFAULT; UINT BindFlags = 0; UINT CPUAccessFlags = 0; @@ -541,7 +541,7 @@ namespace wiGraphics LOADOP_CLEAR, LOADOP_DONTCARE, } loadop = LOADOP_LOAD; - const Texture2D* texture = nullptr; + const Texture* texture = nullptr; int subresource = -1; enum STORE_OPERATION { diff --git a/WickedEngine/wiGraphicsDevice.h b/WickedEngine/wiGraphicsDevice.h index 361256738..4aa1a3384 100644 --- a/WickedEngine/wiGraphicsDevice.h +++ b/WickedEngine/wiGraphicsDevice.h @@ -31,9 +31,7 @@ namespace wiGraphics public: virtual HRESULT CreateBuffer(const GPUBufferDesc *pDesc, const SubresourceData* pInitialData, GPUBuffer *pBuffer) = 0; - virtual HRESULT CreateTexture1D(const TextureDesc* pDesc, const SubresourceData *pInitialData, Texture1D *pTexture1D) = 0; - virtual HRESULT CreateTexture2D(const TextureDesc* pDesc, const SubresourceData *pInitialData, Texture2D *pTexture2D) = 0; - virtual HRESULT CreateTexture3D(const TextureDesc* pDesc, const SubresourceData *pInitialData, Texture3D *pTexture3D) = 0; + virtual HRESULT CreateTexture(const TextureDesc* pDesc, const SubresourceData *pInitialData, Texture *pTexture) = 0; virtual HRESULT CreateInputLayout(const VertexLayoutDesc *pInputElementDescs, UINT NumElements, const ShaderByteCode* shaderCode, VertexLayout *pInputLayout) = 0; virtual HRESULT CreateVertexShader(const void *pShaderBytecode, SIZE_T BytecodeLength, VertexShader *pVertexShader) = 0; virtual HRESULT CreatePixelShader(const void *pShaderBytecode, SIZE_T BytecodeLength, PixelShader *pPixelShader) = 0; @@ -53,9 +51,7 @@ namespace wiGraphics virtual void DestroyResource(GPUResource* pResource) = 0; virtual void DestroyBuffer(GPUBuffer *pBuffer) = 0; - virtual void DestroyTexture1D(Texture1D *pTexture1D) = 0; - virtual void DestroyTexture2D(Texture2D *pTexture2D) = 0; - virtual void DestroyTexture3D(Texture3D *pTexture3D) = 0; + virtual void DestroyTexture(Texture *pTexture) = 0; virtual void DestroyInputLayout(VertexLayout *pInputLayout) = 0; virtual void DestroyVertexShader(VertexShader *pVertexShader) = 0; virtual void DestroyPixelShader(PixelShader *pPixelShader) = 0; @@ -94,7 +90,7 @@ namespace wiGraphics virtual void SetResolution(int width, int height) = 0; - virtual Texture2D GetBackBuffer() = 0; + virtual Texture GetBackBuffer() = 0; enum GRAPHICSDEVICE_CAPABILITY { @@ -150,9 +146,9 @@ namespace wiGraphics virtual void DrawIndexedInstancedIndirect(const GPUBuffer* args, UINT args_offset, CommandList cmd) = 0; virtual void Dispatch(UINT threadGroupCountX, UINT threadGroupCountY, UINT threadGroupCountZ, CommandList cmd) = 0; virtual void DispatchIndirect(const GPUBuffer* args, UINT args_offset, CommandList cmd) = 0; - virtual void CopyTexture2D(const Texture2D* pDst, const Texture2D* pSrc, CommandList cmd) = 0; - virtual void CopyTexture2D_Region(const Texture2D* pDst, UINT dstMip, UINT dstX, UINT dstY, const Texture2D* pSrc, UINT srcMip, CommandList cmd) = 0; - virtual void MSAAResolve(const Texture2D* pDst, const Texture2D* pSrc, CommandList cmd) = 0; + virtual void CopyResource(const GPUResource* pDst, const GPUResource* pSrc, CommandList cmd) = 0; + virtual void CopyTexture2D_Region(const Texture* pDst, UINT dstMip, UINT dstX, UINT dstY, const Texture* pSrc, UINT srcMip, CommandList cmd) = 0; + virtual void MSAAResolve(const Texture* pDst, const Texture* pSrc, CommandList cmd) = 0; virtual void UpdateBuffer(const GPUBuffer* buffer, const void* data, CommandList cmd, int dataSize = -1) = 0; virtual void QueryBegin(const GPUQuery *query, CommandList cmd) = 0; virtual void QueryEnd(const GPUQuery *query, CommandList cmd) = 0; diff --git a/WickedEngine/wiGraphicsDevice_DX11.cpp b/WickedEngine/wiGraphicsDevice_DX11.cpp index 04c4c86cc..4d831b996 100644 --- a/WickedEngine/wiGraphicsDevice_DX11.cpp +++ b/WickedEngine/wiGraphicsDevice_DX11.cpp @@ -701,8 +701,8 @@ inline D3D11_TEXTURE2D_DESC _ConvertTextureDesc2D(const TextureDesc* pDesc) desc.MipLevels = pDesc->MipLevels; desc.ArraySize = pDesc->ArraySize; desc.Format = _ConvertFormat(pDesc->Format); - desc.SampleDesc.Count = pDesc->SampleDesc.Count; - desc.SampleDesc.Quality = pDesc->SampleDesc.Quality; + desc.SampleDesc.Count = pDesc->SampleCount; + desc.SampleDesc.Quality = 0; desc.Usage = _ConvertUsage(pDesc->Usage); desc.BindFlags = _ParseBindFlags(pDesc->BindFlags); desc.CPUAccessFlags = _ParseCPUAccessFlags(pDesc->CPUAccessFlags); @@ -1047,8 +1047,7 @@ inline TextureDesc _ConvertTextureDesc_Inv(const D3D11_TEXTURE2D_DESC* pDesc) desc.MipLevels = pDesc->MipLevels; desc.ArraySize = pDesc->ArraySize; desc.Format = _ConvertFormat_Inv(pDesc->Format); - desc.SampleDesc.Count = pDesc->SampleDesc.Count; - desc.SampleDesc.Quality = pDesc->SampleDesc.Quality; + desc.SampleCount = pDesc->SampleDesc.Count; desc.Usage = _ConvertUsage_Inv(pDesc->Usage); desc.BindFlags = _ParseBindFlags_Inv(pDesc->BindFlags); desc.CPUAccessFlags = _ParseCPUAccessFlags_Inv(pDesc->CPUAccessFlags); @@ -1280,11 +1279,10 @@ void GraphicsDevice_DX11::SetResolution(int width, int height) } } -Texture2D GraphicsDevice_DX11::GetBackBuffer() +Texture GraphicsDevice_DX11::GetBackBuffer() { - Texture2D result; + Texture result; result.resource = (wiCPUHandle)backBuffer; - backBuffer->AddRef(); D3D11_TEXTURE2D_DESC desc; backBuffer->GetDesc(&desc); @@ -1297,7 +1295,7 @@ HRESULT GraphicsDevice_DX11::CreateBuffer(const GPUBufferDesc *pDesc, const Subr { DestroyBuffer(pBuffer); DestroyResource(pBuffer); - pBuffer->type = GPUResource::BUFFER; + pBuffer->type = GPUResource::GPU_RESOURCE_TYPE::BUFFER; pBuffer->Register(this); D3D11_BUFFER_DESC desc; @@ -1403,134 +1401,14 @@ HRESULT GraphicsDevice_DX11::CreateBuffer(const GPUBufferDesc *pDesc, const Subr return hr; } -HRESULT GraphicsDevice_DX11::CreateTexture1D(const TextureDesc* pDesc, const SubresourceData *pInitialData, Texture1D *pTexture1D) +HRESULT GraphicsDevice_DX11::CreateTexture(const TextureDesc* pDesc, const SubresourceData *pInitialData, Texture *pTexture) { - DestroyTexture1D(pTexture1D); - DestroyResource(pTexture1D); - pTexture1D->type = GPUResource::TEXTURE_1D; - pTexture1D->Register(this); + DestroyTexture(pTexture); + DestroyResource(pTexture); + pTexture->type = GPUResource::GPU_RESOURCE_TYPE::TEXTURE; + pTexture->Register(this); - pTexture1D->desc = *pDesc; - - D3D11_TEXTURE1D_DESC desc = _ConvertTextureDesc1D(&pTexture1D->desc); - - D3D11_SUBRESOURCE_DATA* data = nullptr; - if (pInitialData != nullptr) - { - data = new D3D11_SUBRESOURCE_DATA[pDesc->ArraySize]; - for (UINT slice = 0; slice < pDesc->ArraySize; ++slice) - { - data[slice] = _ConvertSubresourceData(pInitialData[slice]); - } - } - - HRESULT hr; - - hr = device->CreateTexture1D(&desc, data, (ID3D11Texture1D**)&(pTexture1D->resource)); - SAFE_DELETE_ARRAY(data); - assert(SUCCEEDED(hr)); - if (FAILED(hr)) - return hr; - - if (pTexture1D->desc.MipLevels == 0) - { - pTexture1D->desc.MipLevels = (UINT)log2(pTexture1D->desc.Width); - } - - if (pTexture1D->desc.BindFlags & BIND_RENDER_TARGET) - { - CreateSubresource(pTexture1D, RTV, 0, -1, 0, -1); - } - if (pTexture1D->desc.BindFlags & BIND_DEPTH_STENCIL) - { - CreateSubresource(pTexture1D, DSV, 0, -1, 0, -1); - } - if (pTexture1D->desc.BindFlags & BIND_SHADER_RESOURCE) - { - CreateSubresource(pTexture1D, SRV, 0, -1, 0, -1); - } - if (pTexture1D->desc.BindFlags & BIND_UNORDERED_ACCESS) - { - CreateSubresource(pTexture1D, UAV, 0, -1, 0, -1); - } - - return hr; -} -HRESULT GraphicsDevice_DX11::CreateTexture2D(const TextureDesc* pDesc, const SubresourceData *pInitialData, Texture2D *pTexture2D) -{ - DestroyTexture2D(pTexture2D); - DestroyResource(pTexture2D); - pTexture2D->type = GPUResource::TEXTURE_2D; - pTexture2D->Register(this); - - pTexture2D->desc = *pDesc; - - if (pTexture2D->desc.SampleDesc.Count > 1) - { - UINT quality; - device->CheckMultisampleQualityLevels(_ConvertFormat(pTexture2D->desc.Format), pTexture2D->desc.SampleDesc.Count, &quality); - pTexture2D->desc.SampleDesc.Quality = quality - 1; - if (quality == 0) - { - assert(0 && "MSAA Samplecount not supported!"); - pTexture2D->desc.SampleDesc.Count = 1; - } - } - - D3D11_TEXTURE2D_DESC desc = _ConvertTextureDesc2D(&pTexture2D->desc); - - std::vector data; - if (pInitialData != nullptr) - { - UINT dataCount = pDesc->ArraySize * std::max(1u, pDesc->MipLevels); - data.resize(dataCount); - for (UINT slice = 0; slice < dataCount; ++slice) - { - data[slice] = _ConvertSubresourceData(pInitialData[slice]); - } - } - - HRESULT hr = S_OK; - - hr = device->CreateTexture2D(&desc, data.data(), (ID3D11Texture2D**)&(pTexture2D->resource)); - assert(SUCCEEDED(hr)); - if (FAILED(hr)) - return hr; - - if (pTexture2D->desc.MipLevels == 0) - { - pTexture2D->desc.MipLevels = (UINT)log2(std::max(pTexture2D->desc.Width, pTexture2D->desc.Height)); - } - - if (pTexture2D->desc.BindFlags & BIND_RENDER_TARGET) - { - CreateSubresource(pTexture2D, RTV, 0, -1, 0, -1); - } - if (pTexture2D->desc.BindFlags & BIND_DEPTH_STENCIL) - { - CreateSubresource(pTexture2D, DSV, 0, -1, 0, -1); - } - if (pTexture2D->desc.BindFlags & BIND_SHADER_RESOURCE) - { - CreateSubresource(pTexture2D, SRV, 0, -1, 0, -1); - } - if (pTexture2D->desc.BindFlags & BIND_UNORDERED_ACCESS) - { - CreateSubresource(pTexture2D, UAV, 0, -1, 0, -1); - } - - return hr; -} -HRESULT GraphicsDevice_DX11::CreateTexture3D(const TextureDesc* pDesc, const SubresourceData *pInitialData, Texture3D *pTexture3D) -{ - DestroyTexture3D(pTexture3D); - DestroyResource(pTexture3D); - pTexture3D->type = GPUResource::TEXTURE_3D; - pTexture3D->Register(this); - - pTexture3D->desc = *pDesc; - - D3D11_TEXTURE3D_DESC desc = _ConvertTextureDesc3D(&pTexture3D->desc); + pTexture->desc = *pDesc; std::vector data; if (pInitialData != nullptr) @@ -1545,27 +1423,55 @@ HRESULT GraphicsDevice_DX11::CreateTexture3D(const TextureDesc* pDesc, const Sub HRESULT hr = S_OK; - hr = device->CreateTexture3D(&desc, data.data(), (ID3D11Texture3D**)&(pTexture3D->resource)); + switch (pTexture->desc.type) + { + case TextureDesc::TEXTURE_1D: + { + D3D11_TEXTURE1D_DESC desc = _ConvertTextureDesc1D(&pTexture->desc); + hr = device->CreateTexture1D(&desc, data.data(), (ID3D11Texture1D**)&pTexture->resource); + } + break; + case TextureDesc::TEXTURE_2D: + { + D3D11_TEXTURE2D_DESC desc = _ConvertTextureDesc2D(&pTexture->desc); + hr = device->CreateTexture2D(&desc, data.data(), (ID3D11Texture2D**)&pTexture->resource); + } + break; + case TextureDesc::TEXTURE_3D: + { + D3D11_TEXTURE3D_DESC desc = _ConvertTextureDesc3D(&pTexture->desc); + hr = device->CreateTexture3D(&desc, data.data(), (ID3D11Texture3D**)&pTexture->resource); + } + break; + default: + assert(0); + break; + } + assert(SUCCEEDED(hr)); if (FAILED(hr)) return hr; - if (pTexture3D->desc.MipLevels == 0) + if (pTexture->desc.MipLevels == 0) { - pTexture3D->desc.MipLevels = (UINT)log2(std::max(pTexture3D->desc.Width, std::max(pTexture3D->desc.Height, pTexture3D->desc.Depth))); + pTexture->desc.MipLevels = (UINT)log2(std::max(pTexture->desc.Width, pTexture->desc.Height)); } - if (pTexture3D->desc.BindFlags & BIND_RENDER_TARGET) + if (pTexture->desc.BindFlags & BIND_RENDER_TARGET) { - CreateSubresource(pTexture3D, RTV, 0, -1, 0, -1); + CreateSubresource(pTexture, RTV, 0, -1, 0, -1); } - if (pTexture3D->desc.BindFlags & BIND_SHADER_RESOURCE) + if (pTexture->desc.BindFlags & BIND_DEPTH_STENCIL) { - CreateSubresource(pTexture3D, SRV, 0, -1, 0, -1); + CreateSubresource(pTexture, DSV, 0, -1, 0, -1); } - if (pTexture3D->desc.BindFlags & BIND_UNORDERED_ACCESS) + if (pTexture->desc.BindFlags & BIND_SHADER_RESOURCE) { - CreateSubresource(pTexture3D, UAV, 0, -1, 0, -1); + CreateSubresource(pTexture, SRV, 0, -1, 0, -1); + } + if (pTexture->desc.BindFlags & BIND_UNORDERED_ACCESS) + { + CreateSubresource(pTexture, UAV, 0, -1, 0, -1); } return hr; @@ -1892,7 +1798,7 @@ int GraphicsDevice_DX11::CreateSubresource(Texture* texture, SUBRESOURCE_TYPE ty break; } - if (texture->type == GPUResource::TEXTURE_1D) + if (texture->desc.type == TextureDesc::TEXTURE_1D) { if (texture->desc.ArraySize > 1) { @@ -1909,7 +1815,7 @@ int GraphicsDevice_DX11::CreateSubresource(Texture* texture, SUBRESOURCE_TYPE ty srv_desc.Texture1D.MipLevels = mipCount; } } - else if (texture->type == GPUResource::TEXTURE_2D) + else if (texture->desc.type == TextureDesc::TEXTURE_2D) { if (texture->desc.ArraySize > 1) { @@ -1932,7 +1838,7 @@ int GraphicsDevice_DX11::CreateSubresource(Texture* texture, SUBRESOURCE_TYPE ty } else { - if (texture->desc.SampleDesc.Count > 1) + if (texture->desc.SampleCount > 1) { srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY; srv_desc.Texture2DMSArray.FirstArraySlice = firstSlice; @@ -1950,7 +1856,7 @@ int GraphicsDevice_DX11::CreateSubresource(Texture* texture, SUBRESOURCE_TYPE ty } else { - if (texture->desc.SampleDesc.Count > 1) + if (texture->desc.SampleCount > 1) { srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DMS; } @@ -1962,7 +1868,7 @@ int GraphicsDevice_DX11::CreateSubresource(Texture* texture, SUBRESOURCE_TYPE ty } } } - else if (texture->type == GPUResource::TEXTURE_3D) + else if (texture->desc.type == TextureDesc::TEXTURE_3D) { srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE3D; srv_desc.Texture3D.MostDetailedMip = firstMip; @@ -2010,7 +1916,7 @@ int GraphicsDevice_DX11::CreateSubresource(Texture* texture, SUBRESOURCE_TYPE ty break; } - if (texture->type == GPUResource::TEXTURE_1D) + if (texture->desc.type == TextureDesc::TEXTURE_1D) { if (texture->desc.ArraySize > 1) { @@ -2025,7 +1931,7 @@ int GraphicsDevice_DX11::CreateSubresource(Texture* texture, SUBRESOURCE_TYPE ty uav_desc.Texture1D.MipSlice = firstMip; } } - else if (texture->type == GPUResource::TEXTURE_2D) + else if (texture->desc.type == TextureDesc::TEXTURE_2D) { if (texture->desc.ArraySize > 1) { @@ -2040,7 +1946,7 @@ int GraphicsDevice_DX11::CreateSubresource(Texture* texture, SUBRESOURCE_TYPE ty uav_desc.Texture2D.MipSlice = firstMip; } } - else if (texture->type == GPUResource::TEXTURE_3D) + else if (texture->desc.type == TextureDesc::TEXTURE_3D) { uav_desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE3D; uav_desc.Texture3D.MipSlice = firstMip; @@ -2089,7 +1995,7 @@ int GraphicsDevice_DX11::CreateSubresource(Texture* texture, SUBRESOURCE_TYPE ty break; } - if (texture->type == GPUResource::TEXTURE_1D) + if (texture->desc.type == TextureDesc::TEXTURE_1D) { if (texture->desc.ArraySize > 1) { @@ -2104,11 +2010,11 @@ int GraphicsDevice_DX11::CreateSubresource(Texture* texture, SUBRESOURCE_TYPE ty rtv_desc.Texture1D.MipSlice = firstMip; } } - else if (texture->type == GPUResource::TEXTURE_2D) + else if (texture->desc.type == TextureDesc::TEXTURE_2D) { if (texture->desc.ArraySize > 1) { - if (texture->desc.SampleDesc.Count > 1) + if (texture->desc.SampleCount > 1) { rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY; rtv_desc.Texture2DMSArray.FirstArraySlice = firstSlice; @@ -2124,7 +2030,7 @@ int GraphicsDevice_DX11::CreateSubresource(Texture* texture, SUBRESOURCE_TYPE ty } else { - if (texture->desc.SampleDesc.Count > 1) + if (texture->desc.SampleCount > 1) { rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DMS; } @@ -2135,7 +2041,7 @@ int GraphicsDevice_DX11::CreateSubresource(Texture* texture, SUBRESOURCE_TYPE ty } } } - else if (texture->type == GPUResource::TEXTURE_3D) + else if (texture->desc.type == TextureDesc::TEXTURE_3D) { rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE3D; rtv_desc.Texture3D.MipSlice = firstMip; @@ -2184,7 +2090,7 @@ int GraphicsDevice_DX11::CreateSubresource(Texture* texture, SUBRESOURCE_TYPE ty break; } - if (texture->type == GPUResource::TEXTURE_1D) + if (texture->desc.type == TextureDesc::TEXTURE_1D) { if (texture->desc.ArraySize > 1) { @@ -2199,11 +2105,11 @@ int GraphicsDevice_DX11::CreateSubresource(Texture* texture, SUBRESOURCE_TYPE ty dsv_desc.Texture1D.MipSlice = firstMip; } } - else if (texture->type == GPUResource::TEXTURE_2D) + else if (texture->desc.type == TextureDesc::TEXTURE_2D) { if (texture->desc.ArraySize > 1) { - if (texture->desc.SampleDesc.Count > 1) + if (texture->desc.SampleCount > 1) { dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY; dsv_desc.Texture2DMSArray.FirstArraySlice = firstSlice; @@ -2219,7 +2125,7 @@ int GraphicsDevice_DX11::CreateSubresource(Texture* texture, SUBRESOURCE_TYPE ty } else { - if (texture->desc.SampleDesc.Count > 1) + if (texture->desc.SampleCount > 1) { dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DMS; } @@ -2293,66 +2199,35 @@ void GraphicsDevice_DX11::DestroyResource(GPUResource* pResource) void GraphicsDevice_DX11::DestroyBuffer(GPUBuffer *pBuffer) { } -void GraphicsDevice_DX11::DestroyTexture1D(Texture1D *pTexture1D) +void GraphicsDevice_DX11::DestroyTexture(Texture *pTexture) { - if (pTexture1D->RTV != WI_NULL_HANDLE) + if (pTexture->RTV != WI_NULL_HANDLE) { - ((ID3D11RenderTargetView*)pTexture1D->RTV)->Release(); - pTexture1D->RTV = WI_NULL_HANDLE; + ((ID3D11RenderTargetView*)pTexture->RTV)->Release(); + pTexture->RTV = WI_NULL_HANDLE; } - for (auto& x : pTexture1D->subresourceRTVs) + for (auto& x : pTexture->subresourceRTVs) { if (x != WI_NULL_HANDLE) { ((ID3D11RenderTargetView*)x)->Release(); } } - pTexture1D->subresourceRTVs.clear(); -} -void GraphicsDevice_DX11::DestroyTexture2D(Texture2D *pTexture2D) -{ - if (pTexture2D->RTV != WI_NULL_HANDLE) - { - ((ID3D11RenderTargetView*)pTexture2D->RTV)->Release(); - pTexture2D->RTV = WI_NULL_HANDLE; - } - for (auto& x : pTexture2D->subresourceRTVs) - { - if (x != WI_NULL_HANDLE) - { - ((ID3D11RenderTargetView*)x)->Release(); - } - } - pTexture2D->subresourceRTVs.clear(); + pTexture->subresourceRTVs.clear(); - if (pTexture2D->DSV != WI_NULL_HANDLE) + if (pTexture->DSV != WI_NULL_HANDLE) { - ((ID3D11DepthStencilView*)pTexture2D->DSV)->Release(); - pTexture2D->DSV = WI_NULL_HANDLE; + ((ID3D11DepthStencilView*)pTexture->DSV)->Release(); + pTexture->DSV = WI_NULL_HANDLE; } - for (auto& x : pTexture2D->subresourceDSVs) + for (auto& x : pTexture->subresourceDSVs) { if (x != WI_NULL_HANDLE) { ((ID3D11DepthStencilView*)x)->Release(); } } - pTexture2D->subresourceDSVs.clear(); -} -void GraphicsDevice_DX11::DestroyTexture3D(Texture3D *pTexture3D) -{ - if (pTexture3D->RTV != WI_NULL_HANDLE) - { - ((ID3D11RenderTargetView*)pTexture3D->RTV)->Release(); - } - for (auto& x : pTexture3D->subresourceRTVs) - { - if (x != WI_NULL_HANDLE) - { - ((ID3D11RenderTargetView*)x)->Release(); - } - } - pTexture3D->subresourceRTVs.clear(); + pTexture->subresourceDSVs.clear(); } void GraphicsDevice_DX11::DestroyInputLayout(VertexLayout *pInputLayout) { @@ -2659,7 +2534,7 @@ void GraphicsDevice_DX11::RenderPassBegin(const RenderPass* renderpass, CommandL for (UINT i = 0; i < desc.numAttachments; ++i) { const RenderPassAttachment& attachment = desc.attachments[i]; - const Texture2D* texture = attachment.texture; + const Texture* texture = attachment.texture; int subresource = attachment.subresource; if (attachment.type == RenderPassAttachment::RENDERTARGET) @@ -3137,16 +3012,16 @@ void GraphicsDevice_DX11::DispatchIndirect(const GPUBuffer* args, UINT args_offs deviceContexts[cmd]->DispatchIndirect((ID3D11Buffer*)args->resource, args_offset); } -void GraphicsDevice_DX11::CopyTexture2D(const Texture2D* pDst, const Texture2D* pSrc, CommandList cmd) +void GraphicsDevice_DX11::CopyResource(const GPUResource* pDst, const GPUResource* pSrc, CommandList cmd) { deviceContexts[cmd]->CopyResource((ID3D11Resource*)pDst->resource, (ID3D11Resource*)pSrc->resource); } -void GraphicsDevice_DX11::CopyTexture2D_Region(const Texture2D* pDst, UINT dstMip, UINT dstX, UINT dstY, const Texture2D* pSrc, UINT srcMip, CommandList cmd) +void GraphicsDevice_DX11::CopyTexture2D_Region(const Texture* pDst, UINT dstMip, UINT dstX, UINT dstY, const Texture* pSrc, UINT srcMip, CommandList cmd) { deviceContexts[cmd]->CopySubresourceRegion((ID3D11Resource*)pDst->resource, D3D11CalcSubresource(dstMip, 0, pDst->GetDesc().MipLevels), dstX, dstY, 0, (ID3D11Resource*)pSrc->resource, D3D11CalcSubresource(srcMip, 0, pSrc->GetDesc().MipLevels), nullptr); } -void GraphicsDevice_DX11::MSAAResolve(const Texture2D* pDst, const Texture2D* pSrc, CommandList cmd) +void GraphicsDevice_DX11::MSAAResolve(const Texture* pDst, const Texture* pSrc, CommandList cmd) { assert(pDst != nullptr && pSrc != nullptr); deviceContexts[cmd]->ResolveSubresource((ID3D11Resource*)pDst->resource, 0, (ID3D11Resource*)pSrc->resource, 0, _ConvertFormat(pDst->desc.Format)); diff --git a/WickedEngine/wiGraphicsDevice_DX11.h b/WickedEngine/wiGraphicsDevice_DX11.h index 0a13de1f2..569502b97 100644 --- a/WickedEngine/wiGraphicsDevice_DX11.h +++ b/WickedEngine/wiGraphicsDevice_DX11.h @@ -69,9 +69,7 @@ namespace wiGraphics virtual ~GraphicsDevice_DX11(); HRESULT CreateBuffer(const GPUBufferDesc *pDesc, const SubresourceData* pInitialData, GPUBuffer *pBuffer) override; - HRESULT CreateTexture1D(const TextureDesc* pDesc, const SubresourceData *pInitialData, Texture1D *pTexture1D) override; - HRESULT CreateTexture2D(const TextureDesc* pDesc, const SubresourceData *pInitialData, Texture2D *pTexture2D) override; - HRESULT CreateTexture3D(const TextureDesc* pDesc, const SubresourceData *pInitialData, Texture3D *pTexture3D) override; + HRESULT CreateTexture(const TextureDesc* pDesc, const SubresourceData *pInitialData, Texture *pTexture) override; HRESULT CreateInputLayout(const VertexLayoutDesc *pInputElementDescs, UINT NumElements, const ShaderByteCode* shaderCode, VertexLayout *pInputLayout) override; HRESULT CreateVertexShader(const void *pShaderBytecode, SIZE_T BytecodeLength, VertexShader *pVertexShader) override; HRESULT CreatePixelShader(const void *pShaderBytecode, SIZE_T BytecodeLength, PixelShader *pPixelShader) override; @@ -91,9 +89,7 @@ namespace wiGraphics void DestroyResource(GPUResource* pResource) override; void DestroyBuffer(GPUBuffer *pBuffer) override; - void DestroyTexture1D(Texture1D *pTexture1D) override; - void DestroyTexture2D(Texture2D *pTexture2D) override; - void DestroyTexture3D(Texture3D *pTexture3D) override; + void DestroyTexture(Texture *pTexture) override; void DestroyInputLayout(VertexLayout *pInputLayout) override; void DestroyVertexShader(VertexShader *pVertexShader) override; void DestroyPixelShader(PixelShader *pPixelShader) override; @@ -122,7 +118,7 @@ namespace wiGraphics void SetResolution(int width, int height) override; - Texture2D GetBackBuffer() override; + Texture GetBackBuffer() override; ///////////////Thread-sensitive//////////////////////// @@ -152,9 +148,9 @@ namespace wiGraphics void DrawIndexedInstancedIndirect(const GPUBuffer* args, UINT args_offset, CommandList cmd) override; void Dispatch(UINT threadGroupCountX, UINT threadGroupCountY, UINT threadGroupCountZ, CommandList cmd) override; void DispatchIndirect(const GPUBuffer* args, UINT args_offset, CommandList cmd) override; - void CopyTexture2D(const Texture2D* pDst, const Texture2D* pSrc, CommandList cmd) override; - void CopyTexture2D_Region(const Texture2D* pDst, UINT dstMip, UINT dstX, UINT dstY, const Texture2D* pSrc, UINT srcMip, CommandList cmd) override; - void MSAAResolve(const Texture2D* pDst, const Texture2D* pSrc, CommandList cmd) override; + void CopyResource(const GPUResource* pDst, const GPUResource* pSrc, CommandList cmd) override; + void CopyTexture2D_Region(const Texture* pDst, UINT dstMip, UINT dstX, UINT dstY, const Texture* pSrc, UINT srcMip, CommandList cmd) override; + void MSAAResolve(const Texture* pDst, const Texture* pSrc, CommandList cmd) override; void UpdateBuffer(const GPUBuffer* buffer, const void* data, CommandList cmd, int dataSize = -1) override; void QueryBegin(const GPUQuery *query, CommandList cmd) override; void QueryEnd(const GPUQuery *query, CommandList cmd) override; diff --git a/WickedEngine/wiGraphicsDevice_DX12.cpp b/WickedEngine/wiGraphicsDevice_DX12.cpp index 632b4f944..1fcb89ee6 100644 --- a/WickedEngine/wiGraphicsDevice_DX12.cpp +++ b/WickedEngine/wiGraphicsDevice_DX12.cpp @@ -1434,7 +1434,7 @@ namespace wiGraphics IDXGISwapChain1* _swapChain; - DXGI_SWAP_CHAIN_DESC1 sd = { 0 }; + DXGI_SWAP_CHAIN_DESC1 sd = {}; sd.Width = SCREENWIDTH; sd.Height = SCREENHEIGHT; sd.Format = _ConvertFormat(GetBackBufferFormat()); @@ -1939,11 +1939,11 @@ namespace wiGraphics } } - Texture2D GraphicsDevice_DX12::GetBackBuffer() + Texture GraphicsDevice_DX12::GetBackBuffer() { - Texture2D result; + Texture result; result.resource = (wiCPUHandle)GetFrameResources().backBuffer; - GetFrameResources().backBuffer->AddRef(); + result.RTV - (wiCPUHandle)GetFrameResources().backBufferRTV.ptr; return result; } @@ -1951,7 +1951,7 @@ namespace wiGraphics { DestroyBuffer(pBuffer); DestroyResource(pBuffer); - pBuffer->type = GPUResource::BUFFER; + pBuffer->type = GPUResource::GPU_RESOURCE_TYPE::BUFFER; pBuffer->Register(this); HRESULT hr = E_FAIL; @@ -2108,29 +2108,14 @@ namespace wiGraphics return hr; } - HRESULT GraphicsDevice_DX12::CreateTexture1D(const TextureDesc* pDesc, const SubresourceData* pInitialData, Texture1D* pTexture1D) + HRESULT GraphicsDevice_DX12::CreateTexture(const TextureDesc* pDesc, const SubresourceData* pInitialData, Texture* pTexture) { - DestroyTexture1D(pTexture1D); - DestroyResource(pTexture1D); - pTexture1D->type = GPUResource::TEXTURE_1D; - pTexture1D->Register(this); + DestroyTexture(pTexture); + DestroyResource(pTexture); + pTexture->type = GPUResource::GPU_RESOURCE_TYPE::TEXTURE; + pTexture->Register(this); - pTexture1D->desc = *pDesc; - - // TODO - - HRESULT hr = E_FAIL; - - return hr; - } - HRESULT GraphicsDevice_DX12::CreateTexture2D(const TextureDesc* pDesc, const SubresourceData* pInitialData, Texture2D* pTexture2D) - { - DestroyTexture2D(pTexture2D); - DestroyResource(pTexture2D); - pTexture2D->type = GPUResource::TEXTURE_2D; - pTexture2D->Register(this); - - pTexture2D->desc = *pDesc; + pTexture->desc = *pDesc; HRESULT hr = E_FAIL; @@ -2148,15 +2133,14 @@ namespace wiGraphics D3D12_HEAP_FLAGS heapFlags = D3D12_HEAP_FLAG_NONE; D3D12_RESOURCE_DESC desc; - desc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D; desc.Format = _ConvertFormat(pDesc->Format); desc.Width = pDesc->Width; desc.Height = pDesc->Height; desc.MipLevels = pDesc->MipLevels; desc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN; desc.DepthOrArraySize = (UINT16)pDesc->ArraySize; - desc.SampleDesc.Count = pDesc->SampleDesc.Count; - desc.SampleDesc.Quality = pDesc->SampleDesc.Quality; + desc.SampleDesc.Count = pDesc->SampleCount; + desc.SampleDesc.Quality = 0; desc.Alignment = 0; desc.Flags = D3D12_RESOURCE_FLAG_NONE; if (pDesc->BindFlags & BIND_DEPTH_STENCIL) @@ -2182,15 +2166,15 @@ namespace wiGraphics desc.Flags |= D3D12_RESOURCE_FLAG_DENY_SHADER_RESOURCE; } - D3D12_RESOURCE_STATES resourceState = _ConvertImageLayout(pTexture2D->desc.layout); + D3D12_RESOURCE_STATES resourceState = _ConvertImageLayout(pTexture->desc.layout); D3D12_CLEAR_VALUE optimizedClearValue = {}; - optimizedClearValue.Color[0] = pTexture2D->desc.clear.color[0]; - optimizedClearValue.Color[1] = pTexture2D->desc.clear.color[1]; - optimizedClearValue.Color[2] = pTexture2D->desc.clear.color[2]; - optimizedClearValue.Color[3] = pTexture2D->desc.clear.color[3]; - optimizedClearValue.DepthStencil.Depth = pTexture2D->desc.clear.depthstencil.depth; - optimizedClearValue.DepthStencil.Stencil = pTexture2D->desc.clear.depthstencil.stencil; + optimizedClearValue.Color[0] = pTexture->desc.clear.color[0]; + optimizedClearValue.Color[1] = pTexture->desc.clear.color[1]; + optimizedClearValue.Color[2] = pTexture->desc.clear.color[2]; + optimizedClearValue.Color[3] = pTexture->desc.clear.color[3]; + optimizedClearValue.DepthStencil.Depth = pTexture->desc.clear.depthstencil.depth; + optimizedClearValue.DepthStencil.Stencil = pTexture->desc.clear.depthstencil.stencil; optimizedClearValue.Format = desc.Format; if (optimizedClearValue.Format == DXGI_FORMAT_R16_TYPELESS) { @@ -2206,6 +2190,23 @@ namespace wiGraphics } bool useClearValue = pDesc->BindFlags & BIND_RENDER_TARGET || pDesc->BindFlags & BIND_DEPTH_STENCIL; + switch (pTexture->desc.type) + { + case TextureDesc::TEXTURE_1D: + desc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE1D; + break; + case TextureDesc::TEXTURE_2D: + desc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D; + break; + case TextureDesc::TEXTURE_3D: + desc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE3D; + desc.DepthOrArraySize = (UINT16)pDesc->Depth; + break; + default: + assert(0); + break; + } + ID3D12Resource* resource; D3D12MA::Allocation* allocation; hr = allocator->CreateResource( @@ -2217,14 +2218,14 @@ namespace wiGraphics IID_PPV_ARGS(&resource) ); assert(SUCCEEDED(hr)); - pTexture2D->resource = (wiCPUHandle)resource; + pTexture->resource = (wiCPUHandle)resource; destroylocker.lock(); - mem_allocations[pTexture2D->resource] = allocation; + mem_allocations[pTexture->resource] = allocation; destroylocker.unlock(); - if (pTexture2D->desc.MipLevels == 0) + if (pTexture->desc.MipLevels == 0) { - pTexture2D->desc.MipLevels = (UINT)log2(std::max(pTexture2D->desc.Width, pTexture2D->desc.Height)); + pTexture->desc.MipLevels = (UINT)log2(std::max(pTexture->desc.Width, pTexture->desc.Height)); } @@ -2248,7 +2249,7 @@ namespace wiGraphics { uint8_t* dest = textureUploader->allocate(static_cast(RequiredSize), D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT); - UINT64 dataSize = UpdateSubresources(static_cast(copyCommandList), (ID3D12Resource*)pTexture2D->resource, + UINT64 dataSize = UpdateSubresources(static_cast(copyCommandList), (ID3D12Resource*)pTexture->resource, textureUploader->resource, textureUploader->calculateOffset(dest), 0, dataCount, data); } copyQueueLock.unlock(); @@ -2256,40 +2257,25 @@ namespace wiGraphics SAFE_DELETE_ARRAY(data); } - if (pTexture2D->desc.BindFlags & BIND_RENDER_TARGET) + if (pTexture->desc.BindFlags & BIND_RENDER_TARGET) { - CreateSubresource(pTexture2D, RTV, 0, -1, 0, -1); + CreateSubresource(pTexture, RTV, 0, -1, 0, -1); } - if (pTexture2D->desc.BindFlags & BIND_DEPTH_STENCIL) + if (pTexture->desc.BindFlags & BIND_DEPTH_STENCIL) { - CreateSubresource(pTexture2D, DSV, 0, -1, 0, -1); + CreateSubresource(pTexture, DSV, 0, -1, 0, -1); } - if (pTexture2D->desc.BindFlags & BIND_SHADER_RESOURCE) + if (pTexture->desc.BindFlags & BIND_SHADER_RESOURCE) { - CreateSubresource(pTexture2D, SRV, 0, -1, 0, -1); + CreateSubresource(pTexture, SRV, 0, -1, 0, -1); } - if (pTexture2D->desc.BindFlags & BIND_UNORDERED_ACCESS) + if (pTexture->desc.BindFlags & BIND_UNORDERED_ACCESS) { - CreateSubresource(pTexture2D, UAV, 0, -1, 0, -1); + CreateSubresource(pTexture, UAV, 0, -1, 0, -1); } return hr; } - HRESULT GraphicsDevice_DX12::CreateTexture3D(const TextureDesc* pDesc, const SubresourceData* pInitialData, Texture3D* pTexture3D) - { - DestroyTexture3D(pTexture3D); - DestroyResource(pTexture3D); - pTexture3D->type = GPUResource::TEXTURE_3D; - pTexture3D->Register(this); - - pTexture3D->desc = *pDesc; - - // TODO - - HRESULT hr = E_FAIL; - - return hr; - } HRESULT GraphicsDevice_DX12::CreateInputLayout(const VertexLayoutDesc* pInputElementDescs, UINT NumElements, const ShaderByteCode* shaderCode, VertexLayout* pInputLayout) { DestroyInputLayout(pInputLayout); @@ -2508,8 +2494,7 @@ namespace wiGraphics for (UINT i = 0; i < pDesc->numAttachments; ++i) { wiHelper::hash_combine(renderpass->hash, pDesc->attachments[i].texture->desc.Format); - wiHelper::hash_combine(renderpass->hash, pDesc->attachments[i].texture->desc.SampleDesc.Count); - wiHelper::hash_combine(renderpass->hash, pDesc->attachments[i].texture->desc.SampleDesc.Quality); + wiHelper::hash_combine(renderpass->hash, pDesc->attachments[i].texture->desc.SampleCount); } return S_OK; @@ -2544,7 +2529,7 @@ namespace wiGraphics break; } - if (texture->type == GPUResource::TEXTURE_1D) + if (texture->desc.type == TextureDesc::TEXTURE_1D) { if (texture->desc.ArraySize > 1) { @@ -2561,7 +2546,7 @@ namespace wiGraphics srv_desc.Texture1D.MipLevels = mipCount; } } - else if (texture->type == GPUResource::TEXTURE_2D) + else if (texture->desc.type == TextureDesc::TEXTURE_2D) { if (texture->desc.ArraySize > 1) { @@ -2584,7 +2569,7 @@ namespace wiGraphics } else { - if (texture->desc.SampleDesc.Count > 1) + if (texture->desc.SampleCount > 1) { srv_desc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2DMSARRAY; srv_desc.Texture2DMSArray.FirstArraySlice = firstSlice; @@ -2602,7 +2587,7 @@ namespace wiGraphics } else { - if (texture->desc.SampleDesc.Count > 1) + if (texture->desc.SampleCount > 1) { srv_desc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2DMS; } @@ -2614,7 +2599,7 @@ namespace wiGraphics } } } - else if (texture->type == GPUResource::TEXTURE_3D) + else if (texture->desc.type == TextureDesc::TEXTURE_3D) { srv_desc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE3D; srv_desc.Texture3D.MostDetailedMip = firstMip; @@ -2656,7 +2641,7 @@ namespace wiGraphics break; } - if (texture->type == GPUResource::TEXTURE_1D) + if (texture->desc.type == TextureDesc::TEXTURE_1D) { if (texture->desc.ArraySize > 1) { @@ -2671,7 +2656,7 @@ namespace wiGraphics uav_desc.Texture1D.MipSlice = firstMip; } } - else if (texture->type == GPUResource::TEXTURE_2D) + else if (texture->desc.type == TextureDesc::TEXTURE_2D) { if (texture->desc.ArraySize > 1) { @@ -2686,7 +2671,7 @@ namespace wiGraphics uav_desc.Texture2D.MipSlice = firstMip; } } - else if (texture->type == GPUResource::TEXTURE_3D) + else if (texture->desc.type == TextureDesc::TEXTURE_3D) { uav_desc.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE3D; uav_desc.Texture3D.MipSlice = firstMip; @@ -2729,7 +2714,7 @@ namespace wiGraphics break; } - if (texture->type == GPUResource::TEXTURE_1D) + if (texture->desc.type == TextureDesc::TEXTURE_1D) { if (texture->desc.ArraySize > 1) { @@ -2744,11 +2729,11 @@ namespace wiGraphics rtv_desc.Texture1D.MipSlice = firstMip; } } - else if (texture->type == GPUResource::TEXTURE_2D) + else if (texture->desc.type == TextureDesc::TEXTURE_2D) { if (texture->desc.ArraySize > 1) { - if (texture->desc.SampleDesc.Count > 1) + if (texture->desc.SampleCount > 1) { rtv_desc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2DMSARRAY; rtv_desc.Texture2DMSArray.FirstArraySlice = firstSlice; @@ -2764,7 +2749,7 @@ namespace wiGraphics } else { - if (texture->desc.SampleDesc.Count > 1) + if (texture->desc.SampleCount > 1) { rtv_desc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2DMS; } @@ -2775,7 +2760,7 @@ namespace wiGraphics } } } - else if (texture->type == GPUResource::TEXTURE_3D) + else if (texture->desc.type == TextureDesc::TEXTURE_3D) { rtv_desc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE3D; rtv_desc.Texture3D.MipSlice = firstMip; @@ -2818,7 +2803,7 @@ namespace wiGraphics break; } - if (texture->type == GPUResource::TEXTURE_1D) + if (texture->desc.type == TextureDesc::TEXTURE_1D) { if (texture->desc.ArraySize > 1) { @@ -2833,11 +2818,11 @@ namespace wiGraphics dsv_desc.Texture1D.MipSlice = firstMip; } } - else if (texture->type == GPUResource::TEXTURE_2D) + else if (texture->desc.type == TextureDesc::TEXTURE_2D) { if (texture->desc.ArraySize > 1) { - if (texture->desc.SampleDesc.Count > 1) + if (texture->desc.SampleCount > 1) { dsv_desc.ViewDimension = D3D12_DSV_DIMENSION_TEXTURE2DMSARRAY; dsv_desc.Texture2DMSArray.FirstArraySlice = firstSlice; @@ -2853,7 +2838,7 @@ namespace wiGraphics } else { - if (texture->desc.SampleDesc.Count > 1) + if (texture->desc.SampleCount > 1) { dsv_desc.ViewDimension = D3D12_DSV_DIMENSION_TEXTURE2DMS; } @@ -2911,43 +2896,23 @@ namespace wiGraphics DeferredDestroy({ DestroyItem::RESOURCEVIEW, FRAMECOUNT, pBuffer->CBV }); pBuffer->CBV = WI_NULL_HANDLE; } - void GraphicsDevice_DX12::DestroyTexture1D(Texture1D* pTexture1D) + void GraphicsDevice_DX12::DestroyTexture(Texture* pTexture) { - DeferredDestroy({ DestroyItem::RENDERTARGETVIEW, FRAMECOUNT, pTexture1D->RTV }); - pTexture1D->RTV = WI_NULL_HANDLE; - for (auto& x : pTexture1D->subresourceRTVs) + DeferredDestroy({ DestroyItem::RENDERTARGETVIEW, FRAMECOUNT, pTexture->RTV }); + pTexture->RTV = WI_NULL_HANDLE; + for (auto& x : pTexture->subresourceRTVs) { DeferredDestroy({ DestroyItem::RENDERTARGETVIEW, FRAMECOUNT, x }); } - pTexture1D->subresourceRTVs.clear(); - } - void GraphicsDevice_DX12::DestroyTexture2D(Texture2D* pTexture2D) - { - DeferredDestroy({ DestroyItem::RENDERTARGETVIEW, FRAMECOUNT, pTexture2D->RTV }); - pTexture2D->RTV = WI_NULL_HANDLE; - for (auto& x : pTexture2D->subresourceRTVs) - { - DeferredDestroy({ DestroyItem::RENDERTARGETVIEW, FRAMECOUNT, x }); - } - pTexture2D->subresourceRTVs.clear(); + pTexture->subresourceRTVs.clear(); - DeferredDestroy({ DestroyItem::DEPTHSTENCILVIEW, FRAMECOUNT, pTexture2D->DSV }); - pTexture2D->DSV = WI_NULL_HANDLE; - for (auto& x : pTexture2D->subresourceDSVs) + DeferredDestroy({ DestroyItem::DEPTHSTENCILVIEW, FRAMECOUNT, pTexture->DSV }); + pTexture->DSV = WI_NULL_HANDLE; + for (auto& x : pTexture->subresourceDSVs) { DeferredDestroy({ DestroyItem::DEPTHSTENCILVIEW, FRAMECOUNT, x }); } - pTexture2D->subresourceDSVs.clear(); - } - void GraphicsDevice_DX12::DestroyTexture3D(Texture3D* pTexture3D) - { - DeferredDestroy({ DestroyItem::RENDERTARGETVIEW, FRAMECOUNT, pTexture3D->RTV }); - pTexture3D->RTV = WI_NULL_HANDLE; - for (auto& x : pTexture3D->subresourceRTVs) - { - DeferredDestroy({ DestroyItem::RENDERTARGETVIEW, FRAMECOUNT, x }); - } - pTexture3D->subresourceRTVs.clear(); + pTexture->subresourceDSVs.clear(); } void GraphicsDevice_DX12::DestroyInputLayout(VertexLayout* pInputLayout) { @@ -3441,7 +3406,7 @@ namespace wiGraphics for (UINT i = 0; i < desc.numAttachments; ++i) { const RenderPassAttachment& attachment = desc.attachments[i]; - const Texture2D* texture = attachment.texture; + const Texture* texture = attachment.texture; int subresource = attachment.subresource; if (attachment.type == RenderPassAttachment::RENDERTARGET) @@ -3847,8 +3812,8 @@ namespace wiGraphics break; } - desc.SampleDesc.Count = attachment.texture->desc.SampleDesc.Count; - desc.SampleDesc.Quality = attachment.texture->desc.SampleDesc.Quality; + desc.SampleDesc.Count = attachment.texture->desc.SampleCount; + desc.SampleDesc.Quality = 0; } } desc.SampleMask = pso->desc.sampleMask; @@ -3966,20 +3931,11 @@ namespace wiGraphics GetFrameResources().descriptors[cmd]->validate(cmd); GetDirectCommandList(cmd)->ExecuteIndirect(dispatchIndirectCommandSignature, 1, (ID3D12Resource*)args->resource, args_offset, nullptr, 0); } - void GraphicsDevice_DX12::CopyTexture2D(const Texture2D* pDst, const Texture2D* pSrc, CommandList cmd) + void GraphicsDevice_DX12::CopyResource(const GPUResource* pDst, const GPUResource* pSrc, CommandList cmd) { GetDirectCommandList(cmd)->CopyResource((ID3D12Resource*)pDst->resource, (ID3D12Resource*)pSrc->resource); - - D3D12_RESOURCE_BARRIER barrier = {}; - barrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE; - barrier.Transition.pResource = (ID3D12Resource*)pDst->resource; - barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_COPY_DEST; - barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_COMMON; - barrier.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES; - barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION; - GetDirectCommandList(cmd)->ResourceBarrier(1, &barrier); } - void GraphicsDevice_DX12::CopyTexture2D_Region(const Texture2D* pDst, UINT dstMip, UINT dstX, UINT dstY, const Texture2D* pSrc, UINT srcMip, CommandList cmd) + void GraphicsDevice_DX12::CopyTexture2D_Region(const Texture* pDst, UINT dstMip, UINT dstX, UINT dstY, const Texture* pSrc, UINT srcMip, CommandList cmd) { D3D12_RESOURCE_DESC dst_desc = ((ID3D12Resource*)pDst->resource)->GetDesc(); D3D12_RESOURCE_DESC src_desc = ((ID3D12Resource*)pSrc->resource)->GetDesc(); @@ -3996,17 +3952,8 @@ namespace wiGraphics GetDirectCommandList(cmd)->CopyTextureRegion(&dst, dstX, dstY, 0, &src, nullptr); - - D3D12_RESOURCE_BARRIER barrier = {}; - barrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE; - barrier.Transition.pResource = (ID3D12Resource*)pDst->resource; - barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_COPY_DEST; - barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_COMMON; - barrier.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES; - barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION; - GetDirectCommandList(cmd)->ResourceBarrier(1, &barrier); } - void GraphicsDevice_DX12::MSAAResolve(const Texture2D* pDst, const Texture2D* pSrc, CommandList cmd) + void GraphicsDevice_DX12::MSAAResolve(const Texture* pDst, const Texture* pSrc, CommandList cmd) { } void GraphicsDevice_DX12::UpdateBuffer(const GPUBuffer* buffer, const void* data, CommandList cmd, int dataSize) diff --git a/WickedEngine/wiGraphicsDevice_DX12.h b/WickedEngine/wiGraphicsDevice_DX12.h index 012efecfd..f9423feb0 100644 --- a/WickedEngine/wiGraphicsDevice_DX12.h +++ b/WickedEngine/wiGraphicsDevice_DX12.h @@ -231,9 +231,7 @@ namespace wiGraphics virtual ~GraphicsDevice_DX12(); HRESULT CreateBuffer(const GPUBufferDesc *pDesc, const SubresourceData* pInitialData, GPUBuffer *pBuffer) override; - HRESULT CreateTexture1D(const TextureDesc* pDesc, const SubresourceData *pInitialData, Texture1D *pTexture1D) override; - HRESULT CreateTexture2D(const TextureDesc* pDesc, const SubresourceData *pInitialData, Texture2D *pTexture2D) override; - HRESULT CreateTexture3D(const TextureDesc* pDesc, const SubresourceData *pInitialData, Texture3D *pTexture3D) override; + HRESULT CreateTexture(const TextureDesc* pDesc, const SubresourceData *pInitialData, Texture *pTexture) override; HRESULT CreateInputLayout(const VertexLayoutDesc *pInputElementDescs, UINT NumElements, const ShaderByteCode* shaderCode, VertexLayout *pInputLayout) override; HRESULT CreateVertexShader(const void *pShaderBytecode, SIZE_T BytecodeLength, VertexShader *pVertexShader) override; HRESULT CreatePixelShader(const void *pShaderBytecode, SIZE_T BytecodeLength, PixelShader *pPixelShader) override; @@ -253,9 +251,7 @@ namespace wiGraphics void DestroyResource(GPUResource* pResource) override; void DestroyBuffer(GPUBuffer *pBuffer) override; - void DestroyTexture1D(Texture1D *pTexture1D) override; - void DestroyTexture2D(Texture2D *pTexture2D) override; - void DestroyTexture3D(Texture3D *pTexture3D) override; + void DestroyTexture(Texture *pTexture) override; void DestroyInputLayout(VertexLayout *pInputLayout) override; void DestroyVertexShader(VertexShader *pVertexShader) override; void DestroyPixelShader(PixelShader *pPixelShader) override; @@ -285,7 +281,7 @@ namespace wiGraphics void SetResolution(int width, int height) override; - Texture2D GetBackBuffer() override; + Texture GetBackBuffer() override; ///////////////Thread-sensitive//////////////////////// @@ -315,9 +311,9 @@ namespace wiGraphics void DrawIndexedInstancedIndirect(const GPUBuffer* args, UINT args_offset, CommandList cmd) override; void Dispatch(UINT threadGroupCountX, UINT threadGroupCountY, UINT threadGroupCountZ, CommandList cmd) override; void DispatchIndirect(const GPUBuffer* args, UINT args_offset, CommandList cmd) override; - void CopyTexture2D(const Texture2D* pDst, const Texture2D* pSrc, CommandList cmd) override; - void CopyTexture2D_Region(const Texture2D* pDst, UINT dstMip, UINT dstX, UINT dstY, const Texture2D* pSrc, UINT srcMip, CommandList cmd) override; - void MSAAResolve(const Texture2D* pDst, const Texture2D* pSrc, CommandList cmd) override; + void CopyResource(const GPUResource* pDst, const GPUResource* pSrc, CommandList cmd) override; + void CopyTexture2D_Region(const Texture* pDst, UINT dstMip, UINT dstX, UINT dstY, const Texture* pSrc, UINT srcMip, CommandList cmd) override; + void MSAAResolve(const Texture* pDst, const Texture* pSrc, CommandList cmd) override; void UpdateBuffer(const GPUBuffer* buffer, const void* data, CommandList cmd, int dataSize = -1) override; void QueryBegin(const GPUQuery *query, CommandList cmd) override; void QueryEnd(const GPUQuery *query, CommandList cmd) override; diff --git a/WickedEngine/wiGraphicsDevice_Vulkan.cpp b/WickedEngine/wiGraphicsDevice_Vulkan.cpp index 14c654d74..53cfc6278 100644 --- a/WickedEngine/wiGraphicsDevice_Vulkan.cpp +++ b/WickedEngine/wiGraphicsDevice_Vulkan.cpp @@ -2248,16 +2248,16 @@ namespace wiGraphics } } - Texture2D GraphicsDevice_Vulkan::GetBackBuffer() + Texture GraphicsDevice_Vulkan::GetBackBuffer() { - return Texture2D(); + return Texture(); } HRESULT GraphicsDevice_Vulkan::CreateBuffer(const GPUBufferDesc *pDesc, const SubresourceData* pInitialData, GPUBuffer *pBuffer) { DestroyBuffer(pBuffer); DestroyResource(pBuffer); - pBuffer->type = GPUResource::BUFFER; + pBuffer->type = GPUResource::GPU_RESOURCE_TYPE::BUFFER; pBuffer->Register(this); pBuffer->desc = *pDesc; @@ -2438,31 +2438,18 @@ namespace wiGraphics return res == VK_SUCCESS ? S_OK : E_FAIL; } - HRESULT GraphicsDevice_Vulkan::CreateTexture1D(const TextureDesc* pDesc, const SubresourceData *pInitialData, Texture1D *pTexture1D) + HRESULT GraphicsDevice_Vulkan::CreateTexture(const TextureDesc* pDesc, const SubresourceData *pInitialData, Texture *pTexture) { - DestroyTexture1D(pTexture1D); - DestroyResource(pTexture1D); - pTexture1D->type = GPUResource::TEXTURE_1D; - pTexture1D->Register(this); + DestroyTexture(pTexture); + DestroyResource(pTexture); + pTexture->type = GPUResource::GPU_RESOURCE_TYPE::TEXTURE; + pTexture->Register(this); - pTexture1D->desc = *pDesc; + pTexture->desc = *pDesc; - // TODO - - return E_FAIL; - } - HRESULT GraphicsDevice_Vulkan::CreateTexture2D(const TextureDesc* pDesc, const SubresourceData *pInitialData, Texture2D *pTexture2D) - { - DestroyTexture2D(pTexture2D); - DestroyResource(pTexture2D); - pTexture2D->type = GPUResource::TEXTURE_2D; - pTexture2D->Register(this); - - pTexture2D->desc = *pDesc; - - if (pTexture2D->desc.MipLevels == 0) + if (pTexture->desc.MipLevels == 0) { - pTexture2D->desc.MipLevels = static_cast(log2(std::max(pTexture2D->desc.Width, pTexture2D->desc.Height))); + pTexture->desc.MipLevels = static_cast(log2(std::max(pTexture->desc.Width, pTexture->desc.Height))); } VmaAllocationCreateInfo allocInfo = {}; @@ -2470,31 +2457,30 @@ namespace wiGraphics VkImageCreateInfo imageInfo = {}; imageInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; - imageInfo.imageType = VK_IMAGE_TYPE_2D; - imageInfo.extent.width = pTexture2D->desc.Width; - imageInfo.extent.height = pTexture2D->desc.Height; + imageInfo.extent.width = pTexture->desc.Width; + imageInfo.extent.height = pTexture->desc.Height; imageInfo.extent.depth = 1; - imageInfo.format = _ConvertFormat(pTexture2D->desc.Format); - imageInfo.arrayLayers = pTexture2D->desc.ArraySize; - imageInfo.mipLevels = pTexture2D->desc.MipLevels; - imageInfo.samples = (VkSampleCountFlagBits)pTexture2D->desc.SampleDesc.Count; + imageInfo.format = _ConvertFormat(pTexture->desc.Format); + imageInfo.arrayLayers = pTexture->desc.ArraySize; + imageInfo.mipLevels = pTexture->desc.MipLevels; + imageInfo.samples = (VkSampleCountFlagBits)pTexture->desc.SampleCount; imageInfo.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; imageInfo.tiling = VK_IMAGE_TILING_OPTIMAL; imageInfo.usage = 0; - if (pTexture2D->desc.BindFlags & BIND_SHADER_RESOURCE) + if (pTexture->desc.BindFlags & BIND_SHADER_RESOURCE) { imageInfo.usage |= VK_IMAGE_USAGE_SAMPLED_BIT; } - if (pTexture2D->desc.BindFlags & BIND_UNORDERED_ACCESS) + if (pTexture->desc.BindFlags & BIND_UNORDERED_ACCESS) { imageInfo.usage |= VK_IMAGE_USAGE_STORAGE_BIT; } - if (pTexture2D->desc.BindFlags & BIND_RENDER_TARGET) + if (pTexture->desc.BindFlags & BIND_RENDER_TARGET) { imageInfo.usage |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; allocInfo.flags |= VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT; } - if (pTexture2D->desc.BindFlags & BIND_DEPTH_STENCIL) + if (pTexture->desc.BindFlags & BIND_DEPTH_STENCIL) { imageInfo.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; allocInfo.flags |= VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT; @@ -2503,22 +2489,39 @@ namespace wiGraphics imageInfo.usage |= VK_IMAGE_USAGE_TRANSFER_DST_BIT; imageInfo.flags = 0; - if (pTexture2D->desc.MiscFlags & RESOURCE_MISC_TEXTURECUBE) + if (pTexture->desc.MiscFlags & RESOURCE_MISC_TEXTURECUBE) { imageInfo.flags |= VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT; } imageInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + switch (pTexture->desc.type) + { + case TextureDesc::TEXTURE_1D: + imageInfo.imageType = VK_IMAGE_TYPE_1D; + break; + case TextureDesc::TEXTURE_2D: + imageInfo.imageType = VK_IMAGE_TYPE_2D; + break; + case TextureDesc::TEXTURE_3D: + imageInfo.imageType = VK_IMAGE_TYPE_3D; + imageInfo.extent.depth = pTexture->desc.Depth; + break; + default: + assert(0); + break; + } + VkResult res; VkImage image; VmaAllocation allocation; res = vmaCreateImage(allocator, &imageInfo, &allocInfo, &image, &allocation, nullptr); assert(res == VK_SUCCESS); - pTexture2D->resource = (wiCPUHandle)image; + pTexture->resource = (wiCPUHandle)image; destroylocker.lock(); - vma_allocations[pTexture2D->resource] = allocation; + vma_allocations[pTexture->resource] = allocation; destroylocker.unlock(); // Issue data copy on request: @@ -2574,7 +2577,7 @@ namespace wiGraphics VkImageMemoryBarrier barrier = {}; barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; - barrier.image = (VkImage)pTexture2D->resource; + barrier.image = (VkImage)pTexture->resource; barrier.oldLayout = imageInfo.initialLayout; barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; barrier.srcAccessMask = 0; @@ -2597,10 +2600,10 @@ namespace wiGraphics 1, &barrier ); - vkCmdCopyBufferToImage(copyCommandBuffer, textureUploader->resource, (VkImage)pTexture2D->resource, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, (uint32_t)copyRegions.size(), copyRegions.data()); + vkCmdCopyBufferToImage(copyCommandBuffer, textureUploader->resource, (VkImage)pTexture->resource, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, (uint32_t)copyRegions.size(), copyRegions.data()); barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; - barrier.newLayout = _ConvertImageLayout(pTexture2D->desc.layout);; + barrier.newLayout = _ConvertImageLayout(pTexture->desc.layout);; barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT; @@ -2615,15 +2618,15 @@ namespace wiGraphics VkImageMemoryBarrier barrier = {}; barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; - barrier.image = (VkImage)pTexture2D->resource; + barrier.image = (VkImage)pTexture->resource; barrier.oldLayout = imageInfo.initialLayout; - barrier.newLayout = _ConvertImageLayout(pTexture2D->desc.layout);; + barrier.newLayout = _ConvertImageLayout(pTexture->desc.layout);; barrier.srcAccessMask = 0; barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT; - if (pTexture2D->desc.BindFlags & BIND_DEPTH_STENCIL) + if (pTexture->desc.BindFlags & BIND_DEPTH_STENCIL) { barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT; - if (IsFormatStencilSupport(pTexture2D->desc.Format)) + if (IsFormatStencilSupport(pTexture->desc.Format)) { barrier.subresourceRange.aspectMask |= VK_IMAGE_ASPECT_STENCIL_BIT; } @@ -2643,38 +2646,25 @@ namespace wiGraphics copyQueueLock.unlock(); } - if (pTexture2D->desc.BindFlags & BIND_RENDER_TARGET) + if (pTexture->desc.BindFlags & BIND_RENDER_TARGET) { - CreateSubresource(pTexture2D, RTV, 0, -1, 0, -1); + CreateSubresource(pTexture, RTV, 0, -1, 0, -1); } - if (pTexture2D->desc.BindFlags & BIND_DEPTH_STENCIL) + if (pTexture->desc.BindFlags & BIND_DEPTH_STENCIL) { - CreateSubresource(pTexture2D, DSV, 0, -1, 0, -1); + CreateSubresource(pTexture, DSV, 0, -1, 0, -1); } - if (pTexture2D->desc.BindFlags & BIND_SHADER_RESOURCE) + if (pTexture->desc.BindFlags & BIND_SHADER_RESOURCE) { - CreateSubresource(pTexture2D, SRV, 0, -1, 0, -1); + CreateSubresource(pTexture, SRV, 0, -1, 0, -1); } - if (pTexture2D->desc.BindFlags & BIND_UNORDERED_ACCESS) + if (pTexture->desc.BindFlags & BIND_UNORDERED_ACCESS) { - CreateSubresource(pTexture2D, UAV, 0, -1, 0, -1); + CreateSubresource(pTexture, UAV, 0, -1, 0, -1); } return res == VK_SUCCESS ? S_OK : E_FAIL; } - HRESULT GraphicsDevice_Vulkan::CreateTexture3D(const TextureDesc* pDesc, const SubresourceData *pInitialData, Texture3D *pTexture3D) - { - DestroyTexture3D(pTexture3D); - DestroyResource(pTexture3D); - pTexture3D->type = GPUResource::TEXTURE_3D; - pTexture3D->Register(this); - - pTexture3D->desc = *pDesc; - - // TODO - - return E_FAIL; - } HRESULT GraphicsDevice_Vulkan::CreateInputLayout(const VertexLayoutDesc *pInputElementDescs, UINT NumElements, const ShaderByteCode* shaderCode, VertexLayout *pInputLayout) { DestroyInputLayout(pInputLayout); @@ -3074,7 +3064,7 @@ namespace wiGraphics for (UINT i = 0; i < pDesc->numAttachments; ++i) { wiHelper::hash_combine(renderpass->hash, pDesc->attachments[i].texture->desc.Format); - wiHelper::hash_combine(renderpass->hash, pDesc->attachments[i].texture->desc.SampleDesc.Count); + wiHelper::hash_combine(renderpass->hash, pDesc->attachments[i].texture->desc.SampleCount); } VkResult res; @@ -3092,12 +3082,12 @@ namespace wiGraphics uint32_t validAttachmentCount = 0; for (UINT i = 0; i < renderpass->desc.numAttachments; ++i) { - const Texture2D* texture = desc.attachments[i].texture; + const Texture* texture = desc.attachments[i].texture; const TextureDesc& texdesc = texture->desc; int subresource = desc.attachments[i].subresource; attachmentDescriptions[validAttachmentCount].format = _ConvertFormat(texdesc.Format); - attachmentDescriptions[validAttachmentCount].samples = (VkSampleCountFlagBits)texdesc.SampleDesc.Count; + attachmentDescriptions[validAttachmentCount].samples = (VkSampleCountFlagBits)texdesc.SampleCount; switch (desc.attachments[i].loadop) { @@ -3260,7 +3250,7 @@ namespace wiGraphics view_desc.subresourceRange.levelCount = mipCount; view_desc.format = _ConvertFormat(texture->desc.Format); - if (texture->type == GPUResource::TEXTURE_1D) + if (texture->desc.type == TextureDesc::TEXTURE_1D) { if (texture->desc.ArraySize > 1) { @@ -3271,7 +3261,7 @@ namespace wiGraphics view_desc.viewType = VK_IMAGE_VIEW_TYPE_1D; } } - else if (texture->type == GPUResource::TEXTURE_2D) + else if (texture->desc.type == TextureDesc::TEXTURE_2D) { if (texture->desc.ArraySize > 1) { @@ -3296,7 +3286,7 @@ namespace wiGraphics view_desc.viewType = VK_IMAGE_VIEW_TYPE_2D; } } - else if (texture->type == GPUResource::TEXTURE_3D) + else if (texture->desc.type == TextureDesc::TEXTURE_3D) { view_desc.viewType = VK_IMAGE_VIEW_TYPE_3D; } @@ -3457,100 +3447,42 @@ namespace wiGraphics } pBuffer->subresourceUAVs.clear(); } - void GraphicsDevice_Vulkan::DestroyTexture1D(Texture1D *pTexture1D) + void GraphicsDevice_Vulkan::DestroyTexture(Texture *pTexture) { - DeferredDestroy({ DestroyItem::IMAGE, FRAMECOUNT, pTexture1D->resource }); - pTexture1D->resource = WI_NULL_HANDLE; + DeferredDestroy({ DestroyItem::IMAGE, pTexture->resource }); + pTexture->resource = WI_NULL_HANDLE; - DeferredDestroy({ DestroyItem::IMAGEVIEW, pTexture1D->RTV }); - pTexture1D->RTV = WI_NULL_HANDLE; - for (auto& x : pTexture1D->subresourceRTVs) + DeferredDestroy({ DestroyItem::IMAGEVIEW, pTexture->RTV }); + pTexture->RTV = WI_NULL_HANDLE; + for (auto& x : pTexture->subresourceRTVs) { DeferredDestroy({ DestroyItem::IMAGEVIEW, x }); } - pTexture1D->subresourceRTVs.clear(); + pTexture->subresourceRTVs.clear(); - DeferredDestroy({ DestroyItem::IMAGEVIEW, pTexture1D->SRV }); - pTexture1D->SRV = WI_NULL_HANDLE; - for (auto& x : pTexture1D->subresourceSRVs) + DeferredDestroy({ DestroyItem::IMAGEVIEW, pTexture->DSV }); + pTexture->DSV = WI_NULL_HANDLE; + for (auto& x : pTexture->subresourceDSVs) { DeferredDestroy({ DestroyItem::IMAGEVIEW, x }); } - pTexture1D->subresourceSRVs.clear(); + pTexture->subresourceDSVs.clear(); - DeferredDestroy({ DestroyItem::IMAGEVIEW, pTexture1D->UAV }); - pTexture1D->UAV = WI_NULL_HANDLE; - for (auto& x : pTexture1D->subresourceUAVs) + DeferredDestroy({ DestroyItem::IMAGEVIEW, pTexture->SRV }); + pTexture->SRV = WI_NULL_HANDLE; + for (auto& x : pTexture->subresourceSRVs) { DeferredDestroy({ DestroyItem::IMAGEVIEW, x }); } - pTexture1D->subresourceUAVs.clear(); - } - void GraphicsDevice_Vulkan::DestroyTexture2D(Texture2D *pTexture2D) - { - DeferredDestroy({ DestroyItem::IMAGE, pTexture2D->resource }); - pTexture2D->resource = WI_NULL_HANDLE; + pTexture->subresourceSRVs.clear(); - DeferredDestroy({ DestroyItem::IMAGEVIEW, pTexture2D->RTV }); - pTexture2D->RTV = WI_NULL_HANDLE; - for (auto& x : pTexture2D->subresourceRTVs) + DeferredDestroy({ DestroyItem::IMAGEVIEW, pTexture->UAV }); + pTexture->UAV = WI_NULL_HANDLE; + for (auto& x : pTexture->subresourceUAVs) { DeferredDestroy({ DestroyItem::IMAGEVIEW, x }); } - pTexture2D->subresourceRTVs.clear(); - - DeferredDestroy({ DestroyItem::IMAGEVIEW, pTexture2D->DSV }); - pTexture2D->DSV = WI_NULL_HANDLE; - for (auto& x : pTexture2D->subresourceDSVs) - { - DeferredDestroy({ DestroyItem::IMAGEVIEW, x }); - } - pTexture2D->subresourceDSVs.clear(); - - DeferredDestroy({ DestroyItem::IMAGEVIEW, pTexture2D->SRV }); - pTexture2D->SRV = WI_NULL_HANDLE; - for (auto& x : pTexture2D->subresourceSRVs) - { - DeferredDestroy({ DestroyItem::IMAGEVIEW, x }); - } - pTexture2D->subresourceSRVs.clear(); - - DeferredDestroy({ DestroyItem::IMAGEVIEW, pTexture2D->UAV }); - pTexture2D->UAV = WI_NULL_HANDLE; - for (auto& x : pTexture2D->subresourceUAVs) - { - DeferredDestroy({ DestroyItem::IMAGEVIEW, x }); - } - pTexture2D->subresourceUAVs.clear(); - } - void GraphicsDevice_Vulkan::DestroyTexture3D(Texture3D *pTexture3D) - { - DeferredDestroy({ DestroyItem::IMAGE, pTexture3D->resource }); - pTexture3D->resource = WI_NULL_HANDLE; - - DeferredDestroy({ DestroyItem::IMAGEVIEW, pTexture3D->RTV }); - pTexture3D->RTV = WI_NULL_HANDLE; - for (auto& x : pTexture3D->subresourceRTVs) - { - DeferredDestroy({ DestroyItem::IMAGEVIEW, x }); - } - pTexture3D->subresourceRTVs.clear(); - - DeferredDestroy({ DestroyItem::IMAGEVIEW, pTexture3D->SRV }); - pTexture3D->SRV = WI_NULL_HANDLE; - for (auto& x : pTexture3D->subresourceSRVs) - { - DeferredDestroy({ DestroyItem::IMAGEVIEW, x }); - } - pTexture3D->subresourceSRVs.clear(); - - DeferredDestroy({ DestroyItem::IMAGEVIEW, pTexture3D->UAV }); - pTexture3D->UAV = WI_NULL_HANDLE; - for (auto& x : pTexture3D->subresourceUAVs) - { - DeferredDestroy({ DestroyItem::IMAGEVIEW, x }); - } - pTexture3D->subresourceUAVs.clear(); + pTexture->subresourceUAVs.clear(); } void GraphicsDevice_Vulkan::DestroyInputLayout(VertexLayout *pInputLayout) { @@ -4580,7 +4512,7 @@ namespace wiGraphics multisampling.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; if (active_renderpass[cmd] != nullptr && active_renderpass[cmd]->desc.numAttachments > 0) { - multisampling.rasterizationSamples = (VkSampleCountFlagBits)active_renderpass[cmd]->desc.attachments[0].texture->desc.SampleDesc.Count; + multisampling.rasterizationSamples = (VkSampleCountFlagBits)active_renderpass[cmd]->desc.attachments[0].texture->desc.SampleCount; } multisampling.minSampleShading = 1.0f; VkSampleMask samplemask = pso->desc.sampleMask; @@ -4729,40 +4661,72 @@ namespace wiGraphics GetFrameResources().descriptors[cmd]->validate(cmd); vkCmdDispatchIndirect(GetDirectCommandList(cmd), (VkBuffer)args->resource, (VkDeviceSize)args_offset); } - void GraphicsDevice_Vulkan::CopyTexture2D(const Texture2D* pDst, const Texture2D* pSrc, CommandList cmd) + void GraphicsDevice_Vulkan::CopyResource(const GPUResource* pDst, const GPUResource* pSrc, CommandList cmd) { - VkImageCopy copy; - copy.extent.width = pDst->desc.Width; - copy.extent.height = pDst->desc.Height; - copy.extent.depth = 1; + if (pDst->type == GPUResource::GPU_RESOURCE_TYPE::TEXTURE && pSrc->type == GPUResource::GPU_RESOURCE_TYPE::TEXTURE) + { + const TextureDesc& dst_desc = ((Texture*)pDst)->GetDesc(); + const TextureDesc& src_desc = ((Texture*)pSrc)->GetDesc(); - copy.srcOffset.x = 0; - copy.srcOffset.y = 0; - copy.srcOffset.z = 0; + VkImageCopy copy; + copy.extent.width = dst_desc.Width; + copy.extent.height = src_desc.Height; + copy.extent.depth = 1; - copy.dstOffset.x = 0; - copy.dstOffset.y = 0; - copy.dstOffset.z = 0; + copy.srcOffset.x = 0; + copy.srcOffset.y = 0; + copy.srcOffset.z = 0; - copy.srcSubresource.aspectMask = pSrc->desc.BindFlags & BIND_DEPTH_STENCIL ? VK_IMAGE_ASPECT_DEPTH_BIT : VK_IMAGE_ASPECT_COLOR_BIT; - copy.srcSubresource.baseArrayLayer = 0; - copy.srcSubresource.layerCount = 1; - copy.srcSubresource.mipLevel = 0; + copy.dstOffset.x = 0; + copy.dstOffset.y = 0; + copy.dstOffset.z = 0; - copy.dstSubresource.aspectMask = pDst->desc.BindFlags & BIND_DEPTH_STENCIL ? VK_IMAGE_ASPECT_DEPTH_BIT : VK_IMAGE_ASPECT_COLOR_BIT; - copy.dstSubresource.baseArrayLayer = 0; - copy.dstSubresource.layerCount = 1; - copy.dstSubresource.mipLevel = 0; + if (src_desc.BindFlags & BIND_DEPTH_STENCIL) + { + copy.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT; + if (IsFormatStencilSupport(src_desc.Format)) + { + copy.srcSubresource.aspectMask |= VK_IMAGE_ASPECT_STENCIL_BIT; + } + } + else + { + copy.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + } + copy.srcSubresource.baseArrayLayer = 0; + copy.srcSubresource.layerCount = 1; + copy.srcSubresource.mipLevel = 0; - vkCmdCopyImage(GetDirectCommandList(cmd), - (VkImage)pSrc->resource, VK_IMAGE_LAYOUT_GENERAL, - (VkImage)pDst->resource, VK_IMAGE_LAYOUT_GENERAL, - 1, ©); + if (dst_desc.BindFlags & BIND_DEPTH_STENCIL) + { + copy.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT; + if (IsFormatStencilSupport(dst_desc.Format)) + { + copy.dstSubresource.aspectMask |= VK_IMAGE_ASPECT_STENCIL_BIT; + } + } + else + { + copy.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + } + copy.dstSubresource.baseArrayLayer = 0; + copy.dstSubresource.layerCount = 1; + copy.dstSubresource.mipLevel = 0; + + vkCmdCopyImage(GetDirectCommandList(cmd), + (VkImage)pSrc->resource, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, + (VkImage)pDst->resource, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, + 1, ©); + } + else + { + assert(0); // todo + } } - void GraphicsDevice_Vulkan::CopyTexture2D_Region(const Texture2D* pDst, UINT dstMip, UINT dstX, UINT dstY, const Texture2D* pSrc, UINT srcMip, CommandList cmd) + void GraphicsDevice_Vulkan::CopyTexture2D_Region(const Texture* pDst, UINT dstMip, UINT dstX, UINT dstY, const Texture* pSrc, UINT srcMip, CommandList cmd) { } - void GraphicsDevice_Vulkan::MSAAResolve(const Texture2D* pDst, const Texture2D* pSrc, CommandList cmd) + void GraphicsDevice_Vulkan::MSAAResolve(const Texture* pDst, const Texture* pSrc, CommandList cmd) { } void GraphicsDevice_Vulkan::UpdateBuffer(const GPUBuffer* buffer, const void* data, CommandList cmd, int dataSize) diff --git a/WickedEngine/wiGraphicsDevice_Vulkan.h b/WickedEngine/wiGraphicsDevice_Vulkan.h index 12a0fb53f..2e2b907ea 100644 --- a/WickedEngine/wiGraphicsDevice_Vulkan.h +++ b/WickedEngine/wiGraphicsDevice_Vulkan.h @@ -259,9 +259,7 @@ namespace wiGraphics virtual ~GraphicsDevice_Vulkan(); HRESULT CreateBuffer(const GPUBufferDesc *pDesc, const SubresourceData* pInitialData, GPUBuffer *pBuffer) override; - HRESULT CreateTexture1D(const TextureDesc* pDesc, const SubresourceData *pInitialData, Texture1D *pTexture1D) override; - HRESULT CreateTexture2D(const TextureDesc* pDesc, const SubresourceData *pInitialData, Texture2D *pTexture2D) override; - HRESULT CreateTexture3D(const TextureDesc* pDesc, const SubresourceData *pInitialData, Texture3D *pTexture3D) override; + HRESULT CreateTexture(const TextureDesc* pDesc, const SubresourceData *pInitialData, Texture *pTexture) override; HRESULT CreateInputLayout(const VertexLayoutDesc *pInputElementDescs, UINT NumElements, const ShaderByteCode* shaderCode, VertexLayout *pInputLayout) override; HRESULT CreateVertexShader(const void *pShaderBytecode, SIZE_T BytecodeLength, VertexShader *pVertexShader) override; HRESULT CreatePixelShader(const void *pShaderBytecode, SIZE_T BytecodeLength, PixelShader *pPixelShader) override; @@ -281,9 +279,7 @@ namespace wiGraphics void DestroyResource(GPUResource* pResource) override; void DestroyBuffer(GPUBuffer *pBuffer) override; - void DestroyTexture1D(Texture1D *pTexture1D) override; - void DestroyTexture2D(Texture2D *pTexture2D) override; - void DestroyTexture3D(Texture3D *pTexture3D) override; + void DestroyTexture(Texture *pTexture) override; void DestroyInputLayout(VertexLayout *pInputLayout) override; void DestroyVertexShader(VertexShader *pVertexShader) override; void DestroyPixelShader(PixelShader *pPixelShader) override; @@ -313,7 +309,7 @@ namespace wiGraphics void SetResolution(int width, int height) override; - Texture2D GetBackBuffer() override; + Texture GetBackBuffer() override; ///////////////Thread-sensitive//////////////////////// @@ -343,9 +339,9 @@ namespace wiGraphics void DrawIndexedInstancedIndirect(const GPUBuffer* args, UINT args_offset, CommandList cmd) override; void Dispatch(UINT threadGroupCountX, UINT threadGroupCountY, UINT threadGroupCountZ, CommandList cmd) override; void DispatchIndirect(const GPUBuffer* args, UINT args_offset, CommandList cmd) override; - void CopyTexture2D(const Texture2D* pDst, const Texture2D* pSrc, CommandList cmd) override; - void CopyTexture2D_Region(const Texture2D* pDst, UINT dstMip, UINT dstX, UINT dstY, const Texture2D* pSrc, UINT srcMip, CommandList cmd) override; - void MSAAResolve(const Texture2D* pDst, const Texture2D* pSrc, CommandList cmd) override; + void CopyResource(const GPUResource* pDst, const GPUResource* pSrc, CommandList cmd) override; + void CopyTexture2D_Region(const Texture* pDst, UINT dstMip, UINT dstX, UINT dstY, const Texture* pSrc, UINT srcMip, CommandList cmd) override; + void MSAAResolve(const Texture* pDst, const Texture* pSrc, CommandList cmd) override; void UpdateBuffer(const GPUBuffer* buffer, const void* data, CommandList cmd, int dataSize = -1) override; void QueryBegin(const GPUQuery *query, CommandList cmd) override; void QueryEnd(const GPUQuery *query, CommandList cmd) override; diff --git a/WickedEngine/wiGraphicsResource.cpp b/WickedEngine/wiGraphicsResource.cpp index 81d77408f..d886d84fe 100644 --- a/WickedEngine/wiGraphicsResource.cpp +++ b/WickedEngine/wiGraphicsResource.cpp @@ -107,27 +107,11 @@ namespace wiGraphics } } - Texture1D::~Texture1D() + Texture::~Texture() { if (device != nullptr) { - device->DestroyTexture1D(this); - } - } - - Texture2D::~Texture2D() - { - if (device != nullptr) - { - device->DestroyTexture2D(this); - } - } - - Texture3D::~Texture3D() - { - if (device != nullptr) - { - device->DestroyTexture3D(this); + device->DestroyTexture(this); } } diff --git a/WickedEngine/wiGraphicsResource.h b/WickedEngine/wiGraphicsResource.h index bd7f22487..932b0b170 100644 --- a/WickedEngine/wiGraphicsResource.h +++ b/WickedEngine/wiGraphicsResource.h @@ -82,16 +82,14 @@ namespace wiGraphics struct GPUResource : public GraphicsDeviceChild { - enum GPU_RESOURCE_TYPE + enum class GPU_RESOURCE_TYPE { BUFFER, - TEXTURE_1D, - TEXTURE_2D, - TEXTURE_3D, + TEXTURE, UNKNOWN_TYPE, - } type = UNKNOWN_TYPE; - inline bool IsTexture() const { return type == TEXTURE_1D || type == TEXTURE_2D || type == TEXTURE_3D; } - inline bool IsBuffer() const { return type == BUFFER; } + } type = GPU_RESOURCE_TYPE::UNKNOWN_TYPE; + inline bool IsTexture() const { return type == GPU_RESOURCE_TYPE::TEXTURE; } + inline bool IsBuffer() const { return type == GPU_RESOURCE_TYPE::BUFFER; } wiCPUHandle SRV = WI_NULL_HANDLE; std::vector subresourceSRVs; @@ -161,24 +159,11 @@ namespace wiGraphics wiCPUHandle DSV = WI_NULL_HANDLE; std::vector subresourceDSVs; + ~Texture(); + const TextureDesc& GetDesc() const { return desc; } }; - struct Texture1D : public Texture - { - virtual ~Texture1D(); - }; - - struct Texture2D : public Texture - { - virtual ~Texture2D(); - }; - - struct Texture3D : public Texture - { - virtual ~Texture3D(); - }; - diff --git a/WickedEngine/wiHelper.cpp b/WickedEngine/wiHelper.cpp index 6c1df0198..a5ac0302f 100644 --- a/WickedEngine/wiHelper.cpp +++ b/WickedEngine/wiHelper.cpp @@ -73,7 +73,7 @@ namespace wiHelper assert(result); } - bool saveTextureToFile(wiGraphics::Texture2D& texture, const string& fileName) + bool saveTextureToFile(wiGraphics::Texture& texture, const string& fileName) { using namespace wiGraphics; @@ -88,13 +88,13 @@ namespace wiHelper vector data(data_size); - Texture2D stagingTex; + Texture stagingTex; TextureDesc staging_desc = desc; staging_desc.Usage = USAGE_STAGING; staging_desc.CPUAccessFlags = CPU_ACCESS_READ; staging_desc.BindFlags = 0; staging_desc.MiscFlags = 0; - HRESULT hr = device->CreateTexture2D(&staging_desc, nullptr, &stagingTex); + HRESULT hr = device->CreateTexture(&staging_desc, nullptr, &stagingTex); assert(SUCCEEDED(hr)); bool download_success = device->DownloadResource(&texture, &stagingTex, data.data()); diff --git a/WickedEngine/wiHelper.h b/WickedEngine/wiHelper.h index f3eaa9322..ac5baabe6 100644 --- a/WickedEngine/wiHelper.h +++ b/WickedEngine/wiHelper.h @@ -22,7 +22,7 @@ namespace wiHelper void screenshot(const std::string& name = ""); - bool saveTextureToFile(wiGraphics::Texture2D& texture, const std::string& fileName); + bool saveTextureToFile(wiGraphics::Texture& texture, const std::string& fileName); bool saveTextureToFile(const std::vector& textureData, const wiGraphics::TextureDesc& desc, const std::string& fileName); diff --git a/WickedEngine/wiImage.cpp b/WickedEngine/wiImage.cpp index 4dd5a2f6d..ee866c38c 100644 --- a/WickedEngine/wiImage.cpp +++ b/WickedEngine/wiImage.cpp @@ -43,7 +43,7 @@ namespace wiImage std::atomic_bool initialized{ false }; - void Draw(const Texture2D* texture, const wiImageParams& params, CommandList cmd) + void Draw(const Texture* texture, const wiImageParams& params, CommandList cmd) { if (!initialized.load()) { diff --git a/WickedEngine/wiImage.h b/WickedEngine/wiImage.h index 50a0e4a38..07b9731d1 100644 --- a/WickedEngine/wiImage.h +++ b/WickedEngine/wiImage.h @@ -7,7 +7,7 @@ struct wiImageParams; namespace wiImage { - void Draw(const wiGraphics::Texture2D* texture, const wiImageParams& params, wiGraphics::CommandList cmd); + void Draw(const wiGraphics::Texture* texture, const wiImageParams& params, wiGraphics::CommandList cmd); void LoadShaders(); void Initialize(); @@ -91,9 +91,9 @@ struct wiImageParams SAMPLEMODE sampleFlag; QUALITY quality; - const wiGraphics::Texture2D* maskMap; + const wiGraphics::Texture* maskMap; // Generic texture - void setMaskMap(const wiGraphics::Texture2D* tex) { maskMap = tex; } + void setMaskMap(const wiGraphics::Texture* tex) { maskMap = tex; } void init() { diff --git a/WickedEngine/wiOcean.cpp b/WickedEngine/wiOcean.cpp index 44f7aeac9..16947d105 100644 --- a/WickedEngine/wiOcean.cpp +++ b/WickedEngine/wiOcean.cpp @@ -85,7 +85,7 @@ void createBufferAndUAV(void* data, UINT byte_width, UINT byte_stride, GPUBuffer } -void createTextureAndViews(UINT width, UINT height, FORMAT format, Texture2D* pTex) +void createTextureAndViews(UINT width, UINT height, FORMAT format, Texture* pTex) { GraphicsDevice* device = wiRenderer::GetDevice(); @@ -95,13 +95,12 @@ void createTextureAndViews(UINT width, UINT height, FORMAT format, Texture2D* pT tex_desc.MipLevels = 0; tex_desc.ArraySize = 1; tex_desc.Format = format; - tex_desc.SampleDesc.Count = 1; - tex_desc.SampleDesc.Quality = 0; + tex_desc.SampleCount = 1; tex_desc.Usage = USAGE_DEFAULT; tex_desc.BindFlags = BIND_SHADER_RESOURCE | BIND_UNORDERED_ACCESS | BIND_RENDER_TARGET; tex_desc.CPUAccessFlags = 0; - device->CreateTexture2D(&tex_desc, nullptr, pTex); + device->CreateTexture(&tex_desc, nullptr, pTex); for (UINT i = 0; i < pTex->GetDesc().MipLevels; ++i) { @@ -462,12 +461,12 @@ void wiOcean::Initialize() wiBackLog::post("wiOcean Initialized"); } -const Texture2D* wiOcean::getDisplacementMap() const +const Texture* wiOcean::getDisplacementMap() const { return &m_pDisplacementMap; } -const Texture2D* wiOcean::getGradientMap() const +const Texture* wiOcean::getGradientMap() const { return &m_pGradientMap; } diff --git a/WickedEngine/wiOcean.h b/WickedEngine/wiOcean.h index c4e350f15..2cd06328d 100644 --- a/WickedEngine/wiOcean.h +++ b/WickedEngine/wiOcean.h @@ -15,15 +15,15 @@ public: void UpdateDisplacementMap(const wiSceneSystem::WeatherComponent& weather, float time, wiGraphics::CommandList cmd) const; void Render(const wiSceneSystem::CameraComponent& camera, const wiSceneSystem::WeatherComponent& weather, float time, wiGraphics::CommandList cmd) const; - const wiGraphics::Texture2D* getDisplacementMap() const; - const wiGraphics::Texture2D* getGradientMap() const; + const wiGraphics::Texture* getDisplacementMap() const; + const wiGraphics::Texture* getGradientMap() const; static void Initialize(); static void LoadShaders(); protected: - wiGraphics::Texture2D m_pDisplacementMap; // (RGBA32F) - wiGraphics::Texture2D m_pGradientMap; // (RGBA16F) + wiGraphics::Texture m_pDisplacementMap; // (RGBA32F) + wiGraphics::Texture m_pGradientMap; // (RGBA16F) void initHeightMap(const wiSceneSystem::WeatherComponent& weather, XMFLOAT2* out_h0, float* out_omega); diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index eeafa9ff0..fa7f269b8 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -120,7 +120,7 @@ UINT entityArrayOffset_ForceFields = 0; UINT entityArrayCount_ForceFields = 0; UINT entityArrayOffset_EnvProbes = 0; UINT entityArrayCount_EnvProbes = 0; -Texture2D* enviroMap = nullptr; +Texture* enviroMap = nullptr; float GameSpeed = 1; bool debugLightCulling = false; bool occlusionCulling = false; @@ -148,9 +148,9 @@ struct VoxelizedSceneData std::unique_ptr ocean; -Texture2D shadowMapArray_2D; -Texture2D shadowMapArray_Cube; -Texture2D shadowMapArray_Transparent; +Texture shadowMapArray_2D; +Texture shadowMapArray_Cube; +Texture shadowMapArray_Transparent; std::vector renderpasses_shadow2D; std::vector renderpasses_shadow2DTransparent; std::vector renderpasses_shadowCube; @@ -164,18 +164,18 @@ std::vector renderablePoints; XMFLOAT4 waterPlane = XMFLOAT4(0, 1, 0, 0); wiSpinLock deferredMIPGenLock; -unordered_set deferredMIPGens; +unordered_set deferredMIPGens; wiGPUBVH sceneBVH; static const int atlasClampBorder = 1; -static Texture2D decalAtlas; -static unordered_map packedDecals; +static Texture decalAtlas; +static unordered_map packedDecals; -Texture2D globalLightmap; -unordered_map packedLightmaps; +Texture globalLightmap; +unordered_map packedLightmaps; @@ -4346,7 +4346,7 @@ void DrawWaterRipples(CommandList cmd) void DrawSoftParticles( const CameraComponent& camera, - const Texture2D& lineardepth, + const Texture& lineardepth, bool distortion, CommandList cmd ) @@ -4397,10 +4397,10 @@ void DrawSoftParticles( } void DrawDeferredLights( const CameraComponent& camera, - const Texture2D& depthbuffer, - const Texture2D& gbuffer0, - const Texture2D& gbuffer1, - const Texture2D& gbuffer2, + const Texture& depthbuffer, + const Texture& gbuffer0, + const Texture& gbuffer1, + const Texture& gbuffer2, CommandList cmd ) { @@ -4619,7 +4619,7 @@ void DrawLightVisualizers( } void DrawVolumeLights( const CameraComponent& camera, - const Texture2D& depthbuffer, + const Texture& depthbuffer, CommandList cmd ) { @@ -4716,7 +4716,7 @@ void DrawVolumeLights( } void DrawLensFlares( const CameraComponent& camera, - const Texture2D& depthbuffer, + const Texture& depthbuffer, CommandList cmd ) { @@ -4767,7 +4767,7 @@ void DrawLensFlares( device->BindConstantBuffer(GS, &constantBuffers[CBTYPE_LENSFLARE], CB_GETBINDSLOT(LensFlareCB), cmd); UINT i = 0; - for (const Texture2D* x : light.lensFlareRimTextures) + for (const Texture* x : light.lensFlareRimTextures) { if (x != nullptr) { @@ -4816,15 +4816,14 @@ void SetShadowProps2D(int resolution, int count, int softShadowQuality) desc.Height = SHADOWRES_2D; desc.MipLevels = 1; desc.ArraySize = SHADOWCOUNT_2D; - desc.SampleDesc.Count = 1; - desc.SampleDesc.Quality = 0; + desc.SampleCount = 1; desc.Usage = USAGE_DEFAULT; desc.CPUAccessFlags = 0; desc.MiscFlags = 0; desc.BindFlags = BIND_DEPTH_STENCIL | BIND_SHADER_RESOURCE; desc.Format = DSFormat_small_alias; - device->CreateTexture2D(&desc, nullptr, &shadowMapArray_2D); + device->CreateTexture(&desc, nullptr, &shadowMapArray_2D); desc.BindFlags = BIND_RENDER_TARGET | BIND_SHADER_RESOURCE; desc.Format = RTFormat_ldr; @@ -4833,7 +4832,7 @@ void SetShadowProps2D(int resolution, int count, int softShadowQuality) desc.clear.color[1] = 1; desc.clear.color[2] = 1; desc.clear.color[3] = 0; - device->CreateTexture2D(&desc, nullptr, &shadowMapArray_Transparent); + device->CreateTexture(&desc, nullptr, &shadowMapArray_Transparent); renderpasses_shadow2D.resize(SHADOWCOUNT_2D); renderpasses_shadow2DTransparent.resize(SHADOWCOUNT_2D); @@ -4881,13 +4880,12 @@ void SetShadowPropsCube(int resolution, int count) desc.MipLevels = 1; desc.ArraySize = 6 * SHADOWCOUNT_CUBE; desc.Format = DSFormat_small_alias; - desc.SampleDesc.Count = 1; - desc.SampleDesc.Quality = 0; + desc.SampleCount = 1; desc.Usage = USAGE_DEFAULT; desc.BindFlags = BIND_DEPTH_STENCIL | BIND_SHADER_RESOURCE; desc.CPUAccessFlags = 0; desc.MiscFlags = RESOURCE_MISC_TEXTURECUBE; - device->CreateTexture2D(&desc, nullptr, &shadowMapArray_Cube); + device->CreateTexture(&desc, nullptr, &shadowMapArray_Cube); renderpasses_shadowCube.resize(SHADOWCOUNT_CUBE); @@ -5264,7 +5262,7 @@ void DrawScene(const CameraComponent& camera, bool tessellation, CommandList cmd } -void DrawScene_Transparent(const CameraComponent& camera, const Texture2D& lineardepth, RENDERPASS renderPass, CommandList cmd, bool grass, bool occlusionCulling) +void DrawScene_Transparent(const CameraComponent& camera, const Texture& lineardepth, RENDERPASS renderPass, CommandList cmd, bool grass, bool occlusionCulling) { GraphicsDevice* device = GetDevice(); const Scene& scene = GetScene(); @@ -6034,7 +6032,7 @@ void DrawSun(CommandList cmd) void DrawDeferredDecals( const CameraComponent& camera, - const Texture2D& depthbuffer, + const Texture& depthbuffer, CommandList cmd ) { @@ -6099,7 +6097,7 @@ void DrawDeferredDecals( static const UINT envmapCount = 16; static const UINT envmapRes = 128; static const UINT envmapMIPs = 8; -static Texture2D envrenderingDepthBuffer; +static Texture envrenderingDepthBuffer; static std::vector renderpasses_envmap; vector probesToRefresh(envmapCount); void ManageEnvProbes() @@ -6172,7 +6170,7 @@ void ManageEnvProbes() desc.MiscFlags = RESOURCE_MISC_TEXTURECUBE; desc.Usage = USAGE_DEFAULT; - HRESULT hr = device->CreateTexture2D(&desc, nullptr, &envrenderingDepthBuffer); + HRESULT hr = device->CreateTexture(&desc, nullptr, &envrenderingDepthBuffer); assert(SUCCEEDED(hr)); desc.ArraySize = envmapCount * 6; @@ -6185,8 +6183,8 @@ void ManageEnvProbes() desc.MiscFlags = RESOURCE_MISC_TEXTURECUBE; desc.Usage = USAGE_DEFAULT; - textures[TEXTYPE_CUBEARRAY_ENVMAPARRAY] = new Texture2D; - hr = device->CreateTexture2D(&desc, nullptr, (Texture2D*)textures[TEXTYPE_CUBEARRAY_ENVMAPARRAY]); + textures[TEXTYPE_CUBEARRAY_ENVMAPARRAY] = new Texture; + hr = device->CreateTexture(&desc, nullptr, textures[TEXTYPE_CUBEARRAY_ENVMAPARRAY]); assert(SUCCEEDED(hr)); renderpasses_envmap.resize(envmapCount); @@ -6199,7 +6197,7 @@ void ManageEnvProbes() RenderPassDesc renderpassdesc; renderpassdesc.numAttachments = 2; - renderpassdesc.attachments[0] = { RenderPassAttachment::RENDERTARGET, RenderPassAttachment::LOADOP_DONTCARE,(Texture2D*)textures[TEXTYPE_CUBEARRAY_ENVMAPARRAY], subresource_index }; + renderpassdesc.attachments[0] = { RenderPassAttachment::RENDERTARGET, RenderPassAttachment::LOADOP_DONTCARE,textures[TEXTYPE_CUBEARRAY_ENVMAPARRAY], subresource_index }; renderpassdesc.attachments[1] = { RenderPassAttachment::DEPTH_STENCIL, RenderPassAttachment::LOADOP_CLEAR,&envrenderingDepthBuffer, -1 }; device->CreateRenderPass(&renderpassdesc, &renderpasses_envmap[subresource_index]); } @@ -6334,7 +6332,7 @@ void RefreshEnvProbes(CommandList cmd) device->RenderPassEnd(cmd); - GenerateMipChain(*(Texture2D*)textures[TEXTYPE_CUBEARRAY_ENVMAPARRAY], MIPGENFILTER_LINEAR, cmd, probe.textureIndex); + GenerateMipChain(*textures[TEXTYPE_CUBEARRAY_ENVMAPARRAY], MIPGENFILTER_LINEAR, cmd, probe.textureIndex); // Filter the enviroment map mip chain according to BRDF: // A bit similar to MIP chain generation, but its input is the MIP-mapped texture, @@ -6388,7 +6386,7 @@ void RefreshEnvProbes(CommandList cmd) static const UINT maxImpostorCount = 8; static const UINT impostorTextureArraySize = maxImpostorCount * impostorCaptureAngles * 3; static const UINT impostorTextureDim = 128; -static Texture2D impostorDepthStencil; +static Texture impostorDepthStencil; static std::vector renderpasses_impostor; vector impostorsToRefresh(maxImpostorCount); void ManageImpostors() @@ -6420,7 +6418,7 @@ void ManageImpostors() desc.BindFlags = BIND_DEPTH_STENCIL; desc.ArraySize = 1; desc.Format = DSFormat_small; - HRESULT hr = device->CreateTexture2D(&desc, nullptr, &impostorDepthStencil); + HRESULT hr = device->CreateTexture(&desc, nullptr, &impostorDepthStencil); assert(SUCCEEDED(hr)); device->SetName(&impostorDepthStencil, "impostorDepthStencil"); @@ -6428,8 +6426,8 @@ void ManageImpostors() desc.ArraySize = impostorTextureArraySize; desc.Format = RTFormat_impostor; - textures[TEXTYPE_2D_IMPOSTORARRAY] = new Texture2D; - hr = device->CreateTexture2D(&desc, nullptr, (Texture2D*)textures[TEXTYPE_2D_IMPOSTORARRAY]); + textures[TEXTYPE_2D_IMPOSTORARRAY] = new Texture; + hr = device->CreateTexture(&desc, nullptr, textures[TEXTYPE_2D_IMPOSTORARRAY]); assert(SUCCEEDED(hr)); device->SetName(textures[TEXTYPE_2D_IMPOSTORARRAY], "ImpostorTarget"); @@ -6443,7 +6441,7 @@ void ManageImpostors() RenderPassDesc renderpassdesc; renderpassdesc.numAttachments = 2; - renderpassdesc.attachments[0] = { RenderPassAttachment::RENDERTARGET,RenderPassAttachment::LOADOP_CLEAR,(Texture2D*)textures[TEXTYPE_2D_IMPOSTORARRAY], subresource_index }; + renderpassdesc.attachments[0] = { RenderPassAttachment::RENDERTARGET,RenderPassAttachment::LOADOP_CLEAR,textures[TEXTYPE_2D_IMPOSTORARRAY], subresource_index }; renderpassdesc.attachments[1] = { RenderPassAttachment::DEPTH_STENCIL,RenderPassAttachment::LOADOP_CLEAR,&impostorDepthStencil, subresource_index }; hr = device->CreateRenderPass(&renderpassdesc, &renderpasses_impostor[subresource_index]); } @@ -6613,6 +6611,7 @@ void VoxelRadiance(CommandList cmd) if (textures[TEXTYPE_3D_VOXELRADIANCE] == nullptr) { TextureDesc desc; + desc.type = TextureDesc::TEXTURE_3D; desc.Width = voxelSceneData.res; desc.Height = voxelSceneData.res; desc.Depth = voxelSceneData.res; @@ -6623,8 +6622,8 @@ void VoxelRadiance(CommandList cmd) desc.CPUAccessFlags = 0; desc.MiscFlags = 0; - textures[TEXTYPE_3D_VOXELRADIANCE] = new Texture3D; - HRESULT hr = device->CreateTexture3D(&desc, nullptr, (Texture3D*)textures[TEXTYPE_3D_VOXELRADIANCE]); + textures[TEXTYPE_3D_VOXELRADIANCE] = new Texture; + HRESULT hr = device->CreateTexture(&desc, nullptr, textures[TEXTYPE_3D_VOXELRADIANCE]); assert(SUCCEEDED(hr)); for (UINT i = 0; i < textures[TEXTYPE_3D_VOXELRADIANCE]->GetDesc().MipLevels; ++i) @@ -6642,9 +6641,9 @@ void VoxelRadiance(CommandList cmd) } if (voxelSceneData.secondaryBounceEnabled && textures[TEXTYPE_3D_VOXELRADIANCE_HELPER] == nullptr) { - TextureDesc desc = ((Texture3D*)textures[TEXTYPE_3D_VOXELRADIANCE])->GetDesc(); - textures[TEXTYPE_3D_VOXELRADIANCE_HELPER] = new Texture3D; - HRESULT hr = device->CreateTexture3D(&desc, nullptr, (Texture3D*)textures[TEXTYPE_3D_VOXELRADIANCE_HELPER]); + TextureDesc desc = textures[TEXTYPE_3D_VOXELRADIANCE]->GetDesc(); + textures[TEXTYPE_3D_VOXELRADIANCE_HELPER] = new Texture; + HRESULT hr = device->CreateTexture(&desc, nullptr, textures[TEXTYPE_3D_VOXELRADIANCE_HELPER]); assert(SUCCEEDED(hr)); for (UINT i = 0; i < textures[TEXTYPE_3D_VOXELRADIANCE_HELPER]->GetDesc().MipLevels; ++i) @@ -6670,7 +6669,7 @@ void VoxelRadiance(CommandList cmd) assert(SUCCEEDED(hr)); } - Texture3D* result = (Texture3D*)textures[TEXTYPE_3D_VOXELRADIANCE]; + Texture* result = textures[TEXTYPE_3D_VOXELRADIANCE]; AABB bbox; XMFLOAT3 extents = voxelSceneData.extents; @@ -6741,7 +6740,7 @@ void VoxelRadiance(CommandList cmd) device->EventBegin("Voxel Radiance Secondary Bounce", cmd); device->UnbindUAVs(1, 1, cmd); // Pre-integrate the voxel texture by creating blurred mip levels: - GenerateMipChain(*(Texture3D*)textures[TEXTYPE_3D_VOXELRADIANCE], MIPGENFILTER_LINEAR, cmd); + GenerateMipChain(*textures[TEXTYPE_3D_VOXELRADIANCE], MIPGENFILTER_LINEAR, cmd); device->BindUAV(CS, textures[TEXTYPE_3D_VOXELRADIANCE_HELPER], 0, cmd); device->BindResource(CS, textures[TEXTYPE_3D_VOXELRADIANCE], 0, cmd); device->BindResource(CS, &resourceBuffers[RBTYPE_VOXELSCENE], 1, cmd); @@ -6756,7 +6755,7 @@ void VoxelRadiance(CommandList cmd) device->Dispatch((UINT)(voxelSceneData.res * voxelSceneData.res * voxelSceneData.res / 256), 1, 1, cmd); device->EventEnd(cmd); - result = (Texture3D*)textures[TEXTYPE_3D_VOXELRADIANCE_HELPER]; + result = textures[TEXTYPE_3D_VOXELRADIANCE_HELPER]; } device->UnbindUAVs(0, 2, cmd); @@ -6782,13 +6781,13 @@ inline XMUINT3 GetEntityCullingTileCount() 1); } void ComputeTiledLightCulling( - const Texture2D& depthbuffer, + const Texture& depthbuffer, CommandList cmd, - const Texture2D* gbuffer0, - const Texture2D* gbuffer1, - const Texture2D* gbuffer2, - const Texture2D* lightbuffer_diffuse, - const Texture2D* lightbuffer_specular + const Texture* gbuffer0, + const Texture* gbuffer1, + const Texture* gbuffer2, + const Texture* lightbuffer_diffuse, + const Texture* lightbuffer_specular ) { const bool deferred = lightbuffer_diffuse != nullptr && lightbuffer_specular != nullptr; @@ -6888,15 +6887,14 @@ void ComputeTiledLightCulling( desc.MipLevels = 1; desc.ArraySize = 1; desc.Format = FORMAT_R8G8B8A8_UNORM; - desc.SampleDesc.Count = 1; - desc.SampleDesc.Quality = 0; + desc.SampleCount = 1; desc.Usage = USAGE_DEFAULT; desc.BindFlags = BIND_SHADER_RESOURCE | BIND_UNORDERED_ACCESS; desc.CPUAccessFlags = 0; desc.MiscFlags = 0; - textures[TEXTYPE_2D_DEBUGUAV] = new Texture2D; - device->CreateTexture2D(&desc, nullptr, (Texture2D*)textures[TEXTYPE_2D_DEBUGUAV]); + textures[TEXTYPE_2D_DEBUGUAV] = new Texture; + device->CreateTexture(&desc, nullptr, textures[TEXTYPE_2D_DEBUGUAV]); } // Perform the culling @@ -6975,7 +6973,7 @@ void ComputeTiledLightCulling( } -void ResolveMSAADepthBuffer(const Texture2D& dst, const Texture2D& src, CommandList cmd) +void ResolveMSAADepthBuffer(const Texture& dst, const Texture& src, CommandList cmd) { GraphicsDevice* device = GetDevice(); device->EventBegin("ResolveMSAADepthBuffer", cmd); @@ -6994,7 +6992,7 @@ void ResolveMSAADepthBuffer(const Texture2D& dst, const Texture2D& src, CommandL device->EventEnd(cmd); } -void DownsampleDepthBuffer(const wiGraphics::Texture2D& src, wiGraphics::CommandList cmd) +void DownsampleDepthBuffer(const wiGraphics::Texture& src, wiGraphics::CommandList cmd) { GraphicsDevice* device = GetDevice(); device->EventBegin("DownsampleDepthBuffer", cmd); @@ -7010,11 +7008,7 @@ void DownsampleDepthBuffer(const wiGraphics::Texture2D& src, wiGraphics::Command device->EventEnd(cmd); } -void GenerateMipChain(const Texture1D& texture, MIPGENFILTER filter, CommandList cmd, int arrayIndex) -{ - assert(0 && "Not implemented!"); -} -void GenerateMipChain(const Texture2D& texture, MIPGENFILTER filter, CommandList cmd, int arrayIndex) +void GenerateMipChain(const Texture& texture, MIPGENFILTER filter, CommandList cmd, int arrayIndex) { GraphicsDevice* device = GetDevice(); TextureDesc desc = texture.GetDesc(); @@ -7028,26 +7022,133 @@ void GenerateMipChain(const Texture2D& texture, MIPGENFILTER filter, CommandList bool hdr = !device->IsFormatUnorm(desc.Format); - if (desc.MiscFlags & RESOURCE_MISC_TEXTURECUBE) + if (desc.type == TextureDesc::TEXTURE_1D) + { + assert(0); // not implemented + } + else if (desc.type == TextureDesc::TEXTURE_2D) { - if (desc.ArraySize > 6) + if (desc.MiscFlags & RESOURCE_MISC_TEXTURECUBE) { - // Cubearray - assert(arrayIndex >= 0 && "You should only filter a specific cube in the array for now, so provide its index!"); + if (desc.ArraySize > 6) + { + // Cubearray + assert(arrayIndex >= 0 && "You should only filter a specific cube in the array for now, so provide its index!"); + + switch (filter) + { + case MIPGENFILTER_POINT: + device->EventBegin("GenerateMipChain CubeArray - PointFilter", cmd); + device->BindComputeShader(computeShaders[hdr ? CSTYPE_GENERATEMIPCHAINCUBEARRAY_FLOAT4_SIMPLEFILTER : CSTYPE_GENERATEMIPCHAINCUBEARRAY_UNORM4_SIMPLEFILTER], cmd); + device->BindSampler(CS, &samplers[SSLOT_POINT_CLAMP], SSLOT_ONDEMAND0, cmd); + break; + case MIPGENFILTER_LINEAR: + device->EventBegin("GenerateMipChain CubeArray - LinearFilter", cmd); + device->BindComputeShader(computeShaders[hdr ? CSTYPE_GENERATEMIPCHAINCUBEARRAY_FLOAT4_SIMPLEFILTER : CSTYPE_GENERATEMIPCHAINCUBEARRAY_UNORM4_SIMPLEFILTER], cmd); + device->BindSampler(CS, &samplers[SSLOT_LINEAR_CLAMP], SSLOT_ONDEMAND0, cmd); + break; + default: + assert(0); + break; + } + + for (UINT i = 0; i < desc.MipLevels - 1; ++i) + { + device->BindUAV(CS, &texture, 0, cmd, i + 1); + device->BindResource(CS, &texture, TEXSLOT_UNIQUE0, cmd, i); + desc.Width = std::max(1u, desc.Width / 2); + desc.Height = std::max(1u, desc.Height / 2); + + GenerateMIPChainCB cb; + cb.outputResolution.x = desc.Width; + cb.outputResolution.y = desc.Height; + cb.outputResolution_rcp.x = 1.0f / cb.outputResolution.x; + cb.outputResolution_rcp.y = 1.0f / cb.outputResolution.y; + cb.arrayIndex = arrayIndex; + device->UpdateBuffer(&constantBuffers[CBTYPE_MIPGEN], &cb, cmd); + device->BindConstantBuffer(CS, &constantBuffers[CBTYPE_MIPGEN], CB_GETBINDSLOT(GenerateMIPChainCB), cmd); + + device->Dispatch( + std::max(1u, (desc.Width + GENERATEMIPCHAIN_2D_BLOCK_SIZE - 1) / GENERATEMIPCHAIN_2D_BLOCK_SIZE), + std::max(1u, (desc.Height + GENERATEMIPCHAIN_2D_BLOCK_SIZE - 1) / GENERATEMIPCHAIN_2D_BLOCK_SIZE), + 6, + cmd); + + device->Barrier(&GPUBarrier::Memory(), 1, cmd); + } + } + else + { + // Cubemap + switch (filter) + { + case MIPGENFILTER_POINT: + device->EventBegin("GenerateMipChain Cube - PointFilter", cmd); + device->BindComputeShader(computeShaders[hdr ? CSTYPE_GENERATEMIPCHAINCUBE_FLOAT4_SIMPLEFILTER : CSTYPE_GENERATEMIPCHAINCUBE_UNORM4_SIMPLEFILTER], cmd); + device->BindSampler(CS, &samplers[SSLOT_POINT_CLAMP], SSLOT_ONDEMAND0, cmd); + break; + case MIPGENFILTER_LINEAR: + device->EventBegin("GenerateMipChain Cube - LinearFilter", cmd); + device->BindComputeShader(computeShaders[hdr ? CSTYPE_GENERATEMIPCHAINCUBE_FLOAT4_SIMPLEFILTER : CSTYPE_GENERATEMIPCHAINCUBE_UNORM4_SIMPLEFILTER], cmd); + device->BindSampler(CS, &samplers[SSLOT_LINEAR_CLAMP], SSLOT_ONDEMAND0, cmd); + break; + default: + assert(0); // not implemented + break; + } + + for (UINT i = 0; i < desc.MipLevels - 1; ++i) + { + device->BindUAV(CS, &texture, 0, cmd, i + 1); + device->BindResource(CS, &texture, TEXSLOT_UNIQUE0, cmd, i); + desc.Width = std::max(1u, desc.Width / 2); + desc.Height = std::max(1u, desc.Height / 2); + + GenerateMIPChainCB cb; + cb.outputResolution.x = desc.Width; + cb.outputResolution.y = desc.Height; + cb.outputResolution_rcp.x = 1.0f / cb.outputResolution.x; + cb.outputResolution_rcp.y = 1.0f / cb.outputResolution.y; + cb.arrayIndex = 0; + device->UpdateBuffer(&constantBuffers[CBTYPE_MIPGEN], &cb, cmd); + device->BindConstantBuffer(CS, &constantBuffers[CBTYPE_MIPGEN], CB_GETBINDSLOT(GenerateMIPChainCB), cmd); + + device->Dispatch( + std::max(1u, (desc.Width + GENERATEMIPCHAIN_2D_BLOCK_SIZE - 1) / GENERATEMIPCHAIN_2D_BLOCK_SIZE), + std::max(1u, (desc.Height + GENERATEMIPCHAIN_2D_BLOCK_SIZE - 1) / GENERATEMIPCHAIN_2D_BLOCK_SIZE), + 6, + cmd); + + device->Barrier(&GPUBarrier::Memory(), 1, cmd); + } + } + + } + else + { + // Texture switch (filter) { case MIPGENFILTER_POINT: - device->EventBegin("GenerateMipChain CubeArray - PointFilter", cmd); - device->BindComputeShader(computeShaders[hdr ? CSTYPE_GENERATEMIPCHAINCUBEARRAY_FLOAT4_SIMPLEFILTER : CSTYPE_GENERATEMIPCHAINCUBEARRAY_UNORM4_SIMPLEFILTER], cmd); + device->EventBegin("GenerateMipChain 2D - PointFilter", cmd); + device->BindComputeShader(computeShaders[hdr ? CSTYPE_GENERATEMIPCHAIN2D_FLOAT4_SIMPLEFILTER : CSTYPE_GENERATEMIPCHAIN2D_UNORM4_SIMPLEFILTER], cmd); device->BindSampler(CS, &samplers[SSLOT_POINT_CLAMP], SSLOT_ONDEMAND0, cmd); break; case MIPGENFILTER_LINEAR: - device->EventBegin("GenerateMipChain CubeArray - LinearFilter", cmd); - device->BindComputeShader(computeShaders[hdr ? CSTYPE_GENERATEMIPCHAINCUBEARRAY_FLOAT4_SIMPLEFILTER : CSTYPE_GENERATEMIPCHAINCUBEARRAY_UNORM4_SIMPLEFILTER], cmd); + device->EventBegin("GenerateMipChain 2D - LinearFilter", cmd); + device->BindComputeShader(computeShaders[hdr ? CSTYPE_GENERATEMIPCHAIN2D_FLOAT4_SIMPLEFILTER : CSTYPE_GENERATEMIPCHAIN2D_UNORM4_SIMPLEFILTER], cmd); device->BindSampler(CS, &samplers[SSLOT_LINEAR_CLAMP], SSLOT_ONDEMAND0, cmd); break; + case MIPGENFILTER_GAUSSIAN: + device->EventBegin("GenerateMipChain 2D - GaussianFilter", cmd); + device->BindComputeShader(computeShaders[hdr ? CSTYPE_GENERATEMIPCHAIN2D_FLOAT4_GAUSSIAN : CSTYPE_GENERATEMIPCHAIN2D_UNORM4_GAUSSIAN], cmd); + break; + case MIPGENFILTER_BICUBIC: + device->EventBegin("GenerateMipChain 2D - BicubicFilter", cmd); + device->BindComputeShader(computeShaders[hdr ? CSTYPE_GENERATEMIPCHAIN2D_FLOAT4_BICUBIC : CSTYPE_GENERATEMIPCHAIN2D_UNORM4_BICUBIC], cmd); + break; default: assert(0); break; @@ -7065,91 +7166,41 @@ void GenerateMipChain(const Texture2D& texture, MIPGENFILTER filter, CommandList cb.outputResolution.y = desc.Height; cb.outputResolution_rcp.x = 1.0f / cb.outputResolution.x; cb.outputResolution_rcp.y = 1.0f / cb.outputResolution.y; - cb.arrayIndex = arrayIndex; + cb.arrayIndex = arrayIndex >= 0 ? (uint)arrayIndex : 0; device->UpdateBuffer(&constantBuffers[CBTYPE_MIPGEN], &cb, cmd); device->BindConstantBuffer(CS, &constantBuffers[CBTYPE_MIPGEN], CB_GETBINDSLOT(GenerateMIPChainCB), cmd); device->Dispatch( std::max(1u, (desc.Width + GENERATEMIPCHAIN_2D_BLOCK_SIZE - 1) / GENERATEMIPCHAIN_2D_BLOCK_SIZE), std::max(1u, (desc.Height + GENERATEMIPCHAIN_2D_BLOCK_SIZE - 1) / GENERATEMIPCHAIN_2D_BLOCK_SIZE), - 6, - cmd); - - device->Barrier(&GPUBarrier::Memory(), 1, cmd); - } - } - else - { - // Cubemap - switch (filter) - { - case MIPGENFILTER_POINT: - device->EventBegin("GenerateMipChain Cube - PointFilter", cmd); - device->BindComputeShader(computeShaders[hdr ? CSTYPE_GENERATEMIPCHAINCUBE_FLOAT4_SIMPLEFILTER : CSTYPE_GENERATEMIPCHAINCUBE_UNORM4_SIMPLEFILTER], cmd); - device->BindSampler(CS, &samplers[SSLOT_POINT_CLAMP], SSLOT_ONDEMAND0, cmd); - break; - case MIPGENFILTER_LINEAR: - device->EventBegin("GenerateMipChain Cube - LinearFilter", cmd); - device->BindComputeShader(computeShaders[hdr ? CSTYPE_GENERATEMIPCHAINCUBE_FLOAT4_SIMPLEFILTER : CSTYPE_GENERATEMIPCHAINCUBE_UNORM4_SIMPLEFILTER], cmd); - device->BindSampler(CS, &samplers[SSLOT_LINEAR_CLAMP], SSLOT_ONDEMAND0, cmd); - break; - default: - assert(0); // not implemented - break; - } - - for (UINT i = 0; i < desc.MipLevels - 1; ++i) - { - device->BindUAV(CS, &texture, 0, cmd, i + 1); - device->BindResource(CS, &texture, TEXSLOT_UNIQUE0, cmd, i); - desc.Width = std::max(1u, desc.Width / 2); - desc.Height = std::max(1u, desc.Height / 2); - - GenerateMIPChainCB cb; - cb.outputResolution.x = desc.Width; - cb.outputResolution.y = desc.Height; - cb.outputResolution_rcp.x = 1.0f / cb.outputResolution.x; - cb.outputResolution_rcp.y = 1.0f / cb.outputResolution.y; - cb.arrayIndex = 0; - device->UpdateBuffer(&constantBuffers[CBTYPE_MIPGEN], &cb, cmd); - device->BindConstantBuffer(CS, &constantBuffers[CBTYPE_MIPGEN], CB_GETBINDSLOT(GenerateMIPChainCB), cmd); - - device->Dispatch( - std::max(1u, (desc.Width + GENERATEMIPCHAIN_2D_BLOCK_SIZE - 1) / GENERATEMIPCHAIN_2D_BLOCK_SIZE), - std::max(1u, (desc.Height + GENERATEMIPCHAIN_2D_BLOCK_SIZE - 1) / GENERATEMIPCHAIN_2D_BLOCK_SIZE), - 6, + 1, cmd); device->Barrier(&GPUBarrier::Memory(), 1, cmd); } } + device->UnbindResources(TEXSLOT_UNIQUE0, 1, cmd); + device->UnbindUAVs(0, 1, cmd); + + device->EventEnd(cmd); } - else + else if (desc.type == TextureDesc::TEXTURE_3D) { - // Texture2D switch (filter) { case MIPGENFILTER_POINT: - device->EventBegin("GenerateMipChain 2D - PointFilter", cmd); - device->BindComputeShader(computeShaders[hdr ? CSTYPE_GENERATEMIPCHAIN2D_FLOAT4_SIMPLEFILTER : CSTYPE_GENERATEMIPCHAIN2D_UNORM4_SIMPLEFILTER], cmd); + device->EventBegin("GenerateMipChain 3D - PointFilter", cmd); + device->BindComputeShader(computeShaders[hdr ? CSTYPE_GENERATEMIPCHAIN3D_FLOAT4_SIMPLEFILTER : CSTYPE_GENERATEMIPCHAIN3D_UNORM4_SIMPLEFILTER], cmd); device->BindSampler(CS, &samplers[SSLOT_POINT_CLAMP], SSLOT_ONDEMAND0, cmd); break; case MIPGENFILTER_LINEAR: - device->EventBegin("GenerateMipChain 2D - LinearFilter", cmd); - device->BindComputeShader(computeShaders[hdr ? CSTYPE_GENERATEMIPCHAIN2D_FLOAT4_SIMPLEFILTER : CSTYPE_GENERATEMIPCHAIN2D_UNORM4_SIMPLEFILTER], cmd); + device->EventBegin("GenerateMipChain 3D - LinearFilter", cmd); + device->BindComputeShader(computeShaders[hdr ? CSTYPE_GENERATEMIPCHAIN3D_FLOAT4_SIMPLEFILTER : CSTYPE_GENERATEMIPCHAIN3D_UNORM4_SIMPLEFILTER], cmd); device->BindSampler(CS, &samplers[SSLOT_LINEAR_CLAMP], SSLOT_ONDEMAND0, cmd); break; - case MIPGENFILTER_GAUSSIAN: - device->EventBegin("GenerateMipChain 2D - GaussianFilter", cmd); - device->BindComputeShader(computeShaders[hdr ? CSTYPE_GENERATEMIPCHAIN2D_FLOAT4_GAUSSIAN : CSTYPE_GENERATEMIPCHAIN2D_UNORM4_GAUSSIAN], cmd); - break; - case MIPGENFILTER_BICUBIC: - device->EventBegin("GenerateMipChain 2D - BicubicFilter", cmd); - device->BindComputeShader(computeShaders[hdr ? CSTYPE_GENERATEMIPCHAIN2D_FLOAT4_BICUBIC : CSTYPE_GENERATEMIPCHAIN2D_UNORM4_BICUBIC], cmd); - break; default: - assert(0); + assert(0); // not implemented break; } @@ -7159,96 +7210,40 @@ void GenerateMipChain(const Texture2D& texture, MIPGENFILTER filter, CommandList device->BindResource(CS, &texture, TEXSLOT_UNIQUE0, cmd, i); desc.Width = std::max(1u, desc.Width / 2); desc.Height = std::max(1u, desc.Height / 2); + desc.Depth = std::max(1u, desc.Depth / 2); GenerateMIPChainCB cb; cb.outputResolution.x = desc.Width; cb.outputResolution.y = desc.Height; + cb.outputResolution.z = desc.Depth; cb.outputResolution_rcp.x = 1.0f / cb.outputResolution.x; cb.outputResolution_rcp.y = 1.0f / cb.outputResolution.y; + cb.outputResolution_rcp.z = 1.0f / cb.outputResolution.z; cb.arrayIndex = arrayIndex >= 0 ? (uint)arrayIndex : 0; device->UpdateBuffer(&constantBuffers[CBTYPE_MIPGEN], &cb, cmd); device->BindConstantBuffer(CS, &constantBuffers[CBTYPE_MIPGEN], CB_GETBINDSLOT(GenerateMIPChainCB), cmd); device->Dispatch( - std::max(1u, (desc.Width + GENERATEMIPCHAIN_2D_BLOCK_SIZE - 1) / GENERATEMIPCHAIN_2D_BLOCK_SIZE), - std::max(1u, (desc.Height + GENERATEMIPCHAIN_2D_BLOCK_SIZE - 1) / GENERATEMIPCHAIN_2D_BLOCK_SIZE), - 1, + std::max(1u, (desc.Width + GENERATEMIPCHAIN_3D_BLOCK_SIZE - 1) / GENERATEMIPCHAIN_3D_BLOCK_SIZE), + std::max(1u, (desc.Height + GENERATEMIPCHAIN_3D_BLOCK_SIZE - 1) / GENERATEMIPCHAIN_3D_BLOCK_SIZE), + std::max(1u, (desc.Depth + GENERATEMIPCHAIN_3D_BLOCK_SIZE - 1) / GENERATEMIPCHAIN_3D_BLOCK_SIZE), cmd); device->Barrier(&GPUBarrier::Memory(), 1, cmd); } + + device->UnbindResources(TEXSLOT_UNIQUE0, 1, cmd); + device->UnbindUAVs(0, 1, cmd); + + device->EventEnd(cmd); } - - device->UnbindResources(TEXSLOT_UNIQUE0, 1, cmd); - device->UnbindUAVs(0, 1, cmd); - - device->EventEnd(cmd); -} -void GenerateMipChain(const Texture3D& texture, MIPGENFILTER filter, CommandList cmd, int arrayIndex) -{ - GraphicsDevice* device = GetDevice(); - TextureDesc desc = texture.GetDesc(); - - if (desc.MipLevels < 2) + else { assert(0); - return; } - - bool hdr = !device->IsFormatUnorm(desc.Format); - - switch (filter) - { - case MIPGENFILTER_POINT: - device->EventBegin("GenerateMipChain 3D - PointFilter", cmd); - device->BindComputeShader(computeShaders[hdr ? CSTYPE_GENERATEMIPCHAIN3D_FLOAT4_SIMPLEFILTER : CSTYPE_GENERATEMIPCHAIN3D_UNORM4_SIMPLEFILTER], cmd); - device->BindSampler(CS, &samplers[SSLOT_POINT_CLAMP], SSLOT_ONDEMAND0, cmd); - break; - case MIPGENFILTER_LINEAR: - device->EventBegin("GenerateMipChain 3D - LinearFilter", cmd); - device->BindComputeShader(computeShaders[hdr ? CSTYPE_GENERATEMIPCHAIN3D_FLOAT4_SIMPLEFILTER : CSTYPE_GENERATEMIPCHAIN3D_UNORM4_SIMPLEFILTER], cmd); - device->BindSampler(CS, &samplers[SSLOT_LINEAR_CLAMP], SSLOT_ONDEMAND0, cmd); - break; - default: - assert(0); // not implemented - break; - } - - for (UINT i = 0; i < desc.MipLevels - 1; ++i) - { - device->BindUAV(CS, &texture, 0, cmd, i + 1); - device->BindResource(CS, &texture, TEXSLOT_UNIQUE0, cmd, i); - desc.Width = std::max(1u, desc.Width / 2); - desc.Height = std::max(1u, desc.Height / 2); - desc.Depth = std::max(1u, desc.Depth / 2); - - GenerateMIPChainCB cb; - cb.outputResolution.x = desc.Width; - cb.outputResolution.y = desc.Height; - cb.outputResolution.z = desc.Depth; - cb.outputResolution_rcp.x = 1.0f / cb.outputResolution.x; - cb.outputResolution_rcp.y = 1.0f / cb.outputResolution.y; - cb.outputResolution_rcp.z = 1.0f / cb.outputResolution.z; - cb.arrayIndex = arrayIndex >= 0 ? (uint)arrayIndex : 0; - device->UpdateBuffer(&constantBuffers[CBTYPE_MIPGEN], &cb, cmd); - device->BindConstantBuffer(CS, &constantBuffers[CBTYPE_MIPGEN], CB_GETBINDSLOT(GenerateMIPChainCB), cmd); - - device->Dispatch( - std::max(1u, (desc.Width + GENERATEMIPCHAIN_3D_BLOCK_SIZE - 1) / GENERATEMIPCHAIN_3D_BLOCK_SIZE), - std::max(1u, (desc.Height + GENERATEMIPCHAIN_3D_BLOCK_SIZE - 1) / GENERATEMIPCHAIN_3D_BLOCK_SIZE), - std::max(1u, (desc.Depth + GENERATEMIPCHAIN_3D_BLOCK_SIZE - 1) / GENERATEMIPCHAIN_3D_BLOCK_SIZE), - cmd); - - device->Barrier(&GPUBarrier::Memory(), 1, cmd); - } - - device->UnbindResources(TEXSLOT_UNIQUE0, 1, cmd); - device->UnbindUAVs(0, 1, cmd); - - device->EventEnd(cmd); } -void CopyTexture2D(const Texture2D& dst, UINT DstMIP, UINT DstX, UINT DstY, const Texture2D& src, UINT SrcMIP, CommandList cmd, BORDEREXPANDSTYLE borderExpand) +void CopyTexture2D(const Texture& dst, UINT DstMIP, UINT DstX, UINT DstY, const Texture& src, UINT SrcMIP, CommandList cmd, BORDEREXPANDSTYLE borderExpand) { GraphicsDevice* device = GetDevice(); @@ -7264,12 +7259,12 @@ void CopyTexture2D(const Texture2D& dst, UINT DstMIP, UINT DstX, UINT DstY, cons { if (hdr) { - device->EventBegin("CopyTexture2D_FLOAT4", cmd); + device->EventBegin("CopyTexture_FLOAT4", cmd); device->BindComputeShader(computeShaders[CSTYPE_COPYTEXTURE2D_FLOAT4], cmd); } else { - device->EventBegin("CopyTexture2D_UNORM4", cmd); + device->EventBegin("CopyTexture_UNORM4", cmd); device->BindComputeShader(computeShaders[CSTYPE_COPYTEXTURE2D_UNORM4], cmd); } } @@ -7277,12 +7272,12 @@ void CopyTexture2D(const Texture2D& dst, UINT DstMIP, UINT DstX, UINT DstY, cons { if (hdr) { - device->EventBegin("CopyTexture2D_BORDEREXPAND_FLOAT4", cmd); + device->EventBegin("CopyTexture_BORDEREXPAND_FLOAT4", cmd); device->BindComputeShader(computeShaders[CSTYPE_COPYTEXTURE2D_FLOAT4_BORDEREXPAND], cmd); } else { - device->EventBegin("CopyTexture2D_BORDEREXPAND_UNORM4", cmd); + device->EventBegin("CopyTexture_BORDEREXPAND_UNORM4", cmd); device->BindComputeShader(computeShaders[CSTYPE_COPYTEXTURE2D_UNORM4_BORDEREXPAND], cmd); } } @@ -7429,7 +7424,7 @@ RayBuffers* GenerateScreenRayBuffers(const CameraComponent& camera, CommandList } void RayTraceScene( const RayBuffers* rayBuffers, - const Texture2D* result, + const Texture* result, int accumulation_sample, CommandList cmd ) @@ -7672,14 +7667,13 @@ void ManageDecalAtlas() desc.MipLevels = 0; desc.ArraySize = 1; desc.Format = FORMAT_R8G8B8A8_UNORM; - desc.SampleDesc.Count = 1; - desc.SampleDesc.Quality = 0; + desc.SampleCount = 1; desc.Usage = USAGE_DEFAULT; desc.BindFlags = BIND_SHADER_RESOURCE | BIND_UNORDERED_ACCESS; desc.CPUAccessFlags = 0; desc.MiscFlags = 0; - device->CreateTexture2D(&desc, nullptr, &decalAtlas); + device->CreateTexture(&desc, nullptr, &decalAtlas); device->SetName(&decalAtlas, "decalAtlas"); for (UINT i = 0; i < decalAtlas.GetDesc().MipLevels; ++i) @@ -7798,8 +7792,8 @@ void ManageLightmapAtlas() // But the global atlas will have less precision for good bandwidth for sampling desc.Format = RTFormat_lightmap_object; - object.lightmap = std::make_unique(); - HRESULT hr = device->CreateTexture2D(&desc, nullptr, object.lightmap.get()); + object.lightmap = std::make_unique(); + HRESULT hr = device->CreateTexture(&desc, nullptr, object.lightmap.get()); assert(SUCCEEDED(hr)); device->SetName(object.lightmap.get(), "objectLightmap"); @@ -7822,7 +7816,7 @@ void ManageLightmapAtlas() { refresh = true; // Create a GPU-side per object lighmap if there is none yet, so that copying into atlas can be done efficiently: - object.lightmap.reset(new Texture2D); + object.lightmap.reset(new Texture); wiTextureHelper::CreateTexture(*object.lightmap.get(), object.lightmapTextureData.data(), object.lightmapWidth, object.lightmapHeight, object.GetLightmapFormat()); } @@ -7870,14 +7864,13 @@ void ManageLightmapAtlas() desc.MipLevels = 1; desc.ArraySize = 1; desc.Format = RTFormat_lightmap_global; - desc.SampleDesc.Count = 1; - desc.SampleDesc.Quality = 0; + desc.SampleCount = 1; desc.Usage = USAGE_DEFAULT; desc.BindFlags = BIND_SHADER_RESOURCE | BIND_UNORDERED_ACCESS; desc.CPUAccessFlags = 0; desc.MiscFlags = 0; - device->CreateTexture2D(&desc, nullptr, &globalLightmap); + device->CreateTexture(&desc, nullptr, &globalLightmap); device->SetName(&globalLightmap, "globalLightmap"); } else @@ -8056,7 +8049,7 @@ void RefreshLightmapAtlas(CommandList cmd) } } -const Texture2D* GetGlobalLightmap() +const Texture* GetGlobalLightmap() { if (globalLightmap.IsValid()) { @@ -8138,7 +8131,7 @@ void UpdateFrameCB(CommandList cmd) } if (textures[TEXTYPE_CUBEARRAY_ENVMAPARRAY] != nullptr) { - cb.g_xFrame_EnvProbeMipCount = static_cast(textures[TEXTYPE_CUBEARRAY_ENVMAPARRAY])->GetDesc().MipLevels; + cb.g_xFrame_EnvProbeMipCount = static_cast(textures[TEXTYPE_CUBEARRAY_ENVMAPARRAY])->GetDesc().MipLevels; cb.g_xFrame_EnvProbeMipCount_rcp = 1.0f / (float)cb.g_xFrame_EnvProbeMipCount; } @@ -8247,7 +8240,7 @@ void SetAlphaRef(float alphaRef, CommandList cmd) GetDevice()->UpdateBuffer(&constantBuffers[CBTYPE_API], &apiCB[cmd], cmd); } } -void BindGBufferTextures(const Texture2D* slot0, const Texture2D* slot1, const Texture2D* slot2, CommandList cmd) +void BindGBufferTextures(const Texture* slot0, const Texture* slot1, const Texture* slot2, CommandList cmd) { GraphicsDevice* device = GetDevice(); @@ -8259,7 +8252,7 @@ void BindGBufferTextures(const Texture2D* slot0, const Texture2D* slot1, const T device->BindResource(CS, slot1, TEXSLOT_GBUFFER1, cmd); device->BindResource(CS, slot2, TEXSLOT_GBUFFER2, cmd); } -void BindDepthTextures(const Texture2D* depth, const Texture2D* linearDepth, CommandList cmd) +void BindDepthTextures(const Texture* depth, const Texture* linearDepth, CommandList cmd) { GraphicsDevice* device = GetDevice(); @@ -8274,12 +8267,12 @@ void BindDepthTextures(const Texture2D* depth, const Texture2D* linearDepth, Com device->BindResource(CS, linearDepth, TEXSLOT_LINEARDEPTH, cmd); } -const Texture2D* ComputeLuminance(const Texture2D& sourceImage, CommandList cmd) +const Texture* ComputeLuminance(const Texture& sourceImage, CommandList cmd) { GraphicsDevice* device = GetDevice(); - static std::unique_ptr luminance_map; - static std::vector luminance_avg(0); + static std::unique_ptr luminance_map; + static std::vector luminance_avg(0); if (luminance_map == nullptr) { for (auto& x : luminance_avg) @@ -8294,23 +8287,22 @@ const Texture2D* ComputeLuminance(const Texture2D& sourceImage, CommandList cmd) desc.MipLevels = 1; desc.ArraySize = 1; desc.Format = FORMAT_R32_FLOAT; - desc.SampleDesc.Count = 1; - desc.SampleDesc.Quality = 0; + desc.SampleCount = 1; desc.Usage = USAGE_DEFAULT; desc.BindFlags = BIND_SHADER_RESOURCE | BIND_UNORDERED_ACCESS; desc.CPUAccessFlags = 0; desc.MiscFlags = 0; - luminance_map.reset(new Texture2D); - device->CreateTexture2D(&desc, nullptr, luminance_map.get()); + luminance_map.reset(new Texture); + device->CreateTexture(&desc, nullptr, luminance_map.get()); while (desc.Width > 1) { desc.Width = std::max(desc.Width / 16, 1u); desc.Height = desc.Width; - Texture2D* tex = new Texture2D; - device->CreateTexture2D(&desc, nullptr, tex); + Texture* tex = new Texture; + device->CreateTexture(&desc, nullptr, tex); luminance_avg.push_back(tex); } @@ -8363,13 +8355,13 @@ const Texture2D* ComputeLuminance(const Texture2D& sourceImage, CommandList cmd) void DeferredComposition( - const Texture2D& gbuffer0, - const Texture2D& gbuffer1, - const Texture2D& gbuffer2, - const Texture2D& lightmap_diffuse, - const Texture2D& lightmap_specular, - const Texture2D& ao, - const Texture2D& lineardepth, + const Texture& gbuffer0, + const Texture& gbuffer1, + const Texture& gbuffer2, + const Texture& lightmap_diffuse, + const Texture& lightmap_specular, + const Texture& ao, + const Texture& lineardepth, CommandList cmd ) { @@ -8393,9 +8385,9 @@ void DeferredComposition( } void Postprocess_Blur_Gaussian( - const Texture2D& input, - const Texture2D& temp, - const Texture2D& output, + const Texture& input, + const Texture& temp, + const Texture& output, CommandList cmd, float amountX, float amountY, @@ -8498,10 +8490,10 @@ void Postprocess_Blur_Gaussian( device->EventEnd(cmd); } void Postprocess_Blur_Bilateral( - const Texture2D& input, - const Texture2D& lineardepth, - const Texture2D& temp, - const Texture2D& output, + const Texture& input, + const Texture& lineardepth, + const Texture& temp, + const Texture& output, CommandList cmd, float amountX, float amountY, @@ -8608,10 +8600,10 @@ void Postprocess_Blur_Bilateral( device->EventEnd(cmd); } void Postprocess_SSAO( - const Texture2D& depthbuffer, - const Texture2D& lineardepth, - const Texture2D& temp, - const Texture2D& output, + const Texture& depthbuffer, + const Texture& lineardepth, + const Texture& temp, + const Texture& output, CommandList cmd, float range, uint32_t samplecount, @@ -8663,11 +8655,11 @@ void Postprocess_SSAO( device->EventEnd(cmd); } void Postprocess_SSR( - const Texture2D& input, - const Texture2D& depthbuffer, - const Texture2D& lineardepth, - const Texture2D& gbuffer1, - const Texture2D& output, + const Texture& input, + const Texture& depthbuffer, + const Texture& lineardepth, + const Texture& gbuffer1, + const Texture& output, CommandList cmd ) { @@ -8719,8 +8711,8 @@ void Postprocess_SSR( device->EventEnd(cmd); } void Postprocess_SSS( - const Texture2D& lineardepth, - const Texture2D& gbuffer0, + const Texture& lineardepth, + const Texture& gbuffer0, const RenderPass& input_output_lightbuffer_diffuse, const RenderPass& input_output_temp1, const RenderPass& input_output_temp2, @@ -8804,8 +8796,8 @@ void Postprocess_SSS( device->EventEnd(cmd); } void Postprocess_LightShafts( - const Texture2D& input, - const Texture2D& output, + const Texture& input, + const Texture& output, CommandList cmd, const XMFLOAT2& center ) @@ -8855,10 +8847,10 @@ void Postprocess_LightShafts( device->EventEnd(cmd); } void Postprocess_DepthOfField( - const Texture2D& input_sharp, - const Texture2D& input_blurred, - const Texture2D& output, - const Texture2D& lineardepth, + const Texture& input_sharp, + const Texture& input_blurred, + const Texture& output, + const Texture& lineardepth, CommandList cmd, float focus ) @@ -8905,8 +8897,8 @@ void Postprocess_DepthOfField( device->EventEnd(cmd); } void Postprocess_Outline( - const Texture2D& input, - const Texture2D& output, + const Texture& input, + const Texture& output, CommandList cmd, float threshold, float thickness, @@ -8958,9 +8950,9 @@ void Postprocess_Outline( device->EventEnd(cmd); } void Postprocess_MotionBlur( - const Texture2D& input, - const Texture2D& velocity, - const Texture2D& output, + const Texture& input, + const Texture& velocity, + const Texture& output, CommandList cmd ) { @@ -9004,8 +8996,8 @@ void Postprocess_MotionBlur( device->EventEnd(cmd); } void Postprocess_BloomSeparate( - const Texture2D& input, - const Texture2D& output, + const Texture& input, + const Texture& output, CommandList cmd, float threshold ) @@ -9048,8 +9040,8 @@ void Postprocess_BloomSeparate( device->EventEnd(cmd); } void Postprocess_FXAA( - const Texture2D& input, - const Texture2D& output, + const Texture& input, + const Texture& output, CommandList cmd ) { @@ -9092,10 +9084,10 @@ void Postprocess_FXAA( device->EventEnd(cmd); } void Postprocess_TemporalAA( - const Texture2D& input_current, - const Texture2D& input_history, - const Texture2D& velocity, - const Texture2D& output, + const Texture& input_current, + const Texture& input_history, + const Texture& velocity, + const Texture& output, CommandList cmd ) { @@ -9140,9 +9132,9 @@ void Postprocess_TemporalAA( device->EventEnd(cmd); } void Postprocess_Colorgrade( - const Texture2D& input, - const Texture2D& lookuptable, - const Texture2D& output, + const Texture& input, + const Texture& lookuptable, + const Texture& output, CommandList cmd ) { @@ -9184,8 +9176,8 @@ void Postprocess_Colorgrade( device->EventEnd(cmd); } void Postprocess_Lineardepth( - const Texture2D& input, - const Texture2D& output, + const Texture& input, + const Texture& output, CommandList cmd ) { @@ -9226,8 +9218,8 @@ void Postprocess_Lineardepth( device->EventEnd(cmd); } void Postprocess_Sharpen( - const Texture2D& input, - const Texture2D& output, + const Texture& input, + const Texture& output, CommandList cmd, float amount ) @@ -9270,10 +9262,10 @@ void Postprocess_Sharpen( device->EventEnd(cmd); } void Postprocess_Tonemap( - const Texture2D& input, - const Texture2D& input_luminance, - const Texture2D& input_distortion, - const Texture2D& output, + const Texture& input, + const Texture& input_luminance, + const Texture& input_distortion, + const Texture& output, CommandList cmd, float exposure ) @@ -9318,8 +9310,8 @@ void Postprocess_Tonemap( device->EventEnd(cmd); } void Postprocess_Chromatic_Aberration( - const Texture2D& input, - const Texture2D& output, + const Texture& input, + const Texture& output, CommandList cmd, float amount ) @@ -9393,7 +9385,7 @@ void AddRenderablePoint(const RenderablePoint& point) renderablePoints.push_back(point); } -void AddDeferredMIPGen(const Texture2D* tex) +void AddDeferredMIPGen(const Texture* tex) { deferredMIPGenLock.lock(); deferredMIPGens.insert(tex); @@ -9497,8 +9489,8 @@ float GetSpecularAAParam() { return SPECULARAA; } void SetAdvancedRefractionsEnabled(bool value) { advancedRefractions = value; } bool GetAdvancedRefractionsEnabled() { return advancedRefractions; } bool IsRequestedReflectionRendering() { return requestReflectionRendering; } -void SetEnvironmentMap(wiGraphics::Texture2D* tex) { enviroMap = tex; } -const Texture2D* GetEnvironmentMap() { return enviroMap; } +void SetEnvironmentMap(wiGraphics::Texture* tex) { enviroMap = tex; } +const Texture* GetEnvironmentMap() { return enviroMap; } void SetGameSpeed(float value) { GameSpeed = std::max(0.0f, value); } float GetGameSpeed() { return GameSpeed; } void SetOceanEnabled(bool enabled) diff --git a/WickedEngine/wiRenderer.h b/WickedEngine/wiRenderer.h index bf3960bc7..26185d365 100644 --- a/WickedEngine/wiRenderer.h +++ b/WickedEngine/wiRenderer.h @@ -105,7 +105,7 @@ namespace wiRenderer // Draw the world from a camera. You must call UpdateCameraCB() at least once in this frame prior to this void DrawScene(const wiSceneSystem::CameraComponent& camera, bool tessellation, wiGraphics::CommandList cmd, RENDERPASS renderPass, bool grass, bool occlusionCulling); // Draw the transparent world from a camera. You must call UpdateCameraCB() at least once in this frame prior to this - void DrawScene_Transparent(const wiSceneSystem::CameraComponent& camera, const wiGraphics::Texture2D& lineardepth, RENDERPASS renderPass, wiGraphics::CommandList cmd, bool grass, bool occlusionCulling); + void DrawScene_Transparent(const wiSceneSystem::CameraComponent& camera, const wiGraphics::Texture& lineardepth, RENDERPASS renderPass, wiGraphics::CommandList cmd, bool grass, bool occlusionCulling); // Draw shadow maps for each visible light that has associated shadow maps void DrawShadowmaps(const wiSceneSystem::CameraComponent& camera, wiGraphics::CommandList cmd, uint32_t layerMask = ~0); // Draw debug world. You must also enable what parts to draw, eg. SetToDrawGridHelper, etc, see implementation for details what can be enabled. @@ -113,17 +113,17 @@ namespace wiRenderer // Draw Soft offscreen particles. Linear depth should be already readable (see BindDepthTextures()) void DrawSoftParticles( const wiSceneSystem::CameraComponent& camera, - const wiGraphics::Texture2D& lineardepth, + const wiGraphics::Texture& lineardepth, bool distortion, wiGraphics::CommandList cmd ); // Draw deferred lights. Gbuffer and depth textures should already be readable (see BindGBufferTextures(), BindDepthTextures()) void DrawDeferredLights( const wiSceneSystem::CameraComponent& camera, - const wiGraphics::Texture2D& depthbuffer, - const wiGraphics::Texture2D& gbuffer0, - const wiGraphics::Texture2D& gbuffer1, - const wiGraphics::Texture2D& gbuffer2, + const wiGraphics::Texture& depthbuffer, + const wiGraphics::Texture& gbuffer0, + const wiGraphics::Texture& gbuffer1, + const wiGraphics::Texture& gbuffer2, wiGraphics::CommandList cmd ); // Draw simple light visualizer geometries @@ -134,19 +134,19 @@ namespace wiRenderer // Draw volumetric light scattering effects void DrawVolumeLights( const wiSceneSystem::CameraComponent& camera, - const wiGraphics::Texture2D& depthbuffer, + const wiGraphics::Texture& depthbuffer, wiGraphics::CommandList cmd ); // Draw Lens Flares for lights that have them enabled void DrawLensFlares( const wiSceneSystem::CameraComponent& camera, - const wiGraphics::Texture2D& depthbuffer, + const wiGraphics::Texture& depthbuffer, wiGraphics::CommandList cmd ); // Draw deferred decals void DrawDeferredDecals( const wiSceneSystem::CameraComponent& camera, - const wiGraphics::Texture2D& depthbuffer, + const wiGraphics::Texture& depthbuffer, wiGraphics::CommandList cmd ); // Call once per frame to re-render out of date environment probes @@ -162,45 +162,45 @@ namespace wiRenderer // Compute light grid tiles for tiled rendering paths // If you specify lightbuffers (diffuse, specular), then a tiled deferred lighting will be computed as well. Otherwise, only the light grid gets computed void ComputeTiledLightCulling( - const wiGraphics::Texture2D& depthbuffer, + const wiGraphics::Texture& depthbuffer, wiGraphics::CommandList cmd, - const wiGraphics::Texture2D* gbuffer0 = nullptr, - const wiGraphics::Texture2D* gbuffer1 = nullptr, - const wiGraphics::Texture2D* gbuffer2 = nullptr, - const wiGraphics::Texture2D* lightbuffer_diffuse = nullptr, - const wiGraphics::Texture2D* lightbuffer_specular = nullptr + const wiGraphics::Texture* gbuffer0 = nullptr, + const wiGraphics::Texture* gbuffer1 = nullptr, + const wiGraphics::Texture* gbuffer2 = nullptr, + const wiGraphics::Texture* lightbuffer_diffuse = nullptr, + const wiGraphics::Texture* lightbuffer_specular = nullptr ); // Run a compute shader that will resolve a MSAA depth buffer to a single-sample texture - void ResolveMSAADepthBuffer(const wiGraphics::Texture2D& dst, const wiGraphics::Texture2D& src, wiGraphics::CommandList cmd); - void DownsampleDepthBuffer(const wiGraphics::Texture2D& src, wiGraphics::CommandList cmd); + void ResolveMSAADepthBuffer(const wiGraphics::Texture& dst, const wiGraphics::Texture& src, wiGraphics::CommandList cmd); + void DownsampleDepthBuffer(const wiGraphics::Texture& src, wiGraphics::CommandList cmd); // Compute the luminance for the source image and return the texture containing the luminance value in pixel [0,0] - const wiGraphics::Texture2D* ComputeLuminance(const wiGraphics::Texture2D& sourceImage, wiGraphics::CommandList cmd); + const wiGraphics::Texture* ComputeLuminance(const wiGraphics::Texture& sourceImage, wiGraphics::CommandList cmd); void DeferredComposition( - const wiGraphics::Texture2D& gbuffer0, - const wiGraphics::Texture2D& gbuffer1, - const wiGraphics::Texture2D& gbuffer2, - const wiGraphics::Texture2D& lightmap_diffuse, - const wiGraphics::Texture2D& lightmap_specular, - const wiGraphics::Texture2D& ao, - const wiGraphics::Texture2D& lineardepth, + const wiGraphics::Texture& gbuffer0, + const wiGraphics::Texture& gbuffer1, + const wiGraphics::Texture& gbuffer2, + const wiGraphics::Texture& lightmap_diffuse, + const wiGraphics::Texture& lightmap_specular, + const wiGraphics::Texture& ao, + const wiGraphics::Texture& lineardepth, wiGraphics::CommandList cmd); void Postprocess_Blur_Gaussian( - const wiGraphics::Texture2D& input, - const wiGraphics::Texture2D& temp, - const wiGraphics::Texture2D& output, + const wiGraphics::Texture& input, + const wiGraphics::Texture& temp, + const wiGraphics::Texture& output, wiGraphics::CommandList cmd, float amountX = 1.0f, float amountY = 1.0f, float mip = 0.0f ); void Postprocess_Blur_Bilateral( - const wiGraphics::Texture2D& input, - const wiGraphics::Texture2D& lineardepth, - const wiGraphics::Texture2D& temp, - const wiGraphics::Texture2D& output, + const wiGraphics::Texture& input, + const wiGraphics::Texture& lineardepth, + const wiGraphics::Texture& temp, + const wiGraphics::Texture& output, wiGraphics::CommandList cmd, float amountX = 1.0f, float amountY = 1.0f, @@ -208,105 +208,105 @@ namespace wiRenderer float mip = 0.0f ); void Postprocess_SSAO( - const wiGraphics::Texture2D& depthbuffer, - const wiGraphics::Texture2D& lineardepth, - const wiGraphics::Texture2D& temp, - const wiGraphics::Texture2D& output, + const wiGraphics::Texture& depthbuffer, + const wiGraphics::Texture& lineardepth, + const wiGraphics::Texture& temp, + const wiGraphics::Texture& output, wiGraphics::CommandList cmd, float range = 1.0f, uint32_t samplecount = 16, float blur = 2.3f ); void Postprocess_SSR( - const wiGraphics::Texture2D& input, - const wiGraphics::Texture2D& depthbuffer, - const wiGraphics::Texture2D& lineardepth, - const wiGraphics::Texture2D& gbuffer1, - const wiGraphics::Texture2D& output, + const wiGraphics::Texture& input, + const wiGraphics::Texture& depthbuffer, + const wiGraphics::Texture& lineardepth, + const wiGraphics::Texture& gbuffer1, + const wiGraphics::Texture& output, wiGraphics::CommandList cmd ); void Postprocess_SSS( - const wiGraphics::Texture2D& lineardepth, - const wiGraphics::Texture2D& gbuffer0, + const wiGraphics::Texture& lineardepth, + const wiGraphics::Texture& gbuffer0, const wiGraphics::RenderPass& input_output_lightbuffer_diffuse, const wiGraphics::RenderPass& input_output_temp1, const wiGraphics::RenderPass& input_output_temp2, wiGraphics::CommandList cmd ); void Postprocess_LightShafts( - const wiGraphics::Texture2D& input, - const wiGraphics::Texture2D& output, + const wiGraphics::Texture& input, + const wiGraphics::Texture& output, wiGraphics::CommandList cmd, const XMFLOAT2& center ); void Postprocess_DepthOfField( - const wiGraphics::Texture2D& input_sharp, - const wiGraphics::Texture2D& input_blurred, - const wiGraphics::Texture2D& output, - const wiGraphics::Texture2D& lineardepth, + const wiGraphics::Texture& input_sharp, + const wiGraphics::Texture& input_blurred, + const wiGraphics::Texture& output, + const wiGraphics::Texture& lineardepth, wiGraphics::CommandList cmd, float focus = 10.0f ); void Postprocess_Outline( - const wiGraphics::Texture2D& input, - const wiGraphics::Texture2D& output, + const wiGraphics::Texture& input, + const wiGraphics::Texture& output, wiGraphics::CommandList cmd, float threshold = 0.1f, float thickness = 1.0f, const XMFLOAT4& color = XMFLOAT4(0, 0, 0, 1) ); void Postprocess_MotionBlur( - const wiGraphics::Texture2D& input, - const wiGraphics::Texture2D& velocity, - const wiGraphics::Texture2D& output, + const wiGraphics::Texture& input, + const wiGraphics::Texture& velocity, + const wiGraphics::Texture& output, wiGraphics::CommandList cmd ); void Postprocess_BloomSeparate( - const wiGraphics::Texture2D& input, - const wiGraphics::Texture2D& output, + const wiGraphics::Texture& input, + const wiGraphics::Texture& output, wiGraphics::CommandList cmd, float threshold ); void Postprocess_FXAA( - const wiGraphics::Texture2D& input, - const wiGraphics::Texture2D& output, + const wiGraphics::Texture& input, + const wiGraphics::Texture& output, wiGraphics::CommandList cmd ); void Postprocess_TemporalAA( - const wiGraphics::Texture2D& input_current, - const wiGraphics::Texture2D& input_history, - const wiGraphics::Texture2D& velocity, - const wiGraphics::Texture2D& output, + const wiGraphics::Texture& input_current, + const wiGraphics::Texture& input_history, + const wiGraphics::Texture& velocity, + const wiGraphics::Texture& output, wiGraphics::CommandList cmd ); void Postprocess_Colorgrade( - const wiGraphics::Texture2D& input, - const wiGraphics::Texture2D& lookuptable, - const wiGraphics::Texture2D& output, + const wiGraphics::Texture& input, + const wiGraphics::Texture& lookuptable, + const wiGraphics::Texture& output, wiGraphics::CommandList cmd ); void Postprocess_Lineardepth( - const wiGraphics::Texture2D& input, - const wiGraphics::Texture2D& output, + const wiGraphics::Texture& input, + const wiGraphics::Texture& output, wiGraphics::CommandList cmd ); void Postprocess_Sharpen( - const wiGraphics::Texture2D& input, - const wiGraphics::Texture2D& output, + const wiGraphics::Texture& input, + const wiGraphics::Texture& output, wiGraphics::CommandList cmd, float amount = 1.0f ); void Postprocess_Tonemap( - const wiGraphics::Texture2D& input, - const wiGraphics::Texture2D& input_luminance, - const wiGraphics::Texture2D& input_distortion, - const wiGraphics::Texture2D& output, + const wiGraphics::Texture& input, + const wiGraphics::Texture& input_luminance, + const wiGraphics::Texture& input_distortion, + const wiGraphics::Texture& output, wiGraphics::CommandList cmd, float exposure ); void Postprocess_Chromatic_Aberration( - const wiGraphics::Texture2D& input, - const wiGraphics::Texture2D& output, + const wiGraphics::Texture& input, + const wiGraphics::Texture& output, wiGraphics::CommandList cmd, float amount = 1.0f ); @@ -328,7 +328,7 @@ namespace wiRenderer // Render the scene with ray tracing. You provide the ray buffer, where each ray maps to one pixel of the result testure void RayTraceScene( const RayBuffers* rayBuffers, - const wiGraphics::Texture2D* result, + const wiGraphics::Texture* result, int accumulation_sample, wiGraphics::CommandList cmd ); @@ -350,9 +350,7 @@ namespace wiRenderer MIPGENFILTER_GAUSSIAN, MIPGENFILTER_BICUBIC, }; - void GenerateMipChain(const wiGraphics::Texture1D& texture, MIPGENFILTER filter, wiGraphics::CommandList cmd, int arrayIndex = -1); - void GenerateMipChain(const wiGraphics::Texture2D& texture, MIPGENFILTER filter, wiGraphics::CommandList cmd, int arrayIndex = -1); - void GenerateMipChain(const wiGraphics::Texture3D& texture, MIPGENFILTER filter, wiGraphics::CommandList cmd, int arrayIndex = -1); + void GenerateMipChain(const wiGraphics::Texture& texture, MIPGENFILTER filter, wiGraphics::CommandList cmd, int arrayIndex = -1); enum BORDEREXPANDSTYLE { @@ -363,8 +361,8 @@ namespace wiRenderer // Performs copy operation even between different texture formats // Can also expand border region according to desired sampler func void CopyTexture2D( - const wiGraphics::Texture2D& dst, UINT DstMIP, UINT DstX, UINT DstY, - const wiGraphics::Texture2D& src, UINT SrcMIP, + const wiGraphics::Texture& dst, UINT DstMIP, UINT DstX, UINT DstY, + const wiGraphics::Texture& src, UINT SrcMIP, wiGraphics::CommandList cmd, BORDEREXPANDSTYLE borderExpand = BORDEREXPAND_DISABLE); @@ -455,8 +453,8 @@ namespace wiRenderer void SetAdvancedRefractionsEnabled(bool value); bool GetAdvancedRefractionsEnabled(); bool IsRequestedReflectionRendering(); - void SetEnvironmentMap(wiGraphics::Texture2D* tex); - const wiGraphics::Texture2D* GetEnvironmentMap(); + void SetEnvironmentMap(wiGraphics::Texture* tex); + const wiGraphics::Texture* GetEnvironmentMap(); const XMFLOAT4& GetWaterPlane(); void SetGameSpeed(float value); float GetGameSpeed(); @@ -468,7 +466,7 @@ namespace wiRenderer void SetRaytraceDebugBVHVisualizerEnabled(bool value); bool GetRaytraceDebugBVHVisualizerEnabled(); - const wiGraphics::Texture2D* GetGlobalLightmap(); + const wiGraphics::Texture* GetGlobalLightmap(); // Gets pick ray according to the current screen resolution and pointer coordinates. Can be used as input into RayIntersectWorld() RAY GetPickRay(long cursorX, long cursorY); @@ -495,7 +493,7 @@ namespace wiRenderer void AddRenderablePoint(const RenderablePoint& point); // Add a texture that should be mipmapped whenever it is feasible to do so - void AddDeferredMIPGen(const wiGraphics::Texture2D* tex); + void AddDeferredMIPGen(const wiGraphics::Texture* tex); struct CustomShader { diff --git a/WickedEngine/wiResourceManager.cpp b/WickedEngine/wiResourceManager.cpp index d1d1f4989..d37d195d4 100644 --- a/WickedEngine/wiResourceManager.cpp +++ b/WickedEngine/wiResourceManager.cpp @@ -13,10 +13,10 @@ using namespace std; using namespace wiGraphics; static const std::unordered_map types = { - make_pair("JPG", wiResourceManager::IMAGE_2D), - make_pair("PNG", wiResourceManager::IMAGE_2D), - make_pair("DDS", wiResourceManager::IMAGE_2D), - make_pair("TGA", wiResourceManager::IMAGE_2D), + make_pair("JPG", wiResourceManager::IMAGE), + make_pair("PNG", wiResourceManager::IMAGE), + make_pair("DDS", wiResourceManager::IMAGE), + make_pair("TGA", wiResourceManager::IMAGE), make_pair("WAV", wiResourceManager::SOUND) }; @@ -73,9 +73,7 @@ const void* wiResourceManager::add(const wiHashString& name, Data_Type newType) switch(type) { - case Data_Type::IMAGE_1D: - case Data_Type::IMAGE_2D: - case Data_Type::IMAGE_3D: + case Data_Type::IMAGE: { if (!ext.compare(std::string("DDS"))) { @@ -191,38 +189,29 @@ const void* wiResourceManager::add(const wiHashString& name, Data_Type newType) { case tinyddsloader::DDSFile::TextureDimension::Texture1D: { - Texture1D* image = new Texture1D; - HRESULT hr = wiRenderer::GetDevice()->CreateTexture1D(&desc, InitData.data(), image); - assert(SUCCEEDED(hr)); - wiRenderer::GetDevice()->SetName(image, nameStr); - success = image; - type = Data_Type::IMAGE_1D; + desc.type = TextureDesc::TEXTURE_1D; } break; case tinyddsloader::DDSFile::TextureDimension::Texture2D: { - Texture2D* image = new Texture2D; - HRESULT hr = wiRenderer::GetDevice()->CreateTexture2D(&desc, InitData.data(), image); - assert(SUCCEEDED(hr)); - wiRenderer::GetDevice()->SetName(image, nameStr); - success = image; - type = Data_Type::IMAGE_2D; + desc.type = TextureDesc::TEXTURE_2D; } break; case tinyddsloader::DDSFile::TextureDimension::Texture3D: { - Texture3D* image = new Texture3D; - HRESULT hr = wiRenderer::GetDevice()->CreateTexture3D(&desc, InitData.data(), image); - assert(SUCCEEDED(hr)); - wiRenderer::GetDevice()->SetName(image, nameStr); - success = image; - type = Data_Type::IMAGE_3D; + desc.type = TextureDesc::TEXTURE_3D; } break; default: assert(0); break; } + + Texture* image = new Texture; + HRESULT hr = wiRenderer::GetDevice()->CreateTexture(&desc, InitData.data(), image); + assert(SUCCEEDED(hr)); + wiRenderer::GetDevice()->SetName(image, nameStr); + success = image; } else assert(0); // failed to load DDS @@ -259,8 +248,8 @@ const void* wiResourceManager::add(const wiHashString& name, Data_Type newType) mipwidth = std::max(1u, mipwidth / 2); } - Texture2D* image = new Texture2D; - HRESULT hr = device->CreateTexture2D(&desc, InitData.data(), image); + Texture* image = new Texture; + HRESULT hr = device->CreateTexture(&desc, InitData.data(), image); assert(SUCCEEDED(hr)); device->SetName(image, nameStr); @@ -396,14 +385,8 @@ bool wiResourceManager::del(const wiHashString& name, bool forceDelete) switch (res.type) { - case Data_Type::IMAGE_1D: - SAFE_DELETE(reinterpret_cast(res.data)); - break; - case Data_Type::IMAGE_2D: - SAFE_DELETE(reinterpret_cast(res.data)); - break; - case Data_Type::IMAGE_3D: - SAFE_DELETE(reinterpret_cast(res.data)); + case Data_Type::IMAGE: + SAFE_DELETE(reinterpret_cast(res.data)); break; case Data_Type::VERTEXSHADER: SAFE_DELETE(reinterpret_cast(res.data)); diff --git a/WickedEngine/wiResourceManager.h b/WickedEngine/wiResourceManager.h index 2b55d69f0..a84a18dfd 100644 --- a/WickedEngine/wiResourceManager.h +++ b/WickedEngine/wiResourceManager.h @@ -13,9 +13,7 @@ private: public: enum Data_Type{ DYNAMIC, - IMAGE_1D, - IMAGE_2D, - IMAGE_3D, + IMAGE, SOUND, VERTEXSHADER, PIXELSHADER, diff --git a/WickedEngine/wiResourceManager_BindLua.cpp b/WickedEngine/wiResourceManager_BindLua.cpp index e8d489eb6..641aa0dcf 100644 --- a/WickedEngine/wiResourceManager_BindLua.cpp +++ b/WickedEngine/wiResourceManager_BindLua.cpp @@ -49,8 +49,8 @@ int wiResourceManager_BindLua::Get(lua_State *L) { switch (data.type) { - case wiResourceManager::Data_Type::IMAGE_2D: - Luna::push(L, new Texture_BindLua((Texture2D*)data.data)); + case wiResourceManager::Data_Type::IMAGE: + Luna::push(L, new Texture_BindLua((Texture*)data.data)); return 1; break; case wiResourceManager::Data_Type::SOUND: diff --git a/WickedEngine/wiSceneSystem.cpp b/WickedEngine/wiSceneSystem.cpp index c91bce97c..7fe74937b 100644 --- a/WickedEngine/wiSceneSystem.cpp +++ b/WickedEngine/wiSceneSystem.cpp @@ -226,7 +226,7 @@ namespace wiSceneSystem XMStoreFloat3(&scale_local, S); } - const Texture2D* MaterialComponent::GetBaseColorMap() const + const Texture* MaterialComponent::GetBaseColorMap() const { if (baseColorMap != nullptr) { @@ -234,7 +234,7 @@ namespace wiSceneSystem } return wiTextureHelper::getWhite(); } - const Texture2D* MaterialComponent::GetNormalMap() const + const Texture* MaterialComponent::GetNormalMap() const { return normalMap; //if (normalMap != nullptr) @@ -243,7 +243,7 @@ namespace wiSceneSystem //} //return wiTextureHelper::getNormalMapDefault(); } - const Texture2D* MaterialComponent::GetSurfaceMap() const + const Texture* MaterialComponent::GetSurfaceMap() const { if (surfaceMap != nullptr) { @@ -251,7 +251,7 @@ namespace wiSceneSystem } return wiTextureHelper::getWhite(); } - const Texture2D* MaterialComponent::GetDisplacementMap() const + const Texture* MaterialComponent::GetDisplacementMap() const { if (displacementMap != nullptr) { @@ -259,7 +259,7 @@ namespace wiSceneSystem } return wiTextureHelper::getWhite(); } - const Texture2D* MaterialComponent::GetEmissiveMap() const + const Texture* MaterialComponent::GetEmissiveMap() const { if (emissiveMap != nullptr) { @@ -267,7 +267,7 @@ namespace wiSceneSystem } return wiTextureHelper::getWhite(); } - const Texture2D* MaterialComponent::GetOcclusionMap() const + const Texture* MaterialComponent::GetOcclusionMap() const { if (occlusionMap != nullptr) { @@ -895,8 +895,8 @@ namespace wiSceneSystem staging_desc.BindFlags = 0; staging_desc.MiscFlags = 0; - Texture2D stagingTex; - hr = device->CreateTexture2D(&staging_desc, nullptr, &stagingTex); + Texture stagingTex; + hr = device->CreateTexture(&staging_desc, nullptr, &stagingTex); assert(SUCCEEDED(hr)); bool download_success = device->DownloadResource(lightmap.get(), &stagingTex, lightmapTextureData.data()); @@ -1329,12 +1329,12 @@ namespace wiSceneSystem if (!textureName.empty()) { material.baseColorMapName = textureName; - material.baseColorMap = (Texture2D*)wiResourceManager::GetGlobal().add(material.baseColorMapName); + material.baseColorMap = (Texture*)wiResourceManager::GetGlobal().add(material.baseColorMapName); } if (!normalMapName.empty()) { material.normalMapName = normalMapName; - material.normalMap = (Texture2D*)wiResourceManager::GetGlobal().add(material.normalMapName); + material.normalMap = (Texture*)wiResourceManager::GetGlobal().add(material.normalMapName); } return entity; diff --git a/WickedEngine/wiSceneSystem.h b/WickedEngine/wiSceneSystem.h index 8bfaf5845..1583688b0 100644 --- a/WickedEngine/wiSceneSystem.h +++ b/WickedEngine/wiSceneSystem.h @@ -151,12 +151,12 @@ namespace wiSceneSystem uint32_t uvset_occlusionMap = 0; // Non-serialized attributes: - const wiGraphics::Texture2D* baseColorMap = nullptr; - const wiGraphics::Texture2D* surfaceMap = nullptr; - const wiGraphics::Texture2D* normalMap = nullptr; - const wiGraphics::Texture2D* displacementMap = nullptr; - const wiGraphics::Texture2D* emissiveMap = nullptr; - const wiGraphics::Texture2D* occlusionMap = nullptr; + const wiGraphics::Texture* baseColorMap = nullptr; + const wiGraphics::Texture* surfaceMap = nullptr; + const wiGraphics::Texture* normalMap = nullptr; + const wiGraphics::Texture* displacementMap = nullptr; + const wiGraphics::Texture* emissiveMap = nullptr; + const wiGraphics::Texture* occlusionMap = nullptr; std::unique_ptr constantBuffer; int customShaderID = -1; // for now, this is not serialized; need to consider actual proper use case first @@ -172,12 +172,12 @@ namespace wiSceneSystem return wiRenderer::CombineStencilrefs(engineStencilRef, userStencilRef); } - const wiGraphics::Texture2D* GetBaseColorMap() const; - const wiGraphics::Texture2D* GetNormalMap() const; - const wiGraphics::Texture2D* GetSurfaceMap() const; - const wiGraphics::Texture2D* GetDisplacementMap() const; - const wiGraphics::Texture2D* GetEmissiveMap() const; - const wiGraphics::Texture2D* GetOcclusionMap() const; + const wiGraphics::Texture* GetBaseColorMap() const; + const wiGraphics::Texture* GetNormalMap() const; + const wiGraphics::Texture* GetSurfaceMap() const; + const wiGraphics::Texture* GetDisplacementMap() const; + const wiGraphics::Texture* GetEmissiveMap() const; + const wiGraphics::Texture* GetOcclusionMap() const; inline float GetOpacity() const { return baseColor.w; } inline float GetEmissiveStrength() const { return emissiveColor.w; } @@ -470,7 +470,7 @@ namespace wiSceneSystem // Non-serialized attributes: XMFLOAT4 globalLightMapMulAdd = XMFLOAT4(0, 0, 0, 0); - std::unique_ptr lightmap; + std::unique_ptr lightmap; std::unique_ptr renderpass_lightmap_clear; std::unique_ptr renderpass_lightmap_accumulate; uint32_t lightmapIterationCount = 0; @@ -688,7 +688,7 @@ namespace wiSceneSystem XMFLOAT3 right; int shadowMap_index = -1; - std::vector lensFlareRimTextures; + std::vector lensFlareRimTextures; inline void SetCastShadow(bool value) { if (value) { _flags |= CAST_SHADOW; } else { _flags &= ~CAST_SHADOW; } } inline void SetVolumetricsEnabled(bool value) { if (value) { _flags |= VOLUMETRICS; } else { _flags &= ~VOLUMETRICS; } } @@ -836,8 +836,8 @@ namespace wiSceneSystem XMFLOAT4 atlasMulAdd; XMFLOAT4X4 world; - const wiGraphics::Texture2D* texture = nullptr; - const wiGraphics::Texture2D* normal = nullptr; + const wiGraphics::Texture* texture = nullptr; + const wiGraphics::Texture* normal = nullptr; inline float GetOpacity() const { return color.w; } diff --git a/WickedEngine/wiSceneSystem_Serializers.cpp b/WickedEngine/wiSceneSystem_Serializers.cpp index 3099953a6..e8a5ed837 100644 --- a/WickedEngine/wiSceneSystem_Serializers.cpp +++ b/WickedEngine/wiSceneSystem_Serializers.cpp @@ -131,27 +131,27 @@ namespace wiSceneSystem if (!baseColorMapName.empty()) { - baseColorMap = (wiGraphics::Texture2D*)wiResourceManager::GetGlobal().add(dir + baseColorMapName); + baseColorMap = (wiGraphics::Texture*)wiResourceManager::GetGlobal().add(dir + baseColorMapName); } if (!surfaceMapName.empty()) { - surfaceMap = (wiGraphics::Texture2D*)wiResourceManager::GetGlobal().add(dir + surfaceMapName); + surfaceMap = (wiGraphics::Texture*)wiResourceManager::GetGlobal().add(dir + surfaceMapName); } if (!normalMapName.empty()) { - normalMap = (wiGraphics::Texture2D*)wiResourceManager::GetGlobal().add(dir + normalMapName); + normalMap = (wiGraphics::Texture*)wiResourceManager::GetGlobal().add(dir + normalMapName); } if (!displacementMapName.empty()) { - displacementMap = (wiGraphics::Texture2D*)wiResourceManager::GetGlobal().add(dir + displacementMapName); + displacementMap = (wiGraphics::Texture*)wiResourceManager::GetGlobal().add(dir + displacementMapName); } if (!emissiveMapName.empty()) { - emissiveMap = (wiGraphics::Texture2D*)wiResourceManager::GetGlobal().add(dir + emissiveMapName); + emissiveMap = (wiGraphics::Texture*)wiResourceManager::GetGlobal().add(dir + emissiveMapName); } if (!occlusionMapName.empty()) { - occlusionMap = (wiGraphics::Texture2D*)wiResourceManager::GetGlobal().add(dir + occlusionMapName); + occlusionMap = (wiGraphics::Texture*)wiResourceManager::GetGlobal().add(dir + occlusionMapName); } } @@ -489,7 +489,7 @@ namespace wiSceneSystem { if (!lensFlareNames[i].empty()) { - lensFlareRimTextures[i] = (wiGraphics::Texture2D*)wiResourceManager::GetGlobal().add(dir + lensFlareNames[i]); + lensFlareRimTextures[i] = (wiGraphics::Texture*)wiResourceManager::GetGlobal().add(dir + lensFlareNames[i]); } } } diff --git a/WickedEngine/wiSprite.cpp b/WickedEngine/wiSprite.cpp index 0f8db0f31..25e79c177 100644 --- a/WickedEngine/wiSprite.cpp +++ b/WickedEngine/wiSprite.cpp @@ -12,11 +12,11 @@ wiSprite::wiSprite(const std::string& newTexture, const std::string& newMask) if (!newTexture.empty()) { texture = newTexture; - texturePointer = (Texture2D*)wiResourceManager::GetGlobal().add(newTexture); + texturePointer = (Texture*)wiResourceManager::GetGlobal().add(newTexture); } if (!newMask.empty()) { - maskPointer = (Texture2D*)wiResourceManager::GetGlobal().add(newMask); + maskPointer = (Texture*)wiResourceManager::GetGlobal().add(newMask); params.setMaskMap(maskPointer); mask = newMask; } diff --git a/WickedEngine/wiSprite.h b/WickedEngine/wiSprite.h index ca45ecaa8..75b2692aa 100644 --- a/WickedEngine/wiSprite.h +++ b/WickedEngine/wiSprite.h @@ -9,8 +9,8 @@ class wiSprite { private: std::string texture, mask; - const wiGraphics::Texture2D* texturePointer = nullptr; - const wiGraphics::Texture2D* maskPointer = nullptr; + const wiGraphics::Texture* texturePointer = nullptr; + const wiGraphics::Texture* maskPointer = nullptr; public: wiSprite(const std::string& newTexture = "", const std::string& newMask = ""); void Destroy(); @@ -80,7 +80,7 @@ public: }; Anim anim; - const wiGraphics::Texture2D* getTexture() { return texturePointer; } - void setTexture(const wiGraphics::Texture2D* value) { texturePointer = value; } + const wiGraphics::Texture* getTexture() { return texturePointer; } + void setTexture(const wiGraphics::Texture* value) { texturePointer = value; } }; diff --git a/WickedEngine/wiTextureHelper.cpp b/WickedEngine/wiTextureHelper.cpp index a6648dbf0..a27c99290 100644 --- a/WickedEngine/wiTextureHelper.cpp +++ b/WickedEngine/wiTextureHelper.cpp @@ -20,8 +20,8 @@ namespace wiTextureHelper HELPERTEXTURE_BLACKCUBEMAP, HELPERTEXTURE_COUNT }; - wiGraphics::Texture2D helperTextures[HELPERTEXTURE_COUNT] = {}; - std::unordered_map colorTextures; + wiGraphics::Texture helperTextures[HELPERTEXTURE_COUNT]; + std::unordered_map colorTextures; wiSpinLock colorlock; void Initialize() @@ -91,8 +91,7 @@ namespace wiTextureHelper texDesc.ArraySize = 6; texDesc.Format = FORMAT_R8G8B8A8_UNORM; texDesc.CPUAccessFlags = 0; - texDesc.SampleDesc.Count = 1; - texDesc.SampleDesc.Quality = 0; + texDesc.SampleCount = 1; texDesc.Usage = USAGE_DEFAULT; texDesc.BindFlags = BIND_SHADER_RESOURCE; texDesc.CPUAccessFlags = 0; @@ -114,7 +113,7 @@ namespace wiTextureHelper pData[cubeMapFaceIndex].SysMemSlicePitch = 0; } - HRESULT hr = wiRenderer::GetDevice()->CreateTexture2D(&texDesc, &pData[0], &helperTextures[HELPERTEXTURE_BLACKCUBEMAP]); + HRESULT hr = wiRenderer::GetDevice()->CreateTexture(&texDesc, &pData[0], &helperTextures[HELPERTEXTURE_BLACKCUBEMAP]); assert(SUCCEEDED(hr)); wiRenderer::GetDevice()->SetName(&helperTextures[HELPERTEXTURE_BLACKCUBEMAP], "HELPERTEXTURE_BLACKCUBEMAP"); } @@ -122,42 +121,42 @@ namespace wiTextureHelper wiBackLog::post("wiTextureHelper Initialized"); } - const Texture2D* getRandom64x64() + const Texture* getRandom64x64() { return &helperTextures[HELPERTEXTURE_RANDOM64X64]; } - const Texture2D* getColorGradeDefault() + const Texture* getColorGradeDefault() { return &helperTextures[HELPERTEXTURE_COLORGRADEDEFAULT]; } - const Texture2D* getNormalMapDefault() + const Texture* getNormalMapDefault() { return getColor(wiColor(127, 127, 255, 255)); } - const Texture2D* getBlackCubeMap() + const Texture* getBlackCubeMap() { return &helperTextures[HELPERTEXTURE_BLACKCUBEMAP]; } - const Texture2D* getWhite() + const Texture* getWhite() { return getColor(wiColor(255, 255, 255, 255)); } - const Texture2D* getBlack() + const Texture* getBlack() { return getColor(wiColor(0, 0, 0, 255)); } - const Texture2D* getTransparent() + const Texture* getTransparent() { return getColor(wiColor(0, 0, 0, 0)); } - const Texture2D* getColor(wiColor color) + const Texture* getColor(wiColor color) { colorlock.lock(); auto it = colorTextures.find(color.rgba); @@ -180,7 +179,7 @@ namespace wiTextureHelper data[i + 3] = color.getA(); } - Texture2D* texture = new Texture2D; + Texture* texture = new Texture; if (FAILED(CreateTexture(*texture, data, dim, dim))) { delete texture; @@ -196,7 +195,7 @@ namespace wiTextureHelper } - HRESULT CreateTexture(wiGraphics::Texture2D& texture, const uint8_t* data, UINT width, UINT height, FORMAT format) + HRESULT CreateTexture(wiGraphics::Texture& texture, const uint8_t* data, UINT width, UINT height, FORMAT format) { if (data == nullptr) { @@ -210,8 +209,7 @@ namespace wiTextureHelper textureDesc.MipLevels = 1; textureDesc.ArraySize = 1; textureDesc.Format = format; - textureDesc.SampleDesc.Count = 1; - textureDesc.SampleDesc.Quality = 0; + textureDesc.SampleCount = 1; textureDesc.Usage = USAGE_IMMUTABLE; textureDesc.BindFlags = BIND_SHADER_RESOURCE; textureDesc.CPUAccessFlags = 0; @@ -222,7 +220,7 @@ namespace wiTextureHelper InitData.SysMemPitch = width * device->GetFormatStride(format); HRESULT hr; - hr = device->CreateTexture2D(&textureDesc, &InitData, &texture); + hr = device->CreateTexture(&textureDesc, &InitData, &texture); return hr; } diff --git a/WickedEngine/wiTextureHelper.h b/WickedEngine/wiTextureHelper.h index b329aac6f..57c6d9488 100644 --- a/WickedEngine/wiTextureHelper.h +++ b/WickedEngine/wiTextureHelper.h @@ -7,16 +7,16 @@ namespace wiTextureHelper { void Initialize(); - const wiGraphics::Texture2D* getRandom64x64(); - const wiGraphics::Texture2D* getColorGradeDefault(); - const wiGraphics::Texture2D* getNormalMapDefault(); - const wiGraphics::Texture2D* getBlackCubeMap(); + const wiGraphics::Texture* getRandom64x64(); + const wiGraphics::Texture* getColorGradeDefault(); + const wiGraphics::Texture* getNormalMapDefault(); + const wiGraphics::Texture* getBlackCubeMap(); - const wiGraphics::Texture2D* getWhite(); - const wiGraphics::Texture2D* getBlack(); - const wiGraphics::Texture2D* getTransparent(); - const wiGraphics::Texture2D* getColor(wiColor color); + const wiGraphics::Texture* getWhite(); + const wiGraphics::Texture* getBlack(); + const wiGraphics::Texture* getTransparent(); + const wiGraphics::Texture* getColor(wiColor color); - HRESULT CreateTexture(wiGraphics::Texture2D& texture, const uint8_t* data, UINT width, UINT height, wiGraphics::FORMAT format = wiGraphics::FORMAT_R8G8B8A8_UNORM); + HRESULT CreateTexture(wiGraphics::Texture& texture, const uint8_t* data, UINT width, UINT height, wiGraphics::FORMAT format = wiGraphics::FORMAT_R8G8B8A8_UNORM); }; diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index 642bbbec7..0f08acafa 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -7,9 +7,9 @@ namespace wiVersion // main engine core const int major = 0; // minor features, major updates - const int minor = 32; + const int minor = 33; // minor bug fixes, alterations, refactors, updates - const int revision = 8; + const int revision = 0; long GetVersion()