dzn: use dxil_validator
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15751>
This commit is contained in:

committed by
Marge Bot

parent
0c5d772b71
commit
09c2016d6b
@@ -36,6 +36,8 @@
|
||||
|
||||
#include "glsl_types.h"
|
||||
|
||||
#include "dxil_validator.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -126,14 +128,8 @@ dzn_instance_destroy(dzn_instance *instance, const VkAllocationCallbacks *alloc)
|
||||
if (!instance)
|
||||
return;
|
||||
|
||||
if (instance->dxc.validator)
|
||||
instance->dxc.validator->Release();
|
||||
|
||||
if (instance->dxc.library)
|
||||
instance->dxc.library->Release();
|
||||
|
||||
if (instance->dxc.compiler)
|
||||
instance->dxc.compiler->Release();
|
||||
if (instance->dxil_validator)
|
||||
dxil_destroy_validator(instance->dxil_validator);
|
||||
|
||||
list_for_each_entry_safe(dzn_physical_device, pdev,
|
||||
&instance->physical_devices, link) {
|
||||
@@ -174,14 +170,10 @@ dzn_instance_create(const VkInstanceCreateInfo *pCreateInfo,
|
||||
instance->debug_flags =
|
||||
parse_debug_string(getenv("DZN_DEBUG"), dzn_debug_options);
|
||||
|
||||
instance->dxc.validator = dxil_get_validator();
|
||||
instance->dxc.library = dxc_get_library();
|
||||
instance->dxc.compiler = dxc_get_compiler();
|
||||
instance->dxil_validator = dxil_create_validator(instance);
|
||||
instance->d3d12.serialize_root_sig = d3d12_get_serialize_root_sig();
|
||||
|
||||
if (!instance->dxc.validator ||
|
||||
!instance->dxc.library ||
|
||||
!instance->dxc.compiler ||
|
||||
if (!instance->dxil_validator ||
|
||||
!instance->d3d12.serialize_root_sig) {
|
||||
dzn_instance_destroy(instance, pAllocator);
|
||||
return vk_error(NULL, VK_ERROR_INITIALIZATION_FAILED);
|
||||
@@ -478,7 +470,7 @@ dzn_physical_device_get_d3d12_dev(dzn_physical_device *pdev)
|
||||
|
||||
mtx_lock(&pdev->dev_lock);
|
||||
if (!pdev->dev) {
|
||||
pdev->dev = d3d12_create_device(pdev->adapter, instance->dxc.validator == nullptr);
|
||||
pdev->dev = d3d12_create_device(pdev->adapter, !instance->dxil_validator);
|
||||
|
||||
dzn_physical_device_cache_caps(pdev);
|
||||
dzn_physical_device_init_memory(pdev);
|
||||
|
@@ -28,6 +28,7 @@
|
||||
|
||||
#include "dxil_nir.h"
|
||||
#include "dxil_nir_lower_int_samplers.h"
|
||||
#include "dxil_validator.h"
|
||||
|
||||
static void
|
||||
dzn_meta_compile_shader(dzn_device *device, nir_shader *nir,
|
||||
@@ -35,9 +36,6 @@ dzn_meta_compile_shader(dzn_device *device, nir_shader *nir,
|
||||
{
|
||||
dzn_instance *instance =
|
||||
container_of(device->vk.physical->instance, dzn_instance, vk);
|
||||
IDxcValidator *validator = instance->dxc.validator;
|
||||
IDxcLibrary *library = instance->dxc.library;
|
||||
IDxcCompiler *compiler = instance->dxc.compiler;
|
||||
|
||||
nir_shader_gather_info(nir, nir_shader_get_entrypoint(nir));
|
||||
|
||||
@@ -50,47 +48,37 @@ dzn_meta_compile_shader(dzn_device *device, nir_shader *nir,
|
||||
bool ret = nir_to_dxil(nir, &opts, &dxil_blob);
|
||||
assert(ret);
|
||||
|
||||
dzn_shader_blob blob(dxil_blob.data, dxil_blob.size);
|
||||
ComPtr<IDxcOperationResult> result;
|
||||
validator->Validate(&blob, DxcValidatorFlags_InPlaceEdit, &result);
|
||||
char *err;
|
||||
bool res = dxil_validate_module(instance->dxil_validator,
|
||||
dxil_blob.data,
|
||||
dxil_blob.size, &err);
|
||||
|
||||
if ((instance->debug_flags & DZN_DEBUG_DXIL) &&
|
||||
(instance->debug_flags & DZN_DEBUG_INTERNAL)) {
|
||||
IDxcBlobEncoding *disassembly;
|
||||
compiler->Disassemble(&blob, &disassembly);
|
||||
ComPtr<IDxcBlobEncoding> blobUtf8;
|
||||
library->GetBlobAsUtf8(disassembly, blobUtf8.GetAddressOf());
|
||||
char *disasm = reinterpret_cast<char*>(blobUtf8->GetBufferPointer());
|
||||
disasm[blobUtf8->GetBufferSize() - 1] = 0;
|
||||
fprintf(stderr,
|
||||
"== BEGIN SHADER ============================================\n"
|
||||
"%s\n"
|
||||
"== END SHADER ==============================================\n",
|
||||
disasm);
|
||||
disassembly->Release();
|
||||
}
|
||||
|
||||
HRESULT validationStatus;
|
||||
result->GetStatus(&validationStatus);
|
||||
if (FAILED(validationStatus)) {
|
||||
if ((instance->debug_flags & DZN_DEBUG_DXIL) &&
|
||||
(instance->debug_flags & DZN_DEBUG_INTERNAL)) {
|
||||
ComPtr<IDxcBlobEncoding> printBlob, printBlobUtf8;
|
||||
result->GetErrorBuffer(&printBlob);
|
||||
library->GetBlobAsUtf8(printBlob.Get(), printBlobUtf8.GetAddressOf());
|
||||
|
||||
char *errorString;
|
||||
if (printBlobUtf8) {
|
||||
errorString = reinterpret_cast<char*>(printBlobUtf8->GetBufferPointer());
|
||||
errorString[printBlobUtf8->GetBufferSize() - 1] = 0;
|
||||
fprintf(stderr,
|
||||
"== VALIDATION ERROR =============================================\n"
|
||||
"%s\n"
|
||||
"== END ==========================================================\n",
|
||||
errorString);
|
||||
}
|
||||
char *disasm = dxil_disasm_module(instance->dxil_validator,
|
||||
dxil_blob.data,
|
||||
dxil_blob.size);
|
||||
if (disasm) {
|
||||
fprintf(stderr,
|
||||
"== BEGIN SHADER ============================================\n"
|
||||
"%s\n"
|
||||
"== END SHADER ==============================================\n",
|
||||
disasm);
|
||||
ralloc_free(disasm);
|
||||
}
|
||||
}
|
||||
assert(!FAILED(validationStatus));
|
||||
|
||||
if ((instance->debug_flags & DZN_DEBUG_DXIL) &&
|
||||
(instance->debug_flags & DZN_DEBUG_INTERNAL) &&
|
||||
err) {
|
||||
fprintf(stderr,
|
||||
"== VALIDATION ERROR =============================================\n"
|
||||
"%s\n"
|
||||
"== END ==========================================================\n",
|
||||
err);
|
||||
ralloc_free(err);
|
||||
}
|
||||
assert(res);
|
||||
|
||||
void *data;
|
||||
size_t size;
|
||||
|
@@ -25,6 +25,8 @@
|
||||
|
||||
#include "spirv_to_dxil.h"
|
||||
|
||||
#include "dxil_validator.h"
|
||||
|
||||
#include "vk_alloc.h"
|
||||
#include "vk_util.h"
|
||||
#include "vk_format.h"
|
||||
@@ -32,13 +34,8 @@
|
||||
#include <directx/d3d12.h>
|
||||
#include <dxguids/dxguids.h>
|
||||
|
||||
#include <dxcapi.h>
|
||||
#include <wrl/client.h>
|
||||
|
||||
#include "util/u_debug.h"
|
||||
|
||||
using Microsoft::WRL::ComPtr;
|
||||
|
||||
static dxil_spirv_shader_stage
|
||||
to_dxil_shader_stage(VkShaderStageFlagBits in)
|
||||
{
|
||||
@@ -64,9 +61,6 @@ dzn_pipeline_compile_shader(dzn_device *device,
|
||||
{
|
||||
dzn_instance *instance =
|
||||
container_of(device->vk.physical->instance, dzn_instance, vk);
|
||||
IDxcValidator *validator = instance->dxc.validator;
|
||||
IDxcLibrary *library = instance->dxc.library;
|
||||
IDxcCompiler *compiler = instance->dxc.compiler;
|
||||
const VkSpecializationInfo *spec_info = stage_info->pSpecializationInfo;
|
||||
VK_FROM_HANDLE(vk_shader_module, module, stage_info->module);
|
||||
struct dxil_spirv_object dxil_object;
|
||||
@@ -148,45 +142,34 @@ dzn_pipeline_compile_shader(dzn_device *device,
|
||||
if (!success)
|
||||
return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
|
||||
|
||||
dzn_shader_blob blob(dxil_object.binary.buffer, dxil_object.binary.size);
|
||||
ComPtr<IDxcOperationResult> result;
|
||||
validator->Validate(&blob, DxcValidatorFlags_InPlaceEdit, &result);
|
||||
char *err;
|
||||
bool res = dxil_validate_module(instance->dxil_validator,
|
||||
dxil_object.binary.buffer,
|
||||
dxil_object.binary.size, &err);
|
||||
|
||||
if (instance->debug_flags & DZN_DEBUG_DXIL) {
|
||||
IDxcBlobEncoding *disassembly;
|
||||
compiler->Disassemble(&blob, &disassembly);
|
||||
ComPtr<IDxcBlobEncoding> blobUtf8;
|
||||
library->GetBlobAsUtf8(disassembly, blobUtf8.GetAddressOf());
|
||||
char *disasm = reinterpret_cast<char*>(blobUtf8->GetBufferPointer());
|
||||
disasm[blobUtf8->GetBufferSize() - 1] = 0;
|
||||
fprintf(stderr, "== BEGIN SHADER ============================================\n"
|
||||
"%s\n"
|
||||
"== END SHADER ==============================================\n",
|
||||
disasm);
|
||||
disassembly->Release();
|
||||
char *disasm = dxil_disasm_module(instance->dxil_validator,
|
||||
dxil_object.binary.buffer,
|
||||
dxil_object.binary.size);
|
||||
if (disasm) {
|
||||
fprintf(stderr,
|
||||
"== BEGIN SHADER ============================================\n"
|
||||
"%s\n"
|
||||
"== END SHADER ==============================================\n",
|
||||
disasm);
|
||||
ralloc_free(disasm);
|
||||
}
|
||||
}
|
||||
|
||||
HRESULT validationStatus;
|
||||
result->GetStatus(&validationStatus);
|
||||
if (FAILED(validationStatus)) {
|
||||
if (instance->debug_flags & DZN_DEBUG_DXIL) {
|
||||
ComPtr<IDxcBlobEncoding> printBlob, printBlobUtf8;
|
||||
result->GetErrorBuffer(&printBlob);
|
||||
library->GetBlobAsUtf8(printBlob.Get(), printBlobUtf8.GetAddressOf());
|
||||
|
||||
char *errorString;
|
||||
if (printBlobUtf8) {
|
||||
errorString = reinterpret_cast<char*>(printBlobUtf8->GetBufferPointer());
|
||||
|
||||
errorString[printBlobUtf8->GetBufferSize() - 1] = 0;
|
||||
fprintf(stderr,
|
||||
"== VALIDATION ERROR =============================================\n"
|
||||
"%s\n"
|
||||
"== END ==========================================================\n",
|
||||
errorString);
|
||||
}
|
||||
if (!res) {
|
||||
if (err) {
|
||||
fprintf(stderr,
|
||||
"== VALIDATION ERROR =============================================\n"
|
||||
"%s\n"
|
||||
"== END ==========================================================\n",
|
||||
err);
|
||||
ralloc_free(err);
|
||||
}
|
||||
|
||||
return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
|
||||
}
|
||||
|
||||
|
@@ -55,7 +55,6 @@
|
||||
|
||||
#define D3D12_IGNORE_SDK_LAYERS
|
||||
#include <directx/d3d12.h>
|
||||
#include <dxcapi.h>
|
||||
#include <wrl/client.h>
|
||||
|
||||
#include "spirv_to_dxil.h"
|
||||
@@ -71,6 +70,8 @@ using Microsoft::WRL::ComPtr;
|
||||
|
||||
#define dzn_stub() unreachable("Unsupported feature")
|
||||
|
||||
struct dxil_validator;
|
||||
|
||||
struct dzn_instance;
|
||||
struct dzn_device;
|
||||
|
||||
@@ -217,15 +218,6 @@ dzn_physical_device_get_mem_type_mask_for_resource(const dzn_physical_device *pd
|
||||
IDXGIFactory4 *
|
||||
dxgi_get_factory(bool debug);
|
||||
|
||||
IDxcValidator *
|
||||
dxil_get_validator(void);
|
||||
|
||||
IDxcLibrary *
|
||||
dxc_get_library(void);
|
||||
|
||||
IDxcCompiler *
|
||||
dxc_get_compiler(void);
|
||||
|
||||
PFN_D3D12_SERIALIZE_VERSIONED_ROOT_SIGNATURE
|
||||
d3d12_get_serialize_root_sig(void);
|
||||
|
||||
@@ -675,24 +667,6 @@ enum dzn_register_space {
|
||||
DZN_REGISTER_SPACE_PUSH_CONSTANT,
|
||||
};
|
||||
|
||||
class dzn_shader_blob : public IDxcBlob {
|
||||
public:
|
||||
dzn_shader_blob(void *buf, size_t sz) : data(buf), size(sz) {}
|
||||
|
||||
LPVOID STDMETHODCALLTYPE GetBufferPointer(void) override { return data; }
|
||||
|
||||
SIZE_T STDMETHODCALLTYPE GetBufferSize() override { return size; }
|
||||
|
||||
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID, void**) override { return E_NOINTERFACE; }
|
||||
|
||||
ULONG STDMETHODCALLTYPE AddRef() override { return 1; }
|
||||
|
||||
ULONG STDMETHODCALLTYPE Release() override { return 0; }
|
||||
|
||||
void *data;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
struct dzn_pipeline {
|
||||
struct vk_object_base base;
|
||||
VkPipelineBindPoint type;
|
||||
@@ -966,11 +940,7 @@ enum dzn_debug_flags {
|
||||
struct dzn_instance {
|
||||
struct vk_instance vk;
|
||||
|
||||
struct {
|
||||
IDxcValidator *validator;
|
||||
IDxcLibrary *library;
|
||||
IDxcCompiler *compiler;
|
||||
} dxc;
|
||||
struct dxil_validator *dxil_validator;
|
||||
struct {
|
||||
PFN_D3D12_SERIALIZE_VERSIONED_ROOT_SIGNATURE serialize_root_sig;
|
||||
} d3d12;
|
||||
|
@@ -152,26 +152,6 @@ d3d12_create_device(IUnknown *adapter, bool experimental_features)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
IDxcValidator *
|
||||
dxil_get_validator(void)
|
||||
{
|
||||
IDxcValidator *ret = NULL;
|
||||
|
||||
HMODULE dxil_mod = LoadLibraryA("dxil.dll");
|
||||
if (!dxil_mod) {
|
||||
mesa_loge("failed to load dxil.dll\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
DxcCreateInstanceProc CreateInstance = (DxcCreateInstanceProc)
|
||||
GetProcAddress(dxil_mod, "DxcCreateInstance");
|
||||
HRESULT hr = CreateInstance(CLSID_DxcValidator, IID_PPV_ARGS(&ret));
|
||||
if (FAILED(hr))
|
||||
mesa_loge("DxcCreateInstance failed: %08x\n", hr);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
PFN_D3D12_SERIALIZE_VERSIONED_ROOT_SIGNATURE
|
||||
d3d12_get_serialize_root_sig(void)
|
||||
{
|
||||
@@ -184,43 +164,3 @@ d3d12_get_serialize_root_sig(void)
|
||||
return (PFN_D3D12_SERIALIZE_VERSIONED_ROOT_SIGNATURE)
|
||||
GetProcAddress(d3d12_mod, "D3D12SerializeVersionedRootSignature");
|
||||
}
|
||||
|
||||
IDxcLibrary *
|
||||
dxc_get_library(void)
|
||||
{
|
||||
IDxcLibrary *ret = NULL;
|
||||
|
||||
HMODULE dxil_mod = LoadLibraryA("dxcompiler.dll");
|
||||
if (!dxil_mod) {
|
||||
mesa_loge("failed to load dxcompiler.dll\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
DxcCreateInstanceProc CreateInstance = (DxcCreateInstanceProc)
|
||||
GetProcAddress(dxil_mod, "DxcCreateInstance");
|
||||
HRESULT hr = CreateInstance(CLSID_DxcLibrary, IID_PPV_ARGS(&ret));
|
||||
if (FAILED(hr))
|
||||
mesa_loge("DxcCreateInstance failed: %08x\n", hr);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
IDxcCompiler *
|
||||
dxc_get_compiler(void)
|
||||
{
|
||||
IDxcCompiler *ret = NULL;
|
||||
|
||||
HMODULE dxil_mod = LoadLibraryA("dxcompiler.dll");
|
||||
if (!dxil_mod) {
|
||||
mesa_loge("failed to load dxcompiler.dll\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
DxcCreateInstanceProc CreateInstance = (DxcCreateInstanceProc)
|
||||
GetProcAddress(dxil_mod, "DxcCreateInstance");
|
||||
HRESULT hr = CreateInstance(CLSID_DxcCompiler, IID_PPV_ARGS(&ret));
|
||||
if (FAILED(hr))
|
||||
mesa_loge("DxcCreateInstance failed: %08x\n", hr);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
Reference in New Issue
Block a user