1 // Copyright 2019 The Dawn Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #include "dawn_native/d3d12/D3D12Info.h" 16 17 #include "common/GPUInfo.h" 18 #include "dawn_native/d3d12/AdapterD3D12.h" 19 #include "dawn_native/d3d12/BackendD3D12.h" 20 #include "dawn_native/d3d12/D3D12Error.h" 21 #include "dawn_native/d3d12/PlatformFunctions.h" 22 23 namespace dawn_native { namespace d3d12 { 24 GatherDeviceInfo(const Adapter & adapter)25 ResultOrError<D3D12DeviceInfo> GatherDeviceInfo(const Adapter& adapter) { 26 D3D12DeviceInfo info = {}; 27 28 // Newer builds replace D3D_FEATURE_DATA_ARCHITECTURE with 29 // D3D_FEATURE_DATA_ARCHITECTURE1. However, D3D_FEATURE_DATA_ARCHITECTURE can be used 30 // for backwards compat. 31 // https://docs.microsoft.com/en-us/windows/desktop/api/d3d12/ne-d3d12-d3d12_feature 32 D3D12_FEATURE_DATA_ARCHITECTURE arch = {}; 33 DAWN_TRY(CheckHRESULT(adapter.GetDevice()->CheckFeatureSupport(D3D12_FEATURE_ARCHITECTURE, 34 &arch, sizeof(arch)), 35 "ID3D12Device::CheckFeatureSupport")); 36 37 info.isUMA = arch.UMA; 38 39 D3D12_FEATURE_DATA_D3D12_OPTIONS options = {}; 40 DAWN_TRY(CheckHRESULT(adapter.GetDevice()->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS, 41 &options, sizeof(options)), 42 "ID3D12Device::CheckFeatureSupport")); 43 44 info.resourceHeapTier = options.ResourceHeapTier; 45 46 // Windows builds 1809 and above can use the D3D12 render pass API. If we query 47 // CheckFeatureSupport for D3D12_FEATURE_D3D12_OPTIONS5 successfully, then we can use 48 // the render pass API. 49 info.supportsRenderPass = false; 50 D3D12_FEATURE_DATA_D3D12_OPTIONS5 featureOptions5 = {}; 51 if (SUCCEEDED(adapter.GetDevice()->CheckFeatureSupport( 52 D3D12_FEATURE_D3D12_OPTIONS5, &featureOptions5, sizeof(featureOptions5)))) { 53 // Performance regressions been observed when using a render pass on Intel graphics 54 // with RENDER_PASS_TIER_1 available, so fall back to a software emulated render 55 // pass on these platforms. 56 if (featureOptions5.RenderPassesTier < D3D12_RENDER_PASS_TIER_1 || 57 !gpu_info::IsIntel(adapter.GetPCIInfo().vendorId)) { 58 info.supportsRenderPass = true; 59 } 60 } 61 62 // Used to share resources cross-API. If we query CheckFeatureSupport for 63 // D3D12_FEATURE_D3D12_OPTIONS4 successfully, then we can use cross-API sharing. 64 info.supportsSharedResourceCapabilityTier1 = false; 65 D3D12_FEATURE_DATA_D3D12_OPTIONS4 featureOptions4 = {}; 66 if (SUCCEEDED(adapter.GetDevice()->CheckFeatureSupport( 67 D3D12_FEATURE_D3D12_OPTIONS4, &featureOptions4, sizeof(featureOptions4)))) { 68 // Tier 1 support additionally enables the NV12 format. Since only the NV12 format 69 // is used by Dawn, check for Tier 1. 70 if (featureOptions4.SharedResourceCompatibilityTier >= 71 D3D12_SHARED_RESOURCE_COMPATIBILITY_TIER_1) { 72 info.supportsSharedResourceCapabilityTier1 = true; 73 } 74 } 75 76 D3D12_FEATURE_DATA_SHADER_MODEL knownShaderModels[] = {{D3D_SHADER_MODEL_6_2}, 77 {D3D_SHADER_MODEL_6_1}, 78 {D3D_SHADER_MODEL_6_0}, 79 {D3D_SHADER_MODEL_5_1}}; 80 uint32_t driverShaderModel = 0; 81 for (D3D12_FEATURE_DATA_SHADER_MODEL shaderModel : knownShaderModels) { 82 if (SUCCEEDED(adapter.GetDevice()->CheckFeatureSupport( 83 D3D12_FEATURE_SHADER_MODEL, &shaderModel, sizeof(shaderModel)))) { 84 driverShaderModel = shaderModel.HighestShaderModel; 85 break; 86 } 87 } 88 89 if (driverShaderModel < D3D_SHADER_MODEL_5_1) { 90 return DAWN_INTERNAL_ERROR("Driver doesn't support Shader Model 5.1 or higher"); 91 } 92 93 // D3D_SHADER_MODEL is encoded as 0xMm with M the major version and m the minor version 94 ASSERT(driverShaderModel <= 0xFF); 95 uint32_t shaderModelMajor = (driverShaderModel & 0xF0) >> 4; 96 uint32_t shaderModelMinor = (driverShaderModel & 0xF); 97 98 ASSERT(shaderModelMajor < 10); 99 ASSERT(shaderModelMinor < 10); 100 info.shaderModel = 10 * shaderModelMajor + shaderModelMinor; 101 102 // Profiles are always <stage>s_<minor>_<major> so we build the s_<minor>_major and add 103 // it to each of the stage's suffix. 104 std::wstring profileSuffix = L"s_M_n"; 105 profileSuffix[2] = wchar_t('0' + shaderModelMajor); 106 profileSuffix[4] = wchar_t('0' + shaderModelMinor); 107 108 info.shaderProfiles[SingleShaderStage::Vertex] = L"v" + profileSuffix; 109 info.shaderProfiles[SingleShaderStage::Fragment] = L"p" + profileSuffix; 110 info.shaderProfiles[SingleShaderStage::Compute] = L"c" + profileSuffix; 111 112 D3D12_FEATURE_DATA_D3D12_OPTIONS4 featureData4 = {}; 113 if (SUCCEEDED(adapter.GetDevice()->CheckFeatureSupport( 114 D3D12_FEATURE_D3D12_OPTIONS4, &featureData4, sizeof(featureData4)))) { 115 info.supportsShaderFloat16 = driverShaderModel >= D3D_SHADER_MODEL_6_2 && 116 featureData4.Native16BitShaderOpsSupported; 117 } 118 119 return std::move(info); 120 } 121 122 }} // namespace dawn_native::d3d12 123