From: Vivek Pandya Date: Sat, 20 Mar 2021 06:28:45 +0000 (+0530) Subject: Updated code generation so that for vertex shader output position is written at last... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c94e38e403db723cfa1f93ce384bef273e7594e6;p=mesa.git Updated code generation so that for vertex shader output position is written at last parameter to vs() function. Similar change for fragment shader too. --- diff --git a/src/libre-soc/vulkan/libresoc_device.c b/src/libre-soc/vulkan/libresoc_device.c index 47c53193cd7..f4cac21f550 100644 --- a/src/libre-soc/vulkan/libresoc_device.c +++ b/src/libre-soc/vulkan/libresoc_device.c @@ -1621,8 +1621,8 @@ static void ProcessTriangles(struct TriangleWork *work) b.z = uy; b.w = 0; - if (b.x >= 0 && b.y >= 0 && b.z >= 0) - { + // if (b.x >= 0 && b.y >= 0 && b.z >= 0) + // { struct float4 n; n.x = (float)b.x; n.y = (float)b.y; @@ -1645,7 +1645,7 @@ static void ProcessTriangles(struct TriangleWork *work) bytes[(y * w + x) * bpp + 2] = (byte)(clamp01(pix.x) * 255.0f); bytes[(y * w + x) * bpp + 1] = (byte)(clamp01(pix.y) * 255.0f); bytes[(y * w + x) * bpp + 0] = (byte)(clamp01(pix.z) * 255.0f); - } + // } } } @@ -2088,6 +2088,12 @@ VkResult libresoc_CreateFramebuffer( return VK_SUCCESS; } +void libresoc_DestroyFramebuffer( + VkDevice _device, + VkFramebuffer _fb, + const VkAllocationCallbacks* pAllocator) +{} + VkResult libresoc_CreateBuffer( VkDevice _device, const VkBufferCreateInfo* pCreateInfo, diff --git a/src/libre-soc/vulkan/libresoc_llvm.c b/src/libre-soc/vulkan/libresoc_llvm.c index 054a85c7dba..14f4de0dbd5 100644 --- a/src/libre-soc/vulkan/libresoc_llvm.c +++ b/src/libre-soc/vulkan/libresoc_llvm.c @@ -1904,6 +1904,32 @@ static void visit_store_var(struct libresoc_nir_tran_ctx *ctx, nir_intrinsic_ins switch (deref->mode) { case nir_var_shader_out: + if (ctx->stage == MESA_SHADER_VERTEX && var->data.location == VARYING_SLOT_POS) { + + LLVMValueRef vertexCache = LLVMGetParam(ctx->main_function, 2); + LLVMValueRef idx[3]; + + idx[0] = LLVMConstInt(ctx->lc.i32, 0, false); + idx[1] = LLVMConstInt(ctx->lc.i32, 0, false); + LLVMValueRef outPos = LLVMConstInBoundsGEP(vertexCache, + idx, + 2); + LLVMBuildStore(ctx->lc.builder, src, outPos); + break; + } + if (ctx->stage == MESA_SHADER_FRAGMENT && var->data.location == FRAG_RESULT_DATA0) { + + LLVMValueRef outColor = LLVMGetParam(ctx->main_function, 4); + // LLVMValueRef idx[3]; + + // idx[0] = LLVMConstInt(ctx->lc.i32, 0, false); + // idx[1] = LLVMConstInt(ctx->lc.i32, 0, false); + // LLVMValueRef outPos = LLVMConstInBoundsGEP(vertexCache, + // idx, + // 2); + LLVMBuildStore(ctx->lc.builder, src, outColor); + break; + } /* TODO: remove this after RADV switches to lowered IO */ // if (ctx->stage == MESA_SHADER_TESS_CTRL) { // LLVMValueRef vertex_index = NULL; @@ -2070,8 +2096,9 @@ static void visit_intrinsic(struct libresoc_nir_tran_ctx *ctx, nir_intrinsic_ins // result = ctx->abi->load_local_group_size(ctx->abi); break; case nir_intrinsic_load_vertex_id: - result = LLVMBuildAdd(ctx->lc.builder, LLVMGetParam(ctx->main_function, ctx->args.vertex_id.arg_index), - LLVMGetParam(ctx->main_function, ctx->args.base_vertex.arg_index), ""); + result = LLVMGetParam(ctx->main_function, 1); + // result = LLVMBuildAdd(ctx->lc.builder, LLVMGetParam(ctx->main_function, ctx->args.vertex_id.arg_index), + // LLVMGetParam(ctx->main_function, ctx->args.base_vertex.arg_index), ""); break; case nir_intrinsic_load_vertex_id_zero_base: { // result = ctx->abi->vertex_id; @@ -2686,9 +2713,38 @@ LLVMModuleRef libresoc_nir_translate(struct libresoc_llvm *llvm_ref, struct nir_ arg_types[i] = arg_llvm_type(ctx.args.args[i].type, ctx.args.args[i].size, &ctx.lc); } - //TODO: this is zero argument function and returns void - LLVMTypeRef main_function_type = LLVMFunctionType(ret_type, arg_types, ctx.args.arg_count, 0); - + LLVMTypeRef main_function_type; + if(nir->info.stage == MESA_SHADER_VERTEX) { + LLVMTypeRef arg_types[32]; + LLVMTypeRef floatType = LLVMFloatTypeInContext(llvm_ref->lc.context); + LLVMTypeRef float4 = LLVMVectorType(floatType, 4); + LLVMTypeRef f4arrayType = LLVMArrayType(float4, 10); + arg_types[0] = float4; + arg_types[1] = f4arrayType; + LLVMTypeRef vertexCacheType = LLVMStructTypeInContext(llvm_ref->lc.context, arg_types, 2, false); + LLVMTypeRef gpuStatePtrType = LLVMPointerType(LLVMStructCreateNamed(llvm_ref->lc.context, "GPUState"), 0); + arg_types[0] = gpuStatePtrType; + arg_types[1] = LLVMIntTypeInContext(llvm_ref->lc.context, 32); + arg_types[2] = LLVMPointerType(vertexCacheType, 0); + main_function_type = LLVMFunctionType(ret_type, arg_types, 3, 0); + } else { + + LLVMTypeRef floatType = LLVMFloatTypeInContext(llvm_ref->lc.context); + LLVMTypeRef float4 = LLVMVectorType(floatType, 4); + LLVMTypeRef f4arrayType = LLVMArrayType(float4, 10); + arg_types[0] = float4; + arg_types[1] = f4arrayType; + LLVMTypeRef vertexCacheType = LLVMStructTypeInContext(llvm_ref->lc.context, arg_types, 2, false); + arg_types[3] = LLVMPointerType(vertexCacheType, 0); + LLVMTypeRef gpuStatePtrType = LLVMPointerType(LLVMStructCreateNamed(llvm_ref->lc.context, "GPUState"), 0); + arg_types[0] = gpuStatePtrType; + arg_types[1] = LLVMFloatTypeInContext(llvm_ref->lc.context); + arg_types[2] = LLVMPointerType(float4, 0); + arg_types[4] = LLVMPointerType(float4, 0); + main_function_type = LLVMFunctionType(ret_type, arg_types, 3, 0); + //TODO: this is zero argument function and returns void + main_function_type = LLVMFunctionType(ret_type, arg_types, 5, 0); + } LLVMValueRef main_function = LLVMAddFunction(mod, gl_shader_stage_name(nir->info.stage), main_function_type); LLVMBasicBlockRef main_function_body = LLVMAppendBasicBlockInContext(ctx.lc.context, main_function, "main_body"); diff --git a/src/libre-soc/vulkan/libresoc_shader.c b/src/libre-soc/vulkan/libresoc_shader.c index 533daa893f6..fef2f00d567 100644 --- a/src/libre-soc/vulkan/libresoc_shader.c +++ b/src/libre-soc/vulkan/libresoc_shader.c @@ -28,7 +28,7 @@ #include "libresoc_shader.h" static const struct nir_shader_compiler_options nir_options_llvm = { - .vertex_id_zero_based = true, + .vertex_id_zero_based = false, .lower_scmp = true, .lower_flrp16 = true, .lower_flrp32 = true,